• 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.X+ [TFS 1.3 - MonsterSpell] - How to Use MonsterSpell to Get an Existing Spell to add in MonsterType:addAttack(Spell)?

Yan18

Member
Joined
Jun 14, 2014
Messages
104
Solutions
3
Reaction score
17
Hello people!

As the title said, how can I use the function MonsterSpell to get a Spell and add in a monster by MonsterType:addAttack(Spell)?

I want to add spells not contained in xml from monster that respawns.
 
MonsterSpell is an class that was only designed to add spells to MonsterTypes.
It is recommended that these classes and methods be used only once at server startup or reload system.

Keep in mind that if your code looks like this:
Lua:
local ec = EventCallback
function ec.onSpawn(monster, position, startup, artificial)
    if monster:getName() == "Rotworm" then
        local spell = MonsterSpell()
        -- ...
        monster:getType():addAttack(spell)
    end
    return true
end
ec:register(--[[-1]])
then this will not work, since you would be adding 1 spell for each rotworm spawned and the end result would be rotworms with n spells of the same type

MonsterType affects all monsters of the same type!
 
Based on the above explanation, a possible work-around would be creating 1 spell that holds multiple spells inside of it, which are separated out based on a storage value.

You give the storage value to the monster via onSpawn, and it would then trigger only that 'spell' inside of the multi-spell, since each spell would be based on the storage of that particular monster.
 
Back
Top