- Joined
- Mar 20, 2014
- Messages
- 67
Hey Guys,
So I'm trying to make a multiplayer Clash of Clans game for my friends and I through the world editor, and the biggest challenge has come to me yet. If you've played the game, you'd know that when you train a unit it goes to a random Army Camp (Like a food place) and just kinda runs around it every few seconds, just moving randomly around it. There's a max too at each Army Camp so I need to check the number of units they have. I have this trigger but it doesn't seem to work. I want to add locust to them obviously, but I don't know how I should check if the specific building has the max amount of currently allowed units. Right now I have it using a hashtable value which is safe, but why doesn't my below trigger work?
some globals you may need to decipher what happens.
integer array MaxArmyCampUnits
hashtable MUAC
group array ArmyCamps[200]
group array ArmyUnits[200]
So I'm trying to make a multiplayer Clash of Clans game for my friends and I through the world editor, and the biggest challenge has come to me yet. If you've played the game, you'd know that when you train a unit it goes to a random Army Camp (Like a food place) and just kinda runs around it every few seconds, just moving randomly around it. There's a max too at each Army Camp so I need to check the number of units they have. I have this trigger but it doesn't seem to work. I want to add locust to them obviously, but I don't know how I should check if the specific building has the max amount of currently allowed units. Right now I have it using a hashtable value which is safe, but why doesn't my below trigger work?
some globals you may need to decipher what happens.
integer array MaxArmyCampUnits
hashtable MUAC
group array ArmyCamps[200]
group array ArmyUnits[200]
JASS:
globals
unit acu
endglobals
function ArmyLocustCond takes nothing returns boolean
local unit u = GetTriggerUnit()
local integer i = GetUnitTypeId(u)
if ( i == 'e000' ) then
set u = null
return true
endif
if ( i == 'h008' ) then
set u = null
return true
endif
set u = null
return false
endfunction
function ArmyLocustCondi takes nothing returns boolean
if ( ArmyLocustCond() ) then
return true
endif
return false
endfunction
function ArmyUnitCallback takes nothing returns nothing
local unit u = GetEnumUnit()
local integer i = LoadInteger(MUAC, 0, GetHandleId(u))
local integer p = GetPlayerId(GetOwningPlayer(u))
if ( i < MaxArmyCampUnits) then
set acu = u
call SaveInteger(MUAC, 0, GetHandleId(u), i + 1)
set u = null
endif
endfunction
function ArmyUnit takes integer p returns nothing
call ForGroup(ArmyCamps, function ArmyUnitCallback)
endfunction
function ArmyLocustAct takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer p = GetPlayerId(GetOwningPlayer(u))
local location po
local location loc
call ArmyUnit(p)
set po = GetUnitLoc(acu)
set loc = PolarProjectionBJ(po, GetRandomReal(50.00, 300.00), GetRandomDirectionDeg())
call UnitAddAbility(u, 'Aloc')
call IssuePointOrderLoc(u, "move", loc)
call RemoveLocation(loc)
call RemoveLocation(po)
set u = null
endfunction
//===========================================================================
function InitTrig_Army_Locust takes nothing returns nothing
set gg_trg_Army_Locust = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Army_Locust, EVENT_PLAYER_UNIT_TRAIN_FINISH )
call TriggerAddCondition( gg_trg_Army_Locust, Condition( function ArmyLocustCondi ) )
call TriggerAddAction( gg_trg_Army_Locust, function ArmyLocustAct )
endfunction