Switching Inventory between Multiple Characters [SOLVED]

Started by Frequentor, Wed 10/08/2005 19:03:06

Previous topic - Next topic

Frequentor

The game I'm working on has three different playable characters, and inventory has to be switched between them. When the player uses an inventory item on a phone-box-type-thing, a GUI pops up with the other characters on it. When the player clicks on one the following code is brought up:

character[MAN].inv[character[EGO].activeinv] =1;
LoseInventory (character[EGO].activeinv);

This is to transfer the inventory clicked on the phone box by the character EGO to the character MAN.

The code doesn't work though, and I can't work out why. The inventory item is lost from EGO's inventory, but does not appear in MAN's. Any help would be very enlightening thanks.
See above post for message.

Pumaman

It might just not be refreshing the GUI -- try this:

cMan.AddInventory(cEgo.ActiveInventory);
cEgo.LoseInventory(cEgo.ActiveInventory);

rather than modifying the inv[] directly

Frequentor

See above post for message.

DarkMasterOz

I know the topic is quite old now, but i was wondering seeing i know nothing about scripting, what is the full code to add this effect and where do i put it?
Also seeing im using 5 characters is it possible to make it so that:

1) EGO puts inventory item into a mailbox (object).
2) Any of the other 4 character that uses the mailbox can collect the item.

(also just for this, i'll call the other 4 characters: Barry, Gary, Harry & Larry)

Thanks!

Scorpiorus

Hello and welcome to the AGS forums :)


For the first question, I'm not sure what exactly you are after, do you want to know how to setup a GUI for selecting the player character, or? Can you elaborate a bit?


As for the mailbox thingy...

Open the room script and add the following line at the top of it:

InventoryItem* item_in_mailbox;


Next...

On the Use inventory item on mailbox object event:

// put active inventory item into the box

if (item_in_mailbox)
{
   Display("There is not enough room in the mailbox!");
}
else
{
   item_in_mailbox = player.ActiveInventory;
   player.LoseInventory( player.ActiveInventory );
   player.ActiveInventory = null; // just in case
}


On the Interact the mailbox object event:

if (item_in_mailbox)
{
   // take item back
   player.AddInventory( item_in_mailbox );
   item_in_mailbox = null;
}


[edit to remove explicit "null" initialization as compiler doesn't like it]

DarkMasterOz

Thanks for helping.
What i meant for first bit was: How can i make it so when i use an inventory item like a "key" on the mailbox i just made (or any object for that matter) so it brings up a newly made GUI with pictures of the 5 characters on so i can click one of the character pictures to send it to them. Like in Day of the Tenticle.

I've already done:
* The GUI which pops up when i use the mailbox
* Added the characters to the GUI

Need Doing:
* I cant close the GUI with the pictures of the characters in.
* Not sure how to send items to them.

(I can probably explain it more clearly but thats not important if i can get the script you told me about working, because i prefer that one)


I've added this to Room script
"InventoryItem* item_in_mailbox = null;"


I'm guessing i put this in "Use Inventory on Object" > "Run Script" event:

// put active inventory item into the box

if (item_in_mailbox)
{
Ã,  Ã, Display("There is not enough room in the mailbox!");
}
else
{
Ã,  Ã, item_in_mailbox = player.ActiveInventory;
Ã,  Ã, player.LoseInventory( player.ActiveInventory );
Ã,  Ã, player.ActiveInventory = null; // just in case
}



And ive added this into "Interact Object" > "Run Script" event:



if (item_in_mailbox)
{
Ã,  Ã, // take item back
Ã,  Ã, player.AddInventory( item_in_mailbox );
Ã,  Ã, item_in_mailbox = null;
}



(But this error comes up when i try to run it)

There was an error compiling your script. The problem was:
In: 'Room 1 script'

Error (line 2): cannot assign initial value to global pointer

Is there anything i'm missing?

Scorpiorus

Oops, initializing the pointer with null was a little overdo and isn't liked by the compiler. :)

Just change this line:

InventoryItem* item_in_mailbox = null;

to

InventoryItem* item_in_mailbox;

I've also updated my post above.

Quote* I cant close the GUI with the pictures of the characters in.

You can use GUI.Visible property to close it.

Quote* Not sure how to send items to them.

It's done in a similar way, but let us know if you need more help on this.

DarkMasterOz

Thanks the mailbox thing works great now, i can carry on making my game. Without it, it would have been very short, easy and boring. Now it should be quite long, difficult puzzles and hopefully quite enjoyable.

If you do know how to do a Day of the Tenticle type method, i'd love to know if its no problem for you to tell me.
Like i've said, i've done this:
1) Made the GUI with the character pictures on the buttons
2) Made it so when you click the Mailbox the GUI opens

Only thing i think i need to do now is: (all my 5 characters will have their own mailbox's)
3) Make it so EGO can put an item in Mailbox1 to give to a specific character who has his own/her Mailbox.
4) For some strange reason, now i've got the mailbox working the GUI wont pop up at all when i use mailbox.


If its too much work though, it doesn't matter atleast i can still transfer inventory items. Thanks for your helpful... help.Ã,  :)

Scorpiorus

Quote from: DarkMasterOz on Wed 08/03/2006 14:49:403) Make it so EGO can put an item in Mailbox1 to give to a specific character who has his own/her Mailbox.

First add the following function at the top of the main global script (Ctrl-G):

function TransferItem (Character *From, Character *To, InventoryItem *Item) {

   if (Item == null) return;
   if (From == To) return;
   if (From.InventoryQuantity[Item.ID] <= 0) return;

   if (From.ActiveInventory == Item) From.ActiveInventory = null;
      
   From.LoseInventory( Item );
   To.AddInventory( Item );
}

It's written to transfer inventory Item from character From to character To.


Next, open the GUI Editor, go to your characters GUI, and give a script name to each of its buttons.

Now double click each button and put the appropriate script within its ButtonNameHere_Click function (using newly made TransferItem() function):

For Ego button:
TransferItem( player, cEgo, player.ActiveInventory );
control.OwningGUI.Visible = false; // close GUI

For Barry button:
TransferItem( player, cBarry , player.ActiveInventory );
control.OwningGUI.Visible = false; // close GUI


For Gary button:
TransferItem( player, cGary, player.ActiveInventory );
control.OwningGUI.Visible = false; // close GUI


For Harry button:
TransferItem( player, cHarry, player.ActiveInventory );
control.OwningGUI.Visible = false; // close GUI


For Larry button:
TransferItem( player, cLarry, player.ActiveInventory );
control.OwningGUI.Visible = false; // close GUI



Additionaly, you can also have a separate button to close the GUI:
For close button:
control.OwningGUI.Visible = false; // close GUI


Quote4) For some strange reason, now i've got the mailbox working the GUI wont pop up at all when i use mailbox.

Well, what you need to do is change the script under use inventory item on mailbox object:

gYourCharactersGUINameHere.Visible = true;


See if it works for you :)

DarkMasterOz

#9
Right ive done all that what you said, i've:
1) Put the first script into Main Global Scrip right at the top, just underneith
// main global script file which is on line1

2) Ive edited the newly 3rd GUI which has my character buttons on. An example of one of my buttons information are:

Script name:       BARRY
X-Position:      Ã,  Ã,  Ã,  Ã,  Ã, 0
Y-Position:      Ã,  Ã,  Ã,  Ã,  Ã, 0
Image:         118
Mouseover Image:   (None)
Pushed image:      (None)
Width:         32
Height:         27
Text:         Ã,  Ã,  Ã,  Ã,  Ã, New Button
Font:         Ã,  Ã,  Ã,  Ã,  Ã, 0
Text Color:      Ã,  Ã,  Ã,  Ã,  Ã, 16
Clip image:      Ã,  Ã,  Ã,  Ã,  Ã, No
Left click:      Ã,  Ã,  Ã,  Ã,  Ã, Run Script
New mode number:   N/A
Click:         Ã,  Ã,  Ã,  Ã,  Ã, BARRY_Click

I then double click the button to bring up the the editing script which reads this:

#sectionstart BARRY_Click // DO NOT EDIT OR REMOVE THIS LINE
function BARRY_Click(GUIControl *control, MouseButton button) {
TransferItem( player, cBarry, player.ActiveInventory );
control.OwningGUI.Visible = false; // close GUI
}
#sectionend BARRY_ClickÃ,  // DO NOT EDIT OR REMOVE THIS LINE

But when i go to compile i get this error:

There was an error compiling your script. The problem was:
In: 'Internal character defines'


Error (line 73): Variable '6' is already defined

Do you want to fix the script now? (Your game has not been saved).

when i click "Yes"

This pops up:
The error occured in an internal AGS script. This should never happen; try re-installing the latest version of AGS.


Sorry to keep bugging you over this, I've not removed any of the previous code from what you told me before if that could be it?

Oh yeh, just to make sure i am using: Current Version: 2.71

I think it might have something to do with "Script Name" on the buttons bit, because i deleted all the code except for the buttons information and it still kept popping up, so i deleted the "BARRY_Click" bit and it still kept displaying compile error, but when i deleted BARRY from:

Script name:       BARRY

It seemed to compile.

Scorpiorus

Ah, It's probably because you named it BARRY but you also have BARRY character with the same name.

I would suggest naming GUI buttons something like:

btnBarry
btnLarry

etc...

see if it helps

DarkMasterOz

Yeh, it seems to work now. When i put an item into mailbox it automaticly sends it to other characters inventory. Thanks!

Took some doing, but all is well in the end. Cheers  :)

Scorpiorus


SMF spam blocked by CleanTalk