• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Custom hero not disappearing after purchasing

Status
Not open for further replies.
Level 4
Joined
Jan 6, 2023
Messages
33
I've made a custom hero and now discovered that after purchasing it I can buy it again, how to fix it? (I added the hero in constants)
 
Level 34
Joined
May 14, 2021
Messages
1,600
You probably need a trigger to limit the specific custom heroes. Basically, after purchasing the hero, you just set the limit training of specific heroes to 0.
If you made this mod to be applicable on melee map, you have to use the "Limit training of Hero Type" to 1 and that the campaign heroes must be added to Altar and their "Techtree Requirements - Tiers Used" in the unit data must be set to 3.
 
Level 45
Joined
Feb 27, 2007
Messages
5,578
The default melee init trigger has this line in it:
  • Melee Game - Limit Heroes to 1 per Hero-type (for all players)
But that doesn't actually iterate over the heroes listed in Gameplay Constants. It's actually a hardcoded function that manually limits all 24 melee heroes to 1 per player:
JASS:
    function MeleeStartingHeroLimit takes nothing returns nothing
        local integer index
     
        set index = 0
        loop
            // max heroes per player
            call SetPlayerMaxHeroesAllowed(bj_MELEE_HERO_LIMIT, Player(index))
     
            // each player is restricted to a limit per hero type as well
            call ReducePlayerTechMaxAllowed(Player(index), 'Hamg', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Hmkg', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Hpal', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Hblm', bj_MELEE_HERO_TYPE_LIMIT)
     
            call ReducePlayerTechMaxAllowed(Player(index), 'Obla', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Ofar', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Otch', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Oshd', bj_MELEE_HERO_TYPE_LIMIT)
     
            call ReducePlayerTechMaxAllowed(Player(index), 'Edem', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Ekee', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Emoo', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Ewar', bj_MELEE_HERO_TYPE_LIMIT)
     
            call ReducePlayerTechMaxAllowed(Player(index), 'Udea', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Udre', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Ulic', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Ucrl', bj_MELEE_HERO_TYPE_LIMIT)
     
            call ReducePlayerTechMaxAllowed(Player(index), 'Npbm', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Nbrn', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Nngs', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Nplh', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Nbst', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Nalc', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Ntin', bj_MELEE_HERO_TYPE_LIMIT)
            call ReducePlayerTechMaxAllowed(Player(index), 'Nfir', bj_MELEE_HERO_TYPE_LIMIT)
     
            set index = index + 1
            exitwhen index == bj_MAX_PLAYERS
        endloop
    endfunction
You can write a custom function that similarly limits any hero unit type you pass to it, and then just call that function with the unit type as an argument:
JASS:
    function StartingHeroLimit takes integer heroID returns nothing
        local integer index
     
        set index = 0
        loop
            call ReducePlayerTechMaxAllowed(Player(index), heroID, bj_MELEE_HERO_TYPE_LIMIT)
     
            set index = index + 1
            exitwhen index == bj_MAX_PLAYERS
        endloop
    endfunction

//to use:
call StartingHeroLimit('H001') //see the rawcode in the Object Editor
 
Level 4
Joined
Jan 6, 2023
Messages
33
welp Jass... never tried that one. I guess I'll have to read about since I don't even know how to enter Jass :xxd:


Edit: I think I did it and works fine with "limit unit-type to 1 for picked players" function

But also have one side-question. Is it normal that after making a new hero, the moment he comes out of the altar, theres like a 0.5 freeze for everyone? I thought it's because it's a custom model or something like that
 
Last edited:
Level 45
Joined
Feb 27, 2007
Messages
5,578
Is it normal that after making a new hero, the moment he comes out of the altar, theres like a 0.5 freeze for everyone? I thought it's because it's a custom model or something like that
Yes, the first time the model exists on the map it has to be loaded. You can force this to happen early with the Preload() function (JASS) or by creating and then removing a unit or special effect with that model on map init.
 
Level 4
Joined
Jan 13, 2010
Messages
44
You should add the players you want to forbid to a PlayerGroup variable. Pick all players in the PlayerGroup variable and forbid picked player for training that unit-type of your hero.
 
Status
Not open for further replies.
Top