• 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] Usable item to change a switch

  • 3
    Posts
    1
    Years
    • Seen Aug 11, 2023
    so i have a key item that i want to have when used change a switch on and off, but my brain wont let me comprehend how to do that with my limited scripting knowledge.
     
  • 104
    Posts
    2
    Years
    • Seen Mar 12, 2024
    This is fairly simple to do utilizing Common Events. It will take a couple steps. I will be assuming your item only turns a Switch on and off and has no other stipulations.

    First off, make sure in your PBS, your item has "FieldUse = Direct" as one of its lines. Otherwise the item will not activate by clicking on it in the bag.

    Part two is making the Common Event. Common Events are made just like normal events (like doors, trainer battles etc) but have a trigger that activates them. Go to the Common Event tab in the Database, select an empty one and make an event that looks like this.
    Conditional Branch : Switch [0031: Shiny Wild Pokemon] == ON
    Control Switches: [0031:Shiny Wild Pokemon] == OFF
    Text: Your item is turned off. Wild Pokemon are no longer shiny.
    Else
    Control Switches: [0031: Shint Wild Pokemon] == ON
    Text: Your item is turned on. Wild Pokemon are now shiny.
    Branch End
    Basically, make a Conditional Branch event with the condition being the event you are switching on and off is ON. When this condition is met, the event will turn off the switch. When it is not met, the event will turn on the switch. Replace the switch with the switch you are trying to turn on and off. You should include some text to know if the switch is actually switching or not, especially while testing.

    The final step is making the script for the item. All you have to do is make the item call the common event.
    Code:
    ItemHandlers::UseInField.add(:OLDSEAMAP, proc { |item|
    pbCommonEvent(3)
     next true
    })

    And thats it. This will keep the bag open when you use the item. If you want the bag to close on use, you need to add an additional line, which looks like this:
    Code:
    ItemHandlers::UseFromBag.add(:OLDSEAMAP, proc { |item|
     next 2
    })
    
    ItemHandlers::UseInField.add(:OLDSEAMAP, proc { |item|
    pbCommonEvent(3)
     next true
    })

    Remember to use your item name, switch name and Event Number. Also this is all assuming version 20 or 20.1.
     
  • 3
    Posts
    1
    Years
    • Seen Aug 11, 2023
    Thank you so much, the whole concept of this item is that it "translates" pokemon speech so all of the overworld sprites have basically two modes, one that just utters the cry and gives a description of what its doing, and when the switch is on it will "talk"
     
    Back
    Top