-misterX- Posted February 16, 2013 Share 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 Link to comment
iPrestege Posted February 16, 2013 Share Posted February 16, 2013 you mean you want to save it? i mean how joined the server? Link to comment
Castillo Posted February 16, 2013 Share 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 Link to comment
-misterX- Posted February 16, 2013 Author Share Posted February 16, 2013 @solidsnake14 how could i do what you said? Link to comment
Castillo Posted February 16, 2013 Share Posted February 16, 2013 With these two functions and Lua knowledge. Link to comment
-misterX- Posted February 16, 2013 Author Share Posted February 16, 2013 not useful but thanks anyway Link to comment
50p Posted February 16, 2013 Share Posted February 16, 2013 Server-side: local rndPlayer; -- variable holding random player while( player == rndPlayer ) do rndPlayer = getRandomPlayer(); end Link to comment
arezu Posted February 17, 2013 Share 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)] Link to comment
50p Posted February 17, 2013 Share 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. Link to comment
arezu Posted February 17, 2013 Share 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. Link to comment
Gallardo9944 Posted February 18, 2013 Share 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. 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