Lordkire Posted January 5, 2008 Share Posted January 5, 2008 (edited) 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 January 6, 2008 by Guest Link to comment
BrokenGlass Posted January 5, 2008 Share Posted January 5, 2008 viewtopic.php?f=91&t=21009 norby fixed it Link to comment
Lordkire Posted January 6, 2008 Author Share Posted January 6, 2008 Well, my script looks exactly the same as Norby's. [EDIT]: I also got the same errors at lines 24 and 31, so it's something with the destroyelement. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now