rusztamas Posted March 29, 2017 Share Posted March 29, 2017 Hi! I started writing a script, and i don't know what the problem is. function adminauth() local ips = { ["192.168.56.1"] = true } local p_IP = tostring(getPlayerIP(source)) if tostring(p_IP) == tostring(ips) then setElementData (source, "administrator", true) outputChatBox ("correct! #FFFFFF"..p_IP.."", getRootElement(), 0, 255, 0, true) else outputChatBox ("wrong! #FFFFFF"..p_IP.."", getRootElement(), 255, 0, 0, true) end end addEventHandler ("onPlayerJoin", getRootElement(), adminauth) When i join the game it outputs wrong. I'm playing this on local server, i tried to use it with serials but none of them worked. When you join it should output correct, and set "administrator" element data true, on you. What the problem could be? Please help me! Link to comment
NeXuS™ Posted March 29, 2017 Share Posted March 29, 2017 function adminauth() local ips = { ["192.168.56.1"] = true } local p_IP = tostring(getPlayerIP(source)) if ips[p_IP] then setElementData (source, "administrator", true) outputChatBox ("correct! #FFFFFF"..p_IP.."", getRootElement(), 0, 255, 0, true) else outputChatBox ("wrong! #FFFFFF"..p_IP.."", getRootElement(), 255, 0, 0, true) end end addEventHandler ("onPlayerJoin", getRootElement(), adminauth) 1 Link to comment
rusztamas Posted March 29, 2017 Author Share Posted March 29, 2017 Thank you very mutch! You know, i am a starter lua - mta programmer, and i can't really see the difference, can you please explain it to me? Link to comment
NeXuS™ Posted March 29, 2017 Share Posted March 29, 2017 (edited) It's about indexing the table. You just set the table's value at the index of "192.168.56.1" to true. You can call that value by just indexing the table (tableName[indexName]). As you have true at that index, it will be like "if true then", so it goes into the true part, and outputs the "correct text". But, if you can't index the table, so it doesn't have somone elses IP registered in the table, it'll always return false, so it'll be like "if false then", so it goes into the false part. I hope you can understand it. It was just indexing a table with the corrected code, but at the original code you were comparing a table with a string value, and two different type of variables can't be equal. Edited March 29, 2017 by NeXuS™ 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