• 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.

Temporarily taking away the player's party pokemon and items.

115
Posts
9
Years
    • Seen Nov 17, 2023
    I'm trying to add a section into my game where the Pokémon in the player's party and all of the items in their bag are taken away temporarily.

    Ideally, I would like all of the party Pokémon to just be force stored into the PC automatically, but using a script to save them would work as well, so long as there's a way for me to give the Pokémon back to the player later on, ideally through a switch or variable.

    For the items, I want the player's entire bag emptied out, and for the items to be saved with a script so that (like their party Pokémon) I can give the player their stuff back later on through a switch or variable.

    I already checked the Battle Frontier in the demo to see how it removes certain Pokémon that the player doesn't select to compete with, but those events bug out when they run, which means they don't even work properly. In addition, the only way I currently know how to "take away" items is to delete them, which is not what I want to do. Does anyone know how I would do either of these things?
     
    824
    Posts
    8
    Years
  • Code:
    def StealParty
      $game_variables[84]=$Trainer.party
      $Trainer.party=[]
    end
    
    def ReturnParty
      $Trainer.party=$game_variables[84]
    end
    
    def StealBag
      $game_variables[85]=$PokemonBag
      $PokemonBag.clear
    end
    
    def ReturnBag
      $PokemonBag=$game_variables[85]
    end

    This is untested, especially the bag stealing subroutine. These subroutines would be called upon by events.

    Put them in the scripts above Main.
     
    Last edited:
    115
    Posts
    9
    Years
    • Seen Nov 17, 2023
    Code:
    def StealParty
      $game_variables[84]=$Trainer.party
      $Trainer.party=[]
    end
     
    def ReturnParty
      $Trainer.party=$game_variables[84]
    end
     
    def StealBag
      $game_variables[85]=$PokemonBag
      $PokemonBag.clear
    end
     
    def ReturnBag
      $PokemonBag=$game_variables[85]
    end

    This is untested, especially the bag stealing subroutine. These subroutines would be called upon by events.

    Put them in the scripts above Main.


    Thank you so much! The party stealing works, the only issue is that if the player obtains other pokemon during the time their party is gone, those new pokemon in the player's party will be deleted/overridden when you get your party back. Fortunately I'll be able to make an event to get around that.


    Items are another story though. I put the two subroutines for taking items away in one event, and the subroutine for giving items back in another. When I interacted with the first event, it took the items away like it should. But when I interacted with the event that was supposed to give my items back, my bag was still empty. Is there a reason why I can't get the items back?
     
    824
    Posts
    8
    Years
  • I don't know why it didn't work, unless when I cleared the bag it also cleared the backup.

    But thanks mostly to your idea, I managed to get a bag-stealing event working in my game. However, it isn't a simple plug-and-play script like my last suggestion was, and you shouldn't allow the player to gain items while the bag is stolen, as I don't make the bag disappear so much as I mask the player's access to it ç most of the tediousness of the script is in preventing the player from inadvertently using the bag by way of things like shops or the PC.
     
    115
    Posts
    9
    Years
    • Seen Nov 17, 2023
    I don't know why it didn't work, unless when I cleared the bag it also cleared the backup.

    But thanks mostly to your idea, I managed to get a bag-stealing event working in my game. However, it isn't a simple plug-and-play script like my last suggestion was, and you shouldn't allow the player to gain items while the bag is stolen, as I don't make the bag disappear so much as I mask the player's access to it ç most of the tediousness of the script is in preventing the player from inadvertently using the bag by way of things like shops or the PC.

    I'm glad you liked the idea, and thank you for trying to help me out. Do you think there is any other way to clear the bag without clearing the backup? With the Pokémon stealing script, it doesn't really erase the Pokémon, it just sets the player's party to empty ($Trainer.party=[]). Is there a similar way to do this with the bag, like $PokemonBag[], or something similar?
     
    824
    Posts
    8
    Years
  • I'm glad you liked the idea, and thank you for trying to help me out. Do you think there is any other way to clear the bag without clearing the backup? With the Pokémon stealing script, it doesn't really erase the Pokémon, it just sets the player's party to empty ($Trainer.party=[]). Is there a similar way to do this with the bag, like $PokemonBag=[], or something similar?

    Thing is, I knew $Trainer.party was an array, so I felt safe setting it to empty. I actually don't know what kind of variable $PokemonBag is, so I copied the "Empty Bag" bit from the debug menu. To be safe.

    So upon further research, .clear only works on arrays, meaning $PokemonBag is an array. You can try $PokemonBag=[], but I'm not sure it will work because it may be that $PokemonBag is formatted oddly - after all, the bag remembers the order you put the items into the bag.
     
    Last edited:
    115
    Posts
    9
    Years
    • Seen Nov 17, 2023
    Thing is, I knew $Trainer.party was an array, so I felt safe setting it to empty. I actually don't know what kind of variable $PokemonBag is, so I copied the "Empty Bag" bit from the debug menu. To be safe.

    So upon further research, .clear only works on arrays, meaning $PokemonBag is an array. You can try $PokemonBag=[], but I'm not sure it will work because it may be that $PokemonBag is formatted oddly - after all, the bag remembers the order you put the items into the bag.

    Yeah, it doesn't work. It is ironic though, the first method with ".clear" will successfully take all items away but won't give them back, and the second method with $PokemonBag=[] will successfully give them all back, but you can't access your bag while they're taken away or else the game crashes. Neither method allows you to properly take items away and give them back without issues. Thank you for trying though.
     
    Last edited:
    824
    Posts
    8
    Years
  • Looking it up, $PokemonBag has a lot of functions in it, not just the items you have. The game crashes because when it does $PokemonBag=[], we take those functions - which it needs to store and access items - and throw them away.

    Unfortunately, I'm not finding where those functions are defined so I can copy and paste them into the "blank" bag we created.
     
    115
    Posts
    9
    Years
    • Seen Nov 17, 2023
    Looking it up, $PokemonBag has a lot of functions in it, not just the items you have. The game crashes because when it does $PokemonBag=[], we take those functions - which it needs to store and access items - and throw them away.

    Unfortunately, I'm not finding where those functions are defined so I can copy and paste them into the "blank" bag we created.

    Then they might be defined in another script. I'm not sure where else they would be defined, but I'll try looking for the PokemonBag functions in the other scripts and see what I can find. If you're still looking for them, let me know if you find anything.
     
    Last edited:
    4
    Posts
    4
    Years
    • Seen May 23, 2022
    Hi! 2020 calling! I tried using the scripts listed above for the "StealParty" and "ReturnParty" commands, but I'm certain I'm doing something wrong.

    def StealParty
    $game_variables[84]=$Trainer.party
    $Trainer.party=[]
    end

    def ReturnParty
    $Trainer.party=$game_variables[84]
    end

    ^Is what I'm using, and

    ---------------------------
    Pokemon Essentials
    ---------------------------
    [Pokémon Essentials version 17]

    Exception: RuntimeError

    Message: Script error within event 47 (coords 46,27), map 80 (Viridian City):

    Exception: NameError

    Message: (eval):1:in `pbExecuteScript'uninitialized constant Interpreter::StealParty

    ***Full script:

    StealParty


    Interpreter:243:in `pbExecuteScript'

    Interpreter:1606:in `eval'

    Interpreter:243:in `pbExecuteScript'

    Interpreter:1606:in `command_355'

    Interpreter:494:in `execute_command'

    Interpreter:193:in `update'

    Interpreter:106:in `loop'

    Interpreter:198:in `update'

    Scene_Map:161:in `follow_update'

    Scene_Map:159:in `loop'



    Interpreter:276:in `pbExecuteScript'

    Interpreter:1606:in `command_355'

    Interpreter:494:in `execute_command'

    Interpreter:193:in `update'

    Interpreter:106:in `loop'

    Interpreter:198:in `update'

    Scene_Map:161:in `follow_update'

    Scene_Map:159:in `loop'

    Scene_Map:168:in `follow_update'

    Follow Pokémon:1551:in `update'



    This exception was logged in

    C:\Users\XXXXX\Saved Games\Pokemon Essentials\errorlog.txt.

    Press Ctrl+C to copy this message to the clipboard.
    ---------------------------
    OK
    ---------------------------

    ^Is the error I am receiving. If there's a specific place to put the scripts, then I don't know where that is. Please help.
     
    1,682
    Posts
    8
    Years
    • Seen yesterday
    <attention grabbing>

    Methods can't start with capital letter. That makes the game think it's a constant and it flips out once it can't actually find the constant.
    renaming the method should fix the issue.
     

    thepsynergist

    Vinemon: Sauce Edition Programmer and Composer
    795
    Posts
    15
    Years
  • Code:
    #HOW TO TEST PROPERLY#
    
    #First giving a pokemon
    #Second saving the party
    #Third giving a different pokmeon
    #Fourth restoring the party
    
    #END#
    
    #Going to the past:
     #savecurrentPokemon(123)
    
    #If you've been before:
     #savecurrentPokemon(123)
     #restorepastPokemon(124)
    
    #If going back to the future:
     #savepastPokemon(123)
     #restorecurrentPokemon(124)
     
    #If going back to the future for the last time:
     #savepastPokemon(123)
     #addpastandFuture(123, 124)
    
    def savecurrentPokemon(variable)
      $game_variables[variable] = $Trainer.party
      $Trainer.party = []
    end
    def restorecurrentPokemon(variable)
      $Trainer.party = $game_variables[variable]
    end
    def savepastPokemon(variable)
      $game_variables[variable] = $Trainer.party
      $Trainer.party = []
    end
    def restorepastPokemon(variable)
      $Trainer.party = $game_variables[variable]
    end
    def addpastandFuture(pastvar, futurevar)
      $Trainer.party = $game_variables[futurevar] + $game_variables[variable]
    end

    This is what I use for my game, for saving a party to a variable. Hope it works for you. Credit: CrazyNinjaGuy
     
    Back
    Top