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

Lua TFS 1.3 convert event script into spell

Icaraii

Well-Known Member
Joined
Jan 5, 2020
Messages
469
Solutions
1
Reaction score
58
Hello guys, so @Xikini made a script that increase damage when player uses certain potion. I would like to transform it into a spell, does anyone can help?

data\events\scripts\monster.lua
inside the functionfunction Monster: onSpawn(position, startup, artificial)
paste: self:registerEvent("onHealthChange_damage_buff_potion")
data\scripts\onUse_damage_buff_potion.lua
Lua:
local damageTypes = {
    [COMBAT_PHYSICALDAMAGE] = {45001, 45002}, -- {damageStorage, timeStorage}
    [COMBAT_ENERGYDAMAGE]   = {45003, 45004},
    [COMBAT_EARTHDAMAGE]    = {45005, 45006},
    [COMBAT_FIREDAMAGE]     = {45007, 45008},
    [COMBAT_ICEDAMAGE]      = {45009, 45010},
    [COMBAT_HOLYDAMAGE]     = {45011, 45012},
    [COMBAT_DEATHDAMAGE]    = {45013, 45014}
}

local buff_potions = {
    --[itemid] = {damageType, buffAmount, buffTimeInSeconds, damageTypeText}
    [1111] = {COMBAT_PHYSICALDAMAGE, 30, 60, "physical"},
    [2222] = {COMBAT_ICEDAMAGE, 30, 60, "ice"},
    [3333] = {COMBAT_HOLYDAMAGE, 30, 60, "holy"}
}

local buffPotions = Action()

function buffPotions.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local index, cur_time = buff_potions[item.itemid], os.time()
    local buff_timer = cur_time + index[3]
    local playerPosition = player:getPosition()

    -- if a buff of equal or greater damage is currently active, don't let new buff activate.
    if player:getStorageValue(damageTypes[index[1]][2]) > cur_time then
        if player:getStorageValue(damageTypes[index[1]][1]) >= index[2] then
            playerPosition:sendMagicEffect(CONST_ME_POFF, player)
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "A buff of this damage type (" .. index[4] .. ") is still active.")
            return true
        end
    end

    player:setStorageValue(damageTypes[index[1]][1], index[2])
    player:setStorageValue(damageTypes[index[1]][2], buff_timer)
    playerPosition:sendMagicEffect(CONST_ME_MAGIC_RED)
    player:sendTextMessage(MESSAGE_STATUS_SMALL, "" .. (index[4]:gsub("^%l", string.upper)) .. " damage increased by " .. index[2] .. " for " .. index[3] .. " seconds.")
    item:remove(1)
    return true
end

for k, v in pairs(buff_potions) do
    buffPotions:id(k) -- adds all itemids from table
end
buffPotions:register()


local function damageCalculator(primaryDamage, primaryType, secondaryDamage, secondaryType, playerid)
    local player = Player(playerid)
    local currentTime = os.time()

    if player:getStorageValue(damageTypes[primaryType][2]) > currentTime then
        local damageValue = player:getStorageValue(damageTypes[primaryType][1])
        local additionalDamage = damageValue > 0 and damageValue or 0
        primaryDamage = primaryDamage + additionalDamage
    end

    if player:getStorageValue(damageTypes[secondaryType][2]) > currentTime then
        local damageValue = player:getStorageValue(damageTypes[secondaryType][1])
        local additionalDamage = damageValue > 0 and damageValue or 0
        secondaryDamage = secondaryDamage + additionalDamage
    end

    return primaryDamage, secondaryDamage
end

local healthChange = CreatureEvent("onHealthChange_damage_buff_potion")

function healthChange.onHealthChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if Player(attacker) then
        local attacker_id = attacker:getId()
        primaryDamage, secondaryDamage = damageCalculator(primaryDamage, primaryType, secondaryDamage, secondaryType, attacker_id)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

healthChange:register()


local manaChange = CreatureEvent("onManaChange_damage_buff_potion")

function manaChange.onManaChange(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
    if Player(attacker) then
        local attacker_id = attacker:getId()
        primaryDamage, secondaryDamage = damageCalculator(primaryDamage, primaryType, secondaryDamage, secondaryType, attacker_id)
    end
    return primaryDamage, primaryType, secondaryDamage, secondaryType
end

manaChange:register()


local loginEvent = CreatureEvent("onLogin_damage_buff_potion")
loginEvent:type("login")

function loginEvent.onLogin(player)
    player:registerEvent("onHealthChange_damage_buff_potion")
    player:registerEvent("onManaChange_damage_buff_potion")
    return true
end

loginEvent:register()
 
Last edited:
 
How do I put the display you use for example this:

data\events\scripts\monster.lua
 
thank you aswel. Both of you have the best script, I'm using so many scripts of both of you
Post automatically merged:

well, about this script, can you guys convert to a spell that last for 10 seconds?
 
Last edited:
Back
Top