Resource:Spawnmanager/setSpawnpointRotation

From Multi Theft Auto: Wiki
Revision as of 19:33, 19 October 2007 by Talidan (talk | contribs) (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...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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)