Inventory items problem!

Started by Gs92, Mon 21/07/2008 23:05:28

Previous topic - Next topic

Gs92

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.

Makeout Patrol

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:

Code: ags

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.

Gs92

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.

Makeout Patrol

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.

Gs92

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)

Matti

#5
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:

Code: ags

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)

Gs92

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

Khris

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?)

SSH

Since its a wiki, what's stopping you? ;)
12

Gs92

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.

olafmoriarty

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?

Code: ags

if (player.ActiveInventory == iHalfKey) {
  [the code needed to return an error message]
}
if (player.ActiveInventory == iWholeKey) {
  [the code needed to open the door]
}

Gs92

#11
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

Khris

There's no such command. Or are you looking for QuitGame()?

Gs92

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?

Khris

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?

Gs92

Yeah, thanks for ur help and thanks to everyone else aswell i'm finished with my shitty game :P

SMF spam blocked by CleanTalk