Ir para conteúdo
  • 0

TFS 1.3 converter event script para spell


Icaro Simoes

Pergunta

TFS 1.3

 

Olá amigos do TK, gostaria de pedir uma ajuda para converter o script a seguir em uma spell.

 

data\events\scripts\monster.lua

Dentro da função:

function Monster: onSpawn(position, startup, artificial)

Colar:

self:registerEvent("onHealthChange_damage_buff_potion")

data\scripts\onUse_damage_buff_potion.lua

 

Citar

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()

O código acima está em .lua

Gostaria de transformar esse script em uma spell.

O script funciona da seguinte forma, quando o player usa a poção, ele aumenta o dano dele.

Link para o comentário
Compartilhar em outros sites

0 respostass a esta questão

Posts Recomendados

Até agora não há respostas para essa pergunta

  • Quem Está Navegando   0 membros estão online

    • Nenhum usuário registrado visualizando esta página.
×
×
  • Criar Novo...