• 🏆 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!

Basics - Variables

Status
Not open for further replies.
Level 2
Joined
Jul 12, 2018
Messages
17

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
 

Attachments

  • [Crash Course] Basics - Variables.w3m
    24.5 KB · Views: 77
Status
Not open for further replies.
Top