Jump to content
Northup

How to get update when marker color changes

Recommended Posts

Trying to enable an addaction based on the player side and color marker matching. This is in the init of a supply box on mission start. 

Anyone know how I would go about updating it whenever a marker color changes?

_mrkr = "TowerPost1";  
_mrkrcolor = getMarkerColor _mrkr;  
_color = switch (side player) do  
{  
 case west: { "ColorBlufor" };  
 case east: { "ColorOpfor" };  
 case independent: { "ColorIndependent" };  
 default { "ColorGrey" };  
};  
  
_canRearm = (_color == _mrkrcolor);
  
if (_canRearm) then {   
    player addAction ["Rearm", {   
        private _customLoadout = player getVariable "enh_savedloadout";       
        if (isNil "_customLoadout") exitWith {       
            player setUnitLoadout (configFile >> "CfgVehicles" >> typeOf player);       
            systemChat "Could not find custom loadout";       
            systemChat "Restored default unit loadout";       
        };       
        player setUnitLoadout _customLoadout;       
        systemChat "Rearmed and Reloaded";       
    }];   
}; 

Share this post


Link to post
Share on other sites

Did you consider using the "condition" parameter of addAction to check if player can rearm?

You can't really update an action, you'd have to delete it and create again when needed but I think using the condition is cleaner.

  • Like 1

Share this post


Link to post
Share on other sites
5 hours ago, _foley said:

Did you consider using the "condition" parameter of addAction to check if player can rearm?

You can't really update an action, you'd have to delete it and create again when needed but I think using the condition is cleaner.

I have tried

if (_mrkrcolor == _color) then { 
    player addAction ["Rearm", { 
        _mrkrcolor = getMarkerColor _mrkr; 

and 
 

if (_canRearm) then {
    player addAction ["Rearm", {
        private _customLoadout = player getVariable "enh_savedloadout";
        if (isNil "_customLoadout") exitWith {
            player setUnitLoadout (configFile >> "CfgVehicles" >> typeOf player);
            systemChat "Could not find custom loadout";
            systemChat "Restored default unit loadout";
        };
        player setUnitLoadout _customLoadout;
        systemChat "Rearmed and Reloaded";
    }, [], 0, true, true, "", "_canRearm"];
};

Neither throw errors, nor appears to have any effect.

Share this post


Link to post
Share on other sites
4 hours ago, ghostrider-GRG said:

Did you look into determining the side of the player to start then setting marker colors and anything else you need base on that?

https://community.bistudio.com/wiki/side

Not sure what you mean.

For context, I am creating a small Outpost that will be capturable in a larger MP mission with 3 teams fighting over a single sector.
The idea is that a player captures an outpost by capturing a flag (with code from here). Doing so changes the color of a named marker specific to that base, to not only show who controls it, but to act as a switch of sorts for a couple of things in the outpost.This particular one is a supply crate. The addaction by itself works splendidly, filtering it seems to be quite the chore. Beyond that there will be a healing create, three vehicle repair areas and a respawn location -- all which are only meant to work for the team matching the marker color.

Share this post


Link to post
Share on other sites
1 hour ago, Northup said:

I have tried


if (_mrkrcolor == _color) then { 
    player addAction ["Rearm", { 
        _mrkrcolor = getMarkerColor _mrkr; 

and 
 


if (_canRearm) then {
    player addAction ["Rearm", {
        private _customLoadout = player getVariable "enh_savedloadout";
        if (isNil "_customLoadout") exitWith {
            player setUnitLoadout (configFile >> "CfgVehicles" >> typeOf player);
            systemChat "Could not find custom loadout";
            systemChat "Restored default unit loadout";
        };
        player setUnitLoadout _customLoadout;
        systemChat "Rearmed and Reloaded";
    }, [], 0, true, true, "", "_canRearm"];
};

Neither throw errors, nor appears to have any effect.

The trouble is that "_canRearm" is a local variable and it's only evaluated once, at the beginning of the script.

 

Try this, first define a function that checks if player can rearm:

fnc_canRearm = {
  _mrkr = "TowerPost1";  
  _mrkrcolor = getMarkerColor _mrkr;  
  _color = switch (side player) do  
  {  
   case west: { "ColorBlufor" };  
   case east: { "ColorOpfor" };  
   case independent: { "ColorIndependent" };  
   default { "ColorGrey" };  
  };  
  
  (_color == _mrkrcolor)
}

then in the addAction set the condition to "call fnc_canRearm" instead of "_canRearm".

 

Keep in mind that this condition will be checked on every frame. It's fine in this case but if the function were more complex then it could affect performance.

  • Like 1

Share this post


Link to post
Share on other sites
29 minutes ago, _foley said:

The trouble is that "_canRearm" is a local variable and it's only evaluated once, at the beginning of the script.

 

Try this, first define a function that checks if player can rearm:


fnc_canRearm = {
  _mrkr = "TowerPost1";  
  _mrkrcolor = getMarkerColor _mrkr;  
  _color = switch (side player) do  
  {  
   case west: { "ColorBlufor" };  
   case east: { "ColorOpfor" };  
   case independent: { "ColorIndependent" };  
   default { "ColorGrey" };  
  };  
  
  (_color == _mrkrcolor)
}

then in the addAction set the condition to "call fnc_canRearm" instead of "_canRearm".

 

Keep in mind that this condition will be checked on every frame. It's fine in this case but if the function were more complex then it could affect performance.

In that case, what would be a better, more efficient approach?

Share this post


Link to post
Share on other sites
14 hours ago, Northup said:

Trying to enable an addaction based on the player side and color marker matching. This is in the init of a supply box on mission start. 

Anyone know how I would go about updating it whenever a marker color changes?
 

 

You should add your action on box instead of player. (this instead of player in init field of the box)

You just have to add a condition in your addAction (at the condition param):
 

this addAction [ "Rearm at box", {
  params ["_target", "_caller", "_actionId", "_arguments"];
  }, nil, 1.5, true, true, "", "side _this == TowerPost1Side  ", 10, false, "", "" ];

 

TowerPost1Side can be set at start by:

if (isServer) then {towerPost1Side == sideUnknown; publicVariable "towerPost1Side"};

 

Up to you for changing TowerPost1Side along with your captures. Playing with the color of a marker is not the best solution... because the marker color change already met a condition which could be used for the addAction as well.

 

Anyway, you can use an event handler for that:
 

addMissionEventHandler ["MarkerUpdated", {
  params ["_marker", "_local"];
  if (_marker == "towerPost1") then {
    call {
      if (markerColor _marker == "colorWest" exitWith {towerPost1Side = WEST};
      if (markerColor _marker == "colorEAST" exitWith {towerPost1Side = EAST};
      ....  // what you need
      towerPost1Side = sideUnknown;
    };
  };
}];

 

  • Like 2

Share this post


Link to post
Share on other sites
1 hour ago, pierremgi said:

 

You should add your action on box instead of player. (this instead of player in init field of the box)

You just have to add a condition in your addAction (at the condition param):
 


this addAction [ "Rearm at box", {
  params ["_target", "_caller", "_actionId", "_arguments"];
  }, nil, 1.5, true, true, "", "side _this == TowerPost1Side  ", 10, false, "", "" ];

 

TowerPost1Side can be set at start by:


if (isServer) then {towerPost1Side == sideUnknown; publicVariable "towerPost1Side"};

 

Up to you for changing TowerPost1Side along with your captures. Playing with the color of a marker is not the best solution... because the marker color change already met a condition which could be used for the addAction as well.

 

Anyway, you can use an event handler for that:
 


addMissionEventHandler ["MarkerUpdated", {
  params ["_marker", "_local"];
  if (_marker == "towerPost1") then {
    call {
      if (markerColor _marker == "colorWest" exitWith {towerPost1Side = WEST};
      if (markerColor _marker == "colorEAST" exitWith {towerPost1Side = EAST};
      ....  // what you need
      towerPost1Side = sideUnknown;
    };
  };
}];

 

Works great! Thanks!

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×