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

OTClient Script to get mana/hp reg when using an item

empasor123

New Member
Joined
Jul 17, 2024
Messages
15
Reaction score
1
GitHub
empasor123
Hi, does anyone have a script for (Example) - Using "Vibrant egg" > Give you the Sparkion Mount + 5% permanent HP/MANA Reg

Trying to learn. Im using tfs 1.4.2
 
Hi, does anyone have a script for (Example) - Using "Vibrant egg" > Give you the Sparkion Mount + 5% permanent HP/MANA Reg

Trying to learn. Im using tfs 1.4.2


Create a file named vibrant_egg.lua in the data/scripts/actions/ directory or wherever you organize your action scripts.
LUA:
local mountId = 58 -- ID of the Sparkion mount, adjust if necessary
local permBonusStorage = 10001 -- A unique storage value to track the permanent bonus

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Check if the player already has the Sparkion mount
    if player:hasMount(mountId) then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have the Sparkion mount.")
        return true
    end

    -- Grant the Sparkion mount to the player
    player:addMount(mountId)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received the Sparkion mount!")

    -- Add the permanent 5% HP and MANA regeneration bonus
    if player:getStorageValue(permBonusStorage) ~= 1 then
        player:setStorageValue(permBonusStorage, 1)
        player:setMaxHealth(player:getMaxHealth() * 1.05)
        player:setMaxMana(player:getMaxMana() * 1.05)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received a permanent 5% HP and MANA regeneration bonus!")
    else
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You have already received the 5% bonus.")
    end

    -- Remove the Vibrant Egg from the player's inventory
    player:removeItem(item.itemid, 1)
    return true
end

actions.xml

<action itemid="2160" script="vibrant_egg.lua"/>

and onLogin

LUA:
function onLogin(player)
    local permBonusStorage = 10001
    if player:getStorageValue(permBonusStorage) == 1 then
        player:setMaxHealth(player:getMaxHealth() * 1.05)
        player:setMaxMana(player:getMaxMana() * 1.05)
    end
    return true
end




If something goes wrong, wait for someone more experienced to respond with the solution.
Post automatically merged:

LUA:
-- Configuration Table
local config = {
    mountId = 58, -- ID of the Sparkion mount, adjust if necessary
    permBonusStorage = 10001, -- A unique storage value to track the permanent bonus
    bonusPercent = 0.05, -- Percentage of the HP and MANA bonus
    vibrantEggId = 2160 -- ID of the Vibrant Egg
}

-- Action for the Vibrant Egg
local vibrant_egg = Action()

function vibrant_egg.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- Check if the player already has the Sparkion mount
    if player:hasMount(config.mountId) then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You already have the Sparkion mount.")
        return true
    end

    -- Grant the Sparkion mount to the player
    player:addMount(config.mountId)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have received the Sparkion mount and a 5% bonus to HP and MANA.")

    -- Add the permanent 5% HP and MANA bonus if not already given
    if player:getStorageValue(config.permBonusStorage) ~= 1 then
        player:setStorageValue(config.permBonusStorage, 1)
        
        -- Calculate the new max HP and MANA values
        local newMaxHealth = math.floor(player:getMaxHealth() * (1 + config.bonusPercent))
        local newMaxMana = math.floor(player:getMaxMana() * (1 + config.bonusPercent))

        -- Store the new max HP and MANA values in separate storage entries
        player:setStorageValue(config.permBonusStorage .. "_MAX_HEALTH", newMaxHealth)
        player:setStorageValue(config.permBonusStorage .. "_MAX_MANA", newMaxMana)

        player:setMaxHealth(newMaxHealth)
        player:setMaxMana(newMaxMana)
    end

    -- Remove the Vibrant Egg from the player's inventory
    player:removeItem(item.itemid, 1)
    return true
end

vibrant_egg:id(config.vibrantEggId) -- ID of the Vibrant Egg
vibrant_egg:register() -- Register the action
 
Last edited:
Back
Top