Making a scripted item destroy itself

Magnus

Water Chip? Been There, Done That
Modder
I've made this script for Meat Jerky.

Code:
#include "..\headers\define.h"
#define NAME                    SCRIPT_ZIJERKY
#include "..\headers\command.h"

procedure start;
procedure use_p_proc;

procedure start begin
end

procedure use_p_proc begin
   script_overrides;
   critter_heal(source_obj, random(1,4));
   if (source_obj == dude_obj) then begin
      radiation_inc(dude_obj, 2);
      display_msg("You gained 2 Current Radiation Level.");
   end
   rm_obj_from_inven(source_obj, self_obj); // does not happen
   scr_return(1); // no effect
end


The healing and radiation works, but the Jerky stays in my inventory. I'd like it to disappear once I've used it, like a drug/book, etc. The Cat's Paw #5 magazine disappears when used, which is why I tried sc_return, but it seems to have no effect. I've tried destroy_object(self_obj) too, but that just crashes the game.

Also, this only works in the mapper, when I run the game I get the default message when I try to use Jerky. Do I have to do something special in order to get the script working in-game?[/code]
 
If I may suggest - it'd be better if you put the code for disappearing meat jerky in obj_dude.int - Player's script. If you want to attach scripts to every instance of meat jerky in game, this will take you a lot of time and might later cause problems (Fallout engine doesn't like many scripted items in your inventory - I'm not sure whether this was fixed in sfall or not).

I'd write it like that:

Code:
procedure use_obj_on_p_proc begin
   if (obj_pid(obj_being_used_with) == PID_MEAT_JERKY) then begin
      script_overrides; 
      critter_heal(source_obj, random(1,4)); 
      if (source_obj == dude_obj) then begin 
         radiation_inc(dude_obj, 2); 
         display_msg("You gained 2 Current Radiation Level."); 
      end 
      destroy_object(obj_being_used_with);
   end
end

The problem with this solution is that it won't work when you use the item from inside your inventory (I guess that's an engine bug). It works fine when you use it from hand though.
 
Ardent said:
If I may suggest - it'd be better if you put the code for disappearing meat jerky in obj_dude.int - Player's script. If you want to attach scripts to every instance of meat jerky in game, this will take you a lot of time and might later cause problems (Fallout engine doesn't like many scripted items in your inventory - I'm not sure whether this was fixed in sfall or not).
No it never was. killap's 'fix' was just to move some of the items scripts to obj_dude.int, so adding new scripts to items will just bring back that map corrupting bug.
Putting a script on an item such as the meat jerky could potentially be disastrous as you can have pretty many of them at the same time. The original items with scripts were all unique (there would only be one instance of every script). So I never tested what would happen with many items with the same script, but if they act the same way, you'll be in trouble.
 
Ardent said:
The problem with this solution is that it won't work when you use the item from inside your inventory (I guess that's an engine bug). It works fine when you use it from hand though.

No. See the link in my post. It only does *not* work, if the item proto has the "usable" flag. If you deactivate this, you can use it from the inventory and the script will work. The "usable on something" should remain active.
 
Lexx said:
No. See the link in my post. It only does *not* work, if the item proto has the "usable" flag. If you deactivate this, you can use it from the inventory and the script will work. The "usable on something" should remain active.

Not entirely. I have several items (drug class) which only have the "use on" setting on and if you use them from inside your inventory, the effects saved in the proto file (such as +1 Strength etc.) do work, but any script actions defined in use_obj_on_p_proc in obj_dude script don't. Hopefully, it's not the case with Misc Items, as you pointed out.

This is the main drawback with my food system - you can only eat from your active hand.
 
Maybe it's because your items are drug class. My items (which 100% work) are normal msc items.

I think "drug" items are destroyed in the inventory before the script can run.
 
Thanks a bunch for all the answers guys. Putting it in obj_dude was my first idea, but I don't have the source code for the RP. I'd still like to know how misc items like the Fallout 2 Hintbook and the Cat's Paw#5 are removed from the player, there's no mention of it in their scripts. I'll leave Drymeat in the vanilla state for now.
 
I've just tested it and it doesn't work for me. Here's what happens:

1. I collect a misc item (Cheezy Poofs). It has the "Use on" flag, and no "Use" flag.
2. I open the inventory (press INV button on the interface).
3. I select Cheezy Poofs and hold the mouse button to open the menu.
4. I choose the "open hand" action.
5. The game says 'nothing happens' and the code for filling your stomach and destroying the item does not work. Note that the same code is both in use_obj_on_p_proc and in use_p_proc.

Is there anything I'm doing wrong here?
 
Does it work in the mapper? Try opening a map, and edit your proto to be sure it's the way you want it. Put a Cheezy Poofs on the ground, press F8 and see if it works. This was my problem, items would work in the mapper but not the game.
 
Magnus said:
Putting it in obj_dude was my first idea, but I don't have the source code for the RP. I'd still like to know how misc items like the Fallout 2 Hintbook and the Cat's Paw#5 are removed from the player, there's no mention of it in their scripts.
Why don't you just decompile the obj_dude script from the RP?
Anyway, I assume Cat's Paw#5 is removed specifically by the engine.
If you remove the script return command, the magazine won't get removed from your inventory.
 
why scripted?a drug item will do both of those effects,and the engine will destroy it

Nirran
 
Ah, but I can't just go changing Drymeat from a misc item into a drug - that will add around 30 bytes to the file, meaning all maps that contain it will have to be rebuilt, all savegames will be invalid, etc...

It's the equivalent of making the program fit a watermelon into a hole the size of a lemon.
 
Magnus said:
Does it work in the mapper? Try opening a map, and edit your proto to be sure it's the way you want it. Put a Cheezy Poofs on the ground, press F8 and see if it works. This was my problem, items would work in the mapper but not the game.

No, it doesn't. The whole food system thingy doesn't work in the Mapper for me. Besides, I don't need stuff that works in the Mapper but doesn't in the game :P
 
Yeah, but if it works in the mapper that's one step closer to victory. Though I take it you're using global scripts, and I doubt those work in the mapper. Post some code, let's see what's wrong!
 
Magnus said:
Yeah, but if it works in the mapper that's one step closer to victory. Though I take it you're using global scripts, and I doubt those work in the mapper. Post some code, let's see what's wrong!

No, I'm not using any global scripts for the food mod. All is contained in obj_dude.int or in COMMAND.H. As for the code, I'll post it later - atm, I'm a little busy with other engagements.
 
Back
Top