Scripted items not removing from the inventory?

FDO

Still Mildly Glowing
Hey guys,

I have a hopefully simple problem, but I don't manage to figure it out.
The following lines are removing a item from the player inventory, and is working when I use the item in the hand\weapon slot, however it isn't working when I use the item directly in the inventory:

variable smoke;
variable JunkIt;
script_overrides;
smoke:=obj_carrying_pid_obj(dude_obj, PID_CIGS);
display_msg(mstr(102));
JunkIt=rm_mult_objs_from_inven(dude_obj,smoke,1);
set_local_var(LVAR_Count, 0);

The procedure fire once the conditions are met, but the item stay in the inventory, except if I use it with the weapon slot, where it properly get removed. Am I missing something?
 
You need to add a check into the obj_dude script. Item scripts won't fire like that from the inventory if I remember right.
 
I have a working script which seems to work from inventory just fine.

Code:
variable item;

script_overrides;
item := obj_being_used_with; // or item := obj_carrying_pid_obj(dude_obj, PID_RUSSELL_PUMP_PART); if u didnt u the item on somthing.
rm_obj_from_inven(dude_obj, item);
destroy_object(item);

Edit:

is it possible that that the item was removed from your hand slot, when u use item from inventory? it seems to me that rm_mult doesn't necessarily removes the instance of an item that u pointed to, and just checks what PID the object pointer is, and then removes a certain amount of instances of the same PID, again, not necessarily the original object pointed to.
 
Last edited:
Lexx, the item scripts do fire on their own from the inventory, my dude is smoking his cigarette for example, it's just the removing from the inventory that don't want to get done so far. I just tried adding checks in the obj_dude but so far no luck.

Zorchar, actually your script make me think that items used on something seem to get removed properly, my trouble is with items which have the 'use' tag, and not the 'use on'. Gonna try something else.
 
you can use a hook script 'HS_Useobjon' and
Code:
set_sfall_return(1);

it works for me with my book mod
 
Just to be clear, u mean this code isn't working as well?

Code:
#define PID_OBJECT_USED ("choose PID")


variable item;

script_overrides;
item := obj_carrying_pid_obj(dude_obj, PID_OBJECT_USED );
rm_obj_from_inven(dude_obj, item);
destroy_object(item);

Edit:

Which script is activating the function? and which procedure?
 
Last edited:
Nope, or to be accurate, if I remove the destroy_object, it produce the same result that I started with, the item is removed if i use it from a weapon slot. If I activate the destroy_object, the game crash.

A part of a short script concerned by the issue: (a item script, there also is a timed_event procedure for related animations but all that work just fine, only the 'remove' part is bugging me...)

Code:
procedure use_p_proc begin
   if not (combat_is_initialized) then begin
      if (dude_is_male) then begin
         if ( ((obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_WORN)) == PID_POWERED_ARMOR) or (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_WORN)) == PID_HARDENED_POWER_ARMOR)) and (obj_is_carrying_obj_pid(dude_obj, PID_LIGHTER) >= 1)) then begin
             script_overrides;
             if (local_var(LVAR_Count) != CHARGES) then

            add_timer_event(self_obj, 1, 1);

             set_local_var(LVAR_Count,local_var(LVAR_Count)+1);

             if (local_var(LVAR_Count) == CHARGES) then begin
               script_overrides;
               call remove;
            end

         end

         else if ( (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_WORN)) == PID_ADVANCED_POWER_ARMOR) or (obj_pid(critter_inven_obj(dude_obj,INVEN_TYPE_WORN)) == PID_ADVANCED_POWER_ARMOR_MK2) ) then begin
             script_overrides;
            display_msg(mstr(100));
         end

         else if ((dude_is_male) and (source_obj == dude_obj) and (obj_is_carrying_obj_pid(dude_obj, PID_LIGHTER) >= 1)) then begin
             script_overrides;
             if (local_var(LVAR_Count) != CHARGES) then

             add_timer_event(self_obj, 1, 0);

             set_local_var(LVAR_Count,local_var(LVAR_Count)+1);

            if (local_var(LVAR_Count) == CHARGES) then begin
               script_overrides;
               call remove;
            end
         end

         if (obj_is_carrying_obj_pid(dude_obj, PID_LIGHTER) == 0) then begin
            script_overrides;
            display_msg(mstr(101));
         end

      end
   end
end

procedure remove begin
          variable smoke;
          variable JunkIt;
          script_overrides;
          smoke:=obj_carrying_pid_obj(dude_obj, PID_CIGS);
          JunkIt:=remove_items_pid(dude_obj,PID_CIGS, 1);
//         rm_obj_from_inven(dude_obj,PID_CIGS);
//          destroy_object(PID_CIGS);
          display_msg(mstr(102));
          set_local_var(LVAR_Count, 0);
//          destroy_object(smoke);
  end

I will try a hook tomorow I guess, I downloaded your book mod Nirran, to see if I can understand because so far my use of sfall extended functions has been limited.
 
I can't make sense of it. Tried every variations I could think of these,
JunkIt:=remove_items_pid(dude_obj,PID_CIGS, 1);
rm_obj_from_inven(dude_obj,PID_CIGS);

Using macros, vanilla or sfall commands, and nothing work... As for the hook scripts, after study I can't say I understand how to even use them, but what bother me is that in that case I shoudn't need them, I saw several vanilla scripts using rm_obj_from_inven or variations to remove items from the inventory. If I replace this command by any other I can think of in my scripts, create a item, set a variable, launch a other procedure, ect, it does work, so I know the concerned scripts are functional.
For some unknown mystery, rm_obj_from_inven just doesn't work for me, and I tried in critters scripts as well.

Oh well, unless I think of something, moving on to advance on other efforts until it's time to solve this thing.
 
Hm, according to the log the hook 8 is running each time I try to use the item, so my understanding of these hooks is improving, but it seem I messed up somewhere in redoing my code to paste it because either I have animations not being found by the engine, or the all script stop doing anything at all. I need a break, tomorow is a other day and all that.

Thanks, Nirran. I will figure it out, eventually.
 
Yes! It's working now:

Code:
procedure start begin
   variable user;
   variable item;
   if (init_hook) then begin
   end else begin
      user := get_sfall_arg;
      item := get_sfall_arg;
      if (user == dude_obj) then begin
         if (obj_pid(item) == PID_CIGS) then begin
            //your code here
     if (global_var(GVAR_SMOKER) == 2) then begin
      set_sfall_return(1);
      set_global_var(GVAR_SMOKER, 0);
      display_msg(message_str(SCRIPT_CIGS, 103));
end
end
end
end
end

I changed the hook for HS_useobj so no need to point a target. The use part is still covered by the item script, and the item doesn't delete before the GVAR reach the correct state. Thanks Nirran, I learned what hook scripts do beside solving my issue.
 
Back
Top