Jump to content

Get Random Players Position


Recommended Posts

  
g_Root = getRootElement() 
function randomize () 
alive = getAlivePlayers() 
randomP = math.random(#alive) 
outputChatBox("Airstrike is coming to"..getPlayerName(randomP)"and coming to"..getElementPosition(randomP),g_Root,0,255,0,true) 
end 
setTimer(randomize,60000,1) 
  

I will get random player forum Alive players but dont work.

Link to comment
  
g_Root = getRootElement() 
function randomize () 
alive = getAlivePlayers()            
if alive then                   
random = getRandomPlayer()      
x,y,z = getElementPosition(random)       
createExplosion(x,y,z+4,4) -- create Explosion for test  
outputChatBox("Airstrike is coming to"..getPlayerName(random),g_Root,0,255,0,false)           
      end 
end 
setTimer(randomize,60000,1) 
  

Link to comment
  
function randomize() 
    alive = getAlivePlayers()           
    if (#alive > 0) then                   
        random = math.random(#alive) 
        random = alive[random] 
        x, y, z = getElementPosition(random)       
        createExplosion(x, y, z+4, 4) 
        outputChatBox("Airstrike is coming to"..getPlayerName(random), root, 0, 255, 0, false)        
    end 
end 
setTimer(randomize, 60000, 1) --shouldn't that 1 be a 0 for infinite times? 
  

Link to comment

Server-Side

function randomize() 
    alive = getAlivePlayers()           
    if (#alive > 0) then                   
        random = math.random(#alive) 
        random = alive[random] 
        g_V = getPedOccupiedVehicle(random) 
        if g_V then 
        triggerClientEvent ( "onBomb", getRootElement()) 
        outputChatBox("Airstrike is coming to"..getPlayerName(random), getRootElement(), 0, 255, 0, false)       
    end 
end 
setTimer(randomize, 30000, 0) 

Client Side

function bomb() 
        x, y, z = getElementPosition(g_V) 
        rotX,rotY,rotZ = getElementRotation(g_V) 
        target = random 
        createProjectile(target, 21, x,y,z + 3, 200,target,rotX,rotY,rotZ) 
        end 
        addEvent("onBomb",true) 
        addEventHandler("onBomb",getRootElement(),bomb) 

Why this code doesnt works can you fix it?

Link to comment

g_V is only defined server side,

Try this:

Server side

function randomize() 
    alive = getAlivePlayers()           
    if (#alive > 0) then                   
        random = math.random(#alive) 
        random = alive[random] 
        g_V = getPedOccupiedVehicle(random) 
        if g_V then 
        setElementID(g_V, "bombedVehicle")   
        triggerClientEvent ( "onBomb", getRootElement()) 
        outputChatBox("Airstrike is coming to"..getPlayerName(random), getRootElement(), 0, 255, 0, false)     
    end 
end 
setTimer(randomize, 30000, 0) 

Client side:

function bomb() 
        local g_V = getElementByID("bombedVehicle") 
        x, y, z = getElementPosition(g_V) 
        rotX,rotY,rotZ = getElementRotation(g_V) 
        target = random 
        createProjectile(target, 21, x,y,z + 3, 200,target,rotX,rotY,rotZ) 
        end 
        addEvent("onBomb",true) 
        addEventHandler("onBomb",getRootElement(),bomb) 

Link to comment

server:

function randomize() 
    alive = getAlivePlayers()           
    if (#alive > 0) then                   
        random = math.random(#alive) 
        random = alive[random] 
        g_V = getPedOccupiedVehicle(random) 
        if g_V then   
        triggerClientEvent ( "onBomb", getRootElement(), random, g_V) 
        outputChatBox("Airstrike is coming to"..getPlayerName(random), getRootElement(), 0, 255, 0, false)     
    end 
end 
setTimer(randomize, 30000, 0) 

client

function bomb(target, g_V) 
        x, y, z = getElementPosition(g_V) 
        rotX,rotY,rotZ = getElementRotation(g_V) 
        createProjectile(target, 21, x,y,z + 3, 200,target,rotX,rotY,rotZ) 
        end 
        addEvent("onBomb",true) 
        addEventHandler("onBomb",getRootElement(),bomb) 

Both can achieve what he wants.

Link to comment

both can, yes, but setting element ID to find some element right away (when you can use the same event) is unnecessary.

1. what if client recieves the event before this element ID is synced with this client (im not sure if its possible, though)?

2. what will happen when the next element recieves the same ID? now there's a real problem.

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