Continuously production :O

jomik

New Member
Reaction score
17
Heya, I have this code, where I want the unit to train continuesly.
That part works... I just want to know how I can check if the player doesn't have enough money to train the unit, and if he doesn't then say that in a message to him...
Here's my code:
JASS:
scope ProductionContinue initializer Init
    
    private function actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit tu = GetTrainedUnit()
        local integer uid = GetUnitTypeId(tu)
        
        if (IsUnitType(tu, UNIT_TYPE_ANCIENT)) then
            call IssueImmediateOrderById(u, uid)
        endif
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_TRAIN_FINISH)
        call TriggerAddAction(t, function actions)
    endfunction
    
endscope


Thought of using the custom value, and just check the custom value of the trained unit, and see if it's higher than the players gold. - but what if more units try to train at the same time? :O
 

Azlier

Old World Ghost
Reaction score
461
This is untested, unverified.

JASS:
scope ProductionContinue initializer Init

    //CONSTANTS
    globals
        private constant integer CHICKEN = 'a000'
    endglobals

    globals
        private hashtable ht = InitHashtable()
    endglobals  
    
    private function actions takes nothing returns nothing
        local integer uid = GetUnitTypeId(GetTrainedUnit())
        
        if LoadBoolean(ht, 0, uid) then
            if not IssueImmediateOrderById(GetTriggerUnit(), uid) then
            	call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, "You do not have enough gold to continue training " + GetObjectName(uid) + "s. Cancelling production.")
            endif
        endif
    endfunction
    
    private function Save takes integer i returns nothing
    	call SaveBoolean(ht, 0, i, true)
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_TRAIN_FINISH)
        call TriggerAddAction(t, function actions)
        
        //Save all livestock rawcodes here.
        call Save(CHICKEN)
    endfunction
    
endscope
 

jomik

New Member
Reaction score
17
Ahh man, I'm using NewGen with the 1.21b edition of Wc3? Dual Installation...
 

jomik

New Member
Reaction score
17
Hmm, just made it like this:
JASS:
scope ProductionContinue initializer Init
    
    private function actions takes nothing returns nothing
        local unit tu = GetTrainedUnit()
        local integer uid = GetUnitTypeId(tu)
        
        if (IsUnitType(tu, UNIT_TYPE_ANCIENT)) then
            call UnitApplyTimedLife(tu, 'BTLF', 20)
            if not (IssueImmediateOrderById(GetTriggerUnit(), uid)) then
                call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, "You do not have enough gold to continue producing " + GetObjectName(uid) + "s. Cancelling production.")
            endif
        endif
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_TRAIN_FINISH)
        call TriggerAddAction(t, function actions)
    endfunction
    
endscope

That works :O But should I really update to 1.24b? :O
EDIT: Fuuuck, double post :S
 
General chit-chat
Help Users

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top