Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: proskiier on Tue 04/12/2007 00:57:29

Title: Place inventory anywhere(SOLVED TY ASHEN)
Post by: proskiier on Tue 04/12/2007 00:57:29
Hey I was wondering if there is a way to have a room in which when you gain inventory items you can put them anywhere.

Ill explain a lot better for you all... my game is an adventure where you solve puzzles and mini games and each time you get an object like a tv or another item from your bedroom that was stolen from you and *scattered* among the lands...


I know that I could probably have a bunch of not visible versions in the room and hotspots and depending on which one they clicked it would place it there, but I really want them to be able to put them anywhere in the room and that would require me to make tons of those.  I also wanted to make it that they can pick them up by clicking them with the finger icon, which would bring up a gui asking if you want to move it (with yes/no buttons)....

my whole plan is at the end of the game for a screenshot to be taken so everyone has pictures of their different room layouts, because I think that would be neat.

So basically can anyone tell me if this is possible please. Thanks a ton in advance for any suggestions/code/help. :)
Title: Re: Place inventory anywhere
Post by: Ashen on Tue 04/12/2007 01:07:35
How many items are you talking about?
The obvious solution is to use Characters to represent the Items - V2.72 has a limit of 300 Characters, and 300 InvItems (3.0 has no limit on Characters, and still 300 Items). You could either have dummy Characters to represent items in that room, or change Views and use conditions in Character interactions to use existing characters, as Items in that Room. Setting Character coordinates within a room is easy, and then you'd just need a variable to store what Items you've got to place in your room.
Title: Re: Place inventory anywhere
Post by: proskiier on Tue 04/12/2007 01:11:30
ok awesome ashen... im not sure how many as im still working on the plot and I kinda think of stuff as I go along, but ill guess ill just use characters... i never thought of that... could you help me out on the gui code though, this is my first game and I have no idea how after placing the item down it would work when i try to pick them up.


ALso how exactly would my code go, Ok so I have a tv in my inventory and I walk into my bedroom and select it, place it down, and then I make the whole room a hotspot and where ever they click the character (tv) moves and becomes visible???

thanks man already I appreciate your help and fast reply
Title: Re: Place inventory anywhere
Post by: Ashen on Tue 04/12/2007 01:22:35
Rooms can have their own on_mouse_click functions, so you could use that along with ClaimEvent (http://www.adventuregamestudio.co.uk/manual/ClaimEvent.htm) to basically make the whole room a Hotspot. GUI code would basically just be an InventoryWindow object on the GUI and eModeUseinv, same as using Inventory on anything.

I guess the code would be something like (pseudocode):

// Room script for Bedroom
function on_mouse_click(MouseButton button) {
  if (button == eMouseLeft && mouse.Mode == eModeUseinv) {
    character[player.ActiveInventory.ID].ChangeRoom(player.Room, mouse.x, mouse.y);
    player.LoseInventory(player.ActiveInventory);
    ClaimEvent();
  }
}


But don't quote me on that...
Title: Re: Place inventory anywhere
Post by: proskiier on Tue 04/12/2007 01:30:09
I am still kind of confused ashen with this whole claimevent thing and I read the page you pointed me to, what does that whole spacebar thing mean?

And also how can I make it so that when you click on an object(character) that you placed down(tv) a GUI pops up that says "Do you want to pick this item up?, yes, no"

^^can you do that with an input box type code (visual basic, if i remember correctly)??^^

sorry im a pretty awful coder/new to this
Title: Re: Place inventory anywhere
Post by: Ashen on Tue 04/12/2007 01:44:40
Sorry to be so vague, but there's just a whole bunch of things that MIGHT need to be taken into account, depending on how you've got things set up, but don't HAVE to be. So, it's not easy to give a single definitive code you can use...

The spacebar thing isn't really relevant to your question - all the ClaimEvent function does is stop other conditons from happening (i.e. it'll stop any Global script from running). Actually, you might not even need ClaimEvent - it depends on your Global script - the on_mouse_click bit is the important part.

AGS has InputBoxes (http://www.adventuregamestudio.co.uk/manual/Game.InputBox.htm) too, so you could for example do:

String Temp = Game.InputBox("Do you want to pick this up? (Yes/No)");
if (Temp == "Yes") {
  cWhatever.ChangeRoom(-1);
  player.AddInventory(inventory[cWhatever.ID]);
}


But, it might be easier to do this with a GUI (see SupSuper's Confirmation GUI module (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=27676.0), for example).
Title: Re: Place inventory anywhere
Post by: proskiier on Tue 04/12/2007 01:57:20
Ok i think im getting it a bit now... thanks for that module link

so this goes into my room script

function on_mouse_click(MouseButton button) {
  if (button == eMouseLeft && mouse.Mode == eModeUseinv) {
    character[player.ActiveInventory.ID].ChangeRoom(player.Room, mouse.x, mouse.y);
    player.LoseInventory(player.ActiveInventory);
    ClaimEvent();
  }
}


and then below that I can put all of the functions for calling the different objects (say for example tv) or does that code automatically work if i make iTV a name of a character (since character[player.ActiveInventory.ID] will be character[iTV] ), setting the view the same sprite as my inventory one??

sorry if I am kinda slow at getting this but, I am just trying to grasp this whole concept so I dont just use your code but understand it aswell, so I can learn from it.


OH and also will I have to make the whole room walkable so that iTV can get to the location or will the changeroom command take care of that?

Can't thank you enough ashen :)
Title: Re: Place inventory anywhere
Post by: Ashen on Tue 04/12/2007 11:49:46
As I said that's pseudocode, it's not really meant to be used as-is, just to give you an idea of what's involved. What it does is move the character with the same ID number (not script-o-name or 'real' name) as the current ActiveInventory item into the current room, at the point the player clicks. You'd need to add something to change the Character's View so they look like the item , and maybe some check of where was clicked (so things aren't stuck floating halfway up a wall) - Hotspots or Walkable Areas might work for that. Even if you're using dedicated Characters (so cTv is only used in that room, as a TV), you might want to change their appearance based on where they are in the room (e.g. they look different on a shelf facing left than they do facing fowards) - again, the Hotspot or Walkable area would help you set that, but you'll need to store what View/Loop - and you need some way to get which Character represents which Item. Custom Properties (http://www.adventuregamestudio.co.uk/manual/Custom%20Properties.htm) will probably help there - give each Item a property with the ID number of the Character to use, and do something like:

int CharID = player.ActiveInventory.GetProperty("ToUse");
character[CharID].ChangeRoom(player.Room, mouse.y,mouse.y);


Or, if the Item Characters started from character[20], for example, you could do:

int CharID = player.ActiveInventory.ID + 19; // First item ID = 1, + 19 = char 20, etc
character[CharID].ChangeRoom(player.Room, mouse.y,mouse.y);


Again, sorry to be so vague, but a lot of the final code would be based on how you want the Bedroom to be set out - without being certain of that, I can only give general suggestions or risk forcing features on you that you don't want/need. If you want to talk about the details in PM, so as not to spoil too much about the finished game, go ahead and contact me. Despite what you may be thinking, once you get the details of what you want clear it really shouldn't be that hard to do :) - there's a fair amount of code involved, but none of it's that complicated (mostly ChangeRoom and SetView stuff, with a few extra variables thrown in).

Quote
will I have to make the whole room walkable so that iTV can get to the location or will the changeroom command take care of that
Unless you choose to use them to mark shelves, desktops, etc (and Hotspots would be better for that, IMO), or so the player can wander round looking at his trophies, you don't need to include walkable areas. ChangeRoom will place the Item Character at the right location, and they don't need Walkable areas to just stand somewhere, only if they're actually going to be walking on them - and I don't think you'd want your TV doing that...
Title: Re: Place inventory anywhere
Post by: proskiier on Tue 04/12/2007 18:47:48
ok ashen here is my new idea, because i think I can handle the code of it, but I just have one more question with it so I added some pictures

Ok so my new idea is that say you got a tv from a minigame and you walk into your room and select the tv ( so a script runs for the tv cursor{if mouse.Mode == eModeUseinv} where it makes the possible spots to put it be visible(outlines) and when you click in one it is placed there)
So i want the tv to be a character and depending on which outline you click inside it to move to... can you help me out with that code?


(http://img231.imageshack.us/img231/2030/bedroomtveditfa8.png)

my map will have more furniture but I figured for each item you get I can just make a certain ammount of places with object.visible, but I dont want to have double that amount with the actual tv, so ide make it a character like you said. I hope you can understand me... does that make sense??

thanks man for any code or help
Title: Re: Place inventory anywhere
Post by: Scorpiorus on Fri 07/12/2007 16:49:47
So have you had any success on making it work?

It is of course possible to make it that the player could drop/put objects anywhere in any room but is it really a necessary feature to have to benefit game-playability?

Basically, because each room in AGS is a standalone entity with its hotspots/walkbehinds/perspective/etc you'd need to define a set of locations in each room for each inventory item to put, and that seems quite a lot of work to do.

You could probably make it less hassling by having certain locations where a variety of inventory items can be put in, but that would require you to classify the items (so a certain location will accept any item of a given class) which means extra coding as well as extra effort to specify a type for each inventory item. Depending on an overall complexity of the game world this task may be not very trivial to accomplish.
Title: Re: Place inventory anywhere
Post by: Ashen on Fri 07/12/2007 17:40:35
The reason there's been no updates here, is that I'm working with proskiier via PM to sort this out. We've got some semi-working code, but there's still some kinks to be worked out - once it's finished it'll be posted here for all to see, comment on, and generally point out that there's a much easier way of doing it...

Quote
you'd need to define a set of locations in each room for each inventory item to put ... Depending on an overall complexity of the game world this task may be not very trivial to accomplish.

If I understand proskiier right, this is only one room in the game - basically a trophy room for the Items you've recaptured - which makes it a whole lot simpler.
Title: Re: Place inventory anywhere
Post by: Scorpiorus on Fri 07/12/2007 17:52:52
Ah good to know you are getting sorted it out!

And I indeed seem to misread it yeah, having it in only one room makes things easier to handle.

:)
Title: Re: Place inventory anywhere
Post by: proskiier on Fri 07/12/2007 20:26:08
yeh ashen has helped me so much... ashen fell free to post your code here so that It can help anyone else who has a similar idea like mine :)