inventory?

Linsky

First time out of the vault
im very new to scripting(just started learning 3 days ago) and need help.

heres an example story:
the player is walking around the toxic waste dump. after a certain number of minuts in that map if theres an item in his inventory called a rad catcher(like a dream catcher, but catches rads) then a procedure would be called to add an item to the inventory called a radrock.

i know how to add an item to the inventory and can figure out the add_timer thing on my own but how would i check if there is a certain item in the players inventory?
 
The new item will have a prototype ID (PID) number. Add a name and its number to the list of items in the itempid.h header file (its in the mapper's \scripts\headers directory).

#define PID_RAD_CATCHER (540)

Then in the script you can do this:

if (obj_is_carrying_obj_pid(self_obj,PID_RAD_CATCHER )) then begin

That command actually returns a count of the number of items carried, but the if condition considers zero to be false, any count will be true.

There is a command obj_carrying_pid_obj that returns a pointer to the item.
item:=obj_carrying_pid_obj(dude_obj,PID_RAD_CATCHER);

This is for commands that expect an object pointer (not PID number), like this one:
rm_obj_from_inven(who, ObjectPtr).

You can do stuff like this:
rm_obj_from_inven(dude_obj, obj_carrying_pid_obj(dude_obj,PID_RAD_CATCHER));

Always look in the mapper docs for the command list. Often the syntax is not clear. In that case do a search on the keyword in the mapper directory, which will find script source code that uses it. Then you can see an example of usage of that command. For example, searching for keyword "carrying" I find 135 scripts from FO2 that use it.
 
thanks. that also answered some other questions i had.

but one remains. whats the difference between self_obj and dude_obj?



is this right?

#define PID_RAD_X (109)
#define PID_JET (259)

/* if done correctly, this should add jet to the players inventory only if there is rad X in his inventory*/
if (obj_is_carrying_obj_pid(self_obj,PID_RAD_X)) then begin
add_obj_to_inven(self_obj,PID_JET)
end
 
self_obj is YOU the object (the one that the script is attached to). An NPC's script can check his inventory the same way using self_obj. An NPC's script could check the the player's inventory using dude_obj. Both are object pointers, dude_obj is always the player character.

Map scripts can do stuff like this:
smiley_ptr := create_object_sid(PID_MALE_TRAPPER,0,0,SCRIPT_KCSMILEY);

Which allows them to refer to smiley_ptr or anyone else ....

As to the second question, an item must exist before it can be added to inventory. So something like this does the trick:

item:=create_object(PID_RAD_CATCHER,0,0);
add_mult_objs_to_inven(dude_obj,item,1);
 
item:=create_object(PID_RAD_CATCHER,0,0);

is the 0,0 part the coordinates on the map in which the item is placed after its created?




#define PID_RAD_X (109)
#define PID_JET (259)


/* if done correctly, this should add jet to the players inventory only if there is rad X in his inventory*/
if (dude_obj_is_carrying_obj_pid(dude_obj,PID_RAD_X)) then begin
item:=create_object(PID_JET,0,0);
add_mult_objs_to_inven(dude_obj,item,1);
end
 
Linsky said:
item:=create_object(PID_RAD_CATCHER,0,0);

is the 0,0 part the coordinates on the map in which the item is placed after its created?

Docs say: Creates a new object of prototype (pid), placing it at a given tile # and at a given elevation. If the prototype indicates a script should be attached, then it will be.
 
Back
Top