n3crozzy
Member
- Joined
- Apr 23, 2021
- Messages
- 48
- Reaction score
- 14
Hey everyone!
I have a problem with the script. The script is this:
If a player reaches level 20, 35, 50, 70, 100, he or she receives rewards only once.
I have a problem that I presented in the video.
Files : Nekiro TFS 1.5 Downgrade 8.6
The script looks like this:
data/creaturescripts/scripts/levelUpReward.lua
data/creaturescripts/creaturescripts.xml
data/creaturescripts/scripts/login.lua
He receives rewards at every level, but the problem arises when the character dies or loses a level. Storage is slow.
The first thoughts were to put items directly into the backpack, but the problem was that if a player did not have CAP, he did not receive rewards. Therefore, consider making a deposit.
Please help
I have a problem with the script. The script is this:
If a player reaches level 20, 35, 50, 70, 100, he or she receives rewards only once.
I have a problem that I presented in the video.
Files : Nekiro TFS 1.5 Downgrade 8.6
The script looks like this:
data/creaturescripts/scripts/levelUpReward.lua
LUA:
local rewards = {
[20] = {
backpack = 1991, -- Backpack ID
items = {
{2152, 20}, -- Platinum Coin (20)
{7618, 20}, -- Mana Potion (20)
{7620, 20}, -- Life Potion (20)
{2168, 1} -- Ring of mana regeneration (1)
},
storage = 99112 -- Unique storage identifier for level 20
},
[35] = {
backpack = 1992, -- Backpack ID
items = {
{2152, 35}, -- Platinum Coin (35)
{7618, 35}, -- Mana Potion (35)
{7620, 35}, -- Life Potion (35)
{5908, 1} -- Skinning (50)
},
storage = 99113 -- Unique storage identifier for level 35
},
[50] = {
backpack = 1993, -- Backpack ID
items = {
{2152, 50}, -- Platinum Coin (50)
{2216, 10}, -- Healing Ring
{2165, 1}, -- Stealth Ring
{2197, 1} -- Stealth Amulet
},
storage = 99114 -- Unique storage identifier for level 50
},
[70] = {
backpack = 1994, -- Backpack ID
items = {
{2206, 1}, -- Timer Ring (5)
{2152, 70}, -- Platinum Coin (70)
{10306, 1} -- 50% Stamina
},
storage = 99115 -- Unique storage identifier for level 70
},
[100] = {
backpack = 1995, -- Backpack ID
items = {
{2160, 1}, -- Crystal Coin (10)
{5958, 1}, -- Experience Scroll 2h (10)
{9693, 1} -- Addon Doll (1)
},
storage = 99116 -- Unique storage identifier for level 100
}
}
-- Function to grant rewards to the depot
local function giveRewardsToDepot(player, level)
local rewardData = rewards[level]
-- Check if rewards have already been granted
if player:getStorageValue(rewardData.storage) == 1 then
player:sendTextMessage(MESSAGE_STATUS_WARNING, "You have already received rewards for level " .. level .. ".")
return false
end
local items = rewardData.items
local backpackId = rewardData.backpack
local town = player:getTown() -- Get the player's town
if not town then
player:sendTextMessage(MESSAGE_STATUS_WARNING, "Cannot access the player's town.")
return false
end
local depotChest = player:getDepotChest(town:getId(), true) -- Get the depot for the town
if not depotChest then
return false -- In case of no access to depot
end
-- Add backpack to the depot
local backpack = depotChest:addItem(backpackId, 1)
if not backpack then
return false -- In case of failure to add backpack
end
-- Add items to the backpack
for _, reward in ipairs(items) do
local itemId, count = reward[1], reward[2]
backpack:addItem(itemId, count) -- Add items to the backpack
player:sendTextMessage(MESSAGE_INFO_DESCR, "You receive: " .. ItemType(itemId):getName() .. " x" .. count .. " in your depot backpack.")
end
-- Set storage value to mark rewards granted
player:setStorageValue(rewardData.storage, 1)
return true
end
-- Function called on level up
function onAdvance(player, skill, oldLevel, newLevel)
if skill == SKILL_LEVEL then
for level, _ in pairs(rewards) do
if newLevel >= level and oldLevel < level then
local success = giveRewardsToDepot(player, level)
if success then
player:sendTextMessage(MESSAGE_INFO_DESCR, "Congratulations! You have reached level " .. level .. " and received your rewards!")
end
end
end
end
return true
end
data/creaturescripts/creaturescripts.xml
XML:
<event type="advance" name="LevelUpReward" script="levelUpReward.lua"/>
data/creaturescripts/scripts/login.lua
LUA:
player:registerEvent("LevelUpReward")
He receives rewards at every level, but the problem arises when the character dies or loses a level. Storage is slow.
The first thoughts were to put items directly into the backpack, but the problem was that if a player did not have CAP, he did not receive rewards. Therefore, consider making a deposit.
Please help

Last edited: