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

TFS 1.2 random reward doesnt work

Tbol

Well-Known Member
Joined
Apr 7, 2019
Messages
537
Reaction score
56
Hello so im trying to make a global random reward after completing a missions with this code i wrote which means 50% chance to get it
if math.random(1, 100) <= 50 then
player:addItem(6425, 1)
selfSay("You got lucky and received item.", cid)
end

and this is how full function looks like

Lua:
function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end

    local player = Player(cid)
    if not player then return true end
    
    if msg and msg == "tasks" or msg == "mission" then
        local text = "Tasks: "
        for i = 1, #tasks do
            if i == #tasks then
                text = text..""..tasks[i].name[1].."."
            else
                text = text..""..tasks[i].name[1]..", "
            end
        end
        
        selfSay(text, cid)
        return true


    elseif msg and msg ~= "cancel" then
        local TASK = nil
        
        for i = 1, #tasks do
            if isInArray(tasks[i].name, msg) then
                TASK = tasks[i]
                break
            end
        end
        
        if not TASK then return true end
        
        local playerTask = tasks[player:getStorageValue(taskStorage)]

        if TASK then
            if player:getLevel() < TASK.levelReq then
                selfSay("You must be level "..TASK.levelReq.." to start that task.", cid)
                return true
        end
    end
        
        if player:getStorageValue(taskStorage) == nil or player:getStorageValue(taskStorage) == -1 then
            player:setStorageValue(taskStorage, TASK.id)
            for i = 1, #TASK.monsters do
                player:setStorageValue(TASK.monsters[i].storage, 0)
            end
            selfSay(TASK.msg, cid)
            return true
        end

            
        if player:getStorageValue(taskStorage) ~= playerTask.id then
            selfSay("You must complete the "..playerTask.name[1].." task first. You can also {clear task}.", cid)
            return true
    
        else
            local isComplete = true
        
            for i = 1, #TASK.monsters do
                if player:getStorageValue(TASK.monsters[i].storage) ~= TASK.monsters[i].amount then
                    isComplete = false
                    break
                end
            end
        
            if not isComplete then
              local text = "First you have to finish your current task: "
                    for i = 1, #playerTask.monsters do
                        if i == #playerTask.monsters then
                            text = text.."("..playerTask.monsters[i].amount - player:getStorageValue(playerTask.monsters[i].storage)..") "..playerTask.monsters[i].name.."('s)."
                        else
                            text = text.."("..playerTask.monsters[i].amount - player:getStorageValue(playerTask.monsters[i].storage)..") "..playerTask.monsters[i].name.."('s), "
                        end
                    end
                        
                selfSay(text, cid)
                return true
                
            else
            
                player:setStorageValue(taskStorage, -1)
                for i = 1, #playerTask.monsters do
                    player:setStorageValue(playerTask.monsters[i].storage, -1)
                end
                
                player:takeReward(playerTask)
                selfSay("You have completed the "..playerTask.name[1].." task!", cid)

                -- Check if the player gets lucky for the global reward
                if math.random(1, 100) <= 50 then
                    player:addItem(6425, 1)
                    selfSay("You got lucky and received item.", cid)
                end
                return true
            end
        end
        
    elseif msg == "cancel" then
        local TASK = tasks[player:getStorageValue(taskStorage)]
        
        if not TASK then
            selfSay("You do not have a task.", cid)
        else
            player:setStorageValue(taskStorage, -1)
            for i = 1, #TASK.monsters do
                player:setStorageValue(TASK.monsters[i].storage, -1)
            end
            selfSay("You are no longer doing the "..TASK.name[1].." task.", cid)
            return true
        end
    end
    return true
end
 
Lua:
-- Check if the player gets lucky for the global reward

                local number = math.random(1, 100)

if number <= 50 then

                    player:addItem(6425, 1)

                    selfSay("You got lucky and received item.", cid)

                end
 
Back
Top Bottom