I have written 2 scripts for the mission that I am making (hope to try and submit to the database later on today, if this update ever finishes), and I would love some feedback on whether they are correct/necessary/optimal. They work as intended as far as I can tell testing on my machine.
So anyway, in the editor I have a bunch of vehicles for the platoon to destroy. In my init.sqf at the end I have:
Code: Select all
//Check the status of the motor_pool objective for this mission.
veh_destroyed = 0;
motorpool = [veh1,veh2,veh3,veh4,veh5,veh6,veh7,veh8,veh9,veh10,veh11,veh12,veh13,veh14,veh15,veh16,veh17,veh18,veh19,veh20,veh21,veh22,veh23,veh24];
[] execVM "ee_check_veh_destroyed.sqf";
// Check if all the remaining playable units are downed to set the loss condition.
all_downed = 0;
[] execVM "ee_check_all_downed.sqf";
ee_check_veh_destroyed.sqf:
Code: Select all
if !(isServer) exitWith {};
while {count motorpool > 0} do
{
{
if !(alive _x) then
{
veh_destroyed = veh_destroyed+1;
motorpool = motorpool - [_x];
}
} foreach motorpool;
sleep 5;
};
Code: Select all
if !(isServer) exitWith {};
while {count playableUnits > 0} do
{
_units = f_var_men_BLU;
{
if !(isPlayer _x) then
{
_units = _units - [_x];
}
} foreach _units;
_unitcount = count _units;
_downedcount = 0;
{
if(_x getVariable ["f_wound_down",false]) then
{
_downedcount = (_downedcount + 1);
}
else {};
} foreach _units;
if (_downedcount == _unitcount ) then { all_downed = 1;} else{};
sleep 3;
};
- 1)Am I using isServer right here? (It should only run on the server right?)
2)Am I checking too often, could it affect performance?
3)Is there a better alternative I am missing?
Thanks!
Eagle_Eye
Bonus Script:
I also wrote a little script called manOP, which can be used to place units from the editor into the 3 main positions of the Observation Posts (the green one with the stairs). It basically goes as manOP[_unit,_post,_position] in the init field, and then places the unit either in the front left/right position looking out of the post, or in the back of the post at the top of the stairs looking behind.
Code: Select all
// Call manOP in a units init box to place them in an OP, either facing forward through the portholes, or at the top of the stairs.
// Function takes 2 required inputs, the unit and the OP which are named in the editor.
_man = _this select 0;
_post = _this select 1;
//check for optional position input, if none there then select "left".
//If a string other than "left","right" or "back" is supplied, then the unit is moved away from the OP
_position = "";
if (count _this > 2) then
{
_position = _this select 2;
}
else
{
_position = "left";
};
_vecx = 0;
_vecy = 0;
//choose the required vector to move the unit. Values determined by brute force and ignorance in the editor.
if (_position == "left") then
{
_vecx = -1.7;
_vecy = -0.13;
}
else
{
if (_position == "right") then
{
_vecx = 1.7;
_vecy = -0.13;
}
else
{
if (_position == "back") then
{
_vecx = 2.6;
_vecy = 2.6;
}
else{_vecx = 10;
_vecy = 10;};
};
};
//get the facing of the post (-90 to convert azimuth to a cartesian angle)
_angle = (getdir _post) - 90;
//rotate the x and y vectors
_ypos = _vecx * sin(_angle) + _vecy * cos(_angle);
_xpos = _vecx * cos(_angle) - _vecy * sin(_angle);
//move the unit to the right position
_man setpos ([_ypos,_xpos,3.5] vectoradd getpos _post);