Jump to content

[?] User selectable warp points


Lordkire

Recommended Posts

I have edited the script of the first Weelky Tutorial a bit so it works.

But it still gives errors when people leave the server.

The teleport markers and warp points don't get deleted and after a while it starts to look all verry messy.

These are the errors I get:

WARNING: script.lua: Bad argument @ 'destroyElement' - Line: 56

WARNING: script.lua: Bad argument @ 'destroyElement' - Line: 57

And this is the script I am using:

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 
    end 
end 
addEventHandler ( "onMapLoad", getRootElement(), Script_onMapLoad )         --This event tells what happens when the map loads. 
  
function Script_onPlayerJoin () 
    bindKey ( source, "i", "down", modeIO )                 --Bind the player's "i" key to the function "modeIO" when the key is pressed 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), Script_onPlayerJoin )       --This event tells what happens when a player joins. 
  
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. 
    end 
end 
  
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. 
    end 
end 
addEventHandler ( "onPlayerClick", getRootElement(), Script_onPlayerClick )     --This event tells what happens when a player clicks on the screen with the cursor. 
  
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 
    end 
end 
addEventHandler ( "onMarkerHit", getRootElement(), Script_onMarkerHit )     --This event tells what happens if a player steps inside a marker. 
  
function Script_onPlayerQuit ( reason ) 
    destroyElement ( getElementData ( source, "teleport" ) )            --Destroy his teleport point, if any 
    destroyElement ( getElementData ( source, "destination" ) )         --Destroy his destination point, if any 
end 
addEventHandler ( "onPlayerQuit", getRootElement(), Script_onPlayerQuit )       --This event tells what happens if a player disconnects. 

Edited by Guest
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...