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

[Scripting Question] Disable Key Item in certain Map/Area

15
Posts
5
Years
    • Seen Sep 24, 2020
    Hello Community,

    I recently added a key item to the game that allows the player to change their clothes. I now want to restrict the usage of it but only in certain maps (for example dont allow the player to change their outfit while inside a rocket hideout) - is there a way to add this? As of now I only see a flag for terrain, and I dont know how to really apply that to my idea.

    so, is there a way to limit the use of a key item on certain maps? A switch placed on the ground that works as a toggle would probably also work too, but then I would need to know what this switch needs to do.

    Thanks for the help!
     
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    You can check $game_map.map_id inside the key item's effect. e.g. if you only wanted to allow the item on maps 2, 3, and 5:
    Code:
    ItemHandlers::UseInField.add(:ITEM,proc{|item|
      if [2,3,5].include?($game_map.map_id)
        # Your effect code goes here.
      end
    })
    (Note, I'm not sure what map IDs actually look like, maybe they're not numbers?)
     
    Last edited:
    15
    Posts
    5
    Years
    • Seen Sep 24, 2020
    You can check $game_map.map_id inside the key item's effect. e.g. if you only wanted to allow the item on maps 2, 3, and 5:
    Code:
    ItemHandlers::UseInField.add(:ITEM,proc{|item|
      if [2,3,5].include?($game_map.map_id)
        # Your effect code goes here.
      end
    })
    (Note, I'm not sure what map IDs actually look like, maybe they're not numbers?)

    Thanks a ton mgriffin! This helpt me a lot. I slightly modified that code, to work as an exclude mechanism instead an including one. Modified script looks as follows:

    ItemHandlers::UseInField.add(:ITEM,proc{|item|
    if [2,3,5].include?($game_map.map_id)
    else
    # Your effect code goes here.
    end
    })

    That way it does nothing, when you are on one of the included maps (which results in the default "cant use this here" message), and executes normally on every other!
    Map ID can be found under Map Properties, when rightclicking a selected Map
     
    Last edited:
    1,403
    Posts
    10
    Years
    • Seen Apr 29, 2024
    Just so you know, you could have also made excluding work by using
    Code:
    if ![2,3,5].include?($game_map.map_id)
      # ...
    end
    Instead of an empty if and putting the code in the else, the ! means "not".
     
    Last edited:
    Back
    Top