• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Our friends from the Johto Times are hosting a favorite Pokémon poll - and we'd love for you to participate! Click here for information on how to vote for your favorites!
  • Cyndy, May, Hero (Conquest), or Wes - which Pokémon protagonist is your favorite? Let us know by voting in our poll!
  • 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] Using terrain tags to activate the headbutt tree event

  • 112
    Posts
    10
    Years
    • Seen Nov 17, 2023
    I'm trying to activate headbutt with a terrain tag instead of the usual event because copy/pasting the same headbutt event for more than 10 trees starts to lag my maps.

    1. I set the tag for my headbutt trees in the tag editor as tag 20 and created a new terrain tag for HeadbuttTrees in PBTerrain here:
    Spoiler:
    I also created a definition for isHeadbuttTree? near the bottom of PBTerrain with these lines here:
    Spoiler:

    2. In PField_HiddenMoves, I copy pasted a few lines from the waterfall code and changed/simplified it to function with headbutt trees here:
    Spoiler:
    It works fine up to the point where it prompts you to use headbutt. If you choose no, it's fine. But if you choose yes, it crashes with this error:
    Spoiler:


    I know I'm very close but I'm not exactly sure how to call the highlighted headbutt event. I've tried pbHeadbutt, pbHeadbuttEffect, etc.
    Any help would be appreciated.
     
    Last edited:
    pbHeadbuttEffect is responsible for the animation. Since you're not using events anymore it can't execute this script properly. The easiest solution would be to remove that line from def Kernel.pbHeadbutt(event).
     
    pbHeadbuttEffect is responsible for the animation. Since you're not using events anymore it can't execute this script properly. The easiest solution would be to remove that line from def Kernel.pbHeadbutt(event).

    Thanks! I commented out the Kernel.pbHeadbuttEffect(event) and it stopped throwing the error, but now it looks like I'm not getting any encounters on maps I've defined headbutt encounters for.

    Did I miss something?
    Code:
    Spoiler:

    Edit: To clarify, it prompts me if I want to use headbutt, and selecting yes doesn't produce the "Nope! Nothing" text or a wild encounter.
     
    Last edited:
    Sorry, I got it a bit wrong. What I thought would be for the animation, is actually for the encounters.
    This line
    Code:
    a = (event.x+(event.x/24).floor+1)*(event.y+(event.y/24).floor+1)
    in Kernel.pbHeadbuttEffect(event) is used to calculate the encounter chance, and which type of Headbutt encounter. It uses the events position (x and y). So you need to replace this with something different, an alternative. If you have done that, reenable the line and it should work

    Edit: you could substitute the events x and y with the players x and y
     
    Last edited:
    Sorry, I got it a bit wrong. What I thought would be for the animation, is actually for the encounters.
    This line
    Code:
    a = (event.x+(event.x/24).floor+1)*(event.y+(event.y/24).floor+1)
    in Kernel.pbHeadbuttEffect(event) is used to calculate the encounter chance, and which type of Headbutt encounter. It uses the events position (x and y). So you need to replace this with something different, an alternative. If you have done that, reenable the line and it should work

    Edit: you could substitute the events x and y with the players x and y

    Awesome! I replaced that long equation with a random number since it takes the remainder after dividing the value by 5 anyways:

    Spoiler:
    It works like a charm! Thanks Ego!
     
    Last edited:
    Awesome! I replaced that long equation with a random number since it takes the remainder after dividing the value by 5 anyways:

    Spoiler:
    It works like a charm! Thanks Ego!

    Glad i could help :)
     
    Back
    Top