Xierra Posted March 10, 2010 Share Posted March 10, 2010 Hello guys! I just want to say that I wanted to remake the tutorials by ransom, jhxp, and IJs. I know it's sad to have no tutorials anymore. But, I think I later look around and make these tutorials work again as it should on the recent MTA SA. My first target was the first tutorial: "user selectable warp points" Here we go! This script was awesome as I learn a bit from it. But as usual the script is outdated. I like that kind of portal! Yes, the reason I want to remake this script is because I wanted a "portal gun" from GTA SA's Cleo mod to here! So here's what I get: (Edited the uppermost, the "onResourceLoad" --> "onResourceStart") addEventHandler ( "onResourceStart", getRootElement(), "Script_onResourceLoad" ) function Script_onResourceLoad ( resource ) if ( resource == getThisResource() ) then -- for each player already in the server for index, player in getElementsByType ( "player" ) do -- binds the "i"-key to our function "modeIO" bindKey ( player, "i", "down", "modeIO" ) end end end addEventHandler ( "onPlayerJoin", getRootElement(), "Script_onPlayerJoin" ) function Script_onPlayerJoin () -- binds the "i"-key to our function "modeIO" bindKey ( source, "i", "down", "modeIO" ) end function modeIO ( source, key, keyState ) -- function toggles the cursor if isCursorShowing ( source ) then -- if cursor was already showing: showCursor ( source, false ) -- hide it else -- if it wasn't showing: showCursor ( source, true ) -- show it end end addEventHandler ( "onPlayerClick", getRootElement(), "Script_onPlayerClick" ) function Script_onPlayerClick ( key, keyState, element, x, y, z ) if keyState == "up" then return -- ignore if the button was released end end if key == "left" then -- on a left mousebutton -- destroy his teleport point, if any destroyElement ( getElementData ( source, "teleport" ) ) -- create a normal cylinder marker local marker = createMarker ( x, y, z, "cylinder", 2, 0, 255, 0, 50 ) -- mark the cylinder as our "teleport" type setElementData ( marker, "type", "teleport" ) -- link the creator (player) to the marker, and vice versa setElementData ( source, "teleport", marker ) setElementData ( marker, "owner", source ) elseif key == "right" then -- on a right mousebutton -- destroy his destination point, if any destroyElement ( getElementData ( source, "destination" ) ) -- create a glowing corona local marker = createMarker ( x, y, z+1, "corona", 1, 0, 255, 255, 50 ) -- mark the corona as our "destination" type setElementData ( marker, "type", "destination" ) -- link the creator (player) to the marker, and vice versa setElementData ( source, "destination", marker ) setElementData ( marker, "owner", source ) elseif key == "middle" then -- on a middle mousebutton -- teleport the player to whereever he clicked setElementPosition ( source, x, y, z+1 ) end addEventHandler ( "onMarkerHit", getRootElement(), "Script_onMarkerHit" ) function Script_onMarkerHit ( player ) -- if the marker is a teleport point, proceed if getElementData ( source, "type" ) == "teleport" then -- get the owner linked to the "teleport" type marker local owner = getElementData ( source, "owner" ) -- get the destination point linked to the owner local destination = getElementData ( owner, "destination" ) -- if the destination point exists, proceed if destination then -- get the "destination" marker's position local x, y, z = getElementPosition ( destination ) -- finally, warp the player there setElementPosition ( player, x, y, z ) end end end addEventHandler ( "onPlayerQuit", getRootElement(), "Script_onPlayerQuit" ) function Script_onPlayerQuit ( reason ) --destroy his teleport point, if any destroyElement ( getElementData ( source, "teleport" ) ) -- destroy his destination point, if any destroyElement ( getElementData ( source, "destination" ) ) end Now I found bad arguments as the MTA Script editor said nothing. Errors: [17:01:18] WARNING: script.lua: Bad argument @ 'addEventHandler' - Line: 1 [17:01:18] WARNING: script.lua: Bad argument @ 'addEventHandler' - Line: 11 [17:01:18] WARNING: script.lua: Bad argument @ 'addEventHandler' - Line: 25 [17:01:18] WARNING: script.lua: Bad argument @ 'addEventHandler' - Line: 60 [17:01:18] WARNING: script.lua: Bad argument @ 'addEventHandler' - Line: 78 Can you guys tell me why I keep getting this error? Link to comment
Castillo Posted March 10, 2010 Share Posted March 10, 2010 ok, i fixed those warnings. function Script_onResourceLoad ( resource ) if ( resource == getThisResource() ) then -- for each player already in the server for index, player in getElementsByType ( "player" ) do -- binds the "i"-key to our function "modeIO" bindKey ( player, "i", "down", "modeIO" ) end end end addEventHandler ( "onResourceStart", getRootElement(), Script_onResourceLoad ) function Script_onPlayerJoin () -- binds the "i"-key to our function "modeIO" bindKey ( source, "i", "down", "modeIO" ) end addEventHandler ( "onPlayerJoin", getRootElement(), Script_onPlayerJoin ) function modeIO ( source, key, keyState ) -- function toggles the cursor if isCursorShowing ( source ) then -- if cursor was already showing: showCursor ( source, false ) -- hide it else -- if it wasn't showing: showCursor ( source, true ) -- show it end end function Script_onPlayerClick ( key, keyState, element, x, y, z ) if keyState == "up" then return -- ignore if the button was released end end addEventHandler ( "onPlayerClick", getRootElement(), Script_onPlayerClick ) if key == "left" then -- on a left mousebutton -- destroy his teleport point, if any destroyElement ( getElementData ( source, "teleport" ) ) -- create a normal cylinder marker local marker = createMarker ( x, y, z, "cylinder", 2, 0, 255, 0, 50 ) -- mark the cylinder as our "teleport" type setElementData ( marker, "type", "teleport" ) -- link the creator (player) to the marker, and vice versa setElementData ( source, "teleport", marker ) setElementData ( marker, "owner", source ) elseif key == "right" then -- on a right mousebutton -- destroy his destination point, if any destroyElement ( getElementData ( source, "destination" ) ) -- create a glowing corona local marker = createMarker ( x, y, z+1, "corona", 1, 0, 255, 255, 50 ) -- mark the corona as our "destination" type setElementData ( marker, "type", "destination" ) -- link the creator (player) to the marker, and vice versa setElementData ( source, "destination", marker ) setElementData ( marker, "owner", source ) elseif key == "middle" then -- on a middle mousebutton -- teleport the player to whereever he clicked setElementPosition ( source, x, y, z+1 ) end function Script_onMarkerHit ( player ) -- if the marker is a teleport point, proceed if getElementData ( source, "type" ) == "teleport" then -- get the owner linked to the "teleport" type marker local owner = getElementData ( source, "owner" ) -- get the destination point linked to the owner local destination = getElementData ( owner, "destination" ) -- if the destination point exists, proceed if destination then -- get the "destination" marker's position local x, y, z = getElementPosition ( destination ) -- finally, warp the player there setElementPosition ( player, x, y, z ) end end end addEventHandler ( "onMarkerHit", getRootElement(), Script_onMarkerHit ) function Script_onPlayerQuit ( reason ) --destroy his teleport point, if any destroyElement ( getElementData ( source, "teleport" ) ) -- destroy his destination point, if any destroyElement ( getElementData ( source, "destination" ) ) end addEventHandler ( "onPlayerQuit", getRootElement(), Script_onPlayerQuit ) but there is a error in line 4, the error: attempt to call a table value Link to comment
Jumba' Posted March 10, 2010 Share Posted March 10, 2010 function Script_onResourceLoad ( resource ) if ( resource == getThisResource() ) then -- for each player already in the server for i, player in ipairs getElementsByType ( "player" ) do -- you forgot the "ipairs" part. -- binds the "i"-key to our function "modeIO" bindKey ( player, "i", "down", "modeIO" ) end end end addEventHandler ( "onResourceStart", getRootElement(), Script_onResourceLoad ) Link to comment
Xierra Posted March 10, 2010 Author Share Posted March 10, 2010 Jumba, that gives another error: 'do' expected near 'getElementsByType' line 4 Maybe someone can fix that? Link to comment
Aibo Posted March 10, 2010 Share Posted March 10, 2010 ipairs is an iterator function, so brackets are needed: function Script_onResourceLoad ( resource ) if ( resource == getThisResource() ) then -- for each player already in the server for i, player in ipairs(getElementsByType ( "player" )) do -- you forgot the ipairs ( brackets ) -- binds the "i"-key to our function "modeIO" bindKey ( player, "i", "down", "modeIO" ) end end end addEventHandler ( "onResourceStart", getRootElement(), Script_onResourceLoad ) Link to comment
karlis Posted March 10, 2010 Share Posted March 10, 2010 lol just use bindKey("M","down",function() showCursor( not isCursorShowing() ) end) for showing/hiding cursor 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