Resource:Spawnmanager/setSpawnpointRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(New page: __NOTOC__ {{Server function}} This function sets the starting Z rotation for the specified spawnpoint. ==Syntax== <syntaxhighlight lang="lua"> bool setSpawnpointRotation ( spawnpoint theSpawnpoint, flo...)
 
mNo edit summary
Line 23: Line 23:
local newRotation = math.random() * 360
local newRotation = math.random() * 360
-- we set it as the new rotation for the source spawnpoint
-- we set it as the new rotation for the source spawnpoint
call(getResourceFromName("spawnmanager", "setSpawnpointRotation", source, newRotation )
call(getResourceFromName("spawnmanager"), "setSpawnpointRotation", source, newRotation )
end
end
-- we attach it as a handler for "onSpawnpointUse"
-- we attach it as a handler for "onSpawnpointUse"
addEventHandler("onSpawnpointUse", getRootElement(), randomizeSpawnpointRotation)
addEventHandler("onSpawnpointUse", getRootElement(), randomizeSpawnpointRotation)
</syntaxhighlight>
</syntaxhighlight>

Revision as of 18:02, 27 October 2007

This function sets the starting Z rotation for the specified spawnpoint.

Syntax

bool setSpawnpointRotation ( spawnpoint theSpawnpoint, float rotation )

Required Arguments

  • theSpawnpoint: The spawnpoint element you want to set rotation to.
  • rotation: A float rotation value around the Z axis in degrees.

Returns

Returns true if rotation was successfully set, false if invalid arguments were passed.

Example

This example randomizes a spawnpoint's rotation every time a player spawns on it.

-- we define our randomizing function
function randomizeSpawnpointRotation()
	-- we obtain a new value between 0 and 360 (math.random() generates numbers between 0 and 1)
	local newRotation = math.random() * 360
	-- we set it as the new rotation for the source spawnpoint
	call(getResourceFromName("spawnmanager"), "setSpawnpointRotation", source, newRotation )
end
-- we attach it as a handler for "onSpawnpointUse"
addEventHandler("onSpawnpointUse", getRootElement(), randomizeSpawnpointRotation)