• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Hero Modes

Level 8
Joined
Feb 15, 2009
Messages
463
Hero Modes


1.General Information
So this are several Scripts allowing your map to have the
Allrandom and Teamrandom(till yet) modes which are providing easy configurable , implementable and safe working code HERO MODES are designed for Maps containing 2 Teams fighting each other (like Aos stylerz)



2.What to do to implement?
The only things which need to be changed are the rawcodes of the heros
and the constant variables in the upper section of each trigger
(this is just a very little work taking about 5 seconds)

at beginning of each trigger you can also set the message which needs to be entered by the Choosing Player(the RequiredMessage variable)
:fp: e.g. Here -ar for Allrandom or -tr for Teamrandom

To implement this little System or Script just copy the Modules(Allrandom , Teamrandom , etc...) you want to have in your map but if you dont want to have allrandom mode but others just copy the 2 globals GetChoosingPlayer and IsHeroModeAvailable to your module(just in one)
i know just 2 Modules in this 1st version but more will come



3.Basic Things
:fp:requires JassNewGenPack(im a:spell_breaker:link)
:fp:makes use of the userfriendly Unitpool functions
:fp:Till yet supporting following modes:
:nemad:Allrandom
:nemad:Teamrandom


4.The Scripts

JASS:
//***********************************************************************************
//                                                                                                                                                                    *
//                                              Allrandom Mode by Saia_Djinn                                                                    *
//                                                                                                                                                                    *
//***********************************************************************************
//These globals are used by all modules dont erase them
globals
    boolean IsHeroModeAvailable = true
    constant player GetChoosingPlayer = Player(0)
endglobals
//###################################

scope Allrandom initializer Init

globals
    private constant string RequiredMessage = "-ar" //change to whatever you want to be entered
    private constant string ExcuseMessage = "|cffff2277Allrandom Mode was selected|r |cff42afefExcuse the following mini lags through hero set up|r" //we must say sorry to the players for the laaagg =D
    private constant integer MaxHeros = 15 // this is the amount of all heros ,you must change this to your Heros array size to work(the real value needs to be added a 1 because we use the ZERO slot of the array)
    private constant integer LastPlayerTeamA = 4 // if you have 5 players per team let this else change it to the half of amount -1(e.g. if u have 6 per team put a 5 in here)
    private constant real CreateXTeamA = -800. // these 4 reals should contain the Coordinates where Units from Team A and B should be created
    private constant real CreateYTeamA = -400.
    private constant real CreateXTeamB = 900.
    private constant real CreateYTeamB = -400.
    
//##################################################################################################################################################

    private trigger Mode
    private integer array Heros
    private unitpool RandomPool 
endglobals
    
private function SetUp takes nothing returns nothing
//make this list contain every hero you want to be randomed and change the used ones to the rawcodes of your heros

    set Heros[0] = 'Hmkg'
    set Heros[1] = 'Hblm'
    set Heros[2] = 'Hamg'
    set Heros[3] = 'Hpal'
    set Heros[4] = 'Obla'
    set Heros[5] = 'Ofar'
    set Heros[6] = 'Oshd'
    set Heros[7] = 'Otch'
    set Heros[8] = 'Ucrl'
    set Heros[9] = 'Ulic'
    set Heros[10] = 'Udre'
    set Heros[11] = 'Udea'
    set Heros[12] = 'Edem'
    set Heros[13] = 'Ekee'
    set Heros[14] = 'Emoo'
    set Heros[15] = 'Ewar'
    
    //...
    //...
endfunction

private function Actions takes nothing returns nothing
    local integer a = -1
    local unit t
    
    if IsHeroModeAvailable then
    
        set IsHeroModeAvailable = false
        call SetUp()
        set RandomPool = CreateUnitPool()
        
        call DisplayTextToForce( bj_FORCE_ALL_PLAYERS , ExcuseMessage )
        
        loop 
            set a = a+1
            exitwhen a > MaxHeros 
                call UnitPoolAddUnitType( RandomPool , Heros[a] , 1. )
        endloop

        set a = -1
        
        loop
            set a = a+1
            call TriggerSleepAction( 0.0 )
            exitwhen a > 11
                
                if GetPlayerSlotState( Player(a) ) == PLAYER_SLOT_STATE_PLAYING then
                
                    if a > LastPlayerTeamA then
                        set t = PlaceRandomUnit( RandomPool , Player(a) , CreateXTeamB , CreateYTeamB , 0. )
                        call UnitPoolRemoveUnitType( RandomPool , GetUnitTypeId( t ) )
                    else
                        set t = PlaceRandomUnit( RandomPool , Player(a) , CreateXTeamA , CreateYTeamA , 0. )
                        call UnitPoolRemoveUnitType( RandomPool , GetUnitTypeId( t ) )
                    endif
                    
                endif
                
        endloop
        
        call DestroyUnitPool(RandomPool)
        call DestroyTrigger(Mode)
        
    endif
    
endfunction

private function Init takes nothing returns nothing
    set Mode = CreateTrigger()
    call TriggerAddAction( Mode , function Actions )
    call TriggerRegisterPlayerChatEvent( Mode , GetChoosingPlayer() , RequiredMessage , true )
endfunction

endscope

JASS:
//***********************************************************************************
//                                                                                                                                                                    *
//                                              Teamrandom Mode by Saia_Djinn                                                                *
//                                                                                                                                                                    *
//***********************************************************************************
scope Teamrandom initializer Init

globals
    private constant string RequiredMessage = "-tr" //change to whatever you want to be entered
    private constant string ExcuseMessage = "|cffff2277Teamrandom Mode was selected|r |cff42afefExcuse the following mini lags through hero set up|r" //we must say sorry to the players for the laaagg =D
    private constant integer MaxHeros = 7 // this is the amount of max heros per team you must change this to your Heros array size to work(the real value needs to be added a 1 because we use the ZERO slot of the array)
    private constant integer LastPlayerTeamA = 4 // if you have 5 players per team let this else change it to the half of amount -1(e.g. if u have 6 per team put a 5 in here)
    private constant real CreateXTeamA = -800. // these 4 reals should contain the Coordinates where Units from Team A and B should be created
    private constant real CreateYTeamA = -400.
    private constant real CreateXTeamB = 900.
    private constant real CreateYTeamB = -400.
    
//##################################################################################################################################################

    private trigger Mode
    private integer array HerosA
    private integer array HerosB
    private unitpool RandomPoolA
    private unitpool RandomPoolB 
endglobals
    
private function SetUp takes nothing returns nothing
//make list HerosA contain all Heros to be randomed from TeamA and HerosB containing the rawcodes of TeamB

    set HerosA[0] = 'Hmkg'
    set HerosA[1] = 'Hblm'
    set HerosA[2] = 'Hamg'
    set HerosA[3] = 'Hpal'
    set HerosA[4] = 'Edem'
    set HerosA[5] = 'Ekee'
    set HerosA[6] = 'Emoo'
    set HerosA[7] = 'Ewar'
    
    set HerosB[0] = 'Obla'
    set HerosB[1] = 'Ofar'
    set HerosB[2] = 'Oshd'
    set HerosB[3] = 'Otch'
    set HerosB[4] = 'Ucrl'
    set HerosB[5] = 'Ulic'
    set HerosB[6] = 'Udre'
    set HerosB[7] = 'Udea'
    
    //...
    //...
endfunction

private function Actions takes nothing returns nothing
    local integer a = -1
    local unit t
    
    if IsHeroModeAvailable then
        
        set IsHeroModeAvailable = false
        call SetUp()
        set RandomPoolA = CreateUnitPool()
        set RandomPoolB = CreateUnitPool()
        
        call DisplayTextToForce( bj_FORCE_ALL_PLAYERS , ExcuseMessage )
        
        loop
            set a = a+1
            exitwhen a > MaxHeros 
                call UnitPoolAddUnitType( RandomPoolA , HerosA[a] , 1. )
                call UnitPoolAddUnitType( RandomPoolB , HerosB[a] , 1. )
        endloop

        set a = -1
        
        loop
            set a = a+1
            call TriggerSleepAction( 0.0 )
            exitwhen a > 11
                
                if GetPlayerSlotState( Player(a) ) == PLAYER_SLOT_STATE_PLAYING then
                
                    if a > LastPlayerTeamA then
                        set t = PlaceRandomUnit( RandomPoolB , Player(a) , CreateXTeamB , CreateYTeamB , 0. )
                        call UnitPoolRemoveUnitType( RandomPoolB , GetUnitTypeId( t ) )
                    else
                        set t = PlaceRandomUnit( RandomPoolA , Player(a) , CreateXTeamA , CreateYTeamA , 0. )
                        call UnitPoolRemoveUnitType( RandomPoolA , GetUnitTypeId( t ) )
                    endif
                    
                endif
                
        endloop
        
        call DestroyUnitPool(RandomPoolA)
        call DestroyUnitPool(RandomPoolB)
        call DestroyTrigger(Mode)
        
    endif
    
endfunction

private function Init takes nothing returns nothing
    set Mode = CreateTrigger()
    call TriggerAddAction( Mode , function Actions )
    call TriggerRegisterPlayerChatEvent( Mode , GetChoosingPlayer() , RequiredMessage , true )
endfunction

endscope
I will also attach a quick DemoMap for the -ar and -tr mode :pal:(outdated a bit soon a new one)
:fp:updated presentation a bit
:fp:made the GetChoosingPlayer function constant to get inlined and being faster:ned:
:fp:now GetChoosingPlayer is a constant variable and is in the Allrandom trigger so the basic library is not required anymore
:fp: changed the globals nulling to nothing be done except destroying
 

Attachments

  • HeroModes.w3m
    19.6 KB · Views: 69
Last edited:
Level 11
Joined
Feb 22, 2006
Messages
752
JASS:
function GetChoosingPlayer takes nothing returns player
    return Player(0) //change this to the player who is the one to enter the [  -xx  ] message
endfunction

That can be:

JASS:
globals
    constant player CHOOSING_PLAYER = Player(0)
endglobals

JASS:
        loop
            set a = a+1
            call TriggerSleepAction( 0.0 )
            exitwhen a > 11

What's the point of the TSA?
 
Level 8
Joined
Feb 15, 2009
Messages
463
JASS:
function GetChoosingPlayer takes nothing returns player
    return Player(0) //change this to the player who is the one to enter the [  -xx  ] message
endfunction

That can be:

JASS:
globals
    constant player CHOOSING_PLAYER = Player(0)
endglobals
globals should not be initialized with functions just with values like true , 1 , xx , "see me" , etc.. when i follow jasshelper manual but it could be changed to a constant function
- i will do it here in the 1st script
E: done

JASS:
        loop
            set a = a+1
            call TriggerSleepAction( 0.0 )
            exitwhen a > 11

What's the point of the TSA?
not having a single great preload lag but acceptable small mini lags(just minor)

Edit:changed 1st script to constant function
 
Level 11
Joined
Feb 22, 2006
Messages
752
globals should not be initialized with functions just with values like true , 1 , xx , "see me" , etc.. when i follow jasshelper manual but it could be changed to a constant function

JASS:
globals
    group g = CreateGroup()
    timer t = CreateTimer()
    force f = CreateForce()
endglobals

I can do all of those things.

not having a single great preload lag but acceptable small mini lags(just minor)

what?
 
Level 8
Joined
Feb 15, 2009
Messages
463
man guys if you place a hero trough trigger and that hero had never been on the map before it will cause a small lag/spike , so if i create all at the same time for some wooden pc's this might be enough and they drop which will never happen if you just have a very small 0.05 spike 10 times then a 1 sec. spike one time
with preload i dont mean the normal preload at init but i mean the small lag at placing loading
 
  • Why..... just make a constant global.
    JASS:
    constant function GetChoosingPlayer takes nothing returns player
  • You never null your local unit t in your actions.
  • You don't need to null globals.
    JASS:
        set RandomPool = null
        set Mode = null
  • Whats the point of that TSA?
  • You should combine both libraries into one.
  • You do know you can give globals initial values right?
    JASS:
    set Mode = CreateTrigger() // private trigger Mode = CreateTrigger()
  • This is honestly not configurable enough, some maps have more than two teams (which your system doesn't support) and some teams may have an un-even amount of players. You need to take these scenarios into consideration when making systems. You should add a force array just like you did with heroes in the setup function, this would allow more teams. Though you would have to edit your system a little.
 
Level 8
Joined
Feb 15, 2009
Messages
463
  • Why..... just make a constant global.
    JASS:
    constant function GetChoosingPlayer takes nothing returns player
    done
  • You never null your local unit t in your actions.
    coz it would not have any effect? its like nulling a loacl trigger without destroying--> no effect
  • You don't need to null globals.
    JASS:
        set RandomPool = null
        set Mode = null
    done
  • Whats the point of that TSA?
    explained above
  • You should combine both libraries into one.
    no i should not coz when more modules come people cant decide which they want and must take all if they dont want to edit the trigger
  • You do know you can give globals initial values right?
    JASS:
    set Mode = CreateTrigger() // private trigger Mode = CreateTrigger()
    yeah i used to do that but some days before release i reread the jasshelper manual and was surprised about the initglobals thing
  • This is honestly not configurable enough, some maps have more than two teams (which your system doesn't support) and some teams may have an un-even amount of players. You need to take these scenarios into consideration when making systems. You should add a force array just like you did with heroes in the setup function, this would allow more teams. Though you would have to edit your system a little.
    i know it just support 2 teams but to the uneven thing(there is a integer checking for the maxplayers in the globals and only playing players are given heros(i know 9vs1 will not work with this but i said that this is more for AOS style maps))
 
Top