lgeri000 Posted September 27, 2020 Share Posted September 27, 2020 Hello, can anybody tell me why is this ids table stay empty? local maxPlayers = getMaxPlayers() local ids = {} addEventHandler("onPlayerJoin", root, function() local player = source for i = 1, maxPlayers do if (ids[i] == false) then ids[i] = i setElementData(player,"id",i) break end end end ) addEventHandler("onPlayerQuit", root, function() local i = getElementData(source,"id") ids[i] = false setElementData(source,"id",false) end ) this would be an id-system 1 Link to comment
Moderators IIYAMA Posted September 27, 2020 Moderators Share Posted September 27, 2020 3 hours ago, lgeri000 said: Hello, can anybody tell me why is this ids table stay empty? local maxPlayers = getMaxPlayers() local ids = {} addEventHandler("onPlayerJoin", root, function() local player = source for i = 1, maxPlayers do if (ids[i] == false) then ids[i] = i setElementData(player,"id",i) break end end end ) addEventHandler("onPlayerQuit", root, function() local i = getElementData(source,"id") ids[i] = false setElementData(source,"id",false) end ) this would be an id-system use nil instead of false. false = is still something, even if it is not considered as positive value. nil = nothing false == nil -- false (unlike in languages like JS, where that is true because the === operator is not used.) Also increment the ID value, instead of doing it based on maxPlayers. Keep it simple. local ID = 0 --onPlayerJoin ID = ID + 1 setElementData(player,"id",ID) -- Link to comment
lgeri000 Posted September 28, 2020 Author Share Posted September 28, 2020 thanks for your help 1 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