• 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.X+ Vocation Level Up Item Reward

Extrodus

|| Blazera.net ||
Premium User
Joined
Dec 22, 2008
Messages
2,731
Solutions
7
Reaction score
537
Location
Canada
Hey there guys, I'm trying to figure out why this script isn't delivering rewards and when using "prints" to debug it only goes to check 2 then stops.

Engine: TFS 1.5

Lua:
local rewards = {
    SORCERER = {
    [35] = {items = {
            [1] = {itemid = 2187, count = 1}, -- wand of inferno
            [2] = {itemid = 8900, count = 1} -- spellbook of enlightenment
            }, storage = 39002},
    [100] = {items = {
            [1] = {itemid = 1111, count = 1},
            [2] = {itemid = 1111, count = 1}
            }, storage = 40001},
    },
 
    DRUID = {
    [35] = {items = {
            [1] = {itemid = 2183, count = 1}, -- hailstorm rod
            [2] = {itemid = 8900, count = 1} -- spellbook of enlightenment
            }, storage = 39003},
    [100] = {items = {
            [1] = {itemid = 1111, count = 1},
            [2] = {itemid = 1111, count = 1}
            }, storage = 40003},
    },
 
    PALADIN = {
    [35] = {items = {
            [1] = {itemid = 7367, count = 1}, -- enchanted spear
            [2] = {itemid = 2528, count = 1} -- tower shield
            }, storage = 39004},
    [100] = {items = {
            [1] = {itemid = 1111, count = 1},
            [2] = {itemid = 1111, count = 1}
            }, storage = 40005},
    },
 
    KNIGHT = {
    [35] = {items = {
            [1] = {itemid = 2160, count = 2}, -- 2x crystal coin
            [2] = {itemid = 2528, count = 1} -- tower shield
            }, storage = 39005},
    [100] = {items = {
            [1] = {itemid = 1111, count = 1},
            [2] = {itemid = 1111, count = 1}
            }, storage = 40007},
    }
}

local sorc = {1, 5, 9}
local druid = {2, 6, 10}
local paladin = {3, 7, 11}
local knight = {4, 8, 12}

local magicEffect_reward = 14

function onAdvance(player, skill, oldlevel, newlevel)
        print("1")
        if skill >= SKILL_LEVEL then
            print("2")
            return true
        end
        if isInArray(sorc, player:getVocation():getId()) then
            VOC = rewards.SORC
            print("3")
        elseif isInArray(druid, player:getVocation():getId()) then
            VOC = rewards.DRUID
            print("3")
        elseif isInArray(paladin, player:getVocation():getId()) then
            VOC = rewards.PALADIN
            print("3")
        elseif isInArray(knight, player:getVocation():getId()) then
            VOC = rewards.KNIGHT
            print("3")
        end
 
        if not VOC then
        print("4")
        return true
        end
 
        REWARD = VOC[newlevel]
    
        if not REWARD then
        print("5")
        return true
        end
 
        if player:getStorageValue(REWARD.storage) == -1 then
        print("6")
            for i = 1, #REWARD.items do
                player:addItem(REWARD.items[i].itemid, rewards.items[i].count)
            end
            player:setStorageValue(REWARD.items[i].storage, 1)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations, you have reached level "..player:getLevel().." and received your rewards.")
            player:getPosition():sendMagicEffect(magicEffect_reward)
        end
return true
end
 
Lua:
if skill ~= SKILL_LEVEL then
            print("2")
            return true
        end
It was like that previously and wouldnt even print 2 only through testing I changed it. If I combine the below if statement to run next and move return true after I can get print 3 to run but still nothing else follows.
Code:
if skill >= SKILL_LEVEL then
            print("2")
        if isInArray(sorc, player:getVocation():getId()) then
            VOC = rewards.SORC
and then move return true to end of this vocation check.
 
Here boss, study it.

Lua:
local rewards = {
    [35] = {storage = 39002,
        [1] = {{2187, 1}, {8900, 1}}, -- WOI / Spellbook of enlightment
        [2] = {{2183, 1}, {8900, 1}}, -- Hailstorm / Spellbook of enlightment
        [3] = {{7367, 1}, {2528, 1}}, -- Enchanted Spear / Tower Shield
        [4] = {{2160, 2}, {2528, 1}} -- 2x CC / Tower Shield
    },
    [100] = {storage = 39003,
        [1] = {{1111, 1}, {1111, 1}}, --
        [2] = {{1111, 1}, {1111, 1}}, --
        [3] = {{1111, 1}, {1111, 1}}, --
        [4] = {{1111, 2}, {1111, 1}} --
    }
}


local sorc = {1, 5, 9}
local druid = {2, 6, 10}
local paladin = {3, 7, 11}
local knight = {4, 8, 12}

local magicEffect_reward = 14

function onAdvance(player, skill, oldlevel, newlevel)
    if skill ~= SKILL_LEVEL then return true end
  
    local reward = rewards[skill]
  
    if not reward then return true end
  
    if player:getStorageValue(reward.storage) ~= -1 then
        return true
    end
  
    local vocId = player:getVocation():getId()
  
    if vocId == 0 then return true end -- Don't give level rewards to no vocation players
  
    local rewardVoc = nil
  
    if isInArray(sorc, vocId) then
        rewardVoc = reward[1]
    elseif isInArray(druid, vocId) then
        rewardVoc = reward[2]
    elseif isInArray(paladin, vocId) then
        rewardVoc = reward[3]
    else
        rewardVoc = reward[4]
    end
  
    if not rewardVoc then return true end -- Shouldn't ever happen. We default the reward to knight if there is a problem with voc.

    for i = 1, #rewardVoc do
        player:addItem(rewardVoc[i][1], rewardVoc[i][2])
    end
  
    player:setStorageValue(reward.storage, 1)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations, you have reached level "..player:getLevel().." and received your rewards.")
    player:getPosition():sendMagicEffect(magicEffect_reward)
return true
end

If it doesn't work its because we cant have:
reward.storage and reward[1]... I think lua can't have tables like that but I might be wrong.
 
Last edited:
It was like that previously and wouldnt even print 2 only through testing I changed it. If I combine the below if statement to run next and move return true after I can get print 3 to run but still nothing else follows.
Code:
if skill >= SKILL_LEVEL then
            print("2")
        if isInArray(sorc, player:getVocation():getId()) then
            VOC = rewards.SORC
and then move return true to end of this vocation check.

Here boss, study it.

Lua:
local rewards = {
    [35] = {storage = 39002,
        [1] = {{2187, 1}, {8900, 1}}, -- WOI / Spellbook of enlightment
        [2] = {{2183, 1}, {8900, 1}}, -- Hailstorm / Spellbook of enlightment
        [3] = {{7367, 1}, {2528, 1}}, -- Enchanted Spear / Tower Shield
        [4] = {{2160, 2}, {2528, 1}} -- 2x CC / Tower Shield
    },
    [100] = {storage = 39003,
        [1] = {{1111, 1}, {1111, 1}}, --
        [2] = {{1111, 1}, {1111, 1}}, --
        [3] = {{1111, 1}, {1111, 1}}, --
        [4] = {{1111, 2}, {1111, 1}} --
    }
}


local sorc = {1, 5, 9}
local druid = {2, 6, 10}
local paladin = {3, 7, 11}
local knight = {4, 8, 12}

local magicEffect_reward = 14

function onAdvance(player, skill, oldlevel, newlevel)
    if skill ~= SKILL_LEVEL then return true end
 
    local reward = rewards[skill]
 
    if not reward then return true end
 
    if player:getStorageValue(reward.storage) ~= -1 then
        return true
    end
 
    local vocId = player:getVocation():getId()
 
    if vocId == 0 then return true end -- Don't give level rewards to no vocation players
 
    local rewardVoc = nil
 
    if isInArray(sorc, vocId) then
        rewardVoc = reward[1]
    elseif isInArray(druid, vocId) then
        rewardVoc = reward[2]
    elseif isInArray(paladin, vocId) then
        rewardVoc = reward[3]
    else
        rewardVoc = reward[4]
    end
 
    if not rewardVoc then return true end -- Shouldn't ever happen. We default the reward to knight if there is a problem with voc.

    for i = 1, #rewardVoc do
        player:addItem(rewardVoc[i][1], rewardVoc[i][2])
    end
 
    player:setStorageValue(reward.storage, 1)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations, you have reached level "..player:getLevel().." and received your rewards.")
    player:getPosition():sendMagicEffect(magicEffect_reward)
return true
end

If it doesn't work its because we cant have:
reward.storage and reward[1]... I think lua can't have tables like that but I might be wrong.
Thank you for the responses and even going as far as modifying the script!
Unfortunately upon player turning level 35; rewards still are not added + no errors in console and player doesn't receive storage.

You may be onto something when you mention that tables aren't available this way but with TFS 1.X it seems most things are possible in LUA so that is strange.

Code:
local rewards = {
    [35] = {storage = 39002,
        [1] = {{2187, 1}, {8900, 1}}, -- WOI / Spellbook of enlightment
        [2] = {{2183, 1}, {8900, 1}}, -- Hailstorm / Spellbook of enlightment
        [3] = {{7367, 1}, {2528, 1}}, -- Enchanted Spear / Tower Shield
        [4] = {{2160, 2}, {2528, 1}} -- 2x CC / Tower Shield
    },
    [100] = {storage = 39003,
        [1] = {{1111, 1}, {1111, 1}}, --
        [2] = {{1111, 1}, {1111, 1}}, --
        [3] = {{1111, 1}, {1111, 1}}, --
        [4] = {{1111, 2}, {1111, 1}} --
    }
}


local sorc = {1, 5, 9}
local druid = {2, 6, 10}
local paladin = {3, 7, 11}
local knight = {4, 8, 12}

local magicEffect_reward = 14

function onAdvance(player, skill, oldlevel, newlevel)
    print("1")
    if skill ~= SKILL_LEVEL then print("2") return true end
  
    local reward = rewards[skill]
  
    if not reward then print("3") return true end
  
    if player:getStorageValue(reward.storage) ~= -1 then
        print("4")
        return true
    end
  
    local vocId = player:getVocation():getId()
  
    if vocId == 0 then print("5") return true end -- Don't give level rewards to no vocation players
  
    local rewardVoc = nil
  
    if isInArray(sorc, vocId) then
        print("6")
        rewardVoc = reward[1]
    elseif isInArray(druid, vocId) then
        print("6")
        rewardVoc = reward[2]
    elseif isInArray(paladin, vocId) then
        print("6")
        rewardVoc = reward[3]
    else
        print("6")
        rewardVoc = reward[4]
    end
  
    if not rewardVoc then print("7") return true end -- Shouldn't ever happen. We default the reward to knight if there is a problem with voc.

    for i = 1, #rewardVoc do
        print("8")
        player:addItem(rewardVoc[i][1], rewardVoc[i][2])
    end
    print("9")
    player:setStorageValue(reward.storage, 1)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations, you have reached level "..player:getLevel().." and received your rewards.")
    player:getPosition():sendMagicEffect(magicEffect_reward)
return true
end
Only prints 1, 3. skips 2.
 
Last edited:
sorry change

local reward = rewards[skill]

to

local reward = rewards[newlevel]
Now printed

1 <-- when advancing to level 35
4 <-- when advancing to level 35
1 <-- when advancing to level 36
3 <-- when advancing to level 36

(Still no rewards/storage or message)
 
1663398489667.png
Yep; first thing I checked (I mentioned in the post no storage)
Correction: after level 35 Prints change from 1 + 2 to 1 + 3.
 
Last edited:
nice free script!!
@Itutorial your monster ai sucks
My monster AI? I didn't make any monster AI you inbred ass hat.
Post automatically merged:

View attachment 70616
Yep; first thing I checked (I mentioned in the post no storage)
Correction: after level 35 Prints change from 1 + 2 to 1 + 3.
It should print 1 + 3 always if its not in the reward level config....
Level 35 it should give items so try this code and tell me what it prints when you hit level 35
Lua:
local rewards = {
    [35] = {storage = 39002,
        [1] = {{2187, 1}, {8900, 1}}, -- WOI / Spellbook of enlightment
        [2] = {{2183, 1}, {8900, 1}}, -- Hailstorm / Spellbook of enlightment
        [3] = {{7367, 1}, {2528, 1}}, -- Enchanted Spear / Tower Shield
        [4] = {{2160, 2}, {2528, 1}} -- 2x CC / Tower Shield
    },
    [100] = {storage = 39003,
        [1] = {{1111, 1}, {1111, 1}}, --
        [2] = {{1111, 1}, {1111, 1}}, --
        [3] = {{1111, 1}, {1111, 1}}, --
        [4] = {{1111, 2}, {1111, 1}} --
    }
}


local sorc = {1, 5, 9}
local druid = {2, 6, 10}
local paladin = {3, 7, 11}
local knight = {4, 8, 12}

local magicEffect_reward = 14

function onAdvance(player, skill, oldlevel, newlevel)
    if skill ~= SKILL_LEVEL then return true end
   
    local reward = rewards[newlevel]
   
    if not reward then return true end
   
    if player:getStorageValue(reward.storage) ~= -1 then
        print("Player storage is already set.")
        return true
    end
   
    print("Player storage is not set yet.")
   
    local vocId = player:getVocation():getId()
   
    if vocId == 0 then return true end -- Don't give level rewards to no vocation players
   
    local rewardVoc = nil
   
    if isInArray(sorc, vocId) then
        rewardVoc = reward[1]
    elseif isInArray(druid, vocId) then
        rewardVoc = reward[2]
    elseif isInArray(paladin, vocId) then
        rewardVoc = reward[3]
    else
        rewardVoc = reward[4]
    end
   
    if not rewardVoc then return true end -- Shouldn't ever happen unless you added a new voc and it isn't in the arrays above.

    for i = 1, #rewardVoc do
        player:addItem(rewardVoc[i][1], rewardVoc[i][2])
    end
   
    player:setStorageValue(reward.storage, 1)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations, you have reached level "..player:getLevel().." and received your rewards.")
    player:getPosition():sendMagicEffect(magicEffect_reward)
return true
end
 
Last edited:
My monster AI? I didn't make any monster AI you inbred ass hat.
Post automatically merged:


It should print 1 + 3 always if its not in the reward level config....
Level 35 it should give items so try this code and tell me what it prints when you hit level 35
Lua:
local rewards = {
    [35] = {storage = 39002,
        [1] = {{2187, 1}, {8900, 1}}, -- WOI / Spellbook of enlightment
        [2] = {{2183, 1}, {8900, 1}}, -- Hailstorm / Spellbook of enlightment
        [3] = {{7367, 1}, {2528, 1}}, -- Enchanted Spear / Tower Shield
        [4] = {{2160, 2}, {2528, 1}} -- 2x CC / Tower Shield
    },
    [100] = {storage = 39003,
        [1] = {{1111, 1}, {1111, 1}}, --
        [2] = {{1111, 1}, {1111, 1}}, --
        [3] = {{1111, 1}, {1111, 1}}, --
        [4] = {{1111, 2}, {1111, 1}} --
    }
}


local sorc = {1, 5, 9}
local druid = {2, 6, 10}
local paladin = {3, 7, 11}
local knight = {4, 8, 12}

local magicEffect_reward = 14

function onAdvance(player, skill, oldlevel, newlevel)
    if skill ~= SKILL_LEVEL then return true end
 
    local reward = rewards[newlevel]
 
    if not reward then return true end
 
    if player:getStorageValue(reward.storage) ~= -1 then
        print("Player storage is already set.")
        return true
    end
 
    print("Player storage is not set yet.")
 
    local vocId = player:getVocation():getId()
 
    if vocId == 0 then return true end -- Don't give level rewards to no vocation players
 
    local rewardVoc = nil
 
    if isInArray(sorc, vocId) then
        rewardVoc = reward[1]
    elseif isInArray(druid, vocId) then
        rewardVoc = reward[2]
    elseif isInArray(paladin, vocId) then
        rewardVoc = reward[3]
    else
        rewardVoc = reward[4]
    end
 
    if not rewardVoc then return true end -- Shouldn't ever happen unless you added a new voc and it isn't in the arrays above.

    for i = 1, #rewardVoc do
        player:addItem(rewardVoc[i][1], rewardVoc[i][2])
    end
 
    player:setStorageValue(reward.storage, 1)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations, you have reached level "..player:getLevel().." and received your rewards.")
    player:getPosition():sendMagicEffect(magicEffect_reward)
return true
end
It works now! However if the player advances from level 34 -> 36 and skips 35; the player doesnt get the rewards.
 
Ohhh sorry translando not good, monster panthfinding!!!
It sucks are you an developer or a joke?
I am just going to assume your pfp is a rl image of you. Good luck too you kid. Also, don't blame the translator for you being an idiot.
Post automatically merged:

Try this. Im not testing so it could have an error.

Lua:
local rewards = {
    [35] = {storage = 39002,
        [1] = {{2187, 1}, {8900, 1}}, -- WOI / Spellbook of enlightment
        [2] = {{2183, 1}, {8900, 1}}, -- Hailstorm / Spellbook of enlightment
        [3] = {{7367, 1}, {2528, 1}}, -- Enchanted Spear / Tower Shield
        [4] = {{2160, 2}, {2528, 1}} -- 2x CC / Tower Shield
    },
    [100] = {storage = 39003,
        [1] = {{1111, 1}, {1111, 1}}, --
        [2] = {{1111, 1}, {1111, 1}}, --
        [3] = {{1111, 1}, {1111, 1}}, --
        [4] = {{1111, 2}, {1111, 1}} --
    }
}

local sorc = {1, 5, 9}
local druid = {2, 6, 10}
local paladin = {3, 7, 11}
local knight = {4, 8, 12}

local magicEffect_reward = 14

function onAdvance(player, skill, oldlevel, newlevel)
    if skill ~= SKILL_LEVEL then return true end
    for i, v in pairs(rewards) do
        if player:getLevel() >= i then
            if player:getStorageValue(rewards[i].storage) ~= -1 then
                return true
            end
        
            local vocId = player:getVocation():getId()
        
            if vocId == 0 then return true end -- Don't give level rewards to no vocation players
        
            local rewardVoc = nil
        
            if isInArray(sorc, vocId) then
                rewardVoc = rewards[i][1]
            elseif isInArray(druid, vocId) then
                rewardVoc = rewards[i][2]
            elseif isInArray(paladin, vocId) then
                rewardVoc = rewards[i][3]
            else
                rewardVoc = rewards[i][4]
            end
        
            if not rewardVoc then return true end -- Shouldn't ever happen unless you added a new voc and it isn't in the arrays above.

            for k = 1, #rewardVoc do
                player:addItem(rewardVoc[k][1], rewardVoc[k][2])
            end
        
            player:setStorageValue(rewards[i].storage, 1)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations, you have reached level "..i.." and received your rewards.")
            player:getPosition():sendMagicEffect(magicEffect_reward)
        end
    end
return true
end
 
Last edited:
I am just going to assume your pfp is a rl image of you. Good luck too you kid. Also, don't blame the translator for you being an idiot.
Post automatically merged:

Try this. Im not testing so it could have an error.

Lua:
local rewards = {
    [35] = {storage = 39002,
        [1] = {{2187, 1}, {8900, 1}}, -- WOI / Spellbook of enlightment
        [2] = {{2183, 1}, {8900, 1}}, -- Hailstorm / Spellbook of enlightment
        [3] = {{7367, 1}, {2528, 1}}, -- Enchanted Spear / Tower Shield
        [4] = {{2160, 2}, {2528, 1}} -- 2x CC / Tower Shield
    },
    [100] = {storage = 39003,
        [1] = {{1111, 1}, {1111, 1}}, --
        [2] = {{1111, 1}, {1111, 1}}, --
        [3] = {{1111, 1}, {1111, 1}}, --
        [4] = {{1111, 2}, {1111, 1}} --
    }
}

local sorc = {1, 5, 9}
local druid = {2, 6, 10}
local paladin = {3, 7, 11}
local knight = {4, 8, 12}

local magicEffect_reward = 14

function onAdvance(player, skill, oldlevel, newlevel)
    if skill ~= SKILL_LEVEL then return true end
    for i, v in pairs(rewards) do
        if player:getLevel() >= i then
            if player:getStorageValue(rewards[i].storage) ~= -1 then
                return true
            end
      
            local vocId = player:getVocation():getId()
      
            if vocId == 0 then return true end -- Don't give level rewards to no vocation players
      
            local rewardVoc = nil
      
            if isInArray(sorc, vocId) then
                rewardVoc = rewards[i][1]
            elseif isInArray(druid, vocId) then
                rewardVoc = rewards[i][2]
            elseif isInArray(paladin, vocId) then
                rewardVoc = rewards[i][3]
            else
                rewardVoc = rewards[i][4]
            end
      
            if not rewardVoc then return true end -- Shouldn't ever happen unless you added a new voc and it isn't in the arrays above.

            for k = 1, #rewardVoc do
                player:addItem(rewardVoc[k][1], rewardVoc[k][2])
            end
      
            player:setStorageValue(reward.rewards[i], 1)
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "Congratulations, you have reached level "..i.." and received your rewards.")
            player:getPosition():sendMagicEffect(magicEffect_reward)
        end
    end
return true
end
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/others/advance_items.lua:onAdvance
data/creaturescripts/scripts/others/advance_items.lua:54: attempt to index global 'reward' (a nil value)
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/others/advance_items.lua:54: in function <data/creaturescripts/scripts/others/advance_items.lua:24>
Got this as the error when testing.

Replaced with player:setStorageValue(rewards.storage, 1) and it works now.
Thank you so much for the help <3
 
change
player:setStorageValue(reward.rewards, 1)

to
Lua:
player:setStorageValue(rewards[i].storage, 1)
Oh geez you are completely right; it was giving the rewards over and over with my line.
Thank you for all the help; even while we are being trolled by this jungle primate over here.
Don't listen to him; he's been going off all day yesterday and now into the early hours of the morning.
Couldn't imagine having that type of spare time and not utilizing it.
 
Back
Top