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

[1.0] Custom Curse Spell

Red

Cyntara.org
Staff member
Global Moderator
Premium User
Joined
Aug 9, 2008
Messages
4,455
Solutions
2
Reaction score
921
Location
United States
Hey guys, two days in a row, I'm on a roll!

Basically, the spell works as intended. But if the target dies / logs out the server segfaults.
I was wondering if anyone had any ideas.

Code:
local function curse(cid)
   local creature = Creature(cid)
   if not creature then
     return true
   end

   doTargetCombatHealth(0, cid, COMBAT_HOLYDAMAGE, -1000, -1000, CONST_ME_HOLYDAMAGE)
end

function onCastSpell(cid, var)
   local player = Player(cid)
   if not player then
     return true
   end

   if exhaustion.get(cid, 2003) then
     player:sendCancelMessage("Corruption is still in effect!")
     player:getPosition():sendMagicEffect(CONST_ME_POFF)
     return false
   end

   local target = player:getTarget()
   local enemy = Creature(target)
   local ticks = 10
   local interval = 2000
   for i = 1, ticks do
     addEvent(curse, i * interval, enemy)
   end

   local enemyPos = Position(enemy:getPosition())
   local playerPos = player:getPosition()
   if enemyPos:isSightClear(playerPos, true) then
     playerPos:sendDistanceEffect(enemyPos, CONST_ANI_SMALLHOLY)
     enemyPos:sendMagicEffect(CONST_ME_HOLYDAMAGE)
   end

   if enemy:isPlayer() then
     enemy:sendTextMessage(MESSAGE_DAMAGE_RECEIVED, "You have been cursed.")
   end
   enemy:say("Cursed!", TALKTYPE_ORANGE_1)
   exhaustion.set(cid, 2003, ((interval * ticks) / 1000))
   return false
end

In return, the code will be available for everyone.
Red
 
Back
Top