SOLVED: Temporarily using an object in a room without adding it to the inventory

Started by TurduckenMan, Wed 16/09/2015 21:15:50

Previous topic - Next topic

TurduckenMan

Hello everyone!

I'm currently working on a project, and in this project there's a room where my character is meant to pick up and use a hose to spray a couple of things. However, the player doesn't get to keep the hose, so I only want it to be usable in this one location.

I've tried adding a blank inventory item when the player interacts with the hose, and then removing it when they dismiss it. This actually worked decently, however as I don't want some sort of dynamic-moving hose, I need the player to be locked into that position while using the hose. Using the hose on any hotspots cause the character to walk over to the hotspot even though I've disabled his walk option, and I'm having difficulties preventing such a thing from happening. I feel I may be missing something fairly obvious, but after checking the manual and looking for similar threads I'm not entirely sure what to do. (I've thought of setting the walkto point for all the hotspots to 0 and then manually making the character walk there any other situation where it's needed, but that just feels too janky to be proper or reasonable.)

If there's an easier way to temporarily "equip" something to the player then I'd love to hear it, or if there's a way to make my attempted method described above work properly that would be perfect as well. Is it maybe possible to create a new cursormode?

Any help is much appreciated!

Slasher

Quoteneed the player to be locked into that position while using the hose.
check out LockView in the manual and make animation loop views for the spraying is one option to go with.


Snarky

The short answer is that you probably want to create a custom cursor mode, disable all other cursor modes (depending on your UI style), and handle the "use hose" on different hotspots/objects as a separate event (using the approach slasher describes). Another approach would be to disable the walkable area, but that doesn't make different stuff happen when you spray something with the hose, so you'll still need to code that.

If that doesn't sound like it would work, here's a longer answer...

To "temporarily equip" an object, there are two ways:

-If you want it to appear in the inventory while you have it equipped, just add it as an inventory object, and remove it again when you unequip it.
-If you don't want it to appear in the inventory, just set a flag (a boolean variable) somewhere to indicate that you have it.

And then for any conditions/behaviors that depend on whether you have the object equipped or not, you either check whether the character has the item, or you check the value of the flag.

So that part is easy. What you're asking doesn't really have anything to do with having an item temporarily, but with temporarily changing the rules of interaction: going into a different mode. It would be the same problem if, for example, the character could get temporarily drunk, and that would change his ability to move and interact with objects.

In principle, there are two ways to go about it: (1) for each action the character can perform, you check the condition (has item/flag set), and do the appropriate thing, (2) when you enter/leave the relevant mode (having the item), you change the room or game setup somehow, disabling actions that shouldn't be possible and enabling ones that should. (It sounds like you've been attempting this second approach.)

Exactly how to go about this depends on just what you want to prevent and make possible, and on how your game project is set up. So what templates and modules are you using? (e.g. if you're using the LucasArts template, the solution might be different than if you're using the Sierra template.) With a better understanding, we might be able to help more.

Khris

LockView doesn't come into play here at all.

An additional cursor mode is one way, but you can stick with the inventory item if you add a custom on_mouse_click() to the room script:

Code: ags
function on_mouse_click(MouseButton button) {
  if (button != eMouseLeft) return; // no left click? proceed as usual
  if (player.ActiveInventory != iHose) return; // hose isn't active? proceed as usual
  ClaimEvent(); // prevent global behavior
  Hotspot *h = Hotspot.GetAtScreenXY(mouse.x, mouse.y); // get hotspot under mouse
  if (h == hFlowers) {
    ...
  }
  // implement some way of dropping the hose, call player.ActiveInventory = null; to do so
}

TurduckenMan

Hey, thanks slasher, snarky and Khris for your responses!

I've used the code Khris provided and it worked completely flawlessly. Thanks a ton man, definitely going to credit you as you've helped me with two extremely frustrating things now haha.
Now I have a decent idea on how lockview works as well!

The response time on this forum never ceases to amaze me, thanks a lot you guys.

SMF spam blocked by CleanTalk