Kazafka Posted January 5, 2020 Share Posted January 5, 2020 (edited) Wrote script 3 times, script thinks, that table "playersT", wich's empty, is the same as not empty string. --Table playersT = {} --Code addEventHandler("onPlayerConnect", root, function(nickname) for k, v in ipairs(playersT) do if(nickname ~= v) then --some code end end end) It's just keep not working. I RE-WROTE WHOLE SCRIPT 3 TIMES! Edited January 5, 2020 by VaporZ Link to comment
Moderators Patrick Posted January 5, 2020 Moderators Share Posted January 5, 2020 What is inside playersT? Link to comment
Kazafka Posted January 5, 2020 Author Share Posted January 5, 2020 1 minute ago, stPatrick said: What is inside playersT? Just nothing thats the case I want to add something into this table after player connect, and if players nick isnt already in this table Link to comment
Moderators Patrick Posted January 5, 2020 Moderators Share Posted January 5, 2020 (edited) 1 minute ago, VaporZ said: Just nothing thats the case In this case, it works well if it do nothing. Because you can't loop the nothing. Edited January 5, 2020 by stPatrick Link to comment
Kazafka Posted January 5, 2020 Author Share Posted January 5, 2020 1 minute ago, stPatrick said: In this case, it works well if it do nothing. But, I want to do something like, if connected player's nick isn't already in the table "playersT", then add the nickname. Link to comment
Moderators Patrick Posted January 5, 2020 Moderators Share Posted January 5, 2020 3 minutes ago, VaporZ said: But, I want to do something like, if connected player's nick isn't already in the table "playersT", then add the nickname. --Table playersT = {} --Code function isNicknameAlreadyAdded(nickname) for k, v in ipairs(playersT) do if v == nickname then return true -- found it, stop and return true end end return false -- nickname not found in playersT, return false end addEventHandler("onPlayerConnect", root, function(nickname) local alreadyAdded = isNicknameAlreadyAdded(nickname) if not alreadyAdded then -- some code end end) Link to comment
Kazafka Posted January 5, 2020 Author Share Posted January 5, 2020 Here you have the whole function: addEventHandler("onPlayerConnect", root, function(nickname) for k, v in ipairs(playersT) do if(nickname ~= v) then local size = #playersT local i = size + 1 -- playersT[i] = nickname --Add new player to bank moneyT[i] = "0" --Set new player's bank aco:O value to "0" -- outputChatBox("#09ff00Your account has been added!", player, 255, 255, 255, true) end end end) Just now, stPatrick said: --Table playersT = {} --Code function isNicknameAlreadyAdded(nickname) for k, v in ipairs(playersT) do if v == nickname then return true -- found it, stop and return true end end return false -- nickname not found in playersT, return false end addEventHandler("onPlayerConnect", root, function(nickname) local alreadyAdded = isNicknameAlreadyAdded(nickname) if not alreadyAdded then -- some code end end) I'll try that Oh yeah That started working 4 minutes ago, stPatrick said: --Table playersT = {} --Code function isNicknameAlreadyAdded(nickname) for k, v in ipairs(playersT) do if v == nickname then return true -- found it, stop and return true end end return false -- nickname not found in playersT, return false end addEventHandler("onPlayerConnect", root, function(nickname) local alreadyAdded = isNicknameAlreadyAdded(nickname) if not alreadyAdded then -- some code end end) That started working thank you! TOPIC TO CLOSE! Jesus, now I know, how small knowledge I have 'bout programming! 'gain, thanks! 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