Hey Guys,
This one is really tricky for me.
There's a section in my game, where you have to throw a pebble at a char 3 times for an event to occur.
However, I would like to run a small scrip after each time the pebble is thrown.
Throw first pebble - char dialog 1 + an animation
Throw second pebble - char dialog 2 + an animation
The third time a pebble is thrown an event occurs which is currently handled in the room repeat exec (pasted at the bottom).
I could try repeat exec for the pebble count 1/2 however this would cause other issues.
Please find the existing code below -
// room script file
function hPedoMan_UseInv() {
if (player.ActiveInventory == iPebbles) {
cEgo.Walk(200, 385, eBlock);
cPedoMan.Say("Oooo, I think I've got a bite!");
player.LoseInventory(iPebbles);
pebblehitcount += 1;
}
}
function room_LeaveLeft()
{
player.ChangeRoom (2, 326, 210);
pebblehitcount = 0;
}
function on_event(EventType event, int data)
{
if (((event == eEventAddInventory) || (event == eEventLoseInventory)) && (data == iPebbles.ID))
{
int quantity = player.InventoryQuantity[data];
if (quantity == 1) iPebbles.Graphic = 7; // fill in actual sprite slot numbers
else if (quantity == 2) iPebbles.Graphic = 8;
else if (quantity == 3) iPebbles.Graphic = 9;
}
Repeat exec script.
function room_RepExec()
{
if (pebblehitcount == 3)
{
Display("You see a bookshelf.");
hHotspot2.Enabled = false;
hPedoMan.Enabled = false;
object[0].Visible = true;
cPedoMan.ChangeRoom(7, 100, 50);
pebblehitcount = 0;
}
}
I don't think you need to use either room_RepExec() or on_event(). In the UseInv() function you can just do:
void setPebbleInvGraphic() {
int quantity = player.InventoryQuantity[iPebble.ID];
if (quantity == 1) iPebbles.Graphic = 7; // fill in actual sprite slot numbers
else if (quantity == 2) iPebbles.Graphic = 8;
else if (quantity == 3) iPebbles.Graphic = 9; // For robustness, either quantity >= 3 or another else clause
}
function hPedoMan_UseInv() {
if (player.ActiveInventory == iPebbles) {
// This stuff happens every time
cEgo.Walk(200, 385, eBlock);
cPedoMan.Say("Oooo, I think I've got a bite!");
player.LoseInventory(iPebbles);
pebblehitcount += 1;
if(pebblehitcount == 1) {
// Stuff that happens specifically the first time
setPebbleInvGraphic();
}
else if (pebblehitcount == 2) {
// Stuff that happens the second time
setPebbleInvGraphic();
}
else if (pebblehitcount == 3) {
// Stuff that happens the third time
Display("You see a bookshelf.");
hHotspot2.Enabled = false;
hPedoMan.Enabled = false;
object[0].Visible = true;
cPedoMan.ChangeRoom(7, 100, 50);
pebblehitcount = 0;
}
}
}
That's awesome, thank you for the swift reply. I look forward to trying this out.
Quote from: Nixxon on Fri 16/10/2015 01:54:59
That's awesome, thank you for the swift reply. I look forward to trying this out.
EDIT- Confirming works like a charm, I've removed the exec repeat code. All nice and tidy. This was my last hurdle, thanks very much!