• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Preserve Trainer Party Order

16
Posts
10
Years
    • Seen Jul 18, 2021
    Does anyone know a way to preserve party order for trainers? I am using the Decomp Trainer Editor, and trying out various AI flags, but for whatever reason the trainer I am using as a test decides to send out their designated third (last) Pokemon second. This is problematic, as I am using the custom in-battle messages for plot points, which if the order is changed makes the messages not really make sense. Any help with understanding the AI flags and/or providing a solution to preserve party order will be very appreciated. Thanks in advance.

    EDIT: Working on this now. Will share my findings in a few hours once I make progress. Post if you have a working solution.
     
    Last edited:
    16
    Posts
    10
    Years
    • Seen Jul 18, 2021
    Alright I figured it out. It works in my initial testing, but I'm sure my logic isn't 100% correct, so there may be some edge cases that this doesn't work. If anyone more experienced also wants to delve into the AI and figure out if I went wrong anywhere, feel free.

    Steps:

    Spoiler:


    Spoiler:


    Spoiler:


    And that's it. You can set the flags using the Decomp Trainer Editor, and see for yourself. Tell me if you encounter any errors, I am planning to use this in my own works, so bug reports are welcomed. And if any more experienced people find some random issue with my code, let me know how it can be improved. Thanks.

    EDIT: There may be an issue using the ! operator rather than ~ operator... not entirely sure. Again, if someone more experienced could do a quick code review, that'd be much appreciated.
    EDIT2: Bitwise appears to be the correct way. ! changed to ~. Thanks to mgriffin.
    EDIT3: Bitwise negation can be avoided by wrapping the if statements like so:
    !(AI_THINKING_STRUCT->aiFlags & (AI_SCRIPT_DO_NOT_SWITCH | AI_SCRIPT_PRESERVE_ORDER))
    and
    if(!(gBattleResources->ai->aiFlags & (AI_SCRIPT_DO_NOT_SWITCH | AI_SCRIPT_PRESERVE_ORDER)))
     
    Last edited:
    Back
    Top