Jump to content

Players


Albinix

Recommended Posts

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

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

_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

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