I want to write a script that lets the player choose a hero with the hero picker. It then kicks every other hero out of the party. Then later, after a battle, I want all the heroes to return (in their original formation if possible).
Here are some complications: The party may have a variable number of heroes in their active party at this point (between 1 and 4). Likewise, their might be up to another 4 outside of their active party.
Where do I even begin with this mess? Presumably, I use the hero picker to select a hero. Then how do determine who the unselected heroes are and kick them out, but still remember their positions after the battle? Is this possible.
Anything is possible with the power of magic!
something like this, except Elektrix Style.
step 1: use whatever commands to save the current heroes by slot
step 2: use the hero picker (didn't realize this is a thing now!) assuming it returns the id of the hero selected?
step 3: check by slot and removed all if they're not the same hero id
step 4: use the variables you saved in step 1 to place everyone back
something like this, except Elektrix Style.
If you have duplicated heroes, then this is much more complex and the code below won't work. Many of the party manipulation commands don't handle that correctly and will need to be avoided.
Step one:
'hero by slot'. Returns -1 if there is none.
Step two:
'pick hero' returns a slot in the active party, 0 to 3, or -1 if the player cancels. If you want to force the player to pick a slot, loop:
Step three:
'swap out hero' takes a hero ID number rather than a party slot number.
Step four:
The somewhat tricky step. We'll use swap by position, and check that we're not trying to swap nonexistent heroes, because even though that might work, it's better to play by the rules
Final note: if you swap any heroes INTO the party before step 4, then you'll have to write some additional code to remove them (but don't try to do so before step 4, because you can't ever create a party with no heroes in it).
Step one:
'hero by slot'. Returns -1 if there is none.
Code:
h0 := hero by slot(0)
h1 := hero by slot(1)
h2 := hero by slot(2)
h3 := hero by slot(3)
h1 := hero by slot(1)
h2 := hero by slot(2)
h3 := hero by slot(3)
Step two:
'pick hero' returns a slot in the active party, 0 to 3, or -1 if the player cancels. If you want to force the player to pick a slot, loop:
Code:
picked := -1
while (picked == -1) do (picked := pick hero)
while (picked == -1) do (picked := pick hero)
Step three:
'swap out hero' takes a hero ID number rather than a party slot number.
Code:
for (slot, 0, 3) do (
if (slot <> picked) then (
swap out hero(hero by slot(slot))
)
)
if (slot <> picked) then (
swap out hero(hero by slot(slot))
)
)
Step four:
The somewhat tricky step. We'll use swap by position, and check that we're not trying to swap nonexistent heroes, because even though that might work, it's better to play by the rules
Code:
if (h0 <> -1) then (swap by position(0, find hero(h0)))
if (h1 <> -1) then (swap by position(1, find hero(h1)))
if (h2 <> -1) then (swap by position(2, find hero(h2)))
if (h3 <> -1) then (swap by position(3, find hero(h3)))
if (h1 <> -1) then (swap by position(1, find hero(h1)))
if (h2 <> -1) then (swap by position(2, find hero(h2)))
if (h3 <> -1) then (swap by position(3, find hero(h3)))
Final note: if you swap any heroes INTO the party before step 4, then you'll have to write some additional code to remove them (but don't try to do so before step 4, because you can't ever create a party with no heroes in it).



