-misterX- Posted February 16, 2013 Posted February 16, 2013 how do i gat a random player exept the player i'm using? i mean get someone connected to the server exept the local player
iPrestege Posted February 16, 2013 Posted February 16, 2013 you mean you want to save it? i mean how joined the server?
Castillo Posted February 16, 2013 Posted February 16, 2013 You can create a function which will loop all players, ignoring the local player, then insert on a table and return a random one. getElementsByType math.random San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
-misterX- Posted February 16, 2013 Author Posted February 16, 2013 @solidsnake14 how could i do what you said?
Castillo Posted February 16, 2013 Posted February 16, 2013 With these two functions and Lua knowledge. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
50p Posted February 16, 2013 Posted February 16, 2013 Server-side: local rndPlayer; -- variable holding random player while( player == rndPlayer ) do rndPlayer = getRandomPlayer(); end - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
arezu Posted February 17, 2013 Posted February 17, 2013 Server-side: local rndPlayer; -- variable holding random player while( player == rndPlayer ) do rndPlayer = getRandomPlayer(); end It just hurts to see that while loop... local players = {} for k, player in ipairs(getElementsByType("player"))do if(player ~= localPlayer)then table.insert(players, player) end end local randomPlayer = players[math.random(#players)]
50p Posted February 17, 2013 Posted February 17, 2013 @arezu, Yours is worse, why? Because you have to loop through all the players and create a table of the players. Imagine 30 players online, you have to loop through them all. The chances of my loop to repeat 30 times is very low since getRandomPlayer would have to get the same player 30 times which is unlikely to happen. If the script needs to be client-side script then there is no other way than using the loop that you showed. - MTA Script Editor - Ask your scripting questions properly, please. - 50p's public resources - Meta.xml - what is it for? How is it possible LOL
arezu Posted February 17, 2013 Posted February 17, 2013 @arezu,Yours is worse, why? Because you have to loop through all the players and create a table of the players. Imagine 30 players online, you have to loop through them all. The chances of my loop to repeat 30 times is very low since getRandomPlayer would have to get the same player 30 times which is unlikely to happen. If the script needs to be client-side script then there is no other way than using the loop that you showed. I forgot that getRandomPlayer doesn't loop all players. But anyways: how do i gat a random player exept the player i'm using? i mean get someone connected to the server exept the local player I guess this means he wants it client sided, so getRandomPlayer wont work.
Gallardo9944 Posted February 18, 2013 Posted February 18, 2013 What's the problem? Tables and loops for all the players won't cause any CPU/RAM consumption, so it won't provide any lag. Code Debugger - Minimalistic MTA debug line replacement
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