• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua reward chest, error with elseif

Xleniz

New Member
Joined
Jul 6, 2009
Messages
178
Reaction score
3
Location
Sweden
Hello, I need help with elseif in a rewardchest that opens every 10 minutes.
It works 100% with 3 if(), but when I add elseif it gets error. Here's code:

Code:
function round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getGlobalStorageValue(5536) == 0) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You got a chest reward!")
        doPlayerAddItem(cid, 2000, 1)
        setGlobalStorageValue(5535, 0)
    end
    
    elseif(getGlobalStorageValue(5535) == 1) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There's still " .. round((getGlobalStorageValue(5536))/1000/60, 0) .. " minutes left until you can take the reward.")
    end
    
    elseif(getGlobalStorageValue(5535) == 0) then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "A timer on rewardchest has started, when 10 minutes has passed, you or someone else will take the chest reward.")
    setGlobalStorageValue(5535, 1)
    setGlobalStorageValue(5536, 60*1000*10)
    end
    
    return true
end

Nvm, fixed, needed to delete end after if() and after first elseif()
 
Last edited by a moderator:
As the guy above said, you don't close elseif with end, it should be inside of the whole "if" function and you only close that "if".

Code:
function round(num, idp)
  local mult = 10^(idp or 0)
  return math.floor(num * mult + 0.5) / mult
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if(getGlobalStorageValue(5536) == 0) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Congratulations! You got a chest reward!")
        doPlayerAddItem(cid, 2000, 1)
        setGlobalStorageValue(5535, 0)
    elseif(getGlobalStorageValue(5535) == 1) then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "There's still " .. round((getGlobalStorageValue(5536))/1000/60, 0) .. " minutes left until you can take the reward.")
    elseif(getGlobalStorageValue(5535) == 0) then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "A timer on rewardchest has started, when 10 minutes has passed, you or someone else will take the chest reward.")
    setGlobalStorageValue(5535, 1)
    setGlobalStorageValue(5536, 60*1000*10)
    end
    
    return true
end
 
Back
Top