gokalpfirat Posted July 15, 2011 Share Posted July 15, 2011 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
Kenix Posted July 15, 2011 Share Posted July 15, 2011 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
gokalpfirat Posted July 15, 2011 Author Share Posted July 15, 2011 Thanks but it will write name of an alive player because getRandomPlayer() select a random from all dead and alive players i think. Link to comment
Arran Posted July 15, 2011 Share Posted July 15, 2011 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
gokalpfirat Posted July 15, 2011 Author Share Posted July 15, 2011 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
JR10 Posted July 15, 2011 Share Posted July 15, 2011 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
Aibo Posted July 15, 2011 Share Posted July 15, 2011 you DO know that events have arguments that you can pass along (like you random player or vehicle here)? Link to comment
gokalpfirat Posted July 15, 2011 Author Share Posted July 15, 2011 @JR10 But random is defined in server-side and i use random in client-side to i think it will give error:) Link to comment
JR10 Posted July 15, 2011 Share Posted July 15, 2011 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
Aibo Posted July 15, 2011 Share Posted July 15, 2011 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
gokalpfirat Posted July 15, 2011 Author Share Posted July 15, 2011 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? 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