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

Lua Creature OnDeath cast spell?

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,811
Solutions
582
Reaction score
5,370
The Forgotten Server, version 0.3.7_SVN (Crying Damson)

I want to make a death animation for some creatures.
Easiest and most functional way seems to be to make the creature cast a spell at the time of death.
Can easily make the animation, and make it hit no damage.. or even make it hit damage!
But unsure how to do so.

I can use either..
Code:
function onKill(cid, target, damage, flags)
Code:
function onDeath(cid, corpse, killer)
Unsure how to define the position of the creatures death, and I don't know how to force cast a spell.
Looked around found some OnKill portals and such, but haven't found anything regarding casting a spell.
If using
Code:
local position = getCreaturePosition(cid)
Would this get the position of the creature casting the spell, or the person that dealt damage to the creature?
I believe it would get the position where the creature died, or 'is dying', so now I'm left with casting the spell, but no idea how to execute the spell.
Soo I'm here, anyone know how to force cast a spell? :p
Code:
function onDeath(cid, corpse, killer)
  local position = getCreaturePosition(cid)
   -- castSpell = "Butterflies&Rainbows"
  return TRUE
end
Any help is appreciated. :p

Xikini
 
Have a hunk of messy code that may not work :p not tested.
4x holy orb's shoot from the corpse.
Text appears above corpse "Orange".
Effect at the corpse aswell.

Code:
function onDeath(cid, corpse, deathList)
--Edit Start--
local DistanceEffect = CONST_ANI_HOLY
local MonsterEffect = CONST_ME_HOLY
local Message = 'Killed'
local position = getThingPos(cid)
--Edit End--

        doSendAnimatedText(getThingPos(cid), Message, math.random(255))
        doSendMagicEffect(getThingPos(cid), MonsterEffect)
        doSendDistanceShoot(position, {x = position.x + 3, y = position.y + 3, z = position.z}, DistanceEffect)
        doSendDistanceShoot(position, {x = position.x - 3, y = position.y - 3, z = position.z}, DistanceEffect)
        doSendDistanceShoot(position, {x = position.x + 3, y = position.y - 3, z = position.z}, DistanceEffect)
        doSendDistanceShoot(position, {x = position.x - 3, y = position.y + 3, z = position.z}, DistanceEffect)
end
    return true
end

Its from this.
t3NBOge.png
 
Last edited:
Maybe?
Code:
function onDeath(cid, corpse, killer)
  local position = getCreaturePosition(cid)
  local spellName = "Butterflies&Rainbows"
  doCreatureCastSpell(cid, spellName)
  return TRUE
end
 
Last edited:
Have a hunk of messy code that may not work :p not tested.
4x holy orb's shoot from the corpse.
Text appears above corpse "Orange".
Effect at the corpse aswell.

Code:
function onDeath(cid, corpse, deathList)

--Edit Start--
local DistanceEffect = CONST_ANI_HOLY
local MonsterEffect = CONST_ME_HOLY
local Message = 'Killed'
local position = getThingPos(cid)
--Edit End--

        doSendAnimatedText(getThingPos(cid), Message, math.random(255))
        doSendMagicEffect(getThingPos(cid), MonsterEffect)
        doSendDistanceShoot(position, {x = position.x + 3, y = position.y + 3, z = position.z}, DistanceEffect)
        doSendDistanceShoot(position, {x = position.x - 3, y = position.y - 3, z = position.z}, DistanceEffect)
        doSendDistanceShoot(position, {x = position.x + 3, y = position.y - 3, z = position.z}, DistanceEffect)
        doSendDistanceShoot(position, {x = position.x - 3, y = position.y + 3, z = position.z}, DistanceEffect)
end
    return true
end

Its from this.
t3NBOge.png
The OnDeath is definitely what I'm planning however I don't want to paste / edit the spell for each monster I want it to apply to. :p
Maybe?
Code:
function onDeath(cid, corpse, killer)
  local position = getCreaturePosition(cid)
  local spellName = "Butterflies&Rainbows"
  doCreatureCastSpell(cid, spellName)
  return TRUE
end
I think this in itself is what I was looking for.
Code:
doCreatureCastSpell(cid, spellName)
The rest is playing around with how to trigger it. :p
I'll tinker around for awhile and post a working script later. :D

-- Edit, Update.

Not working code..
No matter what I use I cannot get it to trigger a spell or area combat.
Definitely need some help at this point. :p

I have tried all three types of death that I know of, and both scripts run into the same problem, they simply won't cast or execute the damaging part of the script.
The orange text definitely displays, so the script is working.. but I get no animations after death.. nor do I get error's while loading or killing the monster.
Code:
  function onDeath(cid, corpse)
  function onPrepareDeath(cid)
  function onKill(cid, target, damage, flags)
   -- ID of effect to be displayed:
   local eff = 5
   -- Define area of effect here:
   local arr ={
   {0,1,1,1,0},
   {1,1,1,1,1},
   {1,1,2,1,1},
   {1,1,1,1,1},
   {0,1,1,1,0}
   }
   -- Minimum and maximum damage:
   local min = 10
   local max = 20

   local name = getCreatureName(target):lower()
   if name == 'bum' then
     doCreatureSay(cid, 'You have defeated ' .. name .. '.', TALKTYPE_ORANGE_1)
     doAreaCombatHealth(cid, COMBAT_FIREDAMAGE, getThingPos(cid), arr, -min, -max, eff)
   end
   return true
end
Code:
  function onDeath(cid, corpse)
  function onPrepareDeath(cid)
  function onKill(cid, target, damage, flags)
   local name = getCreatureName(target):lower()
   if name == 'bum' then
     doCreatureSay(cid, 'You have defeated ' .. name .. '.', TALKTYPE_ORANGE_1)
     doPlayerCastSpell(cid, "exori")
   end
   return true
end
 
Last edited:
Just use the script i supplied you it should work pretty good if you want it to deal damage add it
I just tried your script, had an extra end, didn't work.
Tried it with checking for 'bum' didn't work either..
I know animated text didn't work, and again I used the docreaturesay in order to confirm if the script was running or not..
Kind of running out of idea's for this.
 
You don't need to cast a spell if you just want to send an effect.

Go to creaturescripts.xml and add this:

<event type="death" name="deathEffect" event="script" value="deathEffect.lua"/>

In creaturescripts/scripts make a file deathEffect.lua and paste this into it:

function onDeath(cid, corpse, killer)
local eff = 6 -- Enter number of effect here
doSendMagicEffect(getCreaturePosition(cid), eff)
return TRUE
end

Now, to make some monster use this script, go to that monster's XML file and add this:

<script>
<event name="deathEffect"/>
</script>
 
You don't need to cast a spell if you just want to send an effect.

Go to creaturescripts.xml and add this:

<event type="death" name="deathEffect" event="script" value="deathEffect.lua"/>

In creaturescripts/scripts make a file deathEffect.lua and paste this into it:

function onDeath(cid, corpse, killer)
local eff = 6 -- Enter number of effect here
doSendMagicEffect(getCreaturePosition(cid), eff)
return TRUE
end

Now, to make some monster use this script, go to that monster's XML file and add this:

<script>
<event name="deathEffect"/>
</script>
Your script works perfectly..
But how can I deal damage to everything surrounding the monster, and send effects to all those positions?
When I try changing anything it shows 'creature not found' :(
Code:
local arr ={
  {0,1,1,1,0},
  {1,1,1,1,1},
  {1,1,2,1,1},
  {1,1,1,1,1},
  {0,1,1,1,0}
  }
 
Try this:

function onDeath(cid, corpse, killer)
local eff = 6 -- Enter number of effect here
local arr ={
{0,1,1,1,0},
{1,1,1,1,1},
{1,1,2,1,1},
{1,1,1,1,1},
{0,1,1,1,0}
}
doAreaCombatHealth(cid, COMBAT_FIREDAMAGE, getCreaturePosition(cid), arr, -50, -100, eff)
return TRUE
end
 
Try this:

function onDeath(cid, corpse, killer)
local eff = 6 -- Enter number of effect here
local arr ={
{0,1,1,1,0},
{1,1,1,1,1},
{1,1,2,1,1},
{1,1,1,1,1},
{0,1,1,1,0}
}
doAreaCombatHealth(cid, COMBAT_FIREDAMAGE, getCreaturePosition(cid), arr, -50, -100, eff)
return TRUE
end
It sends the effect on top of the creatures body, but nowhere else.
 
I have this is creaturescripts.xml
Code:
<event type="death" name="deathEffect" event="script" value="deathEffect.lua"/>
I have this in deathEffect.lua
Code:
function onDeath(cid, corpse, killer)
local eff = 6
local arr ={
{0,1,1,1,0},
{1,1,1,1,1},
{1,1,2,1,1},
{1,1,1,1,1},
{0,1,1,1,0}
}
doAreaCombatHealth(cid, COMBAT_FIREDAMAGE, getCreaturePosition(cid), arr, -50, -100, eff)
return TRUE
end
I have this as the creature
Code:
<?xml version="1.0" encoding="UTF-8"?>
<monster name="barrel" nameDescription="barrel" race="undead" experience="0" speed="0" manacost="0">
   <health now="1" max="1"/>
   <look typeex="5787" corpse="5968"/>
   <targetchange interval="2000" chance="100"/>
   <strategy attack="100" defense="0"/>
   <flags>
     <flag summonable="0"/>
     <flag attackable="1"/>
     <flag hostile="1"/>
     <flag illusionable="0"/>
     <flag convinceable="0"/>
     <flag pushable="0"/>
     <flag canpushitems="0"/>
     <flag canpushcreatures="1"/>
     <flag targetdistance="1"/>
     <flag staticattack="90"/>
     <flag runonhealth="100"/>
     <flag hidename="1"/>
   </flags>
   <attacks>
   <attack name="melee" interval="500" skill="1" attack="1"/>
  <attack name="melee" interval="500" skill="1" attack="1"/>
   </attacks>
   <defenses armor="0" defense="0">
     <defense name="wizard healing" interval="2000" chance="100" min="20000" max="40000">  <!-- lvl 10 -->
       <attribute key="areaEffect" value="blueshimmer"/>
     </defense>
     <defense name="wizard healing" interval="2000" chance="100" min="40000" max="80000">  <!-- lvl 70 -->
       <attribute key="areaEffect" value="blueshimmer"/>
     </defense>
   </defenses>
   <script>
     <event name="deathEffect"/>
   </script>
   <loot>
     <item id="2395" countmax="1" chance="100"/>
     <item id="2395" countmax="1" chance="100"/>
     <item id="2395" countmax="1" chance="100"/>
   </loot>
</monster>
I reloaded both monsters and creaturescripts, and also restarted server, just to check.
It only sends the effect over the body currently

-- Edit

Been trying many more things, and as far as I can tell the script doesn't care whether 'arr' exists or not.

I tried this, and got the same result as above.
Code:
function onDeath(cid, corpse, killer)
local eff = 6
local arr ={
{0,1,1,1,0},
{1,1,1,1,1},
{1,1,2,1,1},
{1,1,1,1,1},
{0,1,1,1,0}
}
doAreaCombatHealth(cid, COMBAT_FIREDAMAGE, getCreaturePosition(cid), gsgeadgedfg, -50, -100, eff)
return TRUE
end
No error's and puts the flame on top of the body. :D
It's simply not loading the area combat at all.
 
Last edited:
Hm, can't seem to figure out why that wouldn't work for you if it works for me. Could be some difference in the code of the area combat. If you want, you could take a bit different approach and use getSpectators to send a damaging shot to everyone caught in xxx area around the dying creature?
 
Back
Top