Results 1 to 10 of 10

Thread: local markers not changing alpha

  1. #1

    local markers not changing alpha

    hi. i am trying a basic script to auto monitor and react to who takes a town. MP. EAST = AI. GUER = humans.

    script is
    Code:
    // townmind.sqf
    
    // spawn marker to indicate town ownership
    // spawn 2 tiggers, one to sense opfor, other to sense indenependt
    
    private ["_townpos","_townloc","_ownedBy","_townmarkersize","_towntriggersize","_trigE","_trigI","_MarkerE","_MarkerI"];
    
    _townpos = _this select 0;
    _townloc = getPos _townpos;
    _ownedBy = 0;
    _new = 1;
    sleep 5;
    _unitList = allUnits;
    _j = count _unitList;
    _i = 0;
    _max = _j + 1;
    
    _townmarkersize = 200;
    _towntriggersize = 350;
    
    _trigE = createTrigger ["EmptyDetector", _townloc]; // east present
    _trigI = createTrigger ["EmptyDetector", _townloc]; // independet present
    hint "Adding Player Markers";
    
    _trigE setTriggerTimeout  [10, 15, 20, False];
    _trigI setTriggerTimeout  [10, 15, 20 False];
    _trigE setTriggerActivation ["EAST", "PRESENT", true];
    _trigI setTriggerActivation ["GUER", "PRESENT", true];
    _trigE setTriggerArea [_towntriggersize, _towntriggersize, 45, false];
    _trigI setTriggerArea [_towntriggersize, _towntriggersize, 45, false];
    _trigE setTriggerStatements ["_this", "_ownedBy = 1", "hint 'EAST on'"];
    _trigI setTriggerStatements ["_this", "_ownedBy = 2", ""hint 'GUER off'"];
    
    // markers
    // make a made up name so each marker is unique
    /*
    _HeloCrewman = text format["_HeloCrewman%1",_NumberOfCrewman];
    */
    _NumberOfMarkers = count (Markers);//defined in init.sqf
    
    hint format["number of markers is %1",_max];
    sleep 5;
    
    //_markernameE = text format["_MarkerE%1",_NumberOfMarkers+1];
    _markernameE = "markerE" + (str _max);
    _markernameI = "markerI" + (str _max);
    
    hint format["MarkerE is called %1", _markernameE];
    hint format["MarkerI is called %1", _markernameI];
    
    
    _MarkerE = CreateMarkerLocal [_markernameE, getPos _townpos];
    _MarkerE = _markernameE SetMarkerShapeLocal "ELLIPSE";
    _MarkerE = _markernameE SetMarkerColorLocal "ColorBlue";
    _MarkerE = _markernameE SetMarkerSizeLocal [_townmarkersize, _townmarkersize];
    _MarkerI = CreateMarkerLocal [_markernameI, getPos _townpos];
    _MarkerI = _markernameI SetMarkerShapeLocal "ELLIPSE";
    _MarkerI = _markernameI SetMarkerColorLocal "ColorGreen";
    _MarkerI = _markernameI SetMarkerSizeLocal [_townmarkersize, _townmarkersize];
    
    if (_owned == 0) then {
     _MarkerE = _markernameE setMarkerAlphaLocal 0;
     _MarkerI = _markernameI setMarkerAlphaLocal 0;
    };
    
    if (_owned == 1) then {
    
     _MarkerE = _markernameE setMarkerAlphaLocal 1;
     _MarkerI = _markernameI setMarkerAlphaLocal 0;
    };
    
    if (_owned == 2) then {
    
     _MarkerE = _markernameE setMarkerAlphaLocal 0;
     _MarkerI = _markernameI setMarkerAlphaLocal 1;
    
    };
    but the markers don't seem to be changing their visibility based on who owns the town. if anyone can point out where i am oging wrong i'd appreicate iy.

  2. #2
    You declare _ownedby at the top but you run the check against _owned which you don't declare anywhere. You're also trying to use local variables in a trigger statement, which won't work.

  3. #3
    Variables local to some scripts can be used elsewhere. Otherwise they wouldn't be local. The code in the trigger statements are run like they were other scripts.
    Code:
    _trigE setTriggerStatements ["_this", "_ownedBy = 1", "hint 'EAST on'"];
    _trigI setTriggerStatements ["_this", "_ownedBy = 2", ""hint 'GUER off'"];
    So you will probably need to change quite a bit to get it working.

  4. #4
    Thanks for the answers. Fixed that naming error. Silly mistake.

    But then to me it seems there's not much point in using spawned triggers if they can't talk back to the script that created them. Would an if statement that checks nearest objects are East or not be a better way of doing things here.?

  5. #5
    Just use global variables for things you'll need to reference from triggers.

  6. #6
    Quote Originally Posted by kylania View Post
    Just use global variables for things you'll need to reference from triggers.
    thanks. I tried this instead - usingnearestobjects as i needed unique references to each trigger (there's about 19 of these in total). any tips? should i be labelling them local to see the markers?


    Code:
    // townmind.sqf
    
    // spawn marker to indicate town ownership
    // spawn 2 tiggers, one to sense opfor, other to sense indenependt
    
    private ["_townpos","_townloc","_townmarkersize","_towntriggersize","_trigE","_trigI","_MarkerE","_MarkerI"];
    
    _townpos = _this select 0;
    _townloc = getPos _townpos;
    _ownedBy = 2; //neutral
    _new = 1;
    sleep 5;
    _unitList = allUnits;
    _j = count _unitList;
    _i = 0;
    _max = _j + 1;
    
    
    _townmarkersize = 200;
    _towntriggersize = 350;
    
    
    sleep 5;
    
    //_markernameE = text format["_MarkerE%1",_NumberOfMarkers+1];
    _markernameE = "markerE" + (str _max);
    _markernameI = "markerI" + (str _max);
    
    //hint format["MarkerE is called %1", _markernameE];
    //hint format["MarkerI is called %1", _markernameI];
    
    
    _MarkerE = CreateMarker [_markernameE, getPos _townpos];
    _MarkerE = _markernameE SetMarkerShape "ELLIPSE";
    _MarkerE = _markernameE SetMarkerColor "ColorBlue";
    _MarkerE = _markernameE SetMarkerSize [_townmarkersize, _townmarkersize];
    _MarkerI = CreateMarker [_markernameI, getPos _townpos];
    _MarkerI = _markernameI SetMarkerShape "ELLIPSE";
    _MarkerI = _markernameI SetMarkerColor "ColorGreen";
    _MarkerI = _markernameI SetMarkerSize [_townmarkersize, _townmarkersize];
    
    
    _loops = 1;
    while {_loops == 1} do {
    
    _trigE = nearestObjects [_townpos, ["SoldierEB"], 300];
    _trigI = nearestObjects [_townpos, ["SoldierGB"], 300];
    
    _validNearestTargetsE = [];
    _validNearestTargetsW = [];
    
    {if (alive _x) then {_validNearestTargetsE set [(count _validNearestTargetsE),_x];};} foreach _nearestTargetsE;
    {if (alive _x) then {_validNearestTargetsW set [(count _validNearestTargetsW),_x];};} foreach _nearestTargetsW;
    
    _closestE = _validNearestTargetsE select 0;
    _closestW = _validNearestTargetsW select 0;
    
    _distE = _townpos distance _closestE;
    _distW = _townpos distance _closestW;
    
    
    if ((count _validNearestTargetsE) > (count _validNearestTargetsE)) then
    {
    // set town as East
    _ownedBy = 0; //EAST = 0
     
    }; 
    
    if ((count _validNearestTargetsE) < (count _validNearestTargetsE)) then
    {
    // set town as East
    _ownedBy = 1; //WEST = 1
     
    }; 
    
    
    if ((_ownedBy == 0) && (_new == 1)) then
    {
    // set town as recently taken by East
    //
     _new = 0;
    }; 
    
    
    
    // if west approaches then make east spawn
    
    if ((_ownedBy == 0) && (_distW <500) && (_distW > 200)) then {
    
    
    _tempG = [getPos _townpos, EAST, 5] call BIS_fnc_spawnGroup;
    [_tempG,_townloc, 100, 2, true] call CBA_fnc_taskDefend;
    
    };
    
    
    
    
    
    // markers
    // make a made up name so each marker is unique
    
    _NumberOfMarkers = count (Markers);//defined in init.sqf
    
    //hint format["number of markers is %1",_max];
    
    if (_ownedBy == 0) then {
     _MarkerE = _markernameE setMarkerAlpha 0;
     _MarkerI = _markernameI setMarkerAlpha 0.2;
    };
    
    if (_ownedBy == 1) then {
    
     _MarkerE = _markernameE setMarkerAlpha 1;
     _MarkerI = _markernameI setMarkerAlpha 0;
    };
    
    if (_ownedBy == 2) then {
    
     _MarkerE = _markernameE setMarkerAlpha 0;
     _MarkerI = _markernameI setMarkerAlpha 1;
    
    };
    
    sleep 30;
    
    };

  7. #7
    Yeah, instead of having two markers and hiding one or the other just load locally whichever marker the correct side should see.

    The global thing I was talking about was the "ownedby" value since that's what's in the trigger area. Instead of a 0, 1, 2 you might just set that as a side. Then just load/delete markers based on side.

  8. #8
    Quote Originally Posted by twisted View Post
    Thanks for the answers. Fixed that naming error. Silly mistake.

    But then to me it seems there's not much point in using spawned triggers if they can't talk back to the script that created them. Would an if statement that checks nearest objects are East or not be a better way of doing things here.?
    I feel your pain on this - waypoint activation and trigger activations cant use local variables, and you cant pass them in as arguments either. The only way I found that was mildly successful in working was using something like:

    Code:
    _codeString = format ["car doMove %1", _myLocalPos];
    
    _trg setTriggerStatements ["this", _codeString, ""];
    as format returns the actual value, which you can pass (unless its a unit or group name, then you get O 1-1-A:3 which fails to work)

  9. #9
    You can get around having to use global variables by simply storing stuff on the triggers. I made an example where you create a single marker in the editor. The script then creates and sets up the necessary values. There is also a callback functionality to use when the triggers change condition:

    PHP Code:

    #define TIMEOUT_MIN (10)
    #define TIMEOUT_MID (15)
    #define TIMEOUT_MAX (20)

    /*
        Creates triggers and a marker to show who dominates an area
    */
    CreateAreaMonitor = {
        private [
    "_triggerSide","_trigger","_marker","_sides","_code","_triggers"];
        
    _marker _this select 0;
        
    _sides _this select 1;
        
    _code = if (count _this 2then {_this select 2} else { {} };

        
    _triggers = [];
        
    //Create triggers for each side
        
    {
            
    _triggerSide _x call SideToTriggerConditionSide;
            
    _trigger createTrigger ["EmptyDetector"getMarkerPos _marker];
            
    _trigger setTriggerTimeout [TIMEOUT_MINTIMEOUT_MIDTIMEOUT_MAXfalse];
            
    _trigger setTriggerActivation [_triggerSide"PRESENT"true];
            
    //Replicate marker area
            
    _trigger setTriggerArea [getMarkerSize _marker select 0getMarkerSize _marker select 1markerDir _markermarkerShape _marker == "RECTANGLE"];
            
    _trigger setTriggerStatements ["this""0 = [thisTrigger, true] call AreaMonitorChange;""0 = [thisTrigger, false] call AreaMonitorChange;"];

            
    //Set data
            
    _trigger setVariable ["AM_Marker"_marker];
            
    _trigger setVariable ["AM_Side"_x];
            
    _trigger setVariable ["AM_Code"_code];

            
    _triggers set [count _triggers_trigger];

        } forEach 
    _sides;

        {
    _x setVariable ["AM_Triggers"_triggers];} forEach _triggers
    };

    SideToTriggerConditionSide = {
        [
    "WEST","EAST","GUER","CIV"select ([west,east,resistance,civilianfind _this);
    };

    TriggerConditionSideToSide = {
        [
    westeastresistancecivilianselect (["WEST","EAST","GUER","CIV"find _this);    
    };

    SideToMarkerColor = {
        [
    "ColorBlue""ColorRed""ColorGreen""ColorYellow"select ([west,east,resistance,civilianfind _this);
    };


    //Called whenever a trigger goes from activated to deactivated
    AreaMonitorChange = {
        private [
    "_color","_side","_triggered","_triggers","_marker","_numActivated","_forEachIndex","_activated","_activations"];
        
    _triggered _this select 0;
        
    //Unfortunately triggerActivated returns true whilst running the "On De-Act".
        
    _activated _this select 1;

        
    _triggers _triggered getVariable "AM_Triggers";
        
    _marker _triggered getVariable "AM_Marker";

        
    _activations = [];
        
    _activations resize (count _triggers);
        {
            if (
    _x == _triggeredthen {
                
    _activations set [_forEachIndex_activated];
            } else {
                
    _activations set [_forEachIndextriggerActivated _x];
            };
        } forEach 
    _triggers;
        
        
    _numActivated = {_xcount _activations;

        
    _color "Default";

        
    //Nobody there
        
    if (_numActivated == 0then {
            
    //Go grey
            
    _color "Default";
        };

        
    //Too many?
        
    if (_numActivated 1then {
            
    //Find some congested color representing contested area - what about grey?
            
    _color "Default";
        };

        if (
    _numActivated == 1then {
            
    //Find the side who dominates
            
    _side = (_triggers select (_activations find true)) getVariable "AM_Side";
            
    _color _side call SideToMarkerColor;
        };

        
    _marker setMarkerColor _color;

        
    //Handler receives [TRIGGER, SIDE, SIDE_PRESENT]
        
    [_triggered_triggered getVariable "AM_Side"_activatedcall (_triggered getVariable "AM_Code");

    }; 
    First load the script:
    PHP Code:
    [] call compile preProcessFile "FILE.sqf"
    Then you activate the markers:
    PHP Code:
    _markers = ["CityMrk1""CityMrk2""ForestMrk3"];

    //Let's say we want to spawn stuff whenever west enters anyone of those triggers:
    _handler = {
        private [
    "_trigger""_side""_present"];
        
    _trigger _this select 0//The trigger that just activated or deactivated
        
    _side _this select 1//The side that caused the (De)-activation
        
    _present _this select 2;  //Whether the side is now present

        
    if (_side == west && _presentthen {
             
    //Blufor is now there
             //Spawn some enemies .....
             //.....??
             //Profit
        
    };
    };

    //Now put it all together, we only care about blufor and guerilla (resistance):
    {
        [
    _x, [westresistance], _handlercall CreateAreaMonitor;
    } forEach 
    _markers
    That will automatically create triggers that manage the marker. Eg. if only blufor is in the area then the marker would go blue. If only guerrilla then green. If both then grey atm, but that can be changed.

  10. #10
    Quote Originally Posted by Muzzleflash View Post
    You can get around having to use global variables by simply storing stuff on the triggers. I made an example where you create a single marker in the editor. The script then creates and sets up the necessary values. There is also a callback functionality to use when the triggers change condition:

    Spoiler:


    That will automatically create triggers that manage the marker. Eg. if only blufor is in the area then the marker would go blue. If only guerrilla then green. If both then grey atm, but that can be changed.

    thank you very much. your example has helped me see a better way to accomplish this. cheers

Similar Threads

  1. Changing fixed face textures and Alpha
    By sevensixtytwo in forum ADDONS & MODS: DISCUSSION
    Replies: 1
    Last Post: Jul 17 2011, 00:08
  2. Local sound clip (Yell) on Radio Alpha
    By Kerry in forum ARMA - MISSION EDITING & SCRIPTING
    Replies: 1
    Last Post: Apr 16 2009, 07:54
  3. Markers not changing pos in MP
    By Rommel in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 6
    Last Post: Jul 23 2006, 07:35
  4. Changing positions of objects/markers
    By Strango in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 3
    Last Post: Jul 9 2003, 22:37
  5. Local server? local someone?
    By Doolittle in forum OFP : MISSION EDITING & SCRIPTING
    Replies: 1
    Last Post: Nov 2 2002, 02:12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •