I'm using this bit of script:
function on_event(int event, int data) {
if (event == eEventAddInventory) PlaySound(50);
}
...to play a sound when the player picks up an item.
The problem is, it doesn't like being blocked so the sound ends up playing after the 'pick up' animation has finished.
Any ideas on making this a function (or event) impervious to blocking?
Quote from: markbilly on Sat 07/08/2010 18:47:34
I'm using this bit of script:
function on_event(int event, int data) {
if (event == eEventAddInventory) PlaySound(50);
}
...to play a sound when the player picks up an item.
The problem is, it doesn't like being blocked so the sound ends up playing after the 'pick up' animation has finished.
Any ideas on making this a function (or event) impervious to blocking?
If I assume there's a pick up animation there are two ways, have the item lose before the animation, or use animation run script module. But the last is a far-fetch really.
Or go through my whole script adding PlaySound() where applicable. I'm just too lazy, though... ;)
I'd use a function, like this:
void PickUp(Object*o, InventoryItem*i) {
// animate
PlaySound(50);
if (o != null) o.Visible = false;
if (i != null) player.AddInventory(i);
}
Then: PickUp(oPen, iPen);
You'd still have to replace all the current lines though, of course.
Going Khris' route would mean that you'd have to have the animations for each animation type and such scripted within his PickUp function.
I'd simply go this route:
void AddInventoryWithSound(this Character*, InventoryItem *item)
{
PlaySound(50);
this.AddInventory(item);
}
Which would replace the default AGS AddInventory, with this:
player.AddInventoryWithSound(iWhatever);
His would also not work with hotspots or if a character handed it to you, etc.
That's a good solution, I was thinking of writing an alternative function...
Then, although I will have to replace all that I have now, at least I won't have to remember the sound for future scripting.
Cheers!
Quote from: Ryan Timothy on Sat 07/08/2010 19:33:51
His would also not work with hotspots or if a character handed it to you, etc.
In the case of these, simply pass
null as the first parameter.