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

MoveEvent [TFS 1.x] Spell System onEquip

underewar

Well-Known Member
Joined
Feb 9, 2013
Messages
58
Reaction score
65
Location
Brazil
GitHub
Underewarrr
Its a basic onEquip Change storage script.
If you have a magic sword your storage value will be 1 and you can use a single spell.
If value below 1 you cant use that single spell.

data/scripts/movement/xml

XML:
<movevent event="DeEquip" itemid="2400" slot="hand" function="onDeEquipItem" scripts = "yourscript.lua">
 <movevent event="Equip" itemid="2400" slot="hand" function="onEquipItem" script="yourscript.lua"/>

data/scripts/movement/yourscript.lua

Lua:
local stor = 12345 -- storage

function onEquip(cid, item, slot)
    setPlayerStorageValue(cid, stor, 1) -- já que é no callback de equipar, ele recebe o valor de ID 1 (como sendo positivo para a checagem do uso da spell)
        player:sendTextMessage(MESSAGE_INFO_DESCR, "onEquip.")
        return true
end
 
function onDeEquip(cid, item, slot)
    setPlayerStorageValue(cid, stor, -1) -- ao remover o item, ele recebe o valor de ID -1 (como sendo negativo para a checagem do uso da spell)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "onDeEquip.")
    return true
end

data/spells/script/yourscript.lua

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_WEAPONTYPE)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_USECHARGES, true)

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.02) + 4
    local max = (player:getLevel() / 5) + (skill * attack * 0.04) + 9
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(player, variant)
    if player:getStorageValue(12345) < 1 then
        player:sendCancelMessage("You can't cast the spell without using the item that allows it.")
        return false
    end
  
return combat:execute(player, variant)
end
 
The same but in Revscript, compatibility with TFS Master
data/scripts/spell_system_onequip.lua

Lua:
local stor = 12345 -- storage

local moveEvent = MoveEvent()

function moveEvent.onEquip(player, item, slot, isCheck)
    player.storage[stor] = 1
    return true
end

moveEvent:id(2400)
--moveEvent:level(lvl)
--moveEvent:magicLevel(lvl)
moveEvent:slot("hand")
--moveEvent:premium(bool)
--moveEvent:vocation(vocName[, showInDescription = false, lastVoc = false])
moveEvent:register()

local moveEvent = MoveEvent()

function moveEvent.onDeEquip(player, item, slot, isCheck)
    player.storage[stor] = -1
    return true
end

moveEvent:id(2400)
--moveEvent:level(lvl)
--moveEvent:magicLevel(lvl)
moveEvent:slot("hand")
--moveEvent:premium(bool)
--moveEvent:vocation(vocName[, showInDescription = false, lastVoc = false])
moveEvent:register()

local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_FIREDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_FIREAREA)
combat:setArea(createCombatArea(AREA_CIRCLE3X3))

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 8) + 50
    local max = (level / 5) + (magicLevel * 12) + 75
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

local spell = Spell(SPELL_INSTANT)

function spell.onCastSpell(player, variant, isHotkey)
    if player.storage[stor] < 1 then
        player:sendCancelMessage("You can't cast the spell without using the item that allows it.")
        return false
    end
    return combat:execute(player, variant)
end

spell:name("Example Spell Name")
spell:words("exori example")
spell:group("attack")
spell:vocation("sorcerer", "master sorcerer")
spell:id(24)
spell:cooldown(3 * 1000)
spell:groupCooldown(3 * 1000)
spell:level(60)
spell:mana(600)
spell:isPremium(true)
spell:needTarget(true)
spell:register()
 
And without movements script...
Is script add ITEMID this sample is for Hat of the mad [2323]


Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ENERGYAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ENERGY)

function onGetFormulaValues(player, level, maglevel)
    local min = (level / 5) + (maglevel * 1.5) + 108
    local max = (level / 5) + (maglevel * 2.3) + 180
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(cid, var)
    if not isInArray({2323}, getPlayerSlotItem(cid, CONST_SLOT_HEAD).itemid) then
        doPlayerSendCancel(cid, "You can't cast the spell without Hat of the Mad.")
        return false
    end

    return doCombat(cid, combat, var)
end
its "exori vis" spell ;)
 
Back
Top