Author Topic: Remembered Inventory  (Read 2637 times)

0 Members and 1 Guest are viewing this topic.

Offline Corby

Remembered Inventory
« on: June 04, 2003, 03:55:15 AM »
Hey, hopefully this will be the last question I ask in awhile...
  My character will leave her belongings behind for a short time and wander to other rooms. How can I remember what specific items my chracters owned before I give them back, in case different items were picked up or different items used?
Kinda confusing...



Offline Chris Cromer

Re:Remembered Inventory
« Reply #1 on: June 04, 2003, 04:11:21 AM »
Set aside some flags to use to determine if they have the item or not.

Then just put an if around each set/unset command like this:

Code: [Select]
if (has(iA)) {
  set(f45);
}
else {
  unset(f45);
}

Then just get rid of the users inventory. Then to get it back just do this:

Code: [Select]
if (isset(f45)) {
get(iITEM);
}

The more inventory objects you have the more flags it will require.
Chris Cromer

It's all fun and games until someone get's hurt then it's just fun. ;)

Offline Corby

Re:Remembered Inventory
« Reply #2 on: June 04, 2003, 04:32:48 AM »
Hmmm, would this work with variables? I'm pretty low on flags.

Kon-Tiki

  • Guest
Re:Remembered Inventory
« Reply #3 on: June 04, 2003, 04:52:25 AM »
It depends. If there're objects you can't drop or get without other objects, then you can use vars. If you have lots of vars that aren't used, you can use them too, but doing this won't work:
Code: [Select]
if(has("key")) {
 v50 += 1;
 drop("key");
}
if(has("rope")) {
  v50 += 1;
  drop("rope");
}
You'll have to use a different var for each object/group of objects, since the above is clearly one big bug.

-Kon-Tiki-

Offline Nick Sonneveld

Re:Remembered Inventory
« Reply #4 on: June 04, 2003, 05:47:46 AM »
The alternative is to set them to another "room".  Each item can be set to exist in a particular room or in your inventory (room 255).

Obviously you're not going to have 0-254 rooms filled up so pick a number like 254 and set all your inventory items to 254.

Problem is that eval commands has() and obj.in.room() don't read in variables, so it makes it harder to loop.

- Nick
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Nick Sonneveld

Re:Remembered Inventory
« Reply #5 on: June 04, 2003, 05:53:14 AM »
okay, try this code.  in defines.txt you NEED to set the number of objects in the #define num_invobjects, or it won't go through all the objects in the loop.

Just need the variable move_to to some temporary room you wish to move all your inventory items in.  I set it as a variable in case you want to have multiple spare rooms, like a cupboard, under your bed or the boot/trunk of your car.

Wrap up each loop in it's own if(){} statement or it'll move your inventory and then back again each time! :)

I hope this helps.  Reply if it doesn't make much sense.

- Nick


Code: [Select]
/* SET num_invobjects IN DEFINES.TXT*/
/* objects 0-10 is 11 objects */

/* room to move it to */
#define move_to v100
#define room_temp v101
#define inv_count v102

   /* .............. */
   
   move_to  = 254;    
      
   /* .............. */
   
   /* move inventory to room XXX */
   inv_count = 0;
   hide_loop:
   if (inv_count < num_invobjects) /* loop through all inventory items */
   {
      /* get room information for item */
      get.room.v(inv_count, room_temp);
      
      /* if it's in inventory, then move it to the copy room */
      if (room_temp == 255)
         { put.v(inv_count, move_to); }
      
      inv_count++;
         
      goto(hide_loop);
   }
   
   /* .............. */
   
   /* move all XX  as inventory */
   inv_count = 0;
   restore_loop:
   if (inv_count < num_invobjects) /* loop through all inventory items */
   {
      /* get room information for item */
      get.room.v(inv_count, room_temp);
      
      /* if it's in special room, then put in inventory */
      if (room_temp == move_to)
         { get.v(inv_count); }
      
      inv_count++;
         
      goto(restore_loop);
   }
Nick Sonneveld  |  AGI Dev  |  NAGI

Offline Jelle

Re:Remembered Inventory
« Reply #6 on: June 04, 2003, 09:08:37 AM »
Use G
« Last Edit: June 04, 2003, 09:31:35 AM by Jelle »
Politics is supposed to be the second-oldest profession. I have come to realize that it bears a very close resemblance to the first.

Offline Joel

Re:Remembered Inventory
« Reply #7 on: June 04, 2003, 09:32:18 AM »
short answer, although it would mean more code than Nick's version:

look for the put() command
look for the has() command
look for the obj.in.room() command

if your character will be dropping their inventory items in a particular room, you can use put() to put the inventory items in the room (after you test if the character has the item by using has()). Then when your character comes back to the room later, you can test obj.in.room() to find out if the object is in the room (which it will only be if your character had the item in the first place).

Nick's method would mean less code and it automatically works for all inventory objects that the character has, so I personally would recommend using that, but I'm just throwing out the simplest to understand (not the optimal) way of doing it.

Offline Corby

Re:Remembered Inventory
« Reply #8 on: June 04, 2003, 05:44:20 PM »
wow, lots of ways... i'll give them a shot and let you know. Thanks alot :)


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.043 seconds with 21 queries.