Does anyone know how to make an item usage event?

gameking31

  • Posts: 22
So far, I've gotten a menu that only displays the names of items I've acquired in game, but when an item is used, I want to have the game check what actor is in front of it, and have various responses. Example:

-Lemon used while facing piano- You squish the lemon against the D minor key. You are amused
-Orange used while facing piano- You squish the orange into the strings of the piano. This amuses you less than say, a lemon on the D minor key would
-Lemon used while facing other objects or none at all- This is a lemon. If only you could find a piano containing a D minor key...

Does anyone know how I would go about this? Thank you ahead of time

gurigraphics

  • Posts: 688
You can use lists:

If Lemon = 0, then do it.
If Lemon = 1, then do it.
If Lemon = 2, then do it.
And so on.

http://www.stencyl.com/help/view/lists/

gameking31

  • Posts: 22
I understand how to divide up the various responses with 'if' statements, what I don't understand is how to word the, 'if there's a piano in front of you' statement. I'd imagine it would look like this...

If lemon used
   if (Piano is in front of you) then do the thing involving the piano
   else if (any other objects I want to use) do the thing involving that object
   else, thing you do when there's no object.


My problem isn't how to structure it, my problem is that I don't know how to tell stencyl to check what object is in front of the player, or how to set the peramaters for how generous of a box it checks, or what to do if more than one object falls in that location.

doczal

  • Posts: 44
Without more information about your game, it'd be difficult to give you a more specific response.

What kind of game are you making? A side-scroller? Top-down? A visual novel type game? How do you plan to detect the interaction between the player and the object? Are you using collisions?

gameking31

  • Posts: 22
Thank you already for your patience. I will try to be as clear as I can. The game is a horror game. We started it in RPG maker and decided to begin anew in stencyl. It's top-down like the well known 'Witch's hourse' or a bit better known, pokemon. However, this game doesn't run on a grid system like most rpgmaker games and pokemon do. I'm using collisions, and also a Z ordering system. (Something that can identify when a character is behind an object, or in front of it and display it properly.) If you have any more questions feel free to ask. I will try to check back more frequently than I have been. Weekends are a bit busy for me.

doczal

  • Posts: 44
If you want to have the game check if something is in front of the player, a simple solution would be to attach an empty actor (an actor with no animations with a collision box of how big of an area in front of the player that you'd like to check) and then update its x and y positions such that it's always following the player.

Then you can set that as one of the player's attributes (e.g. make an attribute "ItemChecker" and set it as that actor). That way inside the player's behavior, you can check for collisions using "When ItemChecker collides with group", where group is a special group you've created for all items you'd like the player to be able to interact with. If you're worried about the "ItemChecker" colliding with more than one actor, you can either space out interactable items in your game such that the "ItemChecker" collision box will never touch more than one item at the same time, or use a boolean attribute that is set to true the moment it collides with something. Then make it so that the collision checking only happens if that boolean is false. This way collision checking will only happen once. I'm not 100% sure this will work, because I'm not sure how Stencyl handles simultaneous collisions, but I'm pretty it will detect one collision before the other.

gameking31

  • Posts: 22
Doczal, you're awesome. I was thinking something along these lines to do this, but you put it in a way that makes sense to me. Hm, I will have to do this thursday. This week is busy and thursday is the day my buddy and I who are developing this game have planned to set aside this week to work on it. I will let you know if it works. Thank you again.

gameking31

  • Posts: 22
Alright, sorry it's taken me so long to reply. I'm trying to get it to work, but with the dialogue extension having NO way to activate an event, I have to turn on a boolean, and have a constant 'if' statement checking for it. My question now would be how do I get that itemuse hitbox to stay up for only a split second, and if nothing's there, activate it's non collision event, then go away. I'm trying a lot of things, but it looks like Stencyl wants things to actually collide for collision effects, not just be spawned inside of it.

Justin

  • *
  • Posts: 4310
Quote
I'm trying to get it to work, but with the dialogue extension having NO way to activate an event, I have to turn on a boolean, and have a constant 'if' statement checking for it.

If you want to post a thread in the Dialog Extension forum with details about what you're trying to achieve, I might be able to help.

For Live Support: Join our discord server and ping me @justin.
I'm most often available between 8am and midnight Japan time. (GMT+9)

gameking31

  • Posts: 22
Oh thank you so much. Could you post me a link to it? I actually couldn't find it. that was something I was trying to find a little ways back, but I just assumed there wasn't one.

Justin

  • *
  • Posts: 4310

For Live Support: Join our discord server and ping me @justin.
I'm most often available between 8am and midnight Japan time. (GMT+9)

gameking31

  • Posts: 22
Thank you Justin for pointing me in the right direction for that specific problem. I'll still keep this post running for the 'use item on actor' part of the problem, because that doesn't involve the dialogue extension. I still am trying to figure out how to get the box to check if it collides with the hitbox of another actor the second it spawns. The way I had it running was, the box would spawn inside the hitbox of the item it needed to check the collisions for.  I thought this would cause an immediate collision with the object, but it seems like the box would actually have to move into the hitbox, and not simply spawn into it. This is a problem, because the box is only supposed to exist for a split second. (if it doesn't hit anything within this time, it needs to vanish and trigger the 'you didn't use this item on anything' event.)