From ef51dc8087edee3346c9ac9f61c69bcbb3a8d86f Mon Sep 17 00:00:00 2001 From: shennetsind Date: Sun, 23 Jun 2013 17:41:46 -0300 Subject: Fixed Bug #7420 http://hercules.ws/board/tracker/issue-7420-killing-the-npc/ Special Thanks to kyeme, frost, ossi0110 Signed-off-by: shennetsind --- src/map/script.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'src/map/script.c') diff --git a/src/map/script.c b/src/map/script.c index 481cb5870..a61487332 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -2783,28 +2783,31 @@ struct script_state* script_alloc_state(struct script_code* rootscript, int pos, /// Frees a script state. /// /// @param st Script state -void script_free_state(struct script_state* st) -{ - if(st->bk_st) {// backup was not restored - ShowDebug("script_free_state: Previous script state lost (rid=%d, oid=%d, state=%d, bk_npcid=%d).\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid); - } - - if( st->sleep.timer != INVALID_TIMER ) - iTimer->delete_timer(st->sleep.timer, run_script_timer); - script_free_vars(st->stack->var_function); - script->pop_stack(st, 0, st->stack->sp); - aFree(st->stack->stack_data); - ers_free(script->stack_ers, st->stack); - if( st->script && st->script->script_vars && !db_size(st->script->script_vars) ) { - script_free_vars(st->script->script_vars); - st->script->script_vars = NULL; - } - st->stack = NULL; - st->pos = -1; - idb_remove(script->st_db, st->id); - ers_free(script->st_ers, st); - if( --script->active_scripts == 0 ) { - script->next_id = 0; +void script_free_state(struct script_state* st) { + if( idb_exists(script->st_db,st->id) ) { + if(st->bk_st) {// backup was not restored + ShowDebug("script_free_state: Previous script state lost (rid=%d, oid=%d, state=%d, bk_npcid=%d).\n", st->bk_st->rid, st->bk_st->oid, st->bk_st->state, st->bk_npcid); + } + + if( st->sleep.timer != INVALID_TIMER ) + iTimer->delete_timer(st->sleep.timer, run_script_timer); + if( st->stack ) { + script_free_vars(st->stack->var_function); + script->pop_stack(st, 0, st->stack->sp); + aFree(st->stack->stack_data); + ers_free(script->stack_ers, st->stack); + st->stack = NULL; + } + if( st->script && st->script->script_vars && !db_size(st->script->script_vars) ) { + script_free_vars(st->script->script_vars); + st->script->script_vars = NULL; + } + st->pos = -1; + idb_remove(script->st_db, st->id); + ers_free(script->st_ers, st); + if( --script->active_scripts == 0 ) { + script->next_id = 0; + } } } -- cgit v1.2.3-60-g2f50