• 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 Error in Function (Metamethod)

  • Thread starter Deleted member 141899
  • Start date
D

Deleted member 141899

Guest
Hello, can someone help me with this script to work in tfs 1.0?

I tried to put "local attacker = Monster(cid)" but dont works..

Code:
function onChangeHealth(cid, creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)

   if attacker:getMonster() and attacker:getName() == "Zumbi" and creature:isPlayer() then

Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/ZE_creaturescript.lua:onChangeHealth
data/creaturescripts/scripts/ZE_creaturescript.lua:9: attempt to index local 'attacker' (a nil value)
stack traceback:
   [C]: in function '__index'
   data/creaturescripts/scripts/ZE_creaturescript.lua:9: in function <data/creaturescripts/scripts/ZE_creaturescript.lua:6>
 
Last edited by a moderator:
You cant use Monster(cid) as you dont have any cid declared, should be Monster(attacker), but, is that your 6th line of the script?
 
Yes, i tried to use monster(attacker) also, yes, its 6th line, I forgot to mention that tried already cid declare the function and also did not work
 
Ok, so i guess those two lines are lines 6 and 9? As your error is referring those lines.

Are you sure onChangeHealth exists? I think its onHealthChange.
 
Look the full creaturescript:

Code:
-- <event type="healthchange" name="Zumbi_Event" script="ZE_creaturescript.lua"/>
-- add event 'Zumbi_Event' in login.lua

dofile('data/lib/ZE_config.lua')

function onChangeHealth(cid, creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)


local attacker = Monster(attacker)
local creature = Player(cid)
   if attacker:getName() == "Zumbi" and creature:isPlayer() then
   
     if (getGlobalStorageValue(ZE_PLAYERS) > 0) then
       if (getGlobalStorageValue(ZE_PLAYERS) == 1) then
         creature:say("ZUMBI EVENT WIN!", TALKTYPE_MONSTER_SAY)
         setGlobalStorageValue(ZE_PLAYERS, 0)
         Game.broadcastMessage("The player "..creature:getName().." is win Zumbi Event.", MESSAGE_STATUS_WARNING)
         creature:sendTextMessage(MESSAGE_STATUS_WARNING, ZE_MSG_WIN)
         creature:addItem(ZE_REWARD, ZE_REWARD_COUNT)
       else
         attacker:say("DEAD!", TALKTYPE_MONSTER_SAY)

         local summon_position = creature:getPosition()
         Game.createMonster("Zumbi", summon_position)
       end

       setGlobalStorageValue(ZE_PLAYERS, getGlobalStorageValue(ZE_PLAYERS) - 1)
     end

     creature:teleportTo(creature:getTown():getTemplePosition())
   end

  return primaryDamage, primaryType, -secondaryDamage, secondaryType
end

i needed to change "healthchange" to "changehealth" because my tfs 1.0 is old..
You can see in code that i tried all: local monster and local player and not works
Ignore the lines with local =, i added after error
 
Oh i see.

Well, as you say, in TFS 1.0 its onChangeHealth. Then:

1.- Remove the cid thing on the parameters (function onChangeHealth(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin) )
Creature always refers to the creature being attacked.
Attacker always refers to the creature attacking.

You registered the event on players, right?

make : if attacker ~= nill and attacker::getName() == 'Zumbi' and creature::isPlayer() then.
 
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/ZE_creaturescript.lua:onChangeHealth
data/creaturescripts/scripts/ZE_creaturescript.lua:11: attempt to index local 'creature' (a nil value)
stack traceback:
   [C]: in function '__index'
   data/creaturescripts/scripts/ZE_creaturescript.lua:11: in function <data/creaturescripts/scripts/ZE_creaturescript.lua:6>
 
Register the event to the monster and the player.

To register the event on the monster, add before flag tag:
<script>
<event name="Zumbi_Event"/>
</script>

To register the event to the players, add on login.lua
player:registerEvent("Zumbi_Event)
 
Eh?
What you want to do?
If player takes damage by zombie then player teleports away?
or when player makes damage to zombie then player teleports away?
Or something else.. Be more informative.

Or you got it working now, expect the teleportation?
 
Back
Top