Multiple playable characters sharing items (Solved)

Started by G, Thu 22/01/2009 21:04:41

Previous topic - Next topic

G

Hi there!

Right now I'm working on the Vendetta Project. And I've reached a point in the progress of the game where the main character has to work along with another playable character. But, there's not only one more character, there are up to three aditional characters to play with.

So, for allowing one character to give an inventory item to another character I would like to find an easy code, that also allows me to save me from writing lots of lines of repeated code.

I tried with some simple code as:

Function GiveObject (Target character){
Target character.AddInventory (player.ActiveInventory);
player.LoseInventory (player.ActiveInventory);
}

But I found I don't know how to define "Target Character". As soon as I find how to define the target character of the function (The alternative playable character who will receive the object) this should work. Then when coding in the "Use inventory on character" I should write "GiveObject();" and ready.

So, some ideas? Thank you.

Vince Twelve

You're almost there.  All you need to do is pass the character's name as the argument for the GiveObject function for that character's "Use inventory on character" interaction.  So for each character you can give items to, you just have:

Code: ags

function cChar1_UseInv(){
  GiveObject(cChar1);
}

function cChar2_UseInv(){
  GiveObject(cChar2);
}

etc...


Obviously, substituting the characters' script name for cChar1, cChar2, etc.

Then you can start thinking about having the player character walk over to that character and play a giving animation and maybe saying "Here, hold this." in the GiveObject function.  That's how I do it in Resonance.

Khris

In case it is unclear how exactly the code's supposed to look:

Code: ags
void GiveObject(Character*tc) {
  tc.AddInventory(player.ActiveInventory);
  player.LoseInventory(player.ActiveInventory);
}

G

Woah, that worked. Thank you very much both of you guys!

SMF spam blocked by CleanTalk