Character can get item only once

Started by viktor, Sun 09/02/2014 20:11:24

Previous topic - Next topic

viktor

Hy!

In my game I have a lump of dirt that the player can interact with. The first time the player interacts with the dirt he gets an item. Next time he tries to interact he doesn't get anything.

Now I could use for example

if (cEgo.HasInventory(aItem)==false)
{
cEgo.AddInventory(aInventoryItem);
}

The problem is that the player disposes of the item later in the game and he could get a new item from the dirt when he does. How can I prevent that?
signature" border="0
<a target='_blank' href='https://imgbb.com/'>resurrection pictures for facebook</a>

DoorKnobHandle

Search for Game.DoOnceOnly in the manual or use a boolean variable.

viktor

#2
I'll try...

EDIT: I'm looking at it and I don't really understand how this script works. I'll try some more but I may have to check back with you on this one.
signature" border="0
<a target='_blank' href='https://imgbb.com/'>resurrection pictures for facebook</a>

viktor

#3
So I found this in the manual:

Code: ags
if (Game.DoOnceOnly("open cupboard")) {
  GiveScore(5);
}


How do I rework this to work with my item? I'm guessing something like this:

Code: ags
if (Game.DoOnceOnly("interact with object")) {
  cEgo.AddInventory(aItem);
}


But what is the interact with object actually suppose to be? And how do I make the character say something else after he already interacted with the object already?
signature" border="0
<a target='_blank' href='https://imgbb.com/'>resurrection pictures for facebook</a>

Crimson Wizard

#4
Parameter in DoOnceOnly is just a unique string of your own choice that is "tagged" to this particular action, or a linked set of actions (if you can only do one of them in game).

Code: ags

if (Game.DoOnceOnly("interact with object"))
  cEgo.AddInventory(aItem);
else
  cEgo.Say("I can't do this again");



Also: use [ code = ags ], not just [ code ] to post script examples.

viktor

EDIT: Never mind... Solved it! Thank you :).
signature" border="0
<a target='_blank' href='https://imgbb.com/'>resurrection pictures for facebook</a>

DoorKnobHandle

Remove the { at the end of line 3. and the } on line 7.

SMF spam blocked by CleanTalk