Need help debugging a script

notdefix

First time out of the vault
Hello,

I've a script that is supposed to automatically open a jammed door, if the player is successful at unjamming it.

The script:
Code:
/*
    Copyright 1998-2003 Interplay Entertainment Corp.  All rights reserved.
*/

/*
        Name: Jammed Airlock Door
        Location: Klamath Toxic Caves
        Description: The airlock door the player needs to unjam

        Log:
           Please note any changes that have been made to the file in Updated. Then comment
           the code which you have changed/altered/commented out. Please, do not delete any
           code which was written.

           Created:

           Updated:
*/

/* Include Files */

/* Note, the Following Lines need to be in this order so that
   the script will be compilable. The define Name is referenced
   in a module from define.h and used in command.h. Please do
   not change the ordering.
        -rwh2   11/13/97
*/
#include "..\headers\define.h"
#include "..\headers\Klatoxcv.h"

#define NAME                    SCRIPT_KCJAMMDD

#include "..\headers\command.h"

/* Defines and Macros */

#define DOOR_STRENGTH                   2       // Number of explosions needed to destroy this door
#define CROWBAR_BONUS                   -2      // Strenght bonus when using a crowbar
#define CROWBAR_STRAIN                  2       // points of damage when crit fail crowbar attempt (which won't happen)
#define DOOR_TOGGLE_DELAY               1       // in seconds

#define JAMMED                          (0)
#define OPENED                          (1)

/* Standard Script Procedures */
procedure start;
procedure map_enter_p_proc;
procedure map_update_p_proc;
procedure description_p_proc;
procedure use_p_proc;
procedure use_obj_on_p_proc;
procedure damage_p_proc;
procedure timed_event_p_proc;

#define LVAR_Explosion_Attempts         (0)
#define LVAR_Timed_Event                (1)
#define LVAR_Door_Status                (2)


procedure start begin
end

procedure map_enter_p_proc begin
   set_local_var(LVAR_Door_Status, JAMMED);
end

procedure map_update_p_proc begin
   if (local_var(LVAR_Door_Status) == OPENED) then
      obj_open(self_obj); // Should already be in open position, but doens't always happen
end

procedure use_p_proc begin
   script_overrides;
   
   if (local_var(LVAR_Door_Status) == OPENED) then
      obj_open(self_obj); // Ad-Hoc solution: should already be in open position, but it won't auto-open
   
   if (obj_is_open(self_obj)) then
      display_msg(mstr(114));
   else if (local_var(LVAR_Explosion_Attempts) > 0) then
      display_msg(mstr(115));
   else
      display_msg(mstr(100));
end

procedure description_p_proc begin
   script_overrides;
   display_msg(mstr(100));
end

procedure use_obj_on_p_proc begin
   variable Stat_Roll;
   
   if ((obj_pid(obj_being_used_with) == PID_CROWBAR) and (not obj_is_open(self_obj))) then begin
      script_overrides;
     
      Stat_Roll:=do_check(source_obj, STAT_st, CROWBAR_BONUS);
     
      if (is_success(Stat_Roll)) then begin
         
         set_local_var(LVAR_Door_Status, OPENED);
         
         // For some reason, calling obj_open directly does not work, so I tried to defer the call to a timed script.
      // obj_open(self_obj);
         
         set_local_var(LVAR_Timed_Event, 1);
         add_timer_event(self_obj, game_ticks(DOOR_TOGGLE_DELAY), 1);
     
         if (source_obj == dude_obj) then
            display_msg(mstr(101));
         else
            display_msg(mstr(106));
      end
      else if (is_critical(Stat_Roll)) then begin // Critical Fail will never happen on stat check, according to documentation
         critter_dmg(source_obj, CROWBAR_STRAIN, (DMG_normal_dam BWOR DMG_BYPASS_ARMOR));
         
         if (source_obj == dude_obj) then begin
            if (CROWBAR_STRAIN == 1) then
               display_msg(mstr(102));
            else
               display_msg(mstr(103)+CROWBAR_STRAIN+mstr(104));
         end
         else begin
            if (get_critter_stat(source_obj, STAT_gender) == GENDER_MALE) then begin
               if (CROWBAR_STRAIN == 1) then
                  display_msg(mstr(107));
               else
                  display_msg(mstr(108)+CROWBAR_STRAIN+mstr(109));
            end
            else if (CROWBAR_STRAIN == 1) then
               display_msg(mstr(111));
            else
               display_msg(mstr(112)+CROWBAR_STRAIN+mstr(113));
         end
      end
      else if (source_obj == dude_obj) then
         display_msg(mstr(105));
      else
         display_msg(mstr(110));
   end
end

procedure damage_p_proc begin
   if (obj_is_open(self_obj) == false) then begin
      inc_local_var(LVAR_Explosion_Attempts);
         
      if (local_var(LVAR_Explosion_Attempts) >= DOOR_STRENGTH) then begin
         create_object(PID_NS_BLOWN_STEEL_DOOR, tile_num(self_obj), elevation(self_obj)); // Destroyed door does not have script attached
         destroy_object(self_obj);
      end
   end
end

procedure timed_event_p_proc begin
   set_local_var(LVAR_Timed_Event, 0);
   
   if (fixed_param == 1) then
      obj_open(self_obj);
end

For some reason, when I call obj_open(self_obj); from within the use_p_proc procedure, it works. If I call it from within the use_obj_on_p_proc procedure, it won't work.

I tried calling it from a timed event, but that did not solve the issue either :-(

Anyone of you out there that could give me a hint?
 
Back
Top