Tasks
Code
Create a (JASS) trigger that runs when a player types "-" as exact string.
The trigger's goal is to create a footman on the map at a random position.
The unit must be created within the map's playable area.
Increase the "Counter" variable by 1 each time the trigger runs.
Create a new trigger (in the same trigger sheet) that runs when a unit dies.
When the trigger runs, the "Counter" must be decreased by 1, furthermore
the "Counter" 's value must be displayed on screen to get to know how many footmen are alive.
JASS:
scope Part1 initializer init
globals
integer Count = 0
endglobals
private function main takes nothing returns nothing
local unit u
local string text
local real x = GetRandomReal(GetRectMinX(bj_mapInitialPlayableArea), GetRectMaxX(bj_mapInitialPlayableArea))
local real y = GetRandomReal(GetRectMinY(bj_mapInitialPlayableArea), GetRectMaxY(bj_mapInitialPlayableArea))
call CreateUnit(GetTriggerPlayer(), 'hfoo', x, y, GetRandomReal(0, 359.))
set Count = Count + 1
call ClearTextMessages()
call BJDebugMsg("A footman has been created! \n Total: " + I2S(Count) + " footman(s)")
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerChatEvent(t, Player(i), "-", true)
set i = i + 1
exitwhen i > bj_MAX_PLAYERS
endloop
call TriggerAddAction(t, function main)
endfunction
endscope
JASS:
scope Part2 initializer init
private function main takes nothing returns nothing
set Count = Count - 1
call ClearTextMessages()
call BJDebugMsg("A footman has died due to an unknown disease! \n" + I2S(Count) + " footman(s) left")
endfunction
private function isFootman takes nothing returns boolean
return GetUnitTypeId(GetFilterUnit()) == 'hfoo'
endfunction
private function init takes nothing returns nothing
local trigger t = CreateTrigger()
local integer i = 0
loop
call TriggerRegisterPlayerUnitEvent(t, Player(i), EVENT_PLAYER_UNIT_DEATH, Condition(function isFootman))
set i = i + 1
exitwhen i > bj_MAX_PLAYERS
endloop
call TriggerAddAction(t, function main)
endfunction
endscope