Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Gs92 on Mon 21/07/2008 23:05:28

Title: Inventory items problem!
Post by: Gs92 on Mon 21/07/2008 23:05:28
Hello, i'm new to the board and to AGS and making my first "test game" so to speak.

Heres my problem: I've been making a few items and hotspots and as far as making script so that i can pick up items and look at them etc. everything's been going fine. However when I wanted to make script so that the inventory items are usable with eachother I didn't know what to do (usable with eachother meaning combining two inventory items:"use half a key with another half of a key to create a whole key"... you get the idea).

So if anyone can help me with this please reply :P and if possible also how to make inventory items usable with hotspots.

Thanks!

P.S. Yes i've read through the toturial file more than once and I still havn't found the solution there, there could be something i've missed there though.
Title: Re: Inventory items problem!
Post by: Makeout Patrol on Mon 21/07/2008 23:15:15
In the 'interactions' list, there's an option for 'use inventory with this hotspot' or something similar (I don't recall the exact wording, but it's pretty clear). In that function in the script, use some if-then logic to ensure that the player is using the right inventory item. For instance, if the two inventory items in your example are iKey1 and iKey2, your script for iKey2 would look like this:


if(player.ActiveInventory == iKey1){
  player.AddInventory(iKeyWhole);
  player.LoseInventory(iKey1);
  player.LoseInventory(iKey2);
}


You'd put in something similar for the other half of the key. Using inventory with hotspots works exactly the same way.
Title: Re: Inventory items problem!
Post by: Gs92 on Mon 21/07/2008 23:39:19
THANK YOU SO MUCH :D
I tried to find the solution for this for 2 days and now I got it yay! Thanks again :)

Also, for using items with a hotspot, lets say using a item(tableleg for instance) with a hotspot(a broken table) to make it a whole table, is it the same kind of script or different? thanks again.
Title: Re: Inventory items problem!
Post by: Makeout Patrol on Mon 21/07/2008 23:43:19
Quote from: Gs92 on Mon 21/07/2008 23:39:19
THANK YOU SO MUCH :D
I tried to find the solution for this for 2 days and now I got it yay! Thanks again :)

Also, for using items with a hotspot, lets say using a item(tableleg for instance) with a hotspot(a broken table) to make it a whole table, is it the same kind of script or different? thanks again.

Yeah, if you're using it with a hotspot it's the exact same thing - go into the hotspot's interaction list and put the if-then logic in the "player uses inventory item" (or whatever) field. In the case of that table, however, I'd probably use objects so that the player can see that they've fixed the table.
Title: Re: Inventory items problem!
Post by: Gs92 on Tue 22/07/2008 11:29:55
Thanks again!
..sorry to be such a nagger but, how about when i wanna combine 3 inventory items together? I tried scripting it myself but it wouldn't work
(the script for combining two items and the one for combining with hotspot worked fine though)
Title: Re: Inventory items problem!
Post by: Matti on Tue 22/07/2008 11:55:48
Well, you can do it similar to the above mentioned script and put 2 items together and then use the new item to the third one.


Or - if you want to put all three items together at once do something like this:

I use the key-example again:

If the three inventory items in your example are iKey1/iKey2/iKey3, your script for iKey1 would look like this:


if(player.ActiveInventory == iKey2)or(player.ActiveInventory == iKey3){
  cEgo.Say("I'll put together the three keys");
  player.AddInventory(iKeyWhole);
  player.LoseInventory(iKey1);
  player.LoseInventory(iKey2);
  player.LoseInventory(iKey3);
}


Then post the same script for the two other iKeys and change the numbers (in the first line)
Title: Re: Inventory items problem!
Post by: Gs92 on Tue 22/07/2008 12:52:40
Thanks! I worked out the "use 2 items together then with the third" script thing myself, but thanks anyways, i'll remember that one for later. AGS forums saved me again ^^ :P
Title: Re: Inventory items problem!
Post by: Khris on Tue 22/07/2008 14:47:06
This is seriously the most frequently asked question of all times, wouldn't it be sensible to add it to the Tutorial or the BFAQ? (Or both?)
Title: Re: Inventory items problem!
Post by: SSH on Tue 22/07/2008 15:06:36
Since its a wiki, what's stopping you? ;)
Title: Re: Inventory items problem!
Post by: Gs92 on Tue 22/07/2008 17:33:37
One last thing, I wanted to make it so that when you have for example half a key and try to use it with, lets say, a door it wont work, and then when u got the whole key, it works. If you get me. I've been trying to do this by making two different "use inventory on this object" strings with the same object but that doesnt work.
Title: Re: Inventory items problem!
Post by: olafmoriarty on Tue 22/07/2008 17:44:51
Quote from: Gs92 on Tue 22/07/2008 17:33:37
I wanted to make it so that when you have for example half a key and try to use it with, lets say, a door it wont work, and then when you got the whole key, it works. If you get me.

Wouldn't that be as simple as adding two seperate ifs?


if (player.ActiveInventory == iHalfKey) {
  [the code needed to return an error message]
}
if (player.ActiveInventory == iWholeKey) {
  [the code needed to open the door]
}
Title: Re: Inventory items problem!
Post by: Gs92 on Tue 22/07/2008 20:56:39
Ok i'm practically done with my test game now, just need to know what the script command for completing the game? thanks a bunch again for all your help
Title: Re: Inventory items problem!
Post by: Khris on Tue 22/07/2008 21:21:21
There's no such command. Or are you looking for QuitGame()?
Title: Re: Inventory items problem!
Post by: Gs92 on Tue 22/07/2008 21:34:06
really? so what do you do when you want to make the "end" of the game so to speak, you gotta do a cutscene(a "congratulations you've completed the game" thing)?
And no I dont think thats what I mean, Quitgame is the thing you do when you just exit the game if i've understood correctly?
Title: Re: Inventory items problem!
Post by: Khris on Tue 22/07/2008 21:59:23
Yes, a cutscene, credits, do whatever you want, it's up to you how to end the game.
Maybe a screen that let's you restart/load/quit?
Title: Re: Inventory items problem!
Post by: Gs92 on Tue 22/07/2008 22:21:04
Yeah, thanks for ur help and thanks to everyone else aswell i'm finished with my shitty game :P