Destroy script

Discussion in 'Fallout General Modding' started by Josan12, May 7, 2010.

  1. Josan12

    Josan12 Vault Senior Citizen

    Oct 15, 2007
    My goal is:

    To have a spear that destroys itself upon a sucessfull hit.
    Here's my script in the combat_p_proc of obj_dude:

    Code:
    if
    (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_LEFT_HAND)) == PID_SPEAR) or
    (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_RIGHT_HAND)) == PID_SPEAR) and
    (fixed_param == COMBAT_SUBTYPE_HIT_SUCCEEDED) then begin 
    rm_obj_from_inven(self_obj, PID_SPEAR);
    end
    end
    It crashes the mapper. Can someone tell me what i'm doing wrong, and what might be a better way?

    Thanks, Josan
     
  2. Nirran

    Nirran Vault Senior Citizen
    Modder

    Apr 15, 2007
    unequip it first


    Nirran
     
  3. Josan12

    Josan12 Vault Senior Citizen

    Oct 15, 2007
    Ah - yes, good point :oops:

    BUT - i changed it to this:

    Code:
    if
    (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_LEFT_HAND)) == PID_SPEAR) or
    (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_RIGHT_HAND)) == PID_SPEAR) and
    (fixed_param == COMBAT_SUBTYPE_HIT_SUCCEEDED) then begin
    inven_unwield(self_obj);
    rm_obj_from_inven(self_obj, PID_SPEAR);
    end
    end
    it still crashes. Any thoughts?
     
  4. MIB88

    MIB88 So Old I'm Losing Radiation Signs
    Modder

    Feb 22, 2005
    You didn't really delete it, though. You only removed it from inventory. Try adding the code to actually delete it, too. I remember there were some instances of using items on critters that were removed from inventory but were not deleted that also lead to a crash (like iguana on a stick with Dogmeat and Jet antidote on Fannie).

    If it doesn't work after that, it might be because the script is looking for an item that it can't find. I mean, it may be able to find a spear that is in the dude's hands, but it might not be able to find and destroy a spear that was thrown (since it is no longer in inventory).
     
  5. Josan12

    Josan12 Vault Senior Citizen

    Oct 15, 2007
    Hmmmm. Ok. I changed the script to:

    Code:
    if
    (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_LEFT_HAND)) == PID_SPEAR) or
    (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_RIGHT_HAND)) == PID_SPEAR) and
    (fixed_param == COMBAT_SUBTYPE_HIT_SUCCEEDED) then begin
    inven_unwield(self_obj);
    rm_obj_from_inven(self_obj, PID_SPEAR);
    destroy_object(PID_SPEAR);
    end
    end
    Still crashes.

    I tried it without the remove object command and Destroy object command and it ran the 'holster' animation, then froze on the ticking clock icon. So i suspect that's the problem. From past experience with inven_unwield in combat it shouldn't run the animation in combat mode....

    Is there another approach i could take to this? Maybe i should be creating an item script and be attaching it to the spear? Can scripts be attached to weapons?

    Good point about the throwing
     
  6. MIB88

    MIB88 So Old I'm Losing Radiation Signs
    Modder

    Feb 22, 2005
    Another approach... hmmm. I'm at a loss. I don't know how to keep the dude from changing his animations in the middle of his turn, which is the thing you have to do.

    Scripts can be attached to weapons. Be careful, though, not to do that too many times, or else you will get the error that is the result of having too many items with scripts on the same map.

    Maybe, just maybe, it would work if you added a timer to the destroy function. But, that might be a better way to implement it if you decide to add the script to the item instead. Who knows? Maybe it would work in this case, too.
     
  7. Josan12

    Josan12 Vault Senior Citizen

    Oct 15, 2007
    OK - i'll try attaching the above script to a weapon. But i'm not quite sure what procedure to put the code under .... the destroy_proc? Or the use proc? or maybe the combat p proc? I'm not quite sure about item scripts. ....
     
  8. Nirran

    Nirran Vault Senior Citizen
    Modder

    Apr 15, 2007
    you have to create a pointer to the item(s) using the pid will always crash the game

    add this functions with this in the script call it
    Code:
    call remove_inventory(critter_ptr, PID_SPEAR,0);
    Code:
    procedure remove_inventory(variable item, variable remove_item, variable replace_item) begin
       if(obj_is_carrying_obj_pid(item, remove_item) > 0) then 
          begin                                                    
             while(obj_is_carrying_obj_pid(item, remove_item) > 0) do 
                begin                                                 
                   delete_item := obj_carrying_pid_obj(item, remove_item);                                                     
                   rm_obj_from_inven(item, delete_item);                                                                       
                   if(tile_contains_obj_pid(1, 0, remove_item)) then 
                      begin                                                     
                         delete_item := tile_contains_pid_obj(1, 0, remove_item);                                                 
                         destroy_object(delete_item);                                                                             
                      end                                                                                                         
                   number_items_remove := number_items_remove + 1;                                                             
                end                                                                                                            
             add_mult_objs_to_inven(item, create_object_sid(replace_item, 0, 0, -1), number_items_remove);                  
             number_items_remove := 0;                                                                                      
          end                                                                                                               
    end
    
    Nirran
     
  9. Josan12

    Josan12 Vault Senior Citizen

    Oct 15, 2007
    Thanks Nirran. But where should i put this code? In obj_dude under combat_p_proc? Or in a new script attached to the weapon? Or elsewhere?
     
  10. Nirran

    Nirran Vault Senior Citizen
    Modder

    Apr 15, 2007
    in the script it is being run from

    Nirran
     
  11. Josan12

    Josan12 Vault Senior Citizen

    Oct 15, 2007
    I'm a noob scripter, so can someone tell me where i should put Nirran's script?

    I'm guessing this:


    Code:
    procedure remove_inventory(variable item, variable remove_item, variable replace_item) begin
       if(obj_is_carrying_obj_pid(item, remove_item) > 0) then
          begin                                                   
             while(obj_is_carrying_obj_pid(item, remove_item) > 0) do
                begin                                                 
                   delete_item := obj_carrying_pid_obj(item, remove_item);                                                     
                   rm_obj_from_inven(item, delete_item);                                                                       
                   if(tile_contains_obj_pid(1, 0, remove_item)) then
                      begin                                                     
                         delete_item := tile_contains_pid_obj(1, 0, remove_item);                                                 
                         destroy_object(delete_item);                                                                             
                      end                                                                                                         
                   number_items_remove := number_items_remove + 1;                                                             
                end                                                                                                           
             add_mult_objs_to_inven(item, create_object_sid(replace_item, 0, 0, -1), number_items_remove);                 
             number_items_remove := 0;                                                                                     
          end                                                                                                               
    end 
    Gets put on it's own at the bottom of the script as it's a new proc?
    And the variables:

    Code:
    variable item, variable remove_item, variable replace_item)
    Need to be declared in the variables section?

    And this:

    Code:
    call remove_inventory(critter_ptr, PID_SPEAR,0);
    Gets called wherever i want it? (in combat_p_proc? - does it make a difference?)
    What's the difference between calling in obj_dude or a new little script attached to the weapon?

    Roll up, roll up to help a noob scripter!

    :help:
     
  12. Nirran

    Nirran Vault Senior Citizen
    Modder

    Apr 15, 2007
    make it a new procedure,use the line i posted in combat proc,need to add checks and put the line inside the checks,otherwise it will be called every combat turn,may have problems with it,ive tried this kind of thing before,but you can be sure that procedure works

    Nirran
     
  13. pelicano

    pelicano It Wandered In From the Wastes
    Modder

    129
    Jun 14, 2008
    Code:
    if(fixed_param == COMBAT_SUBTYPE_HIT_SUCCEEDED)then begin
       wpn := critter_inven_obj(dude_obj,1) + critter_inven_obj(dude_obj,2);
       if(obj_pid(wpn) == PID_SPEAR)then begin
          inven_unwield(dude_obj);
          rm_obj_from_inven(dude_obj, wpn);
          destroy_object(wpn);
       end
    end
    This in obj_dude's combat_p_proc should be dandy. It didn't crash my game.

    inven_unwield doesn't run unwield animation in combat but rm_obj_from_inven does. Interesting, isn't it?