• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

onDeath Script clear tables..

MadMOOK

Hoo
Joined
Apr 20, 2011
Messages
802
Reaction score
44
Here is the creaturescript..
Code:
function onDeath(cid, corpse)
if isPlayer(cid) then
  for k,v in pairs(instance_config) do
   local instance = instance_config[k]
   if isInArray(instance.players, getPlayerName(cid)) then
    clearInstance(k, true)
    break
   end
  end
end
return true
end

Here is the function in functions.lua
Code:
function clearInstance(id)
   local instance = instance_config[id]
   if instance.players ~= nil then
     for k,v in pairs(instance.players) do
       if v ~= nil then
         local player = v
         if isPlayer(player) then
           doTeleportThing(player, instance.exitPos)
           doPlayerSendCancel(player, "Time has run out.")
         end
       end
     end
     instance.players = nil
   end
end

Here is my error when they die
[14:11:29.918] [Error - CreatureScript Interface]
[14:11:29.928] data/creaturescripts/scripts/InstanceDeath.lua:onDeath
[14:11:29.940] Description:
[14:11:29.946] data/lib/050-function.lua:253: bad argument #1 to 'ipairs' (table
expected, got nil)
[14:11:29.963] stack traceback:
[14:11:29.968] [C]: in function 'ipairs'
[14:11:29.976] data/lib/050-function.lua:253: in function 'isInArray'
[14:11:29.988] data/creaturescripts/scripts/InstanceDeath.lua:5: in function <d
ata/creaturescripts/scripts/InstanceDeath.lua:1>
 
Code:
function onDeath(cid, corpse)
     if isPlayer(cid) then
         for k,v in pairs(instance_config) do
             local instance = instance_config[k]
             if instance.players ~= nil then
                 if isInArray(instance.players, getPlayerName(cid)) then
                     clearInstance(k, true)
                     break
                 end
             end
         end
     end
     return true
end
 
What I did is check if instance.players is not nil, if it is nil, it gives that error.
The other script should make it not nil by setting it to a table and inserting the player ids to the table.
 
The other script should set instance.players to a table since it starts with nil, it is set to a table to insert the player ids, then with the function clearInstance it's set to nil again.
If it isn't set to a player table when it's supposed to do that, then the problem is at the other script, what I added just prevents giving that error when instance.players is nil.
 
What doesn't work? What is the expected result, clearing of the instance?
Like Limos said, instance_config[k].players should be initialized as {}, an empty table. I assume a different script fills that table with playername strings when they enter the instance or something like that.
If it doesn't do that, then it's at fault and you need to post more of the code.
 
Back
Top