Item from hotspot-objects {SOLVED}

Started by Gabarts, Sat 07/06/2014 12:39:31

Previous topic - Next topic

Gabarts

I'm testing in another pc the things I still have to learn...
I can do this with an object but I wanted to know if it's working also with hotspots:

I want player add item from an hotspot only once, checking if that item is already in his inventory, in that case he cannot pick it up again. With this code he collects the item each time (overwriting the item in the inventory)

Maybe there is a mistake in the code:

Code: ags
function hMolliche_AnyClick()
{
  if (MovePlayer(242, 116)) {
     
     if(UsedAction(eGA_LookAt)) {
      player.Say("This is a must to collect.");
      }
      
      else if(UsedAction(eGA_PickUp)) {
        
      if(player.HasInventory(iMolliche)) {
          
          player.Say("Already taken some.");
          }  
      else
      player.Say("Sure.");
      player.AddInventory(iMolliche);
      dDialog1.SetOptionState(5, eOptionOn);
    }
  else Unhandled();
}
}



Khris

1. You have not put brackets around the else statements, which means line 17 and following lines are executed regardless of the check.
2. Testing whether the player has the item in their inventory is pretty unreliable; if they use (and lose) the item elsewhere and return to where they got it from, they can pick it up over and over again.
3. Mostly this situation is why Game.DoOnceOnly was added to AGS:
Code: ags
      else if (UsedAction(eGA_PickUp)) {
        if (Game.DoOnceOnly("pick up molliche")) {
          player.Say("Sure.");
          player.AddInventory(iMolliche);
          dDialog1.SetOptionState(5, eOptionOn);
        }
        else {
          player.Say("Already taken some.");
        }  
      }

This function will return, for each specific text, true the first time, then false for each subsequent call.

Gabarts

Yes, I need the player picks up from the hotspot forever because that item is combined more times with other inventory items. I'll try thanks.

SMF spam blocked by CleanTalk