Jump to content

Get Random Players Position


Recommended Posts

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

mtaubluascripter.png
Posted
  
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) 
  

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted
  
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? 
  

Posted

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?

mtaubluascripter.png
Posted

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) 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

you DO know that events have arguments that you can pass along (like you random player or vehicle here)?

?

Posted

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.

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

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.

?

Posted

You use 2 if and 1 function in server-side but there is 2 "end " but i fixed it :) Thanks for all everyone. Thanks too much to Arran and JR10 to fix my script bugs.

Edit: I use this script only in my race map. There can be problems to in race map?

mtaubluascripter.png

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