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

NEL

NEL

Level 6
Joined
Mar 6, 2017
Messages
113
Part 1

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.

vJASS:
//! zinc
library Variables {
    private {
        integer Counter = 0;
   
        function onInit() {
            trigger trgChat = CreateTrigger();
            integer Index = 0;

            while( Index < bj_MAX_PLAYERS ) {
                TriggerRegisterPlayerChatEvent( trgChat, Player( Index ), "-", true );
                Index = Index + 1;
            }
           
            TriggerAddAction( trgChat, function() {
                unit u;
                real x = GetRandomReal( GetRectMinX( bj_mapInitialPlayableArea ), GetRectMaxX( bj_mapInitialPlayableArea ));
                real y = GetRandomReal( GetRectMinY( bj_mapInitialPlayableArea ), GetRectMaxY( bj_mapInitialPlayableArea ));
                string text;
               
                CreateUnit( GetTriggerPlayer(), 'hfoo', x, y, 0 );

                Counter = Counter + 1;
            });
           
            trgChat = null;
        }
    }
}
//! endzinc





Part 2

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.

vJASS:
//! zinc
library Variable {
    private {
        integer Counter = 0;
   
        function onInit() {
            trigger trgChat = CreateTrigger();
            trigger trgDies = CreateTrigger();
            integer Index = 0;

            while( Index < bj_MAX_PLAYERS ) {
                TriggerRegisterPlayerChatEvent( trgChat, Player( Index ), "-", true );
                TriggerRegisterPlayerUnitEvent( trgDies, Player( Index ), EVENT_PLAYER_UNIT_DEATH, null );
                Index = Index + 1;
            }
           
            TriggerAddAction( trgChat, function() {
                unit u;
                real x = GetRandomReal( GetRectMinX( bj_mapInitialPlayableArea ), GetRectMaxX( bj_mapInitialPlayableArea ));
                real y = GetRandomReal( GetRectMinY( bj_mapInitialPlayableArea ), GetRectMaxY( bj_mapInitialPlayableArea ));
                string text;
               
                CreateUnit( GetTriggerPlayer(), 'hfoo', x, y, 0 );

                Counter = Counter + 1;
            });
           
            TriggerAddAction( trgDies, function() {
                Counter = Counter - 1;
                DisplayTextToPlayer( GetLocalPlayer(), 0, 0, "Counter: " + I2S( Counter ) );
            });
           
            trgChat = null;
            trgDies = null;
        }
    }
}
//! endzinc
 

Attachments

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