Jibble

Author Topic: more hotspots and music(SOLVED)  (Read 492 times)

more hotspots and music(SOLVED)
« on: 20 Jun 2020, 20:32 »
Hey guys.

I'm facing a few problems on my game. It's not much for you I guess, that's why I put it all in the same topic (to avoid flooding too much :) ).

1)HOTSPOTS : I followed a code that was previously given to me here. I'm going for a Sam and max interface. For those who don't know it, the pointers (walk, look,pick up speak and use) animate when the mouse is over a hotspot, item or character. This isn't initially coded on  I had too add it :

        - 1)first, to animate the pointer when over a hotspot (thanks @Khris)

 
Code: Adventure Game Studio
  1.                   bool wasHovering = false;
  2. function HandleCursorHighlight() {
  3.   bool isHovering = GetLocationType(mouse.x, mouse.y) != eLocationNothing;
  4.  
  5.   if (isHovering && !wasHovering) {
  6.     // cursor entered interactive area
  7.     if (player.ActiveInventory) mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.Graphic + 1);    
  8.   }
  9.   else if (!isHovering && wasHovering) {
  10.     // cursor left interactive area
  11.     if (player.ActiveInventory) mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.Graphic);
  12.   }
  13.  
  14.   wasHovering = isHovering;
  15. }
  16.  

It works just fine, but I was wandering if I could adjust it so that the animation doesn't go if the hotspot isn't scripted for the specific action. For instance an item on the floor would not animate the "speak" cursor because I haven't planned to script something in "talk to hotspot". It would just animate the pick up and look at cursors, because this is what the hotspot has functions for. I was thinking maybe with the properties of the hotspot, or if there is a function that recognizes if clicking will do something or not.

       - About hotspots again, weirdly enough, the "walk to" cursor doesn't go through hotspots. If I create a hotspot to changeroom, it doesn't activate. So I used this code to force the action :
Code: Adventure Game Studio
  1. function on_mouse_click(MouseButton button)
  2. {
  3.   // called when a mouse button is clicked. button is either LEFT or RIGHT
  4.   if (IsGamePaused())
  5.   {
  6.     // game is paused, so do nothing (i.e. don't process mouse clicks)
  7.   }
  8.   else if (button == eMouseLeft)
  9. {
  10.     // if it is walk-to command
  11.     if (mouse.Mode == eModeWalkto)
  12.     {
  13.       // if there's a hotspot under mouse cursor
  14.       if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot)
  15.       {
  16.        
  17.          //then fire "interact" event
  18.         Room.ProcessClick(mouse.x, mouse.y, eModeInteract);
  19.         return;} // do not do anything else
  20.            Room.ProcessClick(mouse.x,mouse.y, mouse.Mode);
  21.       }
  22.     }
  23.     // in all other cases - just do default action
  24.     Room.ProcessClick(mouse.x,mouse.y, mouse.Mode);
  25.   }
  26.   else // right-click, so cycle cursor
  27.   {  
  28.     mouse.SelectNextMode();
  29.   }
  30. }
  31.  

Once again, it does the trick. When I "walk to" a hotspot that changes the room, it works. But when I "walk to an "item hotspot" it plays the interact script, which is not cool. I could'nt find the way to have both the interaction on specific hotspots(the exit ones) and the no interaction on regular ones. Again there might be a function that determines the id of the hotspot, that i could use to determine whether it's an exit one or not(1->3 are exits,4+ are regular), or maybe by including comments that a function could recognize? Any ideas ?



2)Second point is about music, I guess an easy one. It's pretty easy to put the music changes in specific room loads so that it loops and there is no discontinuity through the game. But I'm going with 2 playable characters here, and so the player changes will disturb this beautiful continuity.
Actually I tried to write an example but it was so terribly unclear I will just go with the gerenal question and will be more precise if needed :
-imagine you have like in DOTT, two houses with many rooms inside. You want music1 for one house(and all its rooms) and music2 for the other. Music 1 si on cause you play the main character in house1. The music doesn't restart every time you go from a room to the other(so you ant' use music1.play at each room load) but if you switch characters, you need the music to change to music2.
One last thing,in reality there are more than 2 houses and more than one music in one house so you can't just systematically change when you switch character.

I hope that is clear enough...I'm ready to explain as precisely as needed^^


Thanks a lot, and actually, maybe I should have posted different topics.

« Last Edit: 07 Jul 2020, 12:39 by lafouine88 »

Re: more hotspots and music
« Reply #1 on: 21 Jun 2020, 13:59 »
Yo.

I think I came out with quite an easy solution for the music issue. A global int for each character that changes according to the places they go. Then on the GUI button that changes the player character I would add a line to stop the current music and play the aMUSIC(intcharacter1 or 2). I haven't tried it yet but I'm pretty sure this is an easy way.

Still working on the rest :)

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: more hotspots and music
« Reply #2 on: 21 Jun 2020, 21:56 »
Let me check the code from my game, since I did mine like that.

Edit:
The command you need is: IsInteractionAvailable

You place it inside a if/else condition that checks if the mode is available. This if/else will of course be checked where your change/show the options available.

 
Code: Adventure Game Studio
  1. function name()
  2. {
  3.  int click_x = mouse.x;
  4.  int click_y = mouse.y;
  5.  if (IsInteractionAvailable(click_x, click_y, eModeInteract) // this might be inside another condition or have extra conditions to make it work right with your game
  6.  {
  7.    // Add the code to [i]display[/i] the interaction button here
  8.  }
  9.  else // Add the code to [i]hide[/i] the interaction button here
  10.  
  11. // Repeate if/else condition for all your mouse modes here (or there might be simpler way to go thru them)
  12.  
  13. }
  14.  


Hope it helps.
« Last Edit: 21 Jun 2020, 22:37 by Cassiebsg »
There are those who believe that life here began out there...

Re: more hotspots and music
« Reply #3 on: 23 Jun 2020, 15:01 »
Yeah cassiebg this seems perfect. I m currently on vacations so don't have access to my computer to check but I ll confirm asap that it is solved with it. I guess it s gonna be.

Thanks a lot

Re: more hotspots and music
« Reply #4 on: 26 Jun 2020, 21:35 »
Hey guys, me again

So I tried cassiebg function, and just added it to my (slightly modified) hovering script as follows :
Code: Adventure Game Studio
  1. function HandleCursorHighlight() {
  2.   bool isHovering = GetLocationType(mouse.x, mouse.y) != eLocationNothing;
  3.  int click_x = mouse.x;
  4.  int click_y = mouse.y;
  5.    bool inter = IsInteractionAvailable(click_x, click_y, eModeInteract);
  6.  
  7.  
  8.     if (isHovering && inter) {
  9.     // cursor entered interactive area  && interaction is available  
  10.         if (player.ActiveInventory) mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.CursorGraphic + 1);    
  11.     }
  12.   else if (!isHovering) {
  13.     // cursor left interactive area
  14.     if (player.ActiveInventory) mouse.ChangeModeGraphic(eModeUseinv, player.ActiveInventory.CursorGraphic);
  15.   }
  16.  
  17. }
  18.  

That was just a try only with the interaction function. So if my hotspot isn't planned an interaction, the cursor shouldn't animate.

It doesn't but only in "useinventory" mode as planned in the code. But it still does with the regular cursors(walk to, pickup...). Any ideas on how to include this last lot.

Thanks

,and btw if found out a way to solve the exit hotspots problem using "ifinteractionavailable". I just put a lookat interaction on all my hotspots but the exit ones.
 Then i added a check,if the lookat interaction was available then
The mouse stayed normal. If not(exit then) it forced the mouse to emodeinteract, to use the exit.
« Last Edit: 27 Jun 2020, 10:41 by lafouine88 »

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: more hotspots and music
« Reply #5 on: 27 Jun 2020, 19:25 »
You need to add an if/else condition for each mode, not just for interact with/without inventory

That means: IsInteractionAvailable(click_x, click_y, eModelookat); ... IsInteractionAvailable(click_x, click_y, eModeWalkto); ...  IsInteractionAvailable(click_x, click_y, eModePickup); ...
There are those who believe that life here began out there...

Re: more hotspots and music
« Reply #6 on: 27 Jun 2020, 21:10 »
Yop cassiebsg.

I'm not sure I uderstand. I know that I need to add the other interactions (lookat,speakto...) if I want to be complete. But my current problem is not that yet. It actually does'nt overwrite the cursors' animations.
The code I wrote is good, but only because I can specify "player.active inventory". If I try to go with something equivalent like this :
Code: Adventure Game Studio
  1. function actions() {
  2.   bool isHovering = GetLocationType(mouse.x, mouse.y) != eLocationNothing;
  3.  int click_x = mouse.x;
  4.  int click_y = mouse.y;
  5.    bool inter = IsInteractionAvailable(click_x, click_y, eModeInteract);
  6.  
  7.  
  8.     if (isHovering && inter) {
  9.     // cursor entered interactive area
  10.       if (IsInteractionAvailable(click_x, click_y, eModeInteract)==1){
  11.         if (mouse.Mode==eModeInteract) mouse.ChangeModeGraphic(eModeInteract, 42);    
  12.     }}
  13.   else if (!isHovering) {
  14.     // cursor left interactive area
  15.     if (mouse.Mode==eModeInteract) mouse.ChangeModeGraphic(eModeInteract, 41);
  16.   }
  17.  
  18. }


the basic animation planned in the system when you go over  hotspots still goes(on the interaction cursor of course). Did you find a way to get over this ? Maybe my code isn't placed properly or has something wrong. To make it clear, I feel like the cursors work slightly differently to the useinventory. So I could have what I want (I just need to add the lines you wrote for look etc.) for "useinv" but I can't get it for the other cursors.

Thanks and sorry if I don't understand what you're saying.

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
    • Cassiebsg worked on one or more games that won an AGS Award!
    •  
    • Cassiebsg worked on one or more games that was nominated for an AGS Award!
Re: more hotspots and music
« Reply #7 on: 28 Jun 2020, 08:58 »
Uhm, I think you probably have to turn off the automatic "animate over hotspots" and code your manually, so it only animates where you code it.

I used my code on a VerbCoin system, to only display the available options for each hotspot, but my cursor always animated/highlighted when it was over a hotspot, since that was what I wanted it to do.

I can't remember how Sam&Max system worked and I have trouble understanding exactly what you want to do. Sorry. (maybe post a video/animated gif so we can see what's it doing and what you want it to do?)
I'm no experienced coder, I just go in a trial and error mode until things work the way I want, then I look the code through and try to see if I can improve it and tidy it.
There are those who believe that life here began out there...

Re: more hotspots and music
« Reply #8 on: 06 Jul 2020, 19:29 »
Hi cassiebsg. I'm back on my game after some time off. Sorry for not replying.

I'm still looking for a solution. But I won't let it block my progression on the game, I'm pretty sure I'll find something.
&index=2
At 1'35 you have an example of the interface I'm doing and what I want. The hand closes on the mail and there is an adapted answer(stealing the mail etc.)however the sign just after it is NOT pickable, so the hand DOESN'T close on it. It still is a hotspot because yoiu can read it and sam says "I can't pick that up"(he doesn't if you just clic randomly).

I tried something that I put in "repetedly execute of my room(If it worked I would copy it in all the rooms, although unelegant...it doesn't^^)
Code: Adventure Game Studio
  1. function room_RepExec()
  2. {
  3.  
  4.  bool hotsp = GetLocationType(mouse.x, mouse.y) != eLocationNothing;
  5.  
  6.     if (hotsp) {
  7.       if ((IsInteractionAvailable(mouse.x, mouse.y, eModeInteract)==0)&&Mouse.Mode==eModeInteract){
  8.         mouse.ChangeModeGraphic(eModeInteract, 41);    
  9.     }}
  10.   }

It does force the interact mode into its "idle" graphic when I'm on a hotspot that doesn't have an interaction. But it actually struggles against the system that wants it to get back to the "usable" icon. I end up with a blinking cursor that still stays on the "notusable" icon I want but makes the thing irritating and messy.

If anybody has an idea that s very cool, otherwise I'll just let you know if I find out something in the end.

Thanks a lot anyway to cassiebsg, the (IsInteractionAvailable) function is so useful :)

Re: more hotspots and music
« Reply #9 on: 06 Jul 2020, 19:48 »
Put this in a new script module (leave the header empty):
Code: Adventure Game Studio
  1. int cursorSlot[10], cursorSlotActive[10];
  2.  
  3. void game_start() {
  4.   for (int mode = eModeLookat; mode <= 9; mode++) {
  5.     cursorSlot[mode] = mouse.GetModeGraphic(mode);
  6.   }
  7.   // set active cursor mode slots
  8.   cursorSlotActive[eModeLookat] = 2105;
  9.   cursorSlotActive[eModeInteract] = 2111;
  10. }
  11.  
  12. void repeatedly_execute() {
  13.   bool iia = IsInteractionAvailable(mouse.x, mouse.y, mouse.Mode);
  14.   int mg = mouse.GetModeGraphic(mouse.Mode);
  15.   int csa = cursorSlotActive[mouse.Mode];
  16.  
  17.   // default cursor over available interaction: change to active slot
  18.   if (iia && csa > 0 && mg != csa) mouse.ChangeModeGraphic(mouse.Mode, csa);
  19.  
  20.   // no interaction but cursor still using active sprite: change back to default slot
  21.   if (!iia && mg == csa) mouse.ChangeModeGraphic(mouse.Mode, cursorSlot[mouse.Mode]);
  22. }

At the end of game start, set the sprite slots for the active cursors.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: more hotspots and music
« Reply #10 on: 07 Jul 2020, 11:51 »
Hey Khris. Thanks a lot for your code.
So if I understand I just needed to change the sprite number as so :
Code: Adventure Game Studio
  1. void game_start() {
  2.   for (int mode = eModeLookat; mode <= 9; mode++) {
  3.     cursorSlot[mode] = mouse.GetModeGraphic(mode);
  4.   }
  5.   // set active cursor mode slots
  6.   cursorSlotActive[eModeLookat] = 32;
  7.   cursorSlotActive[eModeInteract] = 40;
  8.   cursorSlotActive[eModeTalkto]=43;
  9.   cursorSlotActive[eModePickup]=35;
  10. }

In that case it still doesn't make the trick. I wasn't really familiar with the functions you used but I tried to understand them and ended up removing the thing that could be the problem.
Code: Adventure Game Studio
  1. void repeatedly_execute() {
  2.   bool iia = IsInteractionAvailable(mouse.x, mouse.y, mouse.Mode);
  3.   int mg = mouse.GetModeGraphic(mouse.Mode);
  4.   int csa = cursorSlotActive[mouse.Mode];
  5.  
  6.   // default cursor over available interaction: change to active slot
  7.   if (iia && csa > 0 && mg != csa) mouse.ChangeModeGraphic(mouse.Mode, csa);
  8.  
  9.   // no interaction but cursor still using active sprite: change back to default slot
  10.   if (!iia) mouse.ChangeModeGraphic(mouse.Mode, cursorSlot[mouse.Mode]);        ////////////////////////////<---here
  11. }

I didn't really understand this part of the code, so I tried without. And it does what we need, way better than I wrote it initially. But the fact that it's again a repetedly executed function makes the cursors blink again.
Yet again, maybe I should'nt have removed it, but with the intial lines, it didn't work :(

Thanks again for your help

Re: more hotspots and music
« Reply #11 on: 07 Jul 2020, 12:07 »
I implemented that change and it made no difference.
Did you revert all the changes to the cursor modes? As in, reset their View to 0, and set all the Animation* properties back to false?
Fail at Floaty Rog' now!  still having to deal with what games are going through

Re: more hotspots and music
« Reply #12 on: 07 Jul 2020, 12:35 »
Oh no I didn't do that, and now it works. PERFECT thanks a million!
I'll just put back your intial code then^^

Have a good day