Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: HandsFree on Thu 16/06/2011 23:52:15

Title: Limit actions in unhandled events to hotspots
Post by: HandsFree on Thu 16/06/2011 23:52:15
I'm trying to add standard reactions for certain inventory items.
In function unhandled_event there was already this code

if (mouse.Mode == eModeInteract){
  Display("That's not something you need to touch.");
}
else if (mouse.Mode == eModeLookat){
  Display("Nothing interesting.");
}
else if (mouse.Mode == eModeTalkto){
  player.Say("There's nothing to say.");
}

For money I added:
else if (mouse.Mode == eModeUseinv){
  if (player.ActiveInventory == iMoney){
    player.Say("That's not for sale");
  }
}

What I don't like is that the player says this everywhere you click on the screen with the money.
Is it possible to make it so that this reaction is only triggered when the player uses the money on real hotspots?
(that way it's more clear if you actually hit the hostspot or not).

thanks
Title: Re: Limit actions in unhandled events to hotspots
Post by: Khris on Fri 17/06/2011 00:37:55
  else if (mouse.Mode == eModeUseinv){
    if (GetLocationType(mouse.x, mouse.y) == eLocationNothing) return; // do nothing
    if (player.ActiveInventory == iMoney){
      player.Say("That's not for sale");
    }
  }
Title: Re: Limit actions in unhandled events to hotspots
Post by: ddq on Fri 17/06/2011 00:47:58
The function unhandled event takes two parameters, what and type. The manual states that what for a hotspot is 1 and type for inventory item is 3, so what you can do is include this...

unhandled_event (int what, int type)
{
   // Other code
   if ( what == 1 && type == 3 && player.ActiveInventory == iMoney ) player.Say("That's not for sale");
    // Extra: if player uses money on nothing, just an example, but you can see the things you can do with this function
    else if (what == 4 && type == 3 && player.ActiveInventory == iMoney ) player.Say("I don't want to throw good money away.");
}
Title: Re: Limit actions in unhandled events to hotspots
Post by: Khris on Fri 17/06/2011 08:24:21
Using the mouse.Mode should work fine.
HandsFree, are you using a template? Which one?
Title: Re: Limit actions in unhandled events to hotspots
Post by: HandsFree on Fri 17/06/2011 14:04:12
Yes, the eLocationNothing works. I have to read up on the what/type thing. I'm not sure yet what exactly I can do with that.
I'm using the RON template.

thanks
Title: Re: Limit actions in unhandled events to hotspots
Post by: monkey0506 on Fri 17/06/2011 21:22:29
what and type are parameters to the unhandled_event function, and their values only hold specific meaning within the context of that function. Read up on unhandled_event in the manual for more information on how the function uses the parameters.