• 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.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Conquest protagonist in the poll by clicking here.
  • 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.

help with function

  • 124
    Posts
    9
    Years
    • Seen Apr 5, 2024
    I'm currently trying to make a special that checks for the pokeball used on a caught pokemon, I want it to return TRUE or FALSE and this is what I got so far

    Code:
    bool8 CheckIfPartyMonMasterball()
    {
        u8 ball = ITEM_MASTER_BALL;
        if (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_POKEBALL, &ball) == ITEM_MASTER_BALL)
        {
            return TRUE;
        }
        return FALSE;
    }

    it's used in conjuction with the choosepartymon special. I thought it was working because it said true, but every mon I choose it returns TRUE, how do I make it return TRUE if the mon chosen was caught with a masterball?

    EDIT: I think I got it but if anybody got a more efficient code than the one I made please let me know Im always willing to learn

    Code:
    void CheckIfPartyMonMasterball(void)
    {      
        struct Pokemon *pokemon;
        pokemon = &gPlayerParty[gSpecialVar_0x8004];
        if (GetMonData(pokemon, MON_DATA_POKEBALL) == ITEM_MASTER_BALL)   
        {
            gSpecialVar_Result = TRUE;
            return;
        }
        gSpecialVar_Result = FALSE;   
    }
     

    Attachments

    • [PokeCommunity.com] help with function
      giff.gif
      621 KB · Views: 2
    Last edited:
    EDIT: I think I got it but if anybody got a more efficient code than the one I made please let me know Im always willing to learn
    C:
    u16 GetChosenMonBall(void)
    {
        return GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_POKEBALL);
    }
    Define it as a special function inside gSpecials (data/specials.inc), and inside an overworld script you'd be able to do:
    Code:
    special ChoosePartyMon
    waitstate
    specialvar VAR_RESULT, GetChosenMonBall
    goto_if_eq VAR_RESULT, ITEM_MASTER_BALL, EventScript_CaughtWithMasterBall
    Or the Poryscript equivalent, which is the same thing, but with parentheses enclosing the parameters passed through each macro.
     
    C:
    u16 GetChosenMonBall(void)
    {
        return GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_POKEBALL);
    }
    Define it as a special function inside gSpecials (data/specials.inc), and inside an overworld script you'd be able to do:
    Code:
    special ChoosePartyMon
    waitstate
    specialvar VAR_RESULT, GetChosenMonBall
    goto_if_eq VAR_RESULT, ITEM_MASTER_BALL, EventScript_CaughtWithMasterBall
    Or the Poryscript equivalent, which is the same thing, but with parentheses enclosing the parameters passed through each macro.
    wow thats great and precise Lunos thank you, Im trying for another function, hoping u can help me with this one as well.

    Im trying to make a function similar to the exp candies but in a special. This special gives the chosen mon, 5000 Exp Points but the only thing it doesnt do is give experience after it levels up and it doesnt evolve mons at their level. This is all I got so far.

    Code:
    void GivePartyMonExp(void)
    {
        struct Pokemon *mon = &gPlayerParty[gSpecialVar_0x8004];
        u16 species = GetMonData(mon, MON_DATA_SPECIES);
        u8 level = GetMonData(mon, MON_DATA_LEVEL);
        u32 currExp = GetMonData(mon, MON_DATA_EXP);
        u32 nextLvlExp = gExperienceTables[gSpeciesInfo[species].growthRate][level+1];
        u32 ExpGiven = 5000;
      
        if(currExp + ExpGiven >= nextLvlExp)
        {           
            SetMonData(mon, MON_DATA_EXP, &nextLvlExp);
            CalculateMonStats(mon);
        }          
        else
        {
            currExp += ExpGiven;
            SetMonData(mon, MON_DATA_EXP, &currExp);
        }
    }

    Like I said it works but once the mon levels up, doesnt give the remaining amount of xp. and if the mon reaches the level to evolve, it doesnt. Please help
     
    wow thats great and precise Lunos thank you, Im trying for another function, hoping u can help me with this one as well.

    Im trying to make a function similar to the exp candies but in a special. This special gives the chosen mon, 5000 Exp Points but the only thing it doesnt do is give experience after it levels up and it doesnt evolve mons at their level. This is all I got so far.

    Code:
    void GivePartyMonExp(void)
    {
        struct Pokemon *mon = &gPlayerParty[gSpecialVar_0x8004];
        u16 species = GetMonData(mon, MON_DATA_SPECIES);
        u8 level = GetMonData(mon, MON_DATA_LEVEL);
        u32 currExp = GetMonData(mon, MON_DATA_EXP);
        u32 nextLvlExp = gExperienceTables[gSpeciesInfo[species].growthRate][level+1];
        u32 ExpGiven = 5000;
     
        if(currExp + ExpGiven >= nextLvlExp)
        {          
            SetMonData(mon, MON_DATA_EXP, &nextLvlExp);
            CalculateMonStats(mon);
        }         
        else
        {
            currExp += ExpGiven;
            SetMonData(mon, MON_DATA_EXP, &currExp);
        }
    }

    Like I said it works but once the mon levels up, doesnt give the remaining amount of xp. and if the mon reaches the level to evolve, it doesnt. Please help
    If I were you, I would examine the code for the exp. candies in the expansion thoroughly.
     
    If I were you, I would examine the code for the exp. candies in the expansion thoroughly.
    I did but Im just not as full-fledged and fluent like u in c code. I will keep studying, Im sure I will get better at it. Thanks for your time Lunos.
     
    Back
    Top