Page 1 of 1

hero picker help

Posted: Wed Oct 31, 2012 1:45 am
by Willy Elektrix
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.

Posted: Wed Oct 31, 2012 3:14 am
by charbile
Anything is possible with the power of magic!
  • 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.

Posted: Wed Oct 31, 2012 9:58 am
by TMC
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.

Code: Select all

h0 := hero by slot(0)
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: Select all

picked := -1
while (picked == -1) do (picked := pick hero)
Step three:
'swap out hero' takes a hero ID number rather than a party slot number.

Code: Select all

for (slot, 0, 3) do (
  if &#40;slot <> picked&#41; then &#40;
    swap out hero&#40;hero by slot&#40;slot&#41;&#41;
  &#41;
&#41;
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: Select all

if &#40;h0 <> -1&#41; then &#40;swap by position&#40;0, find hero&#40;h0&#41;&#41;&#41;
if &#40;h1 <> -1&#41; then &#40;swap by position&#40;1, find hero&#40;h1&#41;&#41;&#41;
if &#40;h2 <> -1&#41; then &#40;swap by position&#40;2, find hero&#40;h2&#41;&#41;&#41;
if &#40;h3 <> -1&#41; then &#40;swap by position&#40;3, find hero&#40;h3&#41;&#41;&#41;
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).

Posted: Thu Nov 01, 2012 12:11 am
by Willy Elektrix
TMC: That worked really well and your explanation was great. Thanks so much. However, I have another complication. How can I exclude a hero from the picker if he is dead?

Posted: Thu Nov 01, 2012 1:13 am
by TMC
Simply swap the hero out of the part before calling pickhero. You can check if they are dead with "get hero stat(slot, stat:hp, current stat) <= 0"