Albinix Posted October 10, 2010 Share Posted October 10, 2010 how to make every player have a number from 1 to 32. like when player one hits the marker then object one will move and if player three hits the marker then object three will move. object1 = createObject(8838,3330.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) object2 = createObject(8838,3335.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) object3 = createObject(8838,3340.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) object4 = createObject(8838,3345.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) object5 = createObject(8838,3350.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) function moveobj ( player ) local target = ??? if target == 1 then moveObject ( object1, 0, 0, 0, 0 ) elseif id == "2" then moveObject ( object2, 0, 0, 0, 0 ) elseif id == "3" then moveObject ( object3, 0, 0, 0, 0 ) elseif id == "4" then moveObject ( object4, 0, 0, 0, 0 ) elseif id == "5" then moveObject ( object5, 0, 0, 0, 0 ) end end addEventHandler( "onMarkerHit", getRootElement(), moveobj ) Link to comment
50p Posted October 10, 2010 Share Posted October 10, 2010 You can use some kind of ID system, eg: https://community.multitheftauto.com/index.php?p= ... ils&id=953 Then when you have player ID you can do something like: function moveObj( player ) local ID = --(you need to get player ID with "id system") moveObject( _G[ "object"..tostring(ID) ], 0, 0, 0, 0 ); end Link to comment
Albinix Posted October 11, 2010 Author Share Posted October 11, 2010 Still don't work nothing happends when i hit marker. object1 = createObject(8838,3330.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) object2 = createObject(8838,3335.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) object3 = createObject(8838,3340.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) object4 = createObject(8838,3345.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) object5 = createObject(8838,3350.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) addCommandHandler("ids", function(player, command) players = getElementsByType("player") for id,p in ipairs(players) do outputChatBox(getPlayerName(p) .. ": " .. tostring(id), player) end end) function getIDFromPlayer(player) if player then local theid players = getElementsByType("player") for id,p in ipairs(players) do if player == p then theid = i end end return theid else return false end end function getPlayerFromID(theID) if theID then theID = tonumber(theID) local theplayer players = getElementsByType("player") for id,p in ipairs(players) do if theID == id then theplayer = p end end return theplayer else return false end end function moveobj ( player ) local id = getIDFromPlayer(player) if id == "1" then moveObject ( object1, 0, 0, 0, 0 ) elseif id == "2" then moveObject ( object2, 0, 0, 0, 0 ) elseif id == "3" then moveObject ( object3, 0, 0, 0, 0 ) elseif id == "4" then moveObject ( object4, 0, 0, 0, 0 ) elseif id == "5" then moveObject ( object5, 0, 0, 0, 0 ) end end addEventHandler( "onMarkerHit", getRootElement(), moveobj ) Link to comment
Buffalo Posted October 11, 2010 Share Posted October 11, 2010 _G is a table, so you need to create it, and if you're planning to use lua further, learn to manipulate them - http://lua-users.org/wiki/TablesTutorial so: _G = { 'object1' = createObject(8838,3330.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000), 'object2' = createObject(8838,3335.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000), 'object3' = createObject(8838,3340.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000), 'object4' = createObject(8838,3345.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000), 'object5' = createObject(8838,3350.00000000,-1710.00000000,0.00000000,0.00000000,0.00000000,0.00000000) } use 50p's code and use debug, to find out future mistakes: function moveObj( player ) local ID = getIDFromPlayer(player)--(you need to get player ID with "id system") outputChatBox('[DEBUG]: player ID is '..tostring(ID)) -- shows if its good moveObject( _G[ "object"..tostring(ID) ], 0, 0, 0, 0 ) end addEventHandler( "onMarkerHit", getRootElement(), moveObj) Also you created function 'moveObj', so in event handler it must be identical, not 'moveobj' Link to comment
Albinix Posted October 11, 2010 Author Share Posted October 11, 2010 Script error: move.lua:2: '}' expectet ( to close '{' at line 1 ) near '=' and it's also say player id is a nil value? Link to comment
dzek (varez) Posted October 11, 2010 Share Posted October 11, 2010 ppl should be banned for asking to fix syntax errors 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