babecka Posted April 11, 2014 Share Posted April 11, 2014 Hello. I've this code: function onDeath() alive = getAlivePlayers() if getPlayerCount() <= 0 then outputChatBox("You can not receive your reward because there are not enough players!", source, 255, 0, 0) else if alive >= 3 then local reward = math.random(2000, 3000) local points = math.random(20, 40) givePlayerMoney(source, reward) setElementData(source, "points", getElementData(source, "points") + points) outputChatBox("You have been killed and you won $" .. reward .. " and " .. points .. " points!" , source, 255, 255, 0) elseif alive <= 3 then local reward = math.random(2500, 3000) local points = math.random(40, 60) givePlayerMoney(source, reward) setElementData(source, "points", getElementData(source, "points") + points) outputChatBox("You have been killed and you won $" .. reward .. " and " .. points .. " points!" , source, 255, 255, 0) elseif alive == 1 then local reward = math.random(3500, 4500) local points = math.random(80, 100) givePlayerMoney(source, reward) setElementData(source, "points", getElementData(source, "points") + points) outputChatBox("You have been killed and you won $" .. reward .. " and " .. points .. " points!" , source, 255, 255, 0) end end end The problem is, no message shows up and I don't get the money/points. I get this error: attempt to compare number with table I had the same error with this code: if getPlayerCount() <= 0 then but I've added the () and it fixed the error. However, it doesn't fix it in this case. I tried to remove the variable alive and put getAlivePlayers() instead of it, but it gave me the same error. How do I get this to work? Link to comment
TAPL Posted April 11, 2014 Share Posted April 11, 2014 getAlivePlayers return table so you should use #alive instead of alive. Also you've checked if there less than or equal to zero players which this mean there no players in the server and this make no sense because the code wouldn't have executed if there's no players at all. Link to comment
babecka Posted April 12, 2014 Author Share Posted April 12, 2014 Thank you for the reply. The zero is just for testing purposes, because I have no one to test it with. 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