Comrades in Arms Discussion Board
End Mission - Printable Version

+- Comrades in Arms Discussion Board (http://forum.ciahome.net)
+-- Forum: Comrades in Arms Life (http://forum.ciahome.net/forumdisplay.php?fid=3)
+--- Forum: Mission Making (http://forum.ciahome.net/forumdisplay.php?fid=8)
+--- Thread: End Mission (/showthread.php?tid=2836)



End Mission - ion - 12-03-2014

hey,

i have some trouble with the ending of my mission. i want the mission end when all alive players reach the extrac.

i tryed this: {_x in thisList} count playableUnits == {alive _x} count playableUnits; with every and repedently in trigger.....but didnt work

i thought about to name all of them and count them with "in this list" but i think it will be problematic if one unit isnt alive.

anybody a safe way how to do it for MP?

thx, ion


Re: End Mission - Alwarren - 12-03-2014


What kind of trigger is it? Here's the thing: thisList contains only the units satisfy the activation field. So, setting the trigger activation to "Anyone" will always return as thisList (or list triggerName) all units that are in the trigger.


Of course, there is another issue. Only the driver of a vehicle is listed. If you have a truck full of people, only the driver will appear in thisList. I use this script for that purpose




FHQ_UnitsInTrigger = {
    /*
    * Returns an array of units that are in a trigger, counting vehicle cargo
    *
    * _this select 0: (Object) Trigger name
    * _this select 1: (Boolean Optional) if true, filter for playable units
    */
    private ["_res", "_trigger", "_filter"];
   
    _trigger = [_this, 0, objNull, [objNull]] call BIS_fnc_param;
    _filter = [_this, 1, false, [false]] call BIS_fnc_param;
   
    _res = [];
    {
        if (!(_x isKindOf "Man")) then {
            private "_veh";
            _veh = vehicle _x;
            { _res set [count _res, _x]; } forEach crew _veh;
        } else {
            _res set [count _res, _x];
        };
    } forEach list _trigger;
   
    if (_filter) then {
        {
            if (!(_x in playableUnits)) then {
                _res set [_forEachIndex, objNull];
            };
        } forEach _res;
        _res = _res - [objNull];       
    };
   
    _res
};


This will go through all units in thisList and check if they are the driver of a vehicle, and if so, add the complete crew and cargo to the list. If the second parameter is true, it removes all non-player units afterwards.


Be aware that this requires a named trigger, and should be called only periodically, or under certain conditions. I usually have an FSM controlling mission flow, and make sure to count these only when the rest of the mission's goals are finished.


Re: End Mission - ion - 12-03-2014

hey,

thx for your reply. its an endtrigger or should it be. i want him to fire if all alive playable units reach the marked position. im realy new in scripting things, so im a little bit confused. on activation i set: "End1" call BIS_fnc_endMission; so i thought the condition should be that all alive players reached the marker which activate the trigger to end the mission.

sry for my stupid questions but if i use your script how do i call the script from the condition? is it possible? or, im confused....

what do you think, is such an ending a stupid idea or am i completly wrong. is there a more safe and easy way for ending a mission?


Re: End Mission - ion - 12-03-2014

what do you think about this: (!alive p1) && (!alive p2)


Re: End Mission - Alwarren - 12-03-2014

(12-03-2014, 10:51 PM)ion link Wrote: thx for your reply. its an endtrigger or should it be. i want him to fire if all alive playable units reach the marked position. im realy new in scripting things, so im a little bit confused. on activation i set: "End1" call BIS_fnc_endMission; so i thought the condition should be that all alive players reached the marker which activate the trigger to end the mission.


The condition is fine, the problem is that thisList doesn't contain what you think. thisList does not contain everything that is in the trigger. It only contains what matches the trigger's activation condition, so you need to make sure that the playable units fit that. "Anybody" will always work, or otherwise use BLUFOR or OPFOR accordingly.

Quote:sry for my stupid questions but if i use your script how do i call the script from the condition? is it possible? or, im confused....


I usually either use it from an FSM, or from a script. At the end of init.sqf, I put something like this..


[] spawn {
    while {true} do {
        sleep 5;
        if (<condition to find out if the other tasks are finished>) then {
            _list = [endTriggerName, true] call FHQ_UnitsInTrigger;
            if (
                {_x in _list} count playableUnits == {alive _x} count playableUnits
            ) then {
                // Set the extraction task to true
                sleep 15;
                ["End1", "BIS_fnc_endMission, true] call BIS_fnc_MP;
            ];
        };
    };
};

Something of that nature, this will probably contain syntax errors. You need to use BIS_fnc_MP since the BIS_fnc_endMission must run on all of the clients.

Quote:what do you think, is such an ending a stupid idea or am i completly wrong. is there a more safe and easy way for ending a mission?


No, this is fine. This should work.


Re: End Mission - Alwarren - 12-03-2014

(12-03-2014, 11:12 PM)ion link Wrote: what do you think about this: (!alive p1) && (!alive p2)


I wouldn't do that. If an admin decides to disable p2, then this might give an undefined variable error. Counting is better.


Re: End Mission - ion - 12-04-2014

thx for your help, i will try it.


Re: End Mission - Alwarren - 12-04-2014

You're welcome Smile


Re: End Mission - ion - 12-05-2014

ok cant get it working. shame on me! put the code at the end of init.sqf and changed the trigger name:

[] spawn {
    while {true} do {
        sleep 5;
        if (<condition to find out if the other tasks are finished>) then {
            _list = ["end", true] call FHQ_UnitsInTrigger;
            if (
                {_x in _list} count playableUnits == {alive _x} count playableUnits
            ) then {
                // Set the extraction task to true
                sleep 15;
                ["End1", "BIS_fnc_endMission, true] call BIS_fnc_MP;
            ];
        };
    };
};

called the trigger "end", setting on bluefor and also tryed anybody. but the trigger will not fire. is there anything i forgot?


Re: End Mission - Alwarren - 12-06-2014



(12-05-2014, 07:48 PM)ion link Wrote:         if (<condition to find out if the other tasks are finished>) then {

You did change that to something else, yes?


Re: End Mission - ion - 12-06-2014

jep....but figured it out hours after the post  ;D . i tryed "task1" && "task2", true...but didnt work. for today i watched a lot of sqf scripting stuff but it seems that i have to learn a lot if i want the mission act like i want it. now its enough for me my heads is smoking.  for the moment i found a solution maybe a little bit complicated but it works. i will test it in mp the next days. thx for your help.....cya on sunday!