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

tfs 1.2 spell Help

Doomdice

The N00betarian
Joined
Jul 20, 2009
Messages
659
Reaction score
108
Location
Indiana
Code:
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
  {0, 0, 0, 1, 1, 3, 1, 1, 0, 0, 0},
  {0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
function onSay(player, words, param)
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_ICETORNADO)

function onGetFormulaValues(player, level, maglevel)
    local min = (level / 5) + (maglevel * 5.5) + 25
    local max = (level / 5) + (maglevel * 11) + 50
    return -min, -max
end

function onCastSpell(creature, var)
    return combat:execute(creature, var)
end


from looking at lua.cpp and other spell scripts any idea i dont know if i executed this script right
 
No you did not, you have onSay in there which is used for talkactions, its like you just copied and pasted what you thought you needed into a file and called it a spell :p

We'll use berserk as an example and try to explain the makeup of the script.
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true)
combat:setParameter(COMBAT_PARAM_USECHARGES, true)
combat:setArea(createCombatArea(AREA_SQUARE1X1))

function onGetFormulaValues(player, skill, attack, factor)
    local min = (player:getLevel() / 5) + (skill * attack * 0.03) + 7
    local max = (player:getLevel() / 5) + (skill * attack * 0.05) + 11
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant)
    return combat:execute(creature, variant)
end

Code:
local combat = Combat()

An instance of the Combat() metatable is generated and assigned to a table with an idenifier labeled combat, this instance only exists for the duration of this script, we know this because it has been defined with a scope of local.

Code:
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_PHYSICALDAMAGE)

Since combat is an instance of Combat() it can call upon the Combat metamethods, in this case it uses the setParameter to assign the value of COMBAT_PHYSICALDAMAGE to its index of COMBAT_PARAM_TYPE

The next three setParameter are applied the same way as the above mentioned, using its 1st parameter as the index and its 2nd as the value assigned to it

Code:
combat:setArea(createCombatArea(AREA_SQUARE1X1))
createCombatArea is passed a predefined table labeled AREA_SQUARE1X1, if you want to pass your own just replace your table with AREA_SQUARE1X1

combat then calls upon another metamethod called setArea which stores the return value of createCombatArea

Code:
function onGetFormulaValues(player, skill, attack, factor)

The onGetFormulaValues, is what is known as a callback function, this is the last thing that executes in the script.

Code:
combat:setCallback(CALLBACK_PARAM_SKILLVALUE, "onGetFormulaValues")

combat calls up the setCallback metamethod and passes "onGetFormulaValues" to the index of CALLBACK_PARAM_SKILLVALUE to be executed

Think of it like this, if CALLBACK_PARAM_SKILLVALUE were a method, "onGetFormulaValues" would be the argument

Code:
function onCastSpell(creature, variant)

onCastspell, this is an interface not a function, in some respect if we were to think in terms of a main function, this would be it, but only for spells, other aspects of the server have different interfaces for different tasks

Its 1st parameter is a creature, this is the player/monster etc.. casting the spell, variant is a position of the target if any.
Code:
return combat:execute(creature, variant)

When ever you see a return value this lets you know whatever called the thing that contains the return statement is getting control sent back to it and some kind of value(s)

Code:
combat:execute(creature, variant)

combat calls up execute to initiate all the data assigned to it..

Think of it this way, ever play street fighter?

Ryu is the combat object, he is getting his butt kicked in the ring, so he says hey i know what i can do, i'll do a hadukin.

So with that in mind he charges up his power (assigns the values to combat as explain above), and releases his built up power (combat:execute).

Example:
114567-video_games-Hadouken-memes-736x459.jpg
 
Last edited:
Back
Top