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

Solved stopEvent on death.

whitevo

Feeling good, thats what I do.
Joined
Jan 2, 2015
Messages
3,452
Solutions
1
Reaction score
625
Location
Estonia
Almost perfectly working Script
Script purpose is to remove addEvents before you die.

playerPrepDeath.lua (in creaturescripts, don't forget to register it)
Code:
function onPrepareDeath(creature, killer)
  for i=1, #fire do
  stopEvent(fire[i])
  end
  for j=1, #energy do
  stopEvent(energy[j])
  end
  for x=1, #death do
  stopEvent(death[x])
  end
  for c=1, #poison do
  stopEvent(poison[c])
  end
  return true
end
global.lua
Code:
-- fields
fire={}
energy={}
death={}
poison={}

function fireFieldDamage(cid, eleType, damage, effect, interval, x)
  stopEvent(fire[x])
  fire[x] = addEvent(function() doTargetCombatHealth(0, cid, eleType, damage, damage, effect) end, x*interval)
end

part of The field system where i call for the global function.
Code:
                if fields[k].formula == "fire" then
                    while minDam > 25 do
                        table.insert(minDam2, minDam/2)
                        minDam = minDam/2
                        table.insert(maxDam2, maxDam/2)
                        maxDam = maxDam/2
                    end
                    if #minDam2 > 0 then
                        for x = 1, #minDam2 do
                            fireFieldDamage(cid, fields[k].eleType, minDam2[x], fields[k].effect, fields[k].interval, x)
                        end
                    end
                end
 
Last edited:
actually its not solved..
something weird happens. last time i forgot to register the event and i guess i didn't wait long enough for error to come.

Anyway, registered the prepare for death and here what happens now:
when player takes fatal damage from Field, THEY DON'T DIE!
i think because the damage comes from addEvent.
and if i add this to prepareDeath
doCreatureAddHealth(creature, -getCreatureMaxHealth(creature))
my server crashes.

How can i make Players die when they die?

Edit: that question thought xD
 
ah i missed Return true.
But this did not help at all..
Now the old error is back.
in timer event called from:unknown scriptfile:>blablabla> creature not found.

How do i stop the events on players when they are about to die?
stopEvent is not helping..
 
You are registering the events in the table wrong.
Everytime the event is launched you overwrite it, which doesn't work at all

You'd have to do it like this:
Code:
local id = creature:getId()
fire[id] = addEvent(....) -- we are creating in the table an extra instance for the creature id.
stopEvent(fire[id]) -- we are stopping the event for this certain creature id.

You can also check if an event is still alive with:
Code:
 if not fire[id] then
-- happens if the event for this creature is not valid anymore
end
 
Last edited:
You are registering the events in the table wrong.
Everytime the event is launched you overwrite it, which doesn't work at all

You'd have to do it like this:
Code:
local id = creature:getId()
fire[id] = addEvent(....) -- we are creating in the table an extra instance for the creature id.
stopEvent(fire[id]) -- we are stopping the event for this certain creature id.

You can also check if an event is still alive with:
Code:
 if not fire[id] then
-- happens if the event for this creature is not valid anymore
end
yup, realised it, trying to figure out the way to do it right now, so the codes will look good.
 
alright, got it working, going to update script in post1 with working script.
Well kinda working, i still get error when i die from adding event with replacing event. But its much rarer thing to happen. than simply dieing while addEvent on.
And also it nerfs Fields alot what is nice.
 
it gives the error because you don't check if the event is still valid when you try to stop it.
Code:
for i=1, #fire do
if fire[i] then
stopEvent(fire[i])
end
end
this wont throw an error now
 
it gives the error because you don't check if the event is still valid when you try to stop it.
Code:
for i=1, #fire do
if fire[i] then
stopEvent(fire[i])
end
end
this wont throw an error now
this doesn't help it changes nothing.
 
Code:
-- fields
fire = {}
energy = {}
death = {}
poison = {}


function onPrepareDeath(creature, killer)
    local damageTypes = {fire, energy, death, poison}
    for i = 1, damageTypes do
        stopEvents(damageTypes[i])
    end
    return true
end


function stopEvents(event)
    if next(event) then
        for i = 1, #event do
            stopEvent(event[i])
        end
    end
end

if fields[k].formula == "fire" then
    local i = 1
    while minDam > 25 do
        minDam = minDam / (2 ^ i)
        table.insert(minDam2, minDam)
        i = i + 1
    end
    if #minDam2 > 0 then
        for x = 1, #minDam2 do
            fireFieldDamage(cid, fields[k].eleType, minDam2[x], fields[k].effect, fields[k].interval, x)
        end
    end
end


function fireFieldDamage(cid, eleType, damage, effect, interval, x)
    if isPlayer(cid) then
        fire[x] = addEvent(doTargetCombatHealth, x * interval, 0, cid, eleType, damage, damage, effect)
    end
end
 
Fixed the problem by adding:
Global.lua
playerDeath = false

onPreapreDeath.lua
playerDeath = true

onLogin.lua
playerDeath = false

fields.lua
If playerDeath == true then (before i pass the data to do addevents)
....
 
Back
Top