Jump to content

Players


Albinix

Recommended Posts

Posted

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 ) 

Posted

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 

Posted

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 ) 

Posted

_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'

Powered by Kimsufi©

n-560x95_FFFFFF_FFFFFF_000000_000000.png

ZHP on FacebookZHP on YoutubeSupport us

Posted

ppl should be banned for asking to fix syntax errors o.O

Multi theft auto tools - replace cars and peds, move your map or compile your Lua files online!

programista php rzeszów

Need free webhosting for your small site? PM me. Need help with portforwarding? PM me. Do not PM me asking for help with scripting.

Having problems with port forwarding? Send me pm, I can do whole thing for you using TeamViewer (already helped about 20 people, no worries)!

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...