Mr. Maxilian Posted September 26, 2019 Share Posted September 26, 2019 Hi everyone! I need to do one feature, but I don 't know how. I need every player who enters the game to assign a certain number starting from 1. And I also need these numbers saved before the player comes out. If the player has left the game, then his number may be taken by another. Help me, please. Link to comment
WorthlessCynomys Posted September 26, 2019 Share Posted September 26, 2019 So basically you need an ID system. Simplest way: Set up an array and whenever a player joins run a cycle to find an empty spot in the table. First player enters, cycle runs, finds that the first spot in the array (which is 1) is empty, puts the player there. Next player will find the second spot. First player leaves, you empty this spot, and you're pretty much done. Link to comment
Mr. Maxilian Posted September 26, 2019 Author Share Posted September 26, 2019 2 minutes ago, WorthlessCynomys said: So basically you need an ID system. Simplest way: Set up an array and whenever a player joins run a cycle to find an empty spot in the table. First player enters, cycle runs, finds that the first spot in the array (which is 1) is empty, puts the player there. Next player will find the second spot. First player leaves, you empty this spot, and you're pretty much done. How to write such a function? Link to comment
WorthlessCynomys Posted September 26, 2019 Share Posted September 26, 2019 -- SERVER-SIDE local players = {} addEventHandler("onPlayerJoin", root, function() for i = 1, #players+1, 1 do if getElementType(players[i]) != "player" then players[i] = source outputChatBox(i) break end end end ) 1 Link to comment
Moderators IIYAMA Posted September 27, 2019 Moderators Share Posted September 27, 2019 @WorthlessCynomys isElement -- instead of getElementType Link to comment
WorthlessCynomys Posted September 27, 2019 Share Posted September 27, 2019 2 minutes ago, IIYAMA said: @WorthlessCynomys isElement -- instead of getElementType That's reasonable. 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