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

Give resources to a player per building he controls?

Status
Not open for further replies.
Level 10
Joined
Nov 5, 2008
Messages
536
This will be the last question from me for a while. I will stop flooding the forum with my questions. With this final question I will have collected the pieces I need to put together the remainder of my map.

I am struggling to get a trigger to work. I understand the concept of how this can be done in triggers, but I can´t build it. Perhaps are there other ways.

My problem:


Players play in two teams and I have created two player groups. Players can control Xel naga towers scattered around the map. Every XXX of game time each member in both team gains resources depending on how many towers they control.

For example, if team A control 6 xel naga towers, every player in the team gains 6 resources. The next minute, when it is time to once again recieve resources, if team A only have 4 xel naga towers, each player in the team gains 4 resources.


Anyone feel like showing me the complete trigger or any other complete method?


(Yes I know that is a lot of me to ask, but I am so eager to get my map to work and I need this final thing. I have been struggling with it all day long :/ )
 
>make an integer (or fixed) array that is sized as the number of players in your map
e.g fixed[15] gv_playerTowersCount
>everytime a player gains control of a tower, increment the gv_playerTowersCount for the player by 1
>everytime one is lost decrement by 1
so
JASS:
const fixed c_towerIncomeUpdateInterval = 1.0;
const fixed c_towerIncome               = 1.0;
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncomeUpdate_Func");
fixed[number_of_players_in_your_map_goes_here]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i;
    
    while (lv_i <= number_of_players_in_your_map_goes_here) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome);
        lv_i += 1;
    }
    return true;
}

// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    const int       lv_income   = 1;
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager). The income
    // is how much of the given resource is earned per tower.
    // -------------------------------------------------------------
    unit            lv_u        = EventUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventUnitOwnerOld();
    int             lv_p2       = EventUnitOwnerNew();
    
    if (lv_ut != lv_tower) {
        return true;
    }
    
    gv_playerTowersCount[lv_p1] += -1;
    gv_playerTowersCount[lv_p2] += 1;
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);
}
 
Level 10
Joined
Nov 5, 2008
Messages
536
>make an integer (or fixed) array that is sized as the number of players in your map
e.g fixed[15] gv_playerTowersCount
>everytime a player gains control of a tower, increment the gv_playerTowersCount for the player by 1
>everytime one is lost decrement by 1
so
JASS:
const fixed c_towerIncomeUpdateInterval = 1.0;
const fixed c_towerIncome               = 1.0;
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncomeUpdate_Func");
fixed[number_of_players_in_your_map_goes_here]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i;
    
    while (lv_i <= number_of_players_in_your_map_goes_here) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome);
        lv_i += 1;
    }
    return true;
}

// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    const int       lv_income   = 1;
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager). The income
    // is how much of the given resource is earned per tower.
    // -------------------------------------------------------------
    unit            lv_u        = EventUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventUnitOwnerOld();
    int             lv_p2       = EventUnitOwnerNew();
    
    if (lv_ut != lv_tower) {
        return true;
    }
    
    gv_playerTowersCount[lv_p1] += -1;
    gv_playerTowersCount[lv_p2] += 1;
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);
}



You are my hero!

However, I can´t get this part to work. I follow your instructions but it won´t work. When I try to test the map this error message apperas: "Expected unused global variable or function name. Line: 47" T_T

This line I think: trigger gt_TowerIncome = TriggerCreate("gt_TowerIncomeUpdate_Func");

>make an integer (or fixed) array that is sized as the number of players in your map
e.g fixed[15] gv_playerTowersCount
>everytime a player gains control of a tower, increment the gv_playerTowersCount for the player by 1
>everytime one is lost decrement by 1

Now I am really greedy asking you this, after you have already helped me, but would you mind making this part as well so I can copy + paste it or describe for me step by step what to do? (There will be 14 players in total. 7 in each team.)

(I am retarded when it comes to stuff like this. I can make very basic triggers, but this is beyond my knowledge. T_T)


It looks like this now:
JASS:
const fixed c_towerIncomeUpdateInterval = 1.0;
const fixed c_towerIncome               = 1.0;
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncomeUpdate_Func");
fixed[fixed[14] gv_playerTowersCount]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i;
    
    while (lv_i fixed[14] gv_playerTowersCount <= [B]I ADDED THIS ONE[/B]!) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome);
        lv_i += 1;
    }
    return true;
}

// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    const int       lv_income   = 1;
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager). The income
    // is how much of the given resource is earned per tower.
    // -------------------------------------------------------------
    unit            lv_u        = EventUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventUnitOwnerOld();
    int             lv_p2       = EventUnitOwnerNew();
    
    if (lv_ut != lv_tower) {
        return true;
    }
    
    gv_playerTowersCount[lv_p1] += -1;
    gv_playerTowersCount[lv_p2] += 1;
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);


The scpt appears in a new window when I try to save the map or test the map.:

JASS:
//==================================================================================================
// 
// Generated Map Script
// 
// Name:   Just Another StarCraft II Map
// Author: Unknown Author
// 
//==================================================================================================
include "TriggerLibs/NativeLib"

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

//--------------------------------------------------------------------------------------------------
// Global Variables
//--------------------------------------------------------------------------------------------------
int[16] gv_fixed15gv_playerTowersCount;

void InitGlobals () {
    int init_i;

    init_i = 0;
    while (init_i <= 15) {
        gv_fixed15gv_playerTowersCount[init_i] = 0;
        init_i = init_i + 1;
    }
}

//--------------------------------------------------------------------------------------------------
// Trigger Variables
//--------------------------------------------------------------------------------------------------
trigger gt_MeleeInitialization;
trigger gt_Teamcolor;
trigger gt_Team;
trigger gt_Team2;

//--------------------------------------------------------------------------------------------------
// Custom Script: Resources to each player
//--------------------------------------------------------------------------------------------------
const fixed c_towerIncomeUpdateInterval = 1.0;
const fixed c_towerIncome               = 1.0;
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncomeUpdate_Func");
fixed[fixed[14] gv_playerTowersCount]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i;
    
    while (lv_i fixed[14] gv_playerTowersCount <= number_of_players_in_your_map_goes_here) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome);
        lv_i += 1;
    }
    return true;
}

// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    const int       lv_income   = 1;
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager). The income
    // is how much of the given resource is earned per tower.
    // -------------------------------------------------------------
    unit            lv_u        = EventUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventUnitOwnerOld();
    int             lv_p2       = EventUnitOwnerNew();
    
    if (lv_ut != lv_tower) {
        return true;
    }
    
    gv_playerTowersCount[lv_p1] += -1;
    gv_playerTowersCount[lv_p2] += 1;
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);

//--------------------------------------------------------------------------------------------------
// Custom Script Initialization
//--------------------------------------------------------------------------------------------------
void InitCustomScript () {
}

//--------------------------------------------------------------------------------------------------
// Trigger: Melee Initialization
//--------------------------------------------------------------------------------------------------
bool gt_MeleeInitialization_Func (bool testConds, bool runActions) {
    // Actions
    if (!runActions) {
        return true;
    }

    MeleeInitUnits();
    MeleeInitAI();
    MeleeInitOptions();
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_MeleeInitialization_Init () {
    gt_MeleeInitialization = TriggerCreate("gt_MeleeInitialization_Func");
    TriggerAddEventMapInit(gt_MeleeInitialization);
}

//--------------------------------------------------------------------------------------------------
// Trigger: Team color
//--------------------------------------------------------------------------------------------------
bool gt_Teamcolor_Func (bool testConds, bool runActions) {
    // Actions
    if (!runActions) {
        return true;
    }

    PlayerSetColorIndex(1, 1, true);
    PlayerSetColorIndex(2, 1, true);
    PlayerSetColorIndex(3, 1, true);
    PlayerSetColorIndex(4, 1, true);
    PlayerSetColorIndex(5, 1, true);
    PlayerSetColorIndex(6, 1, true);
    PlayerSetColorIndex(7, 1, true);
    PlayerSetColorIndex(8, 2, true);
    PlayerSetColorIndex(9, 2, true);
    PlayerSetColorIndex(10, 2, true);
    PlayerSetColorIndex(11, 2, true);
    PlayerSetColorIndex(12, 2, true);
    PlayerSetColorIndex(13, 2, true);
    PlayerSetColorIndex(14, 2, true);
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_Teamcolor_Init () {
    gt_Teamcolor = TriggerCreate("gt_Teamcolor_Func");
    TriggerAddEventMapInit(gt_Teamcolor);
}

//--------------------------------------------------------------------------------------------------
// Trigger: Team
//--------------------------------------------------------------------------------------------------
bool gt_Team_Func (bool testConds, bool runActions) {
    // Variable Declarations
    playergroup lv_team1;

    // Variable Initialization
    lv_team1 = PlayerGroupEmpty();

    // Actions
    if (!runActions) {
        return true;
    }

    PlayerGroupAdd(lv_team1, 1);
    PlayerGroupAdd(lv_team1, 2);
    PlayerGroupAdd(lv_team1, 3);
    PlayerGroupAdd(lv_team1, 4);
    PlayerGroupAdd(lv_team1, 5);
    PlayerGroupAdd(lv_team1, 6);
    PlayerGroupAdd(lv_team1, 7);
    libNtve_gf_SetPlayerGroupAlliance(lv_team1, 1);
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_Team_Init () {
    gt_Team = TriggerCreate("gt_Team_Func");
    TriggerAddEventMapInit(gt_Team);
}

//--------------------------------------------------------------------------------------------------
// Trigger: Team 2
//--------------------------------------------------------------------------------------------------
bool gt_Team2_Func (bool testConds, bool runActions) {
    // Variable Declarations
    playergroup lv_Team2;

    // Variable Initialization
    lv_Team2 = PlayerGroupEmpty();

    // Actions
    if (!runActions) {
        return true;
    }

    PlayerGroupAdd(lv_Team2, 8);
    PlayerGroupAdd(lv_Team2, 9);
    PlayerGroupAdd(lv_Team2, 10);
    PlayerGroupAdd(lv_Team2, 11);
    PlayerGroupAdd(lv_Team2, 12);
    PlayerGroupAdd(lv_Team2, 13);
    PlayerGroupAdd(lv_Team2, 14);
    libNtve_gf_SetPlayerGroupAlliance(lv_Team2, 1);
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_Team2_Init () {
    gt_Team2 = TriggerCreate("gt_Team2_Func");
    TriggerAddEventMapInit(gt_Team2);
}

//--------------------------------------------------------------------------------------------------
// Trigger Initialization
//--------------------------------------------------------------------------------------------------
void InitTriggers () {
    gt_MeleeInitialization_Init();
    gt_Teamcolor_Init();
    gt_Team_Init();
    gt_Team2_Init();
}

//--------------------------------------------------------------------------------------------------
// Map Initialization
//--------------------------------------------------------------------------------------------------
void InitMap () {
    InitLibs();
    InitGlobals();
    InitCustomScript();
    InitTriggers();
}
 
Last edited:
Oh, I forgot to rename a variable I copypasted.

JASS:
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncomeUpdate_Func");

They can't have the same name.

I also notice that I forgot to get rid of a local variable we don't need (lv_income wasn't doing anything, might as well just use c_towerIncome.

JASS:
//---------- Configurable Constants ----------
// The time interval that we add resources to each player.
const fixed c_towerIncomeUpdateInterval = 1.0;
// The income is how much of the given resource is earned per tower.
const fixed c_towerIncome               = 1.0;
//--------------------------------------------

trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncomeUpdate        = TriggerCreate("gt_TowerIncomeUpdate_Func");
fixed[14]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i;
    
    while (lv_i <= 14) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome);
        lv_i += 1;
    }
    return true;
}

// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager).
    // -------------------------------------------------------------
    unit            lv_u        = EventUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventUnitOwnerOld();
    int             lv_p2       = EventUnitOwnerNew();
    
    if (lv_ut != lv_tower) {
        return true;
    }
    
    gv_playerTowersCount[lv_p1] += -1;
    gv_playerTowersCount[lv_p2] += 1;
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);
}
 
Level 10
Joined
Nov 5, 2008
Messages
536


JASS:
//---------- Configurable Constants ----------
// The time interval that we add resources to each player.
const fixed c_towerIncomeUpdateInterval = 1.0;
// The income is how much of the given resource is earned per tower.
const fixed c_towerIncome               = 1.0;
//--------------------------------------------

trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncomeUpdate        = TriggerCreate("gt_TowerIncomeUpdate_Func");
fixed[14]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i;
    
    while (lv_i <= 14) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome);
        lv_i += 1;
    }
    return true;
}

// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager).
    // -------------------------------------------------------------
    unit            lv_u        = EventUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventUnitOwnerOld();
    int             lv_p2       = EventUnitOwnerNew();
    
    if (lv_ut != lv_tower) {
        return true;
    }
    
    gv_playerTowersCount[lv_p1] += -1;
    gv_playerTowersCount[lv_p2] += 1;
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);
}



I copy this and paste it in a new script in the trigger editor. Everythings seems to work but ingame no minerals are added to the players, no matther how many xel naga watch towers I control. (By standing near them)

Do I need to add more things to this script or other triggers to get it to work?
 
Level 9
Joined
Dec 21, 2006
Messages
490
add a region around the the towers and use "unit enters region" as the event. BUT you will need lots of validators; for example, there is already a unit inside that region and another one is entering, then your var shouldn't be changed etc. maybe you can use unit leaves region aswell.
 
I went through all the events GUI shows as being there and I don't see ANYTHING that would trigger for this.

However I checked in the data manager and there's an ability the tower uses. So we can use that as the event.

JASS:
TriggerAddEventUnitAbility(gt_TowerIncome, null, AbilityCommand("TowerCapture", 0), c_unitAbilStageExecute, false);

That event should work. You'll also want to get the the owner of the target unit and the previous player to have control over that. I'm extremely tired & in need of sleep right now though so it may be awhile before I do that for you.

JASS:
    lv_u  = EventUnitTargetUnit()
    lv_p1 = EventPlayer();
    lv_p2 = UnitGetOwner(lv_u);

Something like that would probably work...
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
The StarCraft II scripting language is called Galaxy. JASS was the WarCraft III scripting language.

The reason to take BlueBerryWizard's approach is because a trigger hooked to an ability event would be more efficient than every time a unit enters a region. That is if there is one.
 
Level 10
Joined
Nov 5, 2008
Messages
536
The script looks like this for me now after I added the changes:

JASS:
//---------- Configurable Constants ----------
// The time interval that we add resources to each player.
const fixed c_towerIncomeUpdateInterval = 1.0;
// The income is how much of the given resource is earned per tower.
const fixed c_towerIncome               = 1.0;
//--------------------------------------------

trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncomeUpdate        = TriggerCreate("gt_TowerIncomeUpdate_Func");
fixed[14]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i;
    
    while (lv_i <= 14) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome);
        lv_i += 1;
    }
    return true;
}

// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager).
    // -------------------------------------------------------------
    unit            lv_u        = EventUnitTargetUnit()
    int             lv_p1       = EventPlayer();
    int             lv_p2       = UnitGetOwner(lv_u);
    
    if (lv_ut != lv_tower) {
        return true;
    }
    
    gv_playerTowersCount[lv_p1] += -1;
    gv_playerTowersCount[lv_p2] += 1;
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitAbility(gt_TowerIncome, null, AbilityCommand("TowerCapture", 0), c_unitAbilStageExecute, false);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);
}

When I try the map, syntax error line 62:
JASS:
int             lv_p1       = EventPlayer();

How should the script look?
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
First function has a problem: local lv_i is not initialized. I suppose you want to start with player 1. The function should look then like this:

JASS:
bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i = 1;
    while (lv_i <= 14) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome);
        lv_i += 1;
    }
    return true;
}

The error you get is because whoever wrote the script forgot to put a ";" after EventUnitTargetUnit(). The function (variable initialization part only) should look like this:

JASS:
    unit            lv_u        = EventUnitTargetUnit();
    int             lv_p1       = EventPlayer();
    int             lv_p2       = UnitGetOwner(lv_u);
 
Level 10
Joined
Nov 5, 2008
Messages
536
Sorry for causing so much trouble with this. When it comes to scripts I am completely lost. : /

I try the trigger in game but it does not give me any minerals when I control the xel naga towers. Do I need to create any triggers, variables or something as an addition to the script?



JASS:
//---------- Configurable Constants ----------
// The time interval that we add resources to each player.
const fixed c_towerIncomeUpdateInterval = 1.0;
// The income is how much of the given resource is earned per tower.
const fixed c_towerIncome               = 1.0;
//--------------------------------------------

trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncomeUpdate        = TriggerCreate("gt_TowerIncomeUpdate_Func");
fixed[14]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i = 1;
    while (lv_i <= 14) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome);
        lv_i += 1;
    }
    return true;
}
// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager).
    // -------------------------------------------------------------
    unit            lv_u        = EventUnitTargetUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventPlayer();
    int             lv_p2       = UnitGetOwner(lv_u);
    
    if (lv_ut != lv_tower) {
        return true;
    }
    
    gv_playerTowersCount[lv_p1] += -1;
    gv_playerTowersCount[lv_p2] += 1;
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);
}
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
Some observations regarding the current implementation:

- It does not take groups into consideration, but individual players.
- It gives the resource amount to all players, independent of the Xel'Naga towers owned.

Normally if everything else works correctly, the code above should give players 1 mineral every second. Here is the correction (but still for individual players - no teams):

JASS:
PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome*gv_playerTowersCount[lv_i]);

If you could provide me with the name of the global variables in which you store the two teams I could probably help you with fixing the team aspect too.
 
Level 10
Joined
Nov 5, 2008
Messages
536
I don´t use any global variables. I use these local variables inside two triggers:

  • Team1 = (Empty player group) <Player Group>
  • Team 2 = (Empty player group) <Player Group>
Would it be better if I used global variables for the script to work?
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
Naturally. Generically speaking, global variables 'store' resources accessible to other modules (functions/triggers) of a script. Local variables are restricted to the block (function/trigger) in which they were defined.

The player groups you defined may find even other uses thorough the game. Simply define them when you define the groups (I suppose at the beginning of the game), store them in global Player Groups, and then you can access those groups anywhere.

I will now enhance your script taking into account you have only two groups. It could be further generalized to any number of groups, but as I see you don't need this, we'll stick to the restricted case.

JASS:
//---------- Configurable Constants ----------
// The time interval that we add resources to each player.
const fixed c_towerIncomeUpdateInterval = 1.0;
// The income is how much of the given resource is earned per tower.
const fixed c_towerIncome               = 1.0;
//--------------------------------------------

trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncomeUpdate        = TriggerCreate("gt_TowerIncomeUpdate_Func");
int[2]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i = 1;
	int count;
    while (lv_i <= 14) {
		if (PlayerGroupHasPlayer(gv_Team1, lv_p1))
			count = gv_playerTowersCount[gv_Team1];
		else
			count = gv_playerTowersCount[gv_Team2];
		PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome*count);
        lv_i += 1;
    }
    return true;
}
// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager).
    // -------------------------------------------------------------
    unit            lv_u        = EventUnitTargetUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventPlayer();
    int             lv_p2       = UnitGetOwner(lv_u);
    
    if (lv_ut != lv_tower) 
        return true;
    
	if (PlayerGroupHasPlayer(gv_Team1, lv_p1))
		gv_playerTowersCount[0] -= 1;
	else if (PlayerGroupHasPlayer(gv_Team2, lv_p1))
		gv_playerTowersCount[1] -= 1;
	
	if (PlayerGroupHasPlayer(gv_Team1, lv_p2))
		gv_playerTowersCount[0] += 1;
	else if (PlayerGroupHasPlayer(gv_Team2, lv_p2))
		gv_playerTowersCount[1] += 1;
	
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);
}

The following assumptions are made by the alterations:
- Players from the same alliance can steal towers from one another (it will still work correctly).
- Only two player groups exist, but there can be rogue players that don't belong to either - the script still works correctly for the groups.

Hope it works now.
~Daelin
 
Naturally. Generically speaking, global variables 'store' resources accessible to other modules (functions/triggers) of a script. Local variables are restricted to the block (function/trigger) in which they were defined.

The player groups you defined may find even other uses thorough the game. Simply define them when you define the groups (I suppose at the beginning of the game), store them in global Player Groups, and then you can access those groups anywhere.

I will now enhance your script taking into account you have only two groups. It could be further generalized to any number of groups, but as I see you don't need this, we'll stick to the restricted case.

JASS:
//---------- Configurable Constants ----------
// The time interval that we add resources to each player.
const fixed c_towerIncomeUpdateInterval = 1.0;
// The income is how much of the given resource is earned per tower.
const fixed c_towerIncome               = 1.0;
//--------------------------------------------

trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncomeUpdate        = TriggerCreate("gt_TowerIncomeUpdate_Func");
int[2]   gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i = 1;
	int count;
    while (lv_i <= 14) {
		if (PlayerGroupHasPlayer(gv_Team1, lv_p1))
			count = gv_playerTowersCount[gv_Team1];
		else
			count = gv_playerTowersCount[gv_Team2];
		PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, c_towerIncome*count);
        lv_i += 1;
    }
    return true;
}
// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager).
    // -------------------------------------------------------------
    unit            lv_u        = EventUnitTargetUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventPlayer();
    int             lv_p2       = UnitGetOwner(lv_u);
    
    if (lv_ut != lv_tower) 
        return true;
    
	if (PlayerGroupHasPlayer(gv_Team1, lv_p1))
		gv_playerTowersCount[0] -= 1;
	else if (PlayerGroupHasPlayer(gv_Team2, lv_p1))
		gv_playerTowersCount[1] -= 1;
	
	if (PlayerGroupHasPlayer(gv_Team1, lv_p2))
		gv_playerTowersCount[0] += 1;
	else if (PlayerGroupHasPlayer(gv_Team2, lv_p2))
		gv_playerTowersCount[1] += 1;
	
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);
}

The following assumptions are made by the alterations:
- Players from the same alliance can steal towers from one another (it will still work correctly).
- Only two player groups exist, but there can be rogue players that don't belong to either - the script still works correctly for the groups.

Hope it works now.
~Daelin

Wait a moment, you want income to be added to each player on a team based on the number of towers the team controls and not just add income to each player based on the number of towers that individual player has?
 

Do you want each team to have a money pool they all dip into to spend on things (We'll call this Pooled Resources) or just each player gets x number of towers controlled by team income worth (lets call this Team Tower Multiplier)?

If say you have 14 players and 8 towers on a map and one team controls 5 of them while the other controls 3 and you use the Team Tower Multiplier method then in total the team with 5 towers will get 5*7 = 35 income per interval while the other team would get 3*7 = 21 income per interval but if we use Pooled Resources method then the team with 5 towers would get 5 income per interval and the enemy team 3... the disparity in overall team income being 14 in the first example and 2 in the second example... It seems to me like one team getting an extra tower under the Team Tower Multiplier method would suddenly gain the upperhand so fast the game might already be decided at that point.

Edit: Btw Daelin, globals use camel case in .galaxy. So those should be labeled gv_team1 and gv_team2 not gv_Team1, etc. Also that way you modified the script is a really silly way of doing the whole thing. I'm just going to make a test map and try making multiple versions of the script do different things in as efficient a manner as possible and post the map here.
 
Level 10
Joined
Nov 5, 2008
Messages
536
Do you want each team to have a money pool they all dip into to spend on things (We'll call this Pooled Resources) or just each player gets x number of towers controlled by team income worth (lets call this Team Tower Multiplier)?

I think it would be best if each individual player in the teams gains resources equal to the number of towers the whole team together control.

Example: If there are 3 players in team A and they together control 5 towers, each of these 3 players will get 5 minerals every minute. (Until they gain or lose more towers casue that will of course change the amount of minerals they get.)
 
*laughs* There's not anything else I need to add regarding your insulting, yet totally pointless comment.

Kabel, you didn't mention anything regarding the script - whether there were any problems related to it or not.

Really, REALLY now? You're getting butthurt over this? Seriously don't take it personally. I myself always want feedback on my scripts to make them more efficient or to find a better way to do them. You should be pleased I pointed this out for you... well you'll see when I got the next script made why my way of doing it will be so much faster.

Don't get butthurt.

(Now if you feel motivated to "get revenge" there's still some threads by me on here that nobody has responded too which you can critique, although I'll be happy if you do that not mad.)
 
Level 11
Joined
Jul 20, 2004
Messages
2,760
BlueBerry, I simply performed minimal modifications to your script so that it works with 2 teams like Kabel wanted. I suspect the so-called improved, yet trivial modification you brag with does the following:
- Create a new array that stores for each player the team to which it belongs.
- Setup the values of the array at map initialization.
- Simply access the team through the array instead of searching for the player in a group or the other one, avoiding the execution of all the conditionals above.

This solution can then obviously be expanded to any number of teams. Happy now, smartie?

Oh, and fyi, I don't get butthurt over such 'interventions'. More like... amused.
 
*laughs* There's not anything else I need to add regarding your insulting, yet totally pointless comment.

Kabel, you didn't mention anything regarding the script - whether there were any problems related to it or not.

BlueBerry, I simply performed minimal modifications to your script so that it works with 2 teams like Kabel wanted. I suspect the so-called improved, yet trivial modification you brag with does the following:
- Create a new array that stores for each player the team to which it belongs.
- Setup the values of the array at map initialization.
- Simply access the team through the array instead of searching for the player in a group or the other one, avoiding the execution of all the conditionals above.

This solution can then obviously be expanded to any number of teams. Happy now, smartie?

"Happy now, smartie?"

Yes.

Edit: I've tried out so many different ways of trigger the tower capture thing in a test map I made. I've got the script all fixed up but it seems there is just no way at all to make the stupid tower capture thing trigger an event. Apparently it's one of 3 interact abilities in the editor D:

Here's the script as I have it now. You're going to need to make some new ability or something and attach it the tower which auto-casts at the same range which can then be used to tell if the tower is under control.


JASS:
//---------- Configurable Constants ----------
// The time interval that we add resources to each player.
const fixed c_towerIncomeUpdateInterval = 1.0;
// The income is how much of the given resource is earned per tower.
const fixed c_towerIncome               = 1.0;
//--------------------------------------------

trigger     gt_TowerIncome              = TriggerCreate("gt_TowerIncome_Func");
trigger     gt_TowerIncomeUpdate        = TriggerCreate("gt_TowerIncomeUpdate_Func");
int[16]     gv_playerTowersCount;

bool gt_TowerIncomeUpdate_Func (bool testConds, bool runActions) {
    int lv_i;
    
    while (lv_i <= 15) {
        PlayerModifyPropertyFixed(lv_i, c_playerPropMinerals, c_playerPropOperAdd, gv_playerTowersCount[lv_i] * c_towerIncome);
        lv_i += 1;
    }
    return true;
}

// Players play in two teams and I have created two player groups.
// Players can control Xel naga towers scattered around the map.
// Every interval of game time each member in both team gains
// resources depending on how many towers they control.

bool gt_TowerIncome_Func (bool testConds, bool runActions) {
    // ------------------------- Interface -------------------------
    const string    lv_tower    = "XelNagaTower";
    // Set the tower string to your tower ID, I probably have it set
    // right already (look that up in the data manager).
    // -------------------------------------------------------------
    unit            lv_u        = EventUnit();
    string          lv_ut       = UnitGetType(lv_u);
    int             lv_p1       = EventPlayer();
    int             lv_p2       = UnitGetOwner(EventUnitTargetUnit());
    
    if (lv_ut != lv_tower) {
        return true;
    }
    
    gv_playerTowersCount[lv_p1] += -1;
    gv_playerTowersCount[lv_p2] += 1;
    DebugMsg(IntToString(gv_playerTowersCount[lv_p1]));
    DebugMsg(IntToString(gv_playerTowersCount[lv_p2]));
    return true;
}

//--------------------------------------------------------------------------------------------------
void gt_TowerIncome_Init () {
    // Register Unit Ownership Change Event
    //TriggerAddEventUnitChangeOwner(gt_TowerIncome, null);
    TriggerAddEventUnitAbility(gt_TowerIncome, null, AbilityCommand("TowerCapture", 0), c_unitAbilStageAll, false);
    TriggerAddEventUnitOrder(gt_TowerIncome, null, AbilityCommand("TowerCapture", 0));
    TriggerAddEventTimePeriodic(gt_TowerIncomeUpdate, c_towerIncomeUpdateInterval, c_timeReal);
}
 
Last edited:
Status
Not open for further replies.
Top