TFS 1.X+ Crash on /reload spell when spell is casting(addEvent)

kubernik

Member
Joined
Jul 4, 2014
Messages
46
Best answers
4
Reaction score
9
Hello, i have "little" problem..

Well... When i'm casting spell who have addEvent for example:

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_ENERGYDAMAGE)
setCombatParam(combat, COMBAT_PARAM_EFFECT, 15)
setCombatArea(combat, createCombatArea({
{1, 2}
}))
function Spell(level, maglevel)
   local min = -(level * 5.0+ maglevel * 12 +50)
   local max = -(level * 5.0+ maglevel * 13 +50)
   return min, max
end
setCombatCallback(combat1, CALLBACK_PARAM_LEVELMAGICVALUE, "Spell")

function onCastSpell(cid, var)
    addEvent(doPlayerSay, 1000*1, cid, "test!", TALKTYPE_ORANGE_1)
    addEvent(doPlayerSay, 1000*2, cid, "test!", TALKTYPE_ORANGE_1)
    addEvent(doCombat, 1000*3,  cid, combat, var)
    return true
end
It is all okay, but when i do /reload spell when doCombat cannot be executed then i got crash:


When i reload it instantly then i got

test!
test!
crash

Maybe someone know solution for that, or how to clean spells addEvent on reload spells? :(
 

Nekiro

Support Team
Support Team
Joined
Sep 7, 2015
Messages
1,921
Best answers
81
Reaction score
700
You are passing object (combat variable) which is getting reinitialized so the old one is discarded which leads to the crash. Also your code does not look like 1.x, you are using 0.x methods. Try using Combat.execute(creature, combat, var)
 
OP
kubernik

kubernik

Member
Joined
Jul 4, 2014
Messages
46
Best answers
4
Reaction score
9
@Nekiro
Yea, im using old code, because i like it xd i have in lib compat.lua something like this:
Code:
function doCombat(cid, combat, var) return combat:execute(cid, var) end
for all function soo.. it work fine.

im trying with tfs 1.x code:

Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_ICEDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_GIANTICE)
combat:setFormula(COMBAT_FORMULA_LEVELMAGIC, -4.5, -400, -4.0, -400)

local function executeCombat(cid, var)
    local creature = Creature(cid)
    if creature then
        combat:execute(creature, var)
    end
end

function onCastSpell(creature, variant)
    combat:execute(creature, variant)
    addEvent(executeCombat, 1000*2, creature, variant)
    return true
end
And... same here. :/
 

Delusion

Divine Intellect
Support Team
Joined
Feb 14, 2015
Messages
5,220
Best answers
508
Reaction score
2,849
Just stop reloading on a live server; if you need to update changes it's best to restart.
 
OP
kubernik

kubernik

Member
Joined
Jul 4, 2014
Messages
46
Best answers
4
Reaction score
9
Ym.. and this is a solution? XD
in older version i can reload in live, but here i can't, because i get crash, lol.

Whatever..

I will run the server live and it turns out that some spell does not work properly, then I will have to turn off the server by such a small thing, it makes no sense...
 
OP
kubernik

kubernik

Member
Joined
Jul 4, 2014
Messages
46
Best answers
4
Reaction score
9
@Nekiro
1. You are passing object (combat variable) which is getting reinitialized so the old one is discarded which leads to the crash.
-I don't know how to do it differently. :/

2. Also your code does not look like 1.x, you are using 0.x methods. Try using Combat.execute(creature, combat, var)
-i just do it like you see above, but it changed nothing.
* if you meant specifically to call it: Combat.execute(creature, combat, var) it make crash instantly.
 

andu

Sold 649 scripts, 25 maps and 9 events!
Joined
Aug 7, 2009
Messages
923
Best answers
13
Reaction score
280
Almost in all cases you cannot use combat with addevent, doesn't matter it's 0.3, 0.4 or 1.0+ tfs.
If you want to do more advenced spells, you should learn how to avoid using combat function. Maybe your script is quite simple and based on what you really need it can be done with combat function. But becouse we don't know what you have in your xml file we don't know what your combat's variant stands for. Creature? Target? Direction? Selftarget? Position? Maybe param?

I converted your script to version w/o combat function. Not sure about doAreaCombatDamage and area is properly configured.

Lua:
local AREA = {
    {1, 2}
}

local function doTalkSomethingBlaBla(cid, text, text_type)
    local player = Player(cid)
    if player then return cid:say(text, text_type) end
    return false
end

local function letsDoMagics(cid, min, max)
    local player = Player(cid)
    if player then
        return doAreaCombatDamage(0, cid, COMBAT_ENERGYDAMAGE, AREA, -min, -max, 15) 
    end
    return false
end

function onCastSpell(cid, var)
-- var = ?
    local level, maglevel = cid:getLevel(), cid:getMagicLevel()
    local min = -(level * 5.0+ maglevel * 12 +50)
    local max = -(level * 5.0+ maglevel * 13 +50)
    addEvent(doTalkSomethingBlaBla, 1000*1, cid:getId(), "test!", TALKTYPE_ORANGE_1)
    addEvent(doTalkSomethingBlaBla, 1000*2, cid:getId(), "test!", TALKTYPE_ORANGE_1)
    addEvent(letsDoMagics, 1000*3,  cid:getId(), min, max)
    return true
end
 
Top