knowsAbout TriggerList

ArmA 2 editing; configs, modeling, missions, textures, terrain etc.

Moderators: Lone Wolf, Snake Man

Snake Man
Commander-In-Chief
Posts: 9351
Joined: 2000-07-31 22:01:01
Gaming Interests: ArmA, ArmA 2, Falcon 4.0 and OFP.
Editing Interests: All, I (try) to edit everything.
Location: PMC

knowsAbout TriggerList

Post by Snake Man » 2009-07-05 09:51:32

I had a mission where player has to recon Chernarus airbase, its covered with large trigger so that with even 2400m viewdistance you cant really see all the units in the trigger area once. So I needed to have players knowsAbout value of these units more than 0 and check when this is true. It needed a script.

So what I did was place OPFOR present trigger, make it run repeatedly, name it "pmc_opfor_list".

Then launch our script, call it recon.sqf which looks like this:

Code: Select all

/*

    Player knows about all units in specific trigger, simultaneously
    or one by one over time.

*/
private
[
    "_l",
    "_t"
];

// small delay so the trigger will initiate
sleep 3;

// our list of units at the mission start
_l = list pmc_opfor_list;
// _t array is the units at mission start (some may board vehicles etc).
_t = _l;

// loop until we know, or have known/seen each and every one of them
while {count _t > 0} do
{
    // no point of making it cpu intensive
    sleep 2;
    // just debug for monitoring
    hint format["pmc_opfor_list: %1\n\n_t: %2", list pmc_opfor_list, _t];
    /*
    this checks if player knows anyone in the pmc_opfor_list trigger.
    if he does, that unit will be deducted from the _t array.
    the main while loop will then exit when _t array reaches 0, ie empty.
    */
    {
        /*
        the 0 value can be adjusted, zero is the basic essential
        detection, its very relaxed.
        */        
        if (player knowsAbout _x > 0) then
        {
            _t = _t - [_x];
        };
    } count _t;
};

// we know all of the units, exiting from the script.
player sidechat "Congratulations, I now know each and every unit in pmc_opfor_list!";
 
Basically what it does is creates local/temp array of all the units on the opfor trigger at the time the script was launched, then it starts to loop with 2 sec sleep (no cpu hogging) cycles and checks if player knows any of the units in the temporary array. When player knows about a unit, the unit will be removed from the temporary array. The loop ends when player has knowsabout value more than 0 on each and every one of the units listed in array, in any point in time, he doesn't have to detect them all at once, thats the main point of the script.

I posted this here as I have had to look up my script dirs so many time when I've done this exact same type of "check all units in array" thing, that maybe this topic would be more easier to find or someone might help me to improve it a bit etc.

Feel free to post questions or feedback or improvements.
PMC Tactical Forum New User Registration please read new info here.

PMC since 1984

Editing knowledge, visit PMC Editing Wiki
The leading, most detailed and comprehensive modification made for the Vietnam War - Vietnam: The Experience homepage
View our videos in PMC Youtube channel

PMC Tactical forum Advanced Search is power.

"ALPHA BLACK TO PAPA BEAR. ALL RUSSIANS ARE TOAST. OVER."

Who is online

Users browsing this forum: ClaudeBot [Bot] and 0 guests