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?