Forum Jump :

Author Message


Posts: 24
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 29
In-game name:

 
#1 Posted at 2016-06-18 05:23        
     
Well I finally decided to seek some advice on why my script works but it doesn't. Everything on it works except when you respawn (group respawn), it decides not to actually remark the already completed objectives. That's why I said it works but doesn't (not fully working anyway). Thanks in advance for any help. If more information on this issue is required, please let me know.

Here's the troublesome script:
if (isDedicated) exitWith {};
private ["_unit"];
_unit = _this select 0;

waitUntil { _unit == player && !isNil "tsk1" && !isNil "tsk2" };

while {true} do {
	if ((tsk1Complete isEqualTo true) && isNil "extractInProgress") then {
		tsk1 setTaskState "Succeeded";
		_unit setCurrentTask tsk2;
		"enemy" setMarkerColor "ColorGreen";
		extractInProgress = true;
		publicVariable "extractInProgress";
		nul = [(leader grpAlpha)] execVM "extraction.sqf";
	};

	if (tsk2Complete isEqualTo true) then {
		tsk2 setTaskState "Succeeded";
		mission_end = true;
		publicVariable "mission_end";
		if (true) exitWith {};
	};

	if (({alive _x} count units grpAlpha) == 0) then {
		if (tsk1Complete isEqualTo false) then {
			tsk1 setTaskState "Failed";
		};
		if (tsk2Complete isEqualTo false) then {
			tsk2 setTaskState "Failed";
		};
		if (true) exitWith {};
	};

	if (!isNull transporthelo && !alive transporthelo) then {
		if (tsk1Complete isEqualTo false) then {
			tsk1 setTaskState "Failed";
		};
		if (tsk2Complete isEqualTo false) then {
			tsk2 setTaskState "Failed";
		};
		if (!isServer) then {
			["end2", false, 2] call BIS_fnc_endMission;
		};
		if (true) exitWith {};
	};

	if (!alive _unit) exitWith {};

	sleep 1;
};

Philip "5n4k3" Simonson

Author Message


Posts: 9
Rank:


Level: Member

Country: de
Location:
Occupation:
Age:
In-game name: Rallen

 
#2 Posted at 2016-06-18 12:26        
     
Some style recommendations:
  • Instead of private and _this select I would use params ["_unit"], as it creates and sets the variable with the given parameter on its own!
  • Would use isNil {} instead of quotation marks! IMO it highlights code better.
  • taskXComplete isEqualTo true can be replaced either with taskXComplete == true/false (where needed) or just (!)taskXComplete! The variables should be boolean themselves, so a comparison with another bool would be obsolete!
  • exitWith will exit current scope, even an if then, but will still run the main script if it is not used in the main script itself! Would replace the if then with if exitWith where needed and remove the if (true) exitWith

Where do you get your taskXComplete?


Advertisement


Author Message


Posts: 24
Rank:


Level: Member

Country: us
Location: In the dungeon to hell!
Occupation:
Age: 29
In-game name:

 
#3 Posted at 2016-06-18 18:42        
     
I set the variables to true in the mission.sqm (in the eden editor). Also, I initialize the tskXComplete variables inside the init.sqf. The only thing is it works perfect until I die and respawn into someone else in the group.

This code here is what resets the tasks when you die and come back alive.
waitUntil { !isNil {player} };
waitUntil { player == player };

switch (side player) do
{
	case WEST: // BLUFOR briefing here
	{
		player createDiaryRecord ["Diary", ["Situation", "There is a town near you that needs to be exterminated of enemy troops. That is your mission."]];
		player createDiaryRecord ["Diary", ["Intel", "Your mission is to exterminate all OPFOR units in the <marker name='enemy_base'>airbase</marker>. Then go to the <marker name='extraction'>extraction point</marker>."]];

		tsk1 = player createSimpleTask ["Eliminate Insurgents"];
		tsk1 setSimpleTaskDescription ["Eliminate all OPFOR units in the airbase.", "Eliminate Insurgents", "Eliminate Insurgents"];
		tsk1 setTaskState "Assigned";

		tsk2 = player createSimpleTask ["Extraction"];
		tsk2 setSimpleTaskDescription ["Get to the chopper!", "Extraction", "Extraction"];
		tsk2 setTaskState "Created";

		publicVariable "tsk1";
		publicVariable "tsk2";

		player setCurrentTask tsk1;
	};

	case EAST: // OPFOR briefing here
	{
	};

	case RESISTANCE: // RESISTANCE briefing here
	{
	};

	case CIVILIAN: // CIVILIAN briefing here
	{
	};
};

// run this file again when respawning
if (isNil {player getVariable "mk_killedEHadded"}) then {
	player addEventHandler ["killed",
	{
		[] spawn {
			waitUntil { alive player };
			execVM "briefing.sqf";
		};
	}];
	player setVariable ["mk_killedEHadded", true];
};

Here is my init.sqf
PRS_fnc_checkTasks = compile preprocessFile "scripts\checkTasks.sqf";
PRS_fnc_extraction = compile preprocessFile "scripts\extraction.sqf";

execVM "briefing.sqf";

tsk1Complete = false;
tsk2Complete = false;
publicVariable "tsk1Complete";
publicVariable "tsk2Complete";

testVar = 0;
publicVariable "testVar";
transporthelo = objNull;
sad_wp_active = false;
publicVariable "sad_wp_active";

[] execVM "scripts\activePlayers.sqf";

[ap1, 0, ["spawn1","spawn2","spawn3","spawn4","spawn5","spawn6"]] execVM "scripts\randSpawn.sqf";
[["extract1","extract2","extract3"]] execVM "scripts\randExtract.sqf";

[] execVM "scripts\cleanUpWorld.sqf";

EDIT: forgot to include my activePlayers.sqf
T_players = [];
T_trig = createTrigger ["EmptyDetector",getArray(configFile/"CfgWorlds"/worldName/"centerPosition")];
T_trig setTriggerType "NONE";
T_trig setTriggerActivation ["ANY", "PRESENT", true];
T_trig setTriggerArea [30000, 30000, 0, false];
T_trig setTriggerStatements ["this", "", ""];
private ["_ar", "_v"];
while {true} do {
	_ar = [];
	{
		_v = vehicle _x;
		if (_v isKindOf "Man") then {
			if (isPlayer _v) then { _ar = _ar + [_v] };
		} else {
			if (_v isKindOf "AllVehicles") then {
				{ if (isPlayer _x) then { _ar = _ar + [_x] } } forEach (crew _x);
			};
		};
	} forEach (list T_trig);
	T_players = [] + _ar;
	{
		[_x] spawn PRS_fnc_checkTasks; // right here is where I call my checktasks script
	} forEach T_players;
	sleep 5;
};

The only thing left you might need would be the mission.sqm file itself. Hopefully it can be figured out with this but if not let me know.

Philip "5n4k3" Simonson