Skipping the rest of a script containing waits when something happens -- for example stopping an NPC patrol when the player performs an action -- unfortunately isn't entirely straightforward. If you only use "wait" commands and don't move the heroes or NPCs, then it's fairly easy though.
Scripts:Skippable wait explains how a single wait in a script can be made skippable with a keypress.
Let's say that you want the rest of the scene to be skipped when the player presses one of the use or cancel keys. The scripts are easily adapted for other conditions. First, add a global variable to indicate the scene is being skipped.
global variable(1, skipping waits)
Then use the following replacement for wait, which causes not just the one wait to be skipped, but also all the following ones:
script, skippable wait, ticks, begin while (skipping waits == false && ticks > 0) do ( if (key is pressed(key:ENTER) || key is pressed(key:SPACE) || key is pressed(key:CTRL) || (key is pressed(key:ALT) || key is pressed(key:ESC) || key is pressed(joy:button 1) || key is pressed(joy:button 2)) then ( skipping waits := true ) wait (1) ticks -= 1 ) end
Then write your cutscene script as normal, but write skippable wait instead of wait. Also if the scene can be repeated then reset the "skipping waits" global at the beginning. E.g.:
plotscript, a scene, begin skipping waits := false show text box(5) skippable wait(40) advance textbox skippable wait(20) ... end
That handles wait commands. wait for npc and wait for hero are much trickier. We use more replacement scripts like the following:
script, skippable wait for npc, npc, begin while (skipping waits == false && npc is walking(npc) == true) do ( if (key is pressed(key:ENTER) || key is pressed(key:SPACE) || key is pressed(key:CTRL) || (key is pressed(key:ALT) || key is pressed(key:ESC) || key is pressed(joy:button 1) || key is pressed(joy:button 2)) then ( skipping waits := true ) wait (1) ) end
But if you skip all the wait for npc commands, the NPCs will still be moving at the end of the script, and they won't be in the right position! You need to manually place them in the correct final positions and cancel their movement (or delete them or leave them where they are as the case may be).
plotscript, a scene, begin skipping waits := false # Our scene... walk npc (5, south, 3) # walk from 10,10 to 10,13 skippable wait for npc (5) skippable wait (20) walk npc (5, east, 7) # walk from 10,13 to 17,13 skippable wait for npc (5) #... # End of cutscene. Correct NPC position... set npc position (5, 17, 13) # The following commands cancel in-progress movement (note that they cause the NPC direction to change to east). # You only need two walknpc commands in the south/north and east/west directions. walk npc (5, south, 0) walk npc (5, east, 0) end
If you use other wait commands (like wait for key) then those will need still more replacements. Also, what if you wnt the script to stop because the player leaves the map? In that case "walk npc" commands would start moving the NPCs on the new map! That may be bad. Maybe you need a "skippable walk npc" script too:
script, skippable walk npc, npc, direction, distance, begin if (skipping waits == false) then ( walk npc(npc, direction, distance) ) end