How to remove all of the player's items in inventory? (SOLVED)

NecroDeath
18 Mar 2017, 14:51

There is part in my game where the player is captured and has all their possessions taken away, obviously its easy to remove item x, using the 'remove from inventory' script but I don't know what the player will still be carrying at this point and just want to remove everything.

I'm using the online editor btw.

Thanks!


Silver
18 Mar 2017, 15:03

Will the objects be retrievable at a later point? If not the easiest way to do it is to swap the PC that is carrying stuff with a PC that is carrying nothing.
Otherwise you need to know where the objects will be ending up.


NecroDeath
18 Mar 2017, 15:06

no they are gone for the rest of the game, by PC you mean player character? how to I create a second one? And how do I swap from one to the other? Sorry for noob questions!


The Pixie
18 Mar 2017, 15:30

Go though the inventory, call RemoveObject on each object. In code:

foreach (o, ScopeInventory()) {
  RemoveObject(o)
}

NecroDeath
18 Mar 2017, 15:45

Thanks Pixie, but I don't know what items the player will be carrying at that point, or does it not matter? Do I just paste that code in as it is?


Silver
18 Mar 2017, 15:51

If the objects don't need to be retrievable then the easiest way is to abandon the player object carrying the objects for a player object carrying nothing. Here's the quest documentation on player objects:

http://docs.textadventures.co.uk/quest/tutorial/changing_the_player_object.html


Silver
18 Mar 2017, 16:00

I can write some code for this (if nobody beats me to it) when I'm not AFK.


NecroDeath
18 Mar 2017, 16:16

OK, if I do that do I need to place the other 'player' in the room where the currently player is or does that happen automatically? Do I need to make the current player invisible when I do this.

Thanks!


Silver
18 Mar 2017, 16:39

I always have a room in my game called 'junk' (you can call it anything). The room isn't accessible in the game, it merely serves to hold objects I move around for various scene changes etc.

So you could have your second player object in this room. When they get arrested you could code to have the player object change to the one in the room 'junk' (that has no inventory) then move that player object to the room 'cell' triggering code that you've been thrown into a cell. You then move the original player object to the room 'junk' so it isn't in the game anymore.


NecroDeath
18 Mar 2017, 16:45

got ya! Thanks.


Silver
18 Mar 2017, 16:53

Let us know how you get on. I can write a sample game if you can't get it to work.


NecroDeath
18 Mar 2017, 17:14

This worked perfectly, many thanks for your time, people on this forum are damn nice


Silver
18 Mar 2017, 17:17

No worries. Good luck with your game. :)


hegemonkhan
18 Mar 2017, 19:34

the 'ScopeInventory' Function gets/returns the built-in 'inventory' Objectlist Attribute for your 'player' Player Object. This special hidden 'inventory' Objectlist Attribute, holds the object references (names) of all of the Objects contained within your 'player' Player Object, as it's items (Values).

the 'foreach' Function iterates through a List Attribute (aka, through its items/values, for this case, your object references: names, of all of the Objects contained within the 'player' Player Object), allowing you to do (or not do) whatever script/action for in this case, for each of your Objects in your 'player' Player Object.


here's an explanation of how Lists and iteration (usually via quest's 'foreach' Function, in quest) work:

<game name="example">
  <attr name="start" type="script">
    foreach (team_member, team.member_list) {
      do (team_member, "run_laps")
      //
      // it's effectively doing this:
      //
      // team_member = joe
      // do (team_member, "run_laps")
      // do (joe, "run_laps")
      // team_member = jeff
      // do (team_member, "run_laps")
      // do (jeff, "run_laps")
      // team_member = john
      // do (team_member, "run_laps")
      // do (john, "run_laps")
      //
      // result/output:
      //
      // Joe runs laps
      // Jeff runs laps
      // John runs laps
    }
  </attr>
</game>

<object name="team">
  <attr name="member_list" type="objectlist">joe;jeff;john</attr>
</object>

<object name="joe">
  <attr name="run_laps" type="script">
    msg ("Joe runs laps")
  </attr>
</object>

<object name="jeff">
  <attr name="run_laps" type="script">
    msg ("Jeff runs laps")
  </attr>
</object>

<object name="john">
  <attr name="run_laps" type="script">
    msg ("John runs laps")
  </attr>
</object>

<verb>
  <property>run_laps</property>
  <pattern>run_laps</pattern>
  <defaultexpression>It can't run laps!</defaultexpression>
</verb>

and here's a bit on having/using multiple Player Objects (you're only in control of one of them at a time, of course, but you can switch between them):

http://docs.textadventures.co.uk/quest/tutorial/changing_the_player_object.html

will go into more details/explanation if you're interested in this...


and here's more detailed guide on using Lists/Dictionaries:

http://textadventures.co.uk/forum/samples/topic/5137/list-and-dictionary-extensive-guide-by-hk

and sample code (but it's old/poor/bad code) of an application of List/Dictionary usage:

http://textadventures.co.uk/forum/samples/topic/5138/explore-and-travel-code-sample-by-hk


Silver
18 Mar 2017, 19:38

I'd already posted that link... :-p


hegemonkhan
18 Mar 2017, 19:44

oops, didn't see it in your post, my bad... oh well