From 210e33c8b32f3bbc696e5ffd1affef65a7d66b5d Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Mon, 17 Oct 2011 23:41:13 +0200 Subject: Prevent server crash by not having beings talk after spawn for now At the moment it is the responsibility of the script to make sure any references to beings passed into script functions are valid. This means you can't schedule delayed scripts like the one making maggots say 'Roaaarrrr!!!', since the being might have been removed before the script gets executed. In the case of this bug the maggots are removed by some script code testing 'mana.monster_remove'. We should of course fix the way actor handles are used in Lua so that scripts can't end up crashing the server. Mantis-issue: 384 Reviewed-by: Yohann Ferreira --- example/serverdata/scripts/maps/desert.lua | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'example') diff --git a/example/serverdata/scripts/maps/desert.lua b/example/serverdata/scripts/maps/desert.lua index d11be2f..57b4533 100644 --- a/example/serverdata/scripts/maps/desert.lua +++ b/example/serverdata/scripts/maps/desert.lua @@ -91,17 +91,22 @@ function Tamer(npc, ch, list) mana.being_say(npc, "I will now spawn a monster for your training session.") -- Remove monsters in the area - for i, b in ipairs(mana.get_beings_in_rectangle( - mana.posX(npc) - 3 * TILESIZE, mana.posY(npc) - 3 * TILESIZE, - 6 * TILESIZE, 6 * TILESIZE)) do + for i, b in ipairs(mana.get_beings_in_rectangle(mana.posX(npc) - 3 * TILESIZE, + mana.posY(npc) - 3 * TILESIZE, + 6 * TILESIZE, 6 * TILESIZE)) do if mana.being_type(b) == TYPE_MONSTER then mana.monster_remove(b) end end local m1 = mana.monster_create("Maggot", mana.posX(ch), mana.posY(ch)) - schedule_in(0.5, function() - mana.being_say(m1, "Roaaarrrr!!!") - mana.monster_change_anger(m1, ch, 100) - end) + mana.monster_change_anger(m1, ch, 100) + + -- (The following is not safe, since the being might have been removed by + -- the time this function gets executed (especially with the above code)) + -- + --schedule_in(0.5, function() + -- mana.being_say(m1, "Roaaarrrr!!!") + -- mana.monster_change_anger(m1, ch, 100) + -- end) end -- cgit