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

[Galaxy] Basic: Creating a Unit

Hello, and welcome to my tutorial on basic Galaxy Scripting tutorial.
This one is dedicated to Creating a unit purely with Galaxy.
Please make sure that you have knowledge in Jass, C, Java, or any language like those before starting, and knowledge of algorithms.

Now, you will need an empty GalaxyScript. You can obtain one by making a melee map and deleting all the triggers. The result is this
Code:
//==================================================================================================
// 
// Generated Map Script
// 
// Name:   Just Another StarCraft II Map
// Author: Unknown Author
// 
//==================================================================================================
include "TriggerLibs/natives"

//--------------------------------------------------------------------------------------------------
// Map Initialization
//--------------------------------------------------------------------------------------------------
void InitMap () {
}
Cool! We got our Galaxy Script!
Now, moving on to the actual scripting!
Read my next code to see what everything does!

Code:
//==================================================================================================
// 
// Generated Map Script
// 
// Name:   Just Another StarCraft II Map
// Author: Unknown Author
// 
//==================================================================================================
include "TriggerLibs/natives" //includes the natives list, which are a necessary component!

//--------------------------------------------------------------------------------------------------
// Trigger Variables
//--------------------------------------------------------------------------------------------------
trigger gt_UntitledTrigger001;//Each trigger must be declared as a trigger variable.

//--------------------------------------------------------------------------------------------------
// Trigger: Untitled Trigger 001 //This is a trigger that is created to see what happens when a trigger is created.
//--------------------------------------------------------------------------------------------------
bool gt_UntitledTrigger001_Func (bool testConds, bool runActions) {
    return true;
}
//This part is where it runs the conditions. If a trigger's conditions are false, no trigger run, if its true, it runs. Simple as that.

//--------------------------------------------------------------------------------------------------
void gt_UntitledTrigger001_Init () {
    gt_UntitledTrigger001 = TriggerCreate("gt_UntitledTrigger001_Func");
}
//This is what is used to show stuff in the Playtest box! Change the "gt_ stuff" part to change its name!

//--------------------------------------------------------------------------------------------------
// Trigger Initialization
//--------------------------------------------------------------------------------------------------
void InitTriggers () {
    gt_UntitledTrigger001_Init();
}
//Trigger Initialization is where you call upon the Map Initialization based scripts

//--------------------------------------------------------------------------------------------------
// Map Initialization
//--------------------------------------------------------------------------------------------------
void InitMap () {
    InitTriggers();
}//And this is where Map Initialization triggers all the stuff to run!
Now, to actually add the event of Map Init!
Code:
//==================================================================================================
// 
// Generated Map Script
// 
// Name:   Just Another StarCraft II Map
// Author: Unknown Author
// 
//==================================================================================================
include "TriggerLibs/NativeLib"

//--------------------------------------------------------------------------------------------------
// Library Initialization
//--------------------------------------------------------------------------------------------------
void InitLibs () {
    libNtve_InitLib();// This initializes all the libs, like Built-in
}

//--------------------------------------------------------------------------------------------------
// Trigger Variables
//--------------------------------------------------------------------------------------------------
trigger gt_UntitledTrigger001;

//--------------------------------------------------------------------------------------------------
// Trigger: Untitled Trigger 001
//--------------------------------------------------------------------------------------------------
bool gt_UntitledTrigger001_Func (bool testConds, bool runActions) {
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_UntitledTrigger001_Init () {
    gt_UntitledTrigger001 = TriggerCreate("gt_UntitledTrigger001_Func");
    TriggerAddEventMapInit(gt_UntitledTrigger001);//This creates a MapInitialization event for your Triggerscript
}

//--------------------------------------------------------------------------------------------------
// Trigger Initialization
//--------------------------------------------------------------------------------------------------
void InitTriggers () {
    gt_UntitledTrigger001_Init();
}

//--------------------------------------------------------------------------------------------------
// Map Initialization
//--------------------------------------------------------------------------------------------------
void InitMap () {
    InitLibs();//You need this to actually use Map Initialization properly. It initializes all the pre-existing libraries (like the Built-In library)
    InitTriggers();
}
And now to actually create a unit!
Code:
//==================================================================================================
// 
// Generated Map Script
// 
// Name:   Just Another StarCraft II Map
// Author: Unknown Author
// 
//==================================================================================================
include "TriggerLibs/NativeLib"

//--------------------------------------------------------------------------------------------------
// Library Initialization
//--------------------------------------------------------------------------------------------------
void InitLibs () {
    libNtve_InitLib();
}

//--------------------------------------------------------------------------------------------------
// Trigger Variables
//--------------------------------------------------------------------------------------------------
trigger gt_UntitledTrigger001;

//--------------------------------------------------------------------------------------------------
// Trigger: Untitled Trigger 001
//--------------------------------------------------------------------------------------------------
bool gt_UntitledTrigger001_Func (bool testConds, bool runActions) {
    // Actions
    if (!runActions) {
        return true;
    }

    libNtve_gf_CreateUnitsWithDefaultFacing(1, "Zergling", c_unitCreateIgnorePlacement, 1, RegionGetCenter(RegionPlayableMap()));
    return true;
}
//Alright, this is our main target. Lets see now what each thing does
//If(!runActions) checks IF the actions have been run or not. If that is not
//there, i believe that it won't stop unless you have made it to break it
//inside the actions.
//libNtve_gf_CreateUnitsWithDefaultFacing(#number, "ID of Unit in Data
//Editor", c_unitCreateIgnorePlacement (ignores placement), Player
//number, RegionGetCenter(RegionPlayableMap()));
//libNtve(you're calling it from that lib)_gf(never found out what this is,
//I presume its needed)_CreateUnitsWithDefaultFacing(create units with 
//default facing :P) And now, Number of units, ID of the unit in data //editor, c_unitCreateIgnorePlacement must be there IF you want it to //ignore placement, else put 0, Player Number, and Point(i used Center of //region of playable map, which is RegionGetCenter(RegionPlayableMap()) //) and ; in the end to close it.
//So, if i wanted to create 5 marines in the middle of the map for player 5,
//without ignoring placement, i would use this instead:
//    libNtve_gf_CreateUnitsWithDefaultFacing(5, "Marine", 0, 5,RegionGetCenter(RegionPlayableMap()));
//--------------------------------------------------------------------------------------------------
void gt_UntitledTrigger001_Init () {
    gt_UntitledTrigger001 = TriggerCreate("gt_UntitledTrigger001_Func");
    TriggerAddEventMapInit(gt_UntitledTrigger001);
}

//--------------------------------------------------------------------------------------------------
// Trigger Initialization
//--------------------------------------------------------------------------------------------------
void InitTriggers () {
    gt_UntitledTrigger001_Init();
}

//--------------------------------------------------------------------------------------------------
// Map Initialization
//--------------------------------------------------------------------------------------------------
void InitMap () {
    InitLibs();
    InitTriggers();
}
So, this is the part that actually creates the unit!
Code:
libNtve_gf_CreateUnitsWithDefaultFacing(5, "Marine", 0, 5,RegionGetCenter(RegionPlayableMap()));
Also, the code i had written in Notepad++ :p
Code:
include "TriggerLibs/NativeLib" //includes the basic libraries
void InitLibs () {
    libNtve_InitLib();
}
//loads libraries
trigger gt_UntitledTrigger001; //declares our trigger

bool gt_UntitledTrigger001_Func (bool testConds, bool runActions) { //Actions part of the trigger
    if (!runActions) {//If runActions is not equal to true (pregenerated bool var)
        return true;//return true to it
    }

    libNtve_gf_CreateUnitsWithDefaultFacing(1, "Zergling", 0, 1, RegionGetCenter(RegionPlayableMap()));
//creates unit
    return true;//Returns that the whole trigger ran.
}
void gt_UntitledTrigger001_Init () {//Creates the Trigger in the debugging window
//and adds Map Initialization event as its event, and will be called when the map initializes
    gt_UntitledTrigger001 = TriggerCreate("gt_UntitledTrigger001_Func");
    TriggerAddEventMapInit(gt_UntitledTrigger001);//adds Initialization event
}

void InitTriggers () {//This is what initializes your triggers to be run
    gt_UntitledTrigger001_Init();
}
void InitMap () {// This starts at the second your player is in the lobby if i am right.
    InitLibs();//initializes your libs
    InitTriggers();//and initializes your triggers
}

// Cleaned up, and created in notepad++ by Statharas. If you have any suggestions, please tell me.


To use this, simply import it in your map with the name Mapscript.galaxy.

Please comment with any suggestions you have for me to change in this tutorial.
 
Last edited:
Top