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

RevScripts Upgrade scripts :/ Mana leech/hp leech

cocacola13

Member
Joined
Jan 18, 2019
Messages
179
Reaction score
12
Location
poland
Hello, I need a script that will upgrade my wand. For example, I have an item with ID 485 (upgrader), and when I use it "Only" on the wand, it upgrades my mana leech and hp leech by 1%. However, the maximum level of upgrades is 20% for mana leech and 20% for hp leech. Thank you, and best regards.

Tfs 1.5 downgrade by nekiro
 
it doesn't work as I want and I can't do it :/ and it's only supposed to improve the wands, nothing else
Post automatically merged:

it doesn't work as I want and I can't do it :/ and it's only supposed to improve the wands, nothing else
 
Here's the code, for example if you have a good Lua programmer do test and what needs to be add some functions good luck. I'm not very good at Lua and C++.. I like to learn.. one day I'll be a PROFESSIONAL.

Lua:
function onUpdateWand(player, item)
    local updaterItemId = 485
    local maxManaLeech = 20
    local maxHpLeech = 20
    local manaLeechIncrease = 1
    local hpLeechIncrease = 1

    if item:getId() == updaterItemId then
        local wand = player:getSlotItem(SLOT_LEFT)
        if wand and wand:getId() == YOUR_WAND_ID then
            local wandMeta = wand:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
            local currentManaLeech = tonumber(wandMeta:match("Mana Leech %+(%d+)%%"))
            local currentHpLeech = tonumber(wandMeta:match("Life Leech %+(%d+)%%"))
            
            if not currentManaLeech or not currentHpLeech then
                return false -- Wand does not have leech attributes, script execution stopped
            end

            local newManaLeech = currentManaLeech + manaLeechIncrease
            local newHpLeech = currentHpLeech + hpLeechIncrease

            if newManaLeech <= maxManaLeech and newHpLeech <= maxHpLeech then
                wandMeta = wandMeta:gsub("Mana Leech %+%d+%%", "Mana Leech +" .. newManaLeech .. "%")
                wandMeta = wandMeta:gsub("Life Leech %+%d+%%", "Life Leech +" .. newHpLeech .. "%")
                wand:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, wandMeta)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your wand has been updated.")
                item:remove(1) -- Remove the updater item from player's inventory
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your wand is already at maximum leech level.")
            end
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not holding a wand.")
        end
    end
    return false
end
 
it doesn't work as I want and I can't do it :/ and it's only supposed to improve the wands, nothing else
Post automatically merged:


it doesn't work as I want and I can't do it :/ and it's only supposed to improve the wands, nothing else
Okay
 
Here's the code, for example if you have a good Lua programmer do test and what needs to be add some functions good luck. I'm not very good at Lua and C++.. I like to learn.. one day I'll be a PROFESSIONAL.

Lua:
function onUpdateWand(player, item)
    local updaterItemId = 485
    local maxManaLeech = 20
    local maxHpLeech = 20
    local manaLeechIncrease = 1
    local hpLeechIncrease = 1

    if item:getId() == updaterItemId then
        local wand = player:getSlotItem(SLOT_LEFT)
        if wand and wand:getId() == YOUR_WAND_ID then
            local wandMeta = wand:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
            local currentManaLeech = tonumber(wandMeta:match("Mana Leech %+(%d+)%%"))
            local currentHpLeech = tonumber(wandMeta:match("Life Leech %+(%d+)%%"))
           
            if not currentManaLeech or not currentHpLeech then
                return false -- Wand does not have leech attributes, script execution stopped
            end

            local newManaLeech = currentManaLeech + manaLeechIncrease
            local newHpLeech = currentHpLeech + hpLeechIncrease

            if newManaLeech <= maxManaLeech and newHpLeech <= maxHpLeech then
                wandMeta = wandMeta:gsub("Mana Leech %+%d+%%", "Mana Leech +" .. newManaLeech .. "%")
                wandMeta = wandMeta:gsub("Life Leech %+%d+%%", "Life Leech +" .. newHpLeech .. "%")
                wand:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, wandMeta)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your wand has been updated.")
                item:remove(1) -- Remove the updater item from player's inventory
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your wand is already at maximum leech level.")
            end
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not holding a wand.")
        end
    end
    return false
end
not working men very thanks for help me :/
[Warning - Event::checkScript] Event onUse not found. scripts/test.lua
 
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local updaterItemId = 485
    local maxManaLeech = 20
    local maxHpLeech = 20
    local manaLeechIncrease = 1
    local hpLeechIncrease = 1

    if item:getId() == updaterItemId then
        local wand = player:getSlotItem(SLOT_LEFT)
        if wand and wand:getId() == YOUR_WAND_ID then
            local wandMeta = wand:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
            local currentManaLeech = tonumber(wandMeta:match("Mana Leech %+(%d+)%%"))
            local currentHpLeech = tonumber(wandMeta:match("Life Leech %+(%d+)%%"))
            
            if not currentManaLeech or not currentHpLeech then
                return false
            end

            local newManaLeech = currentManaLeech + manaLeechIncrease
            local newHpLeech = currentHpLeech + hpLeechIncrease

            if newManaLeech <= maxManaLeech and newHpLeech <= maxHpLeech then
                wandMeta = wandMeta:gsub("Mana Leech %+%d+%%", "Mana Leech +" .. newManaLeech .. "%")
                wandMeta = wandMeta:gsub("Life Leech %+%d+%%", "Life Leech +" .. newHpLeech .. "%")
                wand:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, wandMeta)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your wand has been updated.")
                item:remove(1) 
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your wand is already at maximum leech level.")
            end
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not holding a wand.")
        end
    end
    return false
end

local useItemEvent = EventType(SCRIPT_USEITEM)
useItemEvent:register("onUse")
useItemEvent:registerEvent()
 
I generally use tfs 1.5 Downgrade by nekiro, and it's weird there because in combat.cpp and item.cpp it is saved as SPECIAL and I don't know how to pull it out to the lua file and send attr
 
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local updaterItemId = 485
    local maxManaLeech = 20
    local maxHpLeech = 20
    local manaLeechIncrease = 1
    local hpLeechIncrease = 1

    if item:getId() == updaterItemId then
        local wand = player:getSlotItem(SLOT_LEFT)
        if wand and wand:getId() == YOUR_WAND_ID then
            local wandMeta = wand:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
            local currentManaLeech = tonumber(wandMeta:match("Mana Leech %+(%d+)%%"))
            local currentHpLeech = tonumber(wandMeta:match("Life Leech %+(%d+)%%"))
        
            if not currentManaLeech or not currentHpLeech then
                return false
            end

            local newManaLeech = currentManaLeech + manaLeechIncrease
            local newHpLeech = currentHpLeech + hpLeechIncrease

            if newManaLeech <= maxManaLeech and newHpLeech <= maxHpLeech then
                wandMeta = wandMeta:gsub("Mana Leech %+%d+%%", "Mana Leech +" .. newManaLeech .. "%")
                wandMeta = wandMeta:gsub("Life Leech %+%d+%%", "Life Leech +" .. newHpLeech .. "%")
                wand:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, wandMeta)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your wand has been updated.")
                item:remove(1)
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Your wand is already at maximum leech level.")
            end
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You are not holding a wand.")
        end
    end
    return false
end

local useItemEvent = EventType(SCRIPT_USEITEM)
useItemEvent:register("onUse")
useItemEvent:registerEvent()
Looks like it was made for revScript but not correctly.
Also i think you have to use action with target..

Lua:
if target:getId() == wandId then
--perform code
end
Import the script with changes below in data/scripts/actions.

Lua:
local Upgrade = Action()
function Upgrade.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local updaterItemId = 485
    local maxManaLeech = 20
    local maxHpLeech = 20
    local manaLeechIncrease = 1
    local hpLeechIncrease = 1
    .......
    end
 
Upgrade:register()
Upgrade:id(485)
 
Looks like it was made for revScript but not correctly.
Also i think you have to use action with target..

Lua:
if target:getId() == wandId then
--perform code
end
Import the script with changes below in data/scripts/actions.

Lua:
local Upgrade = Action()
function Upgrade.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local updaterItemId = 485
    local maxManaLeech = 20
    local maxHpLeech = 20
    local manaLeechIncrease = 1
    local hpLeechIncrease = 1
    .......
    end
 
Upgrade:register()
Upgrade:id(485)
1691072441527.png


something started to show, but I still don't know what it is, it's the first time I encounter such an error
 
I made a new one, but have no idea if this works(Im not able to check it atm), but you could try. Also i'm not sure if you need onInventoryUpdate function, maybe its already in TFS 1.5, check if its enabled or is present in events..


Lua:
local config = {
    [485] = {
        manaLeech = {
            text = "Mana leech",
            param = CONDITION_PARAM_SPECIALSKILL_MANALEECHAMOUNT,
            offset = 50,
            upgradeValue = 1,
            maxUpgrade = 20,
        },
        lifeLeech = {
            text = "Life leech",
            offset = 51,
            param = CONDITION_PARAM_SPECIALSKILL_LIFELEECHAMOUNT,
            upgradeValue = 1,
            maxUpgrade = 20,
        },
    },
}

local wandUpgrade = Action()

function wandUpgrade.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    local itemConfig = config[itemId]
 
    if not itemConfig then
        return false
    end

    local wandId = target:getId()
    local wandType = wandId:getWeaponType()

    for attributeName, data in pairs(itemConfig) do
        if wandType == WEAPON_WAND then
            local wandDescription = target:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
            local searchText = "%("..data.text..": %+(%d+)%%%)"
            local value = data.upgradeValue

            local matchValue = string.match(wandDescription, searchText)

            if matchValue then
                value = value + tonumber(matchValue)

                if value > data.maxUpgrade then
                    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This wand has already reached the maximum level.")
                    return false
                end

                local newDescription = string.gsub(wandDescription, searchText, "\n%("..data.text..": " .. value .. "%%)")
                if newDescription ~= "" then
                    target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, newDescription)
                end
            else
                target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, wandDescription .. "\n" .. "(" .. data.text .. ": " .. value .. "%%)")
            end

            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have upgraded your " .. data.text .. " with " .. data.upgradeValue .. "%.")

            -- SetCondition to player
            local condition = player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, data.offset)
            if not condition then
                condition = Condition(CONDITION_ATTRIBUTES)
                condition:setParameter(CONDITION_PARAM_SUBID, data.offset)
                condition:setParameter(CONDITION_PARAM_TICKS, -1)
            end
            condition:setParameter(data.param, value)

            if value > 0 then
                player:addCondition(condition)
            else
                player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, data.offset)
            end
        else
            return false
        end
    end

    return true
end

for itemId, _ in pairs(config) do
    wandUpgrade:id(itemId)
end
wandUpgrade:register()
 
Last edited:
You have to move wandUpgrade:id(itemId) above wandUpgrade:register()
Also, the warnings you're getting aren't related to only 1 script, You have many scripts missing this scriptName:id(itemIdHeree) or aid or uid instead of id or the same script but you increased the table.
 
Last edited:
Execute wandUpgrade:register() after the loop like:
Lua:
for itemId, _ in pairs(config) do
    wandUpgrade:id(itemId)
end

wandUpgrade:register()
 
I noticed that myself when i was able to test the code. Anyway the code is not working, it needs more work.
I almost got it to work, but im struggling with new description are added each time, and the value would not go higher than 2. Its the string.match() variable that is not good.

Guess ill check it again tomorrow evening. Sorry.
 
Hi again, i havnt been able to do so much tests. I still havnt figoured it out 100%. I know this code will 100% overwrite one of the attributes, but maybe some other ppl would like to continue the code as i will not have the time to do it anymore.
However, this code will add atleast mana, and will upgrade it up to 20%. + its kinda a mess, but yeah, latest status;



Lua:
local config = {
    [2193] = {
        manaLeech = {
            text = "Mana leech",
            param = CONDITION_PARAM_SPECIALSKILL_MANALEECHAMOUNT,
            offset = 50,
            upgradeValue = 1,
            maxUpgrade = 20,
        },
        lifeLeech = {
            text = "Life leech",
            offset = 51,
            param = CONDITION_PARAM_SPECIALSKILL_LIFELEECHAMOUNT,
            upgradeValue = 1,
            maxUpgrade = 20,
        },
    },
}

local wandUpgrade = Action()

function wandUpgrade.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    local itemConfig = config[itemId]

    if not itemConfig then
        return false
    end

    local wandId = ItemType(target:getId())
    local wandType = wandId:getWeaponType()

    for attributeName, data in pairs(itemConfig) do
        if wandType == WEAPON_WAND then
            local wandDescription = target:getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
            local searchText = "%("..data.text..": %+(%d+)%%%)"
            local value = data.upgradeValue
            local matchValue = string.match(wandDescription, searchText)
            if not matchValue then
                local newAttribute = "(" .. data.text .. ": +" .. data.upgradeValue .. "%)"
                local newDescription = wandDescription .. "\n" .. newAttribute
                target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, newDescription)

                -- SetCondition to player
                local condition = player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, data.offset)
                if not condition then
                    condition = Condition(CONDITION_ATTRIBUTES)
                    condition:setParameter(CONDITION_PARAM_SUBID, data.offset)
                    condition:setParameter(CONDITION_PARAM_TICKS, -1)
                end
                condition:setParameter(data.param, data.upgradeValue)

                if value > 0 then
                    player:addCondition(condition)
                else
                    player:removeCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, data.offset)
                end

                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have upgraded your " .. data.text .. " with " .. data.upgradeValue .. "%.")
                return true
            else
                value = tonumber(matchValue) + data.upgradeValue
                local newDescription = string.gsub(wandDescription, searchText, "(" .. data.text .. ": +" .. value .. "%%)")
                target:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, newDescription)

                -- Update the condition value
                local condition = player:getCondition(CONDITION_ATTRIBUTES, CONDITIONID_COMBAT, data.offset)
                if condition then
                    condition:setParameter(data.param, value)
                end

                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have upgraded your " .. data.text .. " with " .. data.upgradeValue .. "%.")
                return true
            end
        end
    end

    return false
end

for itemId, _ in pairs(config) do
    wandUpgrade:id(itemId)
end
wandUpgrade:register()
 
Back
Top