Jump to content
Sign in to follow this  
froggyluv

Count Issue

Recommended Posts

So i had a working script that detects when all enemies are dead after a firefight -and for some reason it just doesnt work anymore. Ive even reverted to earlier builds and still no luck. Stranger still is that the code DOES work in the Debug menu calling the Marker.sqf script im after

 

Quote

_count = {side _x == opfor} count allunits; hint  str _count; while {TRUE} do { if (_count < 1) exitWith {0 = execvm "ego\ego\scripts\marker.sqf"}; false };

 

It gives me an invalid number error yet it does reveal the correct number of opfor but will now fire the execvm again unless i use it in the debug

 

:scratchchin:

Share this post


Link to post
Share on other sites

Where are you putting that code? Also, I would recommend adding a sleep in that while loop. I wasn't aware you could use hint + str like that either. I do:

hintSilent format ["%1", _count];

 

Share this post


Link to post
Share on other sites

So its a script that fires after first nearby shots and detects an enemy. The name of the script is Sample.sqf and it does fire as I get the hint but the error is basically like like #count is not a number

Share this post


Link to post
Share on other sites

[] spawn {

  while {TRUE} do {

  _count = {side _x ==east} count allunits;    // or _count  = east countSide allUnits;

   hint  str _count;

   if (_count < 1) exitWith {execvm "ego\ego\scripts\marker.sqf"}

  }

};

  • Thanks 1

Share this post


Link to post
Share on other sites

_count doesn't update in the loop.

 

edit:

Pierre was faster...

Edited by Lucullus
  • Like 1

Share this post


Link to post
Share on other sites

Where do you call the script from? If you are using that code in the debug console then you'll need to use spawn command with it. As pierremgi has shown above.

Share this post


Link to post
Share on other sites

The strange thing was it only worked in debug even alongside an error message while it wasnt firing from script. Spawn eh...? *pulls out dusty codebook circa 1942*

 

Thanks again Pierre

Share this post


Link to post
Share on other sites
5 minutes ago, froggyluv said:

The strange thing was it only worked in debug even alongside an error message while it wasnt firing from script. Spawn eh...? *pulls out dusty codebook circa 1942*

 

Thanks again Pierre

How else did you use that code with execVM command? Trigger? Another script file? Was that run client-side, server-side or what? (:

Share this post


Link to post
Share on other sites
1 hour ago, HazJ said:

How else did you use that code with execVM command? Trigger? Another script file? Was that run client-side, server-side or what? (:

 

 OK man here is the original script which is alot of Franken-Code so avert your eyes if your queesy. (this is why im trying to understand now every mechanism i implement rather than see something similar and assimilate). Its down at the end. This is Sample.sqf called from Info.sqf which detects if enemy is firing. Basically this script was to oversee when the battle starts/ends and once it detects no enemies it fires Marker.sqf which names the fight gives perks etc. There is some nasty repitition of scripts called multiple times etc thats just for testing purposes.

 

Also I can barely get this girl up for SP so no sorry, not for MP...yet...
 

 

 

Quote

 

hint "sample working!";
nul = execvm"\ego\ego\scripts\Pause.sqf";

if (Frog_Sample) exitWith {};
sleep 3;
Frog_Panic = True;

Frog_rank = [];
_rank = rank player;
_myGroup = group player;  

_myNearestEnemy = (units _myGroup select 0) findNearestEnemy player;
if (_rank == "Private") then {
/*playSound "HP_Private";*/ Frog_rank = "HP_Private"
};

if (_rank == "Corporal")  then {
/* playSound "HP_Corporal"; */ Frog_rank = "HP_Corporal"
};

if (_rank == "Sergeant") then  {
/* playSound "HP_Sargent"; */ Frog_rank = "HP_Sargent"
};

if (_rank == "Lieutenant")  then {
/* playSound "HP_Lieutenent"; */ Frog_rank = "HP_Lieutenent"
};

if (_rank == "Captain")   then {

_countE = count list _bz;
 
hint str format ["%1 %2 Units", _countE, _sideEnemy];
sleep 1;
missionNameSpace setvariable ["aliveE",_countE];

/* playSound "HP_Captain"; */ Frog_rank = "HP_Captain"
};

if (_rank == "Major")  then {
/* playSound "HP_Major";  */Frog_rank = "HP_Major"
};

 
/* private _lcs = [];
{    private _lct = _forEachIndex;
    {    _lcs pushBack [text _x, _lct, locationPosition _x, direction _x, size _x, rectangular _x];
    } forEach nearestLocations [getArray (configFile >> "CfgWorlds" >> worldName >> "centerPosition"), [_x], worldSize];    
} forEach ["NameLocal","NameVillage", "NameCity", "NameCityCapital"];  */

sleep 1;
/* _loc = text (nearestLocations [ position player, ["Airport", "NameLocal", "NameVillage", "NameCity"],1000] select random 4);
hintc format ["The Battle of %1 has begun", _loc]; */
battleStarted = true;

/* missionNamespace setVariable ["cBattle",_loc]; */
sleep 3;
_searchRadius = 300;
_playerPos = getPos player;
_nearE = player findNearestEnemy player;
_nearTargets = _playerPos nearEntities [["CAManBase", "Car", "Tank"], _searchRadius];
_sideEnemy = side _nearE;
_sideP = side player;

_bz = createTrigger ["EmptyDetector", getPos player];
_bz setTriggerArea [300, 300, 0, false];
_bz setTriggerTimeout [5, 10, 7, false];

if (_sideEnemy == East) then {Hint "setting trigger east";
_bz setTriggerActivation ["East", " PRESENT", false];
} else {};

if (_sideEnemy == Resistance) then {Hintc "setting trigger Guerilla";
_bz setTriggerActivation ["Guer", " PRESENT", false];
} else {};

if (_sideEnemy == West) then {
_bz setTriggerActivation ["West", " PRESENT", false];
} else {};

_bz setTriggerStatements ["this", "",""];
hintc format ["Side = %1", _bz];
waituntil {count list _bz > 0};

_bzw = createTrigger ["EmptyDetector", getPos player];

_bzw setTriggerArea [300, 300, 0, false];

if (_sideP == East) then {
_bzw setTriggerActivation ["East", " PRESENT", false];
} else {};

if (_sideP == independent) then {
_bzw setTriggerActivation ["Guer", " PRESENT", false];
} else {};

if (_sideP == west) then {
_bzw setTriggerActivation ["West", " PRESENT", false];
} else {};

//_bzw setTriggerActivation ["west", " PRESENT", true];

_bzw setTriggerStatements ["this", "",""];

waituntil {count list _bzw > 0};

_countW = count list _bzw;
 
//systemchat ["%1 %2 Units", _countW, _sideP];

_ratio = _countE/_countW;

_fight1 = ["Tough","Challenging","Brutal","Uphill","Difficult","Exhausting","Demanding","Complex"] call bis_fnc_selectRandom;
_fight2 = ["Fair","Even","Easy","Basic","Simple","Straightforward","Light"] call bis_fnc_selectRandom;
_fighttype = ["battle","engagement","fight","contact","assault","encounter","skirmish"] call bis_fnc_selectRandom;
 if (_ratio >= 1.5) then {
 player sidechat format ["%2 %3 at a ratio of %1 to 1", _ratio, _fight1, _fighttype];
 } else {
 player sidechat format ["%2 %3 at a ratio of %1 to 1", _ratio, _fight2, _fighttype];
 };

missionNameSpace setVariable ["CombatBonus", _ratio];

 _myNearestEnemy = player findNearestEnemy player;
 if ((typeOf _nearE  in Frog_ReconEast) && (_countE >=1))  then { playsound Frog_rank; sleep 1; playSound "HP_SpecOps";_pos = getPos _nearE; _markertxt = format ["Spec Ops?" ];
_markerstr = createMarker ["PLP ASSET Special Forces",_pos];
_markerstr setMarkerShape "ICON";
_markerstr setMarkerType "plp_mark_as_specialforces";
_markerstr setMarkerSize [0.9,0.9];
_markerstr setMarkerColor "ColorRed";
_markerstr setMarkerText _markertxt};

if ((typeOf _nearE  in Frog_SniperEast) && (_countE >=1)) then { playSound Frog_rank; sleep 1; playSound "PossSniper";_pos = getPos _nearE;  _markertxt = format ["Sniper?"];
_markerstr = createMarker ["plp_mark_as_sniperrifle",_pos];
_markerstr setMarkerShape "ICON";
_markerstr setMarkerType "plp_mark_as_sniperrifle";
_markerstr setMarkerSize [0.9,0.9];

_markerstr setMarkerColor "ColorRed";
_markerstr setMarkerText _markertxt};

if ((typeOf _nearE  in Frog_Agent) && (_countE >=1)) then {playSound Frog_rank; sleep 1; playSound "PossSniper";_pos = getPos _nearE;  _markertxt = format ["Agent"];
_markerstr = createMarker ["plp_mark_as_voltage",_pos];
_markerstr setMarkerShape "ICON";
_markerstr setMarkerType "plp_mark_as_voltage";
_markerstr setMarkerSize [0.9,0.9];

_markerstr setMarkerColor "ColorRed";
_markerstr setMarkerText _markertxt};

_bzC = createTrigger ["EmptyDetector", getPos player];
_bzC setTriggerArea [300, 300, 0, false];
_bzC setTriggerTimeout [5, 10, 7, false];

if (_sideEnemy == East) then {
_bzC setTriggerActivation ["East", "not PRESENT", false];
} else {};

if (_sideEnemy == Independent) then {
_bzC setTriggerActivation ["Guer", "not PRESENT", false];
} else {};

if (_sideEnemy == West) then {
_bzC setTriggerActivation ["West", "not PRESENT", false];
} else {};

_bzC setTriggerActivation ["east", "not PRESENT", false];

if (Brute > 100) then {hintc "Town is in a total panic!"} ;
waituntil {count list _bzC < 1};

_countE = count list _bz;
_bzC setTriggerStatements ["this", "[] execvm 'ego\EGO\scripts\marker.sqf';",""];

_trg = createTrigger ["EmptyDetector", getPos player];
_trg setTriggerArea [300, 300, 0, false];
_trg setTriggerActivation ["East", "Not PRESENT", True];
_trg setTriggerStatements ["this", "[] execvm 'ego\EGO\scripts\marker.sqf';", ""];

 

Quote

 

 

Share this post


Link to post
Share on other sites

You can already optimize each poor if then {code} else {} suite!

As far as you have a grouped conditions (like for each sides) you can:

- switch variable do (I don't like that but it works),

 

- or more versatile with conditions:

call {

  if (first probable cond) exitWith { code 1};

  if (second probable cond) exitWith { code 2};

  default code in any case

};

 

This way, you are faster because your code skip other occurrences when a condition is met. (So, always mind for the best occurrence first).

Don't forget the call {  } which makes sense with exitWith here.

 

In all cases :  if then {code} else {}; doesn't mean something. This "else {}" is often encountered in (poor) scripts, but it's absolutely useless.

 

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×