• 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!

Lua anyy idea why this code aint working correcly ?

Lbtg

Advanced OT User
Joined
Nov 22, 2008
Messages
2,398
Reaction score
165
So i got this sript not working correcly , can someone check it out and fix it :)

globalevent script

onlinegift.lua
PHP:
local config = {
    [1] = {minLevel = 80, maxLevel = 350, item = {2160,5}},
    [2] = {minLevel = 100, maxLevel = 1500, item = {12601,5}},
    [3] = {minLevel = 150, maxLevel = 1600, item = {11225,1}}
}
function FindSuitable(cid)
    local to_return = {}
    for i = 1,#config do
        if getPlayerLevel(cid) >= config[i].minLevel and getPlayerLevel(cid) <= config[i].maxLevel then
            table.insert(to_return,config[i].item[1])
            table.insert(to_return,config[i].item[2])
            break
        end
    end
    return to_return
end
function onThink(interval)
    local players = getPlayersOnline()
    if #players >= 1 then
        for i = 1,#players do
            local reward = FindSuitable(players[i])
            if #reward > 0 then
                doPlayerSetStorageValue(players[i],6722, tonumber(getPlayerStorageValue(players[i],6722)) + 1)
                if getPlayerStorageValue(players[i],6722) >= 60 then
                    doPlayerAddItem(players[i],reward[1],reward[2])
                    doPlayerSetStorageValue(players[i],6722,0)
                    doPlayerSendTextMessage(players[i], 27, "You Have Been Rewarded With "..reward[2].."x Of "..getItemNameById(reward[1])..".")
                end
            end
        end
    end
    return true
end

xml part
PHP:
<globalevent name="onlinegift" interval="1000" event="script" value="onlinegift.lua"/>
 
like this ?
PHP:
function addTimedCc(cid)
if level >= 100 and level <= 500 else
if not isPlayer(cid) thenreturn true
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recieved 2cc because you play ! In another 30 min you will recieve more! ENJOY WARFARE!!!")
doPlayerAddItem(cid,2160,2)
addEvent(addTimedCc, 30 * 60 * 1000, cid)
end
 
Code:
function addTimedCc(cid)
if not isPlayer(cid) then 
    return true
end
local level = getPlayerLevel(cid)
if level >= 100 and level <= 500 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recieved 2cc because you play ! In another 30 min you will recieve more! ENJOY WARFARE!!!")
    doPlayerAddItem(cid,2160,2)
    addEvent(addTimedCc, 30 * 60 * 1000, cid)
end
end
 
Code:
function addTimedCc(cid)
if not isPlayer(cid) then
    return true
end
local level = getPlayerLevel(cid)
if level >= 100 and level <= 500 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recieved 2cc because you play ! In another 30 min you will recieve more! ENJOY WARFARE!!!")
    doPlayerAddItem(cid,2160,2)
    addEvent(addTimedCc, 30 * 60 * 1000, cid)
end
end
trying out
 
like this ?
PHP:
function addTimedCc(cid)
if level >= 100 and level <= 500 else
if not isPlayer(cid) thenreturn true
end
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recieved 2cc because you play ! In another 30 min you will recieve more! ENJOY WARFARE!!!")
doPlayerAddItem(cid,2160,2)
addEvent(addTimedCc, 30 * 60 * 1000, cid)
end
Code:
function addTimedCc(cid)
    -- this always should be placed 1st
    if not isPlayer(cid) then
        -- no need to return true or false unless this is used as a comparison function,
        -- just setting it to return exits the function
        return
    end
    local level = getPlayerLevel(cid)
    -- now that we established its a player
    if level >= 100 and level <= 500 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recieved 2cc because you play ! In another 30 min you will recieve more! ENJOY WARFARE!!!")
        doPlayerAddItem(cid,2160,2)
        addEvent(addTimedCc, 30 * 60 * 1000, cid)
    end
    --[[
        no need to return true or false unless this is used as a comparison function,
        e.g.
        if addTimedCc(cid) then
            -- do something
        end
    
        the code executes in a procedural manner, so when it reaches the end it exits the function
    ]]
end
 
Code:
function addTimedCc(cid)
    -- this always should be placed 1st
    if not isPlayer(cid) then
        -- no need to return true or false unless this is used as a comparison function,
        -- just setting it to return exits the function
        return
    end
    -- now that we established its a player
    if level >= 100 and level <= 500 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recieved 2cc because you play ! In another 30 min you will recieve more! ENJOY WARFARE!!!")
        doPlayerAddItem(cid,2160,2)
        addEvent(addTimedCc, 30 * 60 * 1000, cid)
    end
    --[[
        no need to return true or false unless this is used as a comparison function,
        e.g.
        if addTimedCc(cid) then
            -- do something
        end
    
        the code executes in a procedural manner, so when it reaches the end it exits the function
    ]]
end
dont forget to define level
 
Code:
function addTimedCc(cid)
if not isPlayer(cid) then
    return true
end
local level = getPlayerLevel(cid)
if level >= 100 and level <= 500 then
    doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recieved 2cc because you play ! In another 30 min you will recieve more! ENJOY WARFARE!!!")
    doPlayerAddItem(cid,2160,2)
    addEvent(addTimedCc, 30 * 60 * 1000, cid)
end
end
working fine thanks :)

Code:
function addTimedCc(cid)
    -- this always should be placed 1st
    if not isPlayer(cid) then
        -- no need to return true or false unless this is used as a comparison function,
        -- just setting it to return exits the function
        return
    end
    local level = getPlayerLevel(cid)
    -- now that we established its a player
    if level >= 100 and level <= 500 then
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You recieved 2cc because you play ! In another 30 min you will recieve more! ENJOY WARFARE!!!")
        doPlayerAddItem(cid,2160,2)
        addEvent(addTimedCc, 30 * 60 * 1000, cid)
    end
    --[[
        no need to return true or false unless this is used as a comparison function,
        e.g.
        if addTimedCc(cid) then
            -- do something
        end
   
        the code executes in a procedural manner, so when it reaches the end it exits the function
    ]]
end

Thanks for explainings :)
 
Back
Top