All pastes #735998 Raw Edit

Mine

public lua v1 · immutable
·published 2007-10-14 01:38 UTC
rendered paste body
-- :: MTA Scripting Tutorial I - User selectable warp points-- http://www.mtasa.com/tutorial1.html---- (C) The MTA Team, 2007-- www.mtasa.comaddEventHandler ( "onMapLoad", getRootElement(), "Script_onMapLoad" )			--This event tells what happens when the map loads.function Script_onMapLoad ()	for index, player in getElementsByType ( "player" ) do				--For each player in the server,		bindKey ( player, "i", "down", "modeIO" )				--Bind the player's "i" key to the function "modeIO" when the key is pressed	endend addEventHandler ( "onPlayerJoin", getRootElement(), "Script_onPlayerJoin" )		--This event tells what happens when a player joins.function Script_onPlayerJoin ()	bindKey ( source, "i", "down", "modeIO" )					--Bind the player's "i" key to the function "modeIO" when the key is pressedend function modeIO ( source, key, keyState )						--This function toggles the cursor on/off	if isCursorShowing ( source ) then						--If cursor was already showing,		showCursor ( source, false )						--then hide it;	else										--if it wasn't showing,		showCursor ( source, true )						--then show it.	endend addEventHandler ( "onPlayerClick", getRootElement(), "Script_onPlayerClick" )		--This event tells what happens when a player clicks on the screen with the cursor.function Script_onPlayerClick ( key, keyState, element, x, y, z )	if keyState == "up" then return end						--Don't do anything if he's releasing the button.	if key == "left" then								--If it's left-click:		destroyElement ( getElementData ( source, "teleport" ) )		--Destroy his teleport point, if any		local theMarker = createMarker ( x, y, z, "cylinder", 2, 0, 255, 0, 50 )	--Create a cylindric marker		setElementData ( theMarker, "type", "teleport" )				--Mark the cylinder as a teleport		setElementData ( source, "teleport", theMarker )				--Link the creator to the teleport		setElementData ( theMarker, "owner", source )				--Link the teleport to its creator 	elseif key == "right" then							--If it's right-click		destroyElement ( getElementData ( source, "destination" ) )		--Destroy his destination point, if any		local theMarker = createMarker ( x, y, z+1, "corona", 1, 0, 255, 255, 50 )	--Create a glowing corona		setElementData ( theMarker, "type", "destination" )			--Mark the corona as a destination point		setElementData ( source, "destination", theMarker )			--Link the creator to the teleport		setElementData ( theMarker, "owner", source )				--Link the teleport to its creator 	elseif key == "middle" then							--If it's middle-click		setElementPosition ( source, x, y, z+1 )				--Teleport the player to where he clicked.	endend addEventHandler ( "onMarkerHit", getRootElement(), "Script_onMarkerHit" )		--This event tells what happens if a player steps inside a marker.function Script_onMarkerHit ( player )	if getElementData ( source, "type" ) == "teleport" then				--If the marker is a teleport point,		local owner = getElementData ( source, "owner" )			--Get the owner linked to the teleport point.		local destination = getElementData ( owner, "destination" )		--Get the destination point linked to the owner.		if destination then							--If destination point exists,			local x, y, z = getElementPosition ( destination )		--Get the destination point's position.			setElementPosition ( player, x, y, z )				--Put the player there.		end	endend addEventHandler ( "onPlayerQuit", getRootElement(), "Script_onPlayerQuit" )		--This event tells what happens if a player disconnects.function Script_onPlayerQuit ( reason )	destroyElement ( getElementData ( source, "teleport" ) )			--Destroy his teleport point, if any	destroyElement ( getElementData ( source, "destination" ) )			--Destroy his destination point, if anyend