Limit actions in unhandled events to hotspots

Started by HandsFree, Thu 16/06/2011 23:52:15

Previous topic - Next topic

HandsFree

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

Khris

Code: ags
  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");
    }
  }

ddq

#2
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...
Code: ags

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.");
}

Khris

Using the mouse.Mode should work fine.
HandsFree, are you using a template? Which one?

HandsFree

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

monkey0506

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.

SMF spam blocked by CleanTalk