Make a switch. In your pirate events, make it so the event is only activated when that switch is on by checking the box in the top left of the event and setting it to the switch you chose.
In your mayor event, turn the switch on after the player accepts the quest.
Back in your pirate event, after the battle command, turn self switch A on. Then, make another blank event page in your pirate events with the "control self switch A ON" box in the upper left checked.
I hope this was explained well. I'm not the best explainer sometimes ^^;