IndeedPete 1038 Posted July 12, 2013 Hello folks, i'm having a small problem with counting via script created units. I want to call the script below via: IP_WAVE = compile (preprocessFileLineNumbers "scripts\wave.sqf"); _c = [_countMenGroups, _countVehicleGroups, _menSpawnPoints, _vehicleSpawnPoints, _side, _target, _menCountMin, _menCountMax] call IP_WAVE; But unfortunately in this case it returns "scalar" instead of a number. Also it doesn't seem to work at all sometimes if called with "call". To get it work properly, i use: _c = [_countMenGroups, _countVehicleGroups, _menSpawnPoints, _vehicleSpawnPoints, _side, _target, _menCountMin, _menCountMax] execVM "scripts\wave.sqf"; But this way, i sadly can't catch any return value. Is there another solution or am i missing something? "scripts\wave.sqf": _countMenGroups = _this select 0; _countVehicleGroups = _this select 1; _menSpawnPoints = _this select 2; _vehicleSpawnPoints = _this select 3; _side = _this select 4; // EAST _target = _this select 5; _menCountMin = _this select 6; _menCountMax = _this select 7; _unitCount = 0; private ["_countMenGroups", "_vehicleSpawnPoints", "_side", "_target", "_menCountMin", "_menCountMax", "_unitCount"]; for [{_i = 0}, {_i < _countMenGroups}, {_i = _i + 1}] do { _ldr = [(getMarkerPos (_menSpawnPoints call BIS_fnc_selectRandom)), _side, (_menCountMin + round(random (_menCountMax - _menCountMin)))] call IP_MENSPAWN; _grp = group _ldr; _unitCount = _unitCount + (count units _grp); { _x setBehaviour "AWARE"; _x setCombatMode "RED"; } forEach units _grp; _wp = _grp addWaypoint [(getMarkerPos _target), 0]; _wp setWaypointType "SAD"; }; for [{_i = 0}, {_i < _countVehicleGroups}, {_i = _i + 1}] do { _ldr = [(getMarkerPos (_vehicleSpawnPoints call BIS_fnc_selectRandom)), _side] call IP_VEHICLESPAWN; _grp = group _ldr; _unitCount = _unitCount + (count units _grp); { _x setBehaviour "AWARE"; _x setCombatMode "RED"; } forEach units _grp; _wp = _grp addWaypoint [(getMarkerPos _target), 0]; _wp setWaypointType "SAD"; }; //hintSilent format ["%1 %2 %3 %4 %5 %6 %7 %8 %9", _countMenGroups, _countVehicleGroups, _menSpawnPoints, _vehicleSpawnPoints, _side, _target, _menCountMin, _menCountMax, _unitCount]; _unitCount; Thanks in advance! Share this post Link to post Share on other sites
kylania 567 Posted July 12, 2013 Drop the last ; after _unitCount maybe I believe. Return values from functions can not have trailing ;. Share this post Link to post Share on other sites
IndeedPete 1038 Posted July 12, 2013 Thanks, but i already tried that before. No change. Now i am using a temporary solution by counting them via trigger. Not as accurate as counting from source since they can leave/enter the designated area but still enough to calculate when the next wave will be deployed... Still, very annoying script behaviour. Share this post Link to post Share on other sites
mad_cheese 592 Posted July 13, 2013 (edited) since your code returns the unitcount perfectly by just using conventionally spawned units/vehicles I am guessing the problem lies within IP_MENSPAWN, IP_VEHICLESPAWN or both? just a wild guess... Edited July 13, 2013 by Mad_Cheese Share this post Link to post Share on other sites
IndeedPete 1038 Posted July 13, 2013 (edited) Hm, i "stole" these functions from the AI Spawn Script Pack by spunFIN and they seem to work nicely. Menspawn: //ARMA3Alpha function LV_fnc_menGroup v1.2 - by SPUn / lostvar //Spawn infantry group and returns leader private ["_OPFarrays","_BLUarrays","_INDgrp","_INDhq","_INDmen","_OPFmen2","_BLUmen2","_pos","_side","_size","_BLUmen","_OPFmen","_men","_amount","_BLUhq","_BLUgrp","_OPFhq","_OPFgrp","_grp","_i","_man1","_man","_leader"]; _pos = _this select 0; _side = _this select 1; _size = _this select 2; _grpId = if (count _this > 3) then { _this select 3;} else {nil}; _BLUmen = ["B_Soldier_A_F","B_soldier_AR_F","B_medic_F","B_engineer_F","B_soldier_exp_F","B_Soldier_GL_F","B_soldier_M_F","B_soldier_AA_F","B_soldier_AT_F","B_officer_F","B_soldier_repair_F","B_Soldier_F","B_soldier_LAT_F","B_Soldier_lite_F","B_Soldier_SL_F","B_Soldier_TL_F","B_soldier_AAR_F","B_soldier_AAA_F","B_soldier_AAT_F"]; _BLUmen2 = ["B_recon_exp_F","B_recon_JTAC_F","B_recon_M_F","B_recon_medic_F","B_recon_F","B_recon_LAT_F","B_recon_TL_F","B_soldier_AAR_F","B_soldier_AAA_F","B_soldier_AAT_F"]; _BLUarrays = [_BLUmen,_BLUmen2]; _OPFmen = ["O_Soldier_A_F","O_soldier_AR_F","O_medic_F","O_engineer_F","O_soldier_exp_F","O_Soldier_GL_F","O_soldier_M_F","O_soldier_AA_F","O_soldier_AT_F","O_officer_F","O_soldier_repair_F","O_Soldier_F","O_soldier_LAT_F","O_Soldier_lite_F","O_Soldier_SL_F","O_Soldier_TL_F","O_soldier_AAR_F","O_soldier_AAA_F","O_soldier_AAT_F"]; _OPFmen2 = ["O_recon_exp_F","O_recon_JTAC_F","O_recon_M_F","O_recon_medic_F","O_recon_F","O_recon_LAT_F","O_recon_TL_F","O_soldier_AAR_F","O_soldier_AAA_F","O_soldier_AAT_F"]; _OPFarrays = [_OPFmen,_OPFmen2]; _INDmen = ["I_Soldier_A_F","I_soldier_AR_F","I_medic_F","I_engineer_F","I_soldier_exp_F","I_Soldier_GL_F","I_soldier_M_F","I_soldier_AA_F","I_soldier_AT_F","I_officer_F","I_soldier_repair_F","I_Soldier_F","I_soldier_LAT_F","I_Soldier_lite_F","I_Soldier_SL_F","I_Soldier_TL_F","I_soldier_AAR_F","I_soldier_AAA_F","I_soldier_AAT_F"]; _men = []; if(typeName _size == "ARRAY")then{ _amount = ((random (_size select 0)) + (_size select 1)); }else{ _amount = _size; }; switch(_side)do{ case 0:{ _men = (_BLUarrays call BIS_fnc_selectRandom); _BLUhq = createCenter west; _BLUgrp = createGroup west; _grp = _BLUgrp; }; case 1:{ _men = (_OPFarrays call BIS_fnc_selectRandom); _OPFhq = createCenter east; _OPFgrp = createGroup east; _grp = _OPFgrp; }; case 2:{ _men = _INDmen; _INDhq = createCenter resistance; _INDgrp = createGroup resistance; _grp = _INDgrp; }; }; _i = 0; for "_i" from 0 to _amount do { _man1 = _men select (floor(random(count _men))); _man = _grp createUnit [_man1, _pos, [], 0, "NONE"]; }; if(!isNil("_grpId"))then{ call compile format ["LVgroup%1 = _grp",_grpId]; }; _leader = leader _grp; _leader; Vehiclespawn: //ARMA3Alpha function LV_fnc_fullVehicle v1.2 - by SPUn / lostvar //Spawns random vehicle full of random units and returns driver private ["_INDveh","_OPFarrays","_BLUarrays","_INDgrp","_INDhq","_INDmen","_OPFmen2","_BLUmen2","_pos1","_grp","_BLUhq","_BLUgrp","_men","_veh","_OPFhq","_OPFgrp","_man1","_man","_i","_pos","_side","_BLUmen","_OPFmen","_BLUveh","_OPFveh","_veh1","_vehSpots","_vehicle","_vehCrew","_driver"]; _pos = _this select 0; _side = _this select 1; _BLUmen = ["B_Soldier_A_F","B_soldier_AR_F","B_medic_F","B_engineer_F","B_soldier_exp_F","B_Soldier_GL_F","B_soldier_M_F","B_soldier_AA_F","B_soldier_AT_F","B_officer_F","B_soldier_repair_F","B_Soldier_F","B_soldier_LAT_F","B_Soldier_lite_F","B_Soldier_SL_F","B_Soldier_TL_F","B_soldier_AAR_F","B_soldier_AAA_F","B_soldier_AAT_F"]; _BLUmen2 = ["B_recon_exp_F","B_recon_JTAC_F","B_recon_M_F","B_recon_medic_F","B_recon_F","B_recon_LAT_F","B_recon_TL_F","B_soldier_AAR_F","B_soldier_AAA_F","B_soldier_AAT_F"]; _BLUarrays = [_BLUmen,_BLUmen2]; _OPFmen = ["O_Soldier_A_F","O_soldier_AR_F","O_medic_F","O_engineer_F","O_soldier_exp_F","O_Soldier_GL_F","O_soldier_M_F","O_soldier_AA_F","O_soldier_AT_F","O_officer_F","O_soldier_repair_F","O_Soldier_F","O_soldier_LAT_F","O_Soldier_lite_F","O_Soldier_SL_F","O_Soldier_TL_F","O_soldier_AAR_F","O_soldier_AAA_F","O_soldier_AAT_F"]; _OPFmen2 = ["O_recon_exp_F","O_recon_JTAC_F","O_recon_M_F","O_recon_medic_F","O_recon_F","O_recon_LAT_F","O_recon_TL_F","O_soldier_AAR_F","O_soldier_AAA_F","O_soldier_AAT_F"]; _OPFarrays = [_OPFmen,_OPFmen2]; _INDmen = ["I_Soldier_A_F","I_soldier_AR_F","I_medic_F","I_engineer_F","I_soldier_exp_F","I_Soldier_GL_F","I_soldier_M_F","I_soldier_AA_F","I_soldier_AT_F","I_officer_F","I_soldier_repair_F","I_Soldier_F","I_soldier_LAT_F","I_Soldier_lite_F","I_Soldier_SL_F","I_Soldier_TL_F","I_soldier_AAR_F","I_soldier_AAA_F","I_soldier_AAT_F"]; _BLUveh = ["B_MRAP_01_F","B_MRAP_01_hmg_F","B_MRAP_01_gmg_F","B_Quadbike_01_F","B_Truck_01_transport_F","B_Truck_01_covered_F","B_Heli_Light_01_armed_F","B_Heli_Attack_01_F","B_Heli_Transport_01_F","B_Wheeled_01_cannon_F"]; _OPFveh = ["O_MRAP_02_F","O_MRAP_02_gmg_F","O_MRAP_02_hmg_F","O_Quadbike_01_F","O_Truck_02_transport_F","O_Truck_02_covered_F","O_Heli_Attack_02_F","O_Heli_Attack_02_black_F","O_Heli_Light_02_F","O_Wheeled_02_rcws_F"]; _INDveh = ["I_MRAP_03_F","I_MRAP_03_gmg_F","I_MRAP_03_hmg_F","I_Quadbike_01_F","I_Truck_02_transport_F","I_Truck_02_covered_F","I_Heli_Transport_02_F"]; _men = []; _veh = []; switch(_side)do{ case 0:{ _BLUhq = createCenter west; _BLUgrp = createGroup west; _men = (_BLUarrays call BIS_fnc_selectRandom); _veh = _BLUveh; _grp = _BLUgrp; }; case 1:{ _OPFhq = createCenter east; _OPFgrp = createGroup east; _men = (_OPFarrays call BIS_fnc_selectRandom); _veh = _OPFveh; _grp = _OPFgrp; }; case 2:{ _INDhq = createCenter resistance; _INDgrp = createGroup resistance; _men = _INDmen; _veh = _INDveh; _grp = _INDgrp; }; }; _veh1 = _veh select (floor(random(count _veh))); _vehSpots = getNumber (configFile >> "CfgVehicles" >> _veh1 >> "transportSoldier"); _pos1 = _pos findEmptyPosition[1, 300, _veh1]; sleep 0.5; if(count _pos1 == 0)then{_pos1 = _pos;}; if (_veh1 isKindOf "Air")then{ _vehicle = createVehicle [_veh1, _pos1, [], 0, "FLY"]; }else{ _vehicle = createVehicle [_veh1, _pos1, [], 0, "NONE"]; _vehicle setPos _pos1; }; //Yes, there's function to fill crew, but there occured somekind of problem when I tried to //add BLUFOR crew to OPFOR vehicle.. Gotta figure it out some day. if ((_vehicle emptyPositions "driver") != 0) then { _man1 = _men select (floor(random(count _men))); _man = _grp createUnit [_man1, _pos1, [], 0, "NONE"]; _man moveInDriver _vehicle; }; if ((_vehicle emptyPositions "commander") != 0) then { _man1 = _men select (floor(random(count _men))); _man = _grp createUnit [_man1, _pos1, [], 0, "NONE"]; _man moveInCommander _vehicle; }; if ((_vehicle emptyPositions "gunner") != 0) then { while{(_vehicle emptyPositions "gunner") > 0}do{ _man1 = _men select (floor(random(count _men))); _man = _grp createUnit [_man1, _pos1, [], 0, "NONE"]; _man moveInGunner _vehicle; }; }; //Stupid way to make sure vehicle wont flip on it's side at spawn _vehicle allowDamage false; sleep 2; if(((vectorUp _vehicle) select 2) != 0)then{ _vehicle setvectorup [0,0,0]; }; sleep 2; _vehicle allowDamage true; if(_vehSpots > 0)then{ _i = 1; for "_i" from 1 to _vehSpots do { _man1 = _men select (floor(random(count _men))); _man = _grp createUnit [_man1, _pos1, [], 0, "NONE"]; _man moveInCargo _vehicle; }; }; _driver = driver _vehicle; _driver; It's funny, because the unit counter works if i execute "wave.sqf" via execVM, however i cannot pass the calculated value back. If i use call, the "wave.sqf" doesn't seem to work at all. EDIT: Since there are no editor placed OPFOR on the map i chose to count them via: _BLUFORCount = {(side _x) == west} count allUnits; _OPFORCount = {(side _x) == east} count allUnits; Edited July 13, 2013 by IndeedPete Share this post Link to post Share on other sites
mad_cheese 592 Posted July 13, 2013 (edited) Very strange... Works perfectly here, apart from the sleep lines in Vehiclespawn giving me scripterrors that don't seem to effect anything (probably part of the recent "scripterrors that don't effect functionality" - thing). Vehicles do spawn on top of each other sometimes and explode, but leaders/drivers and unitcount are returned correctly. Only sometimes a vehicle doesnt spawn. I tested with some markers in the editor,also fooled with the group and mencount values, no problem: testcount = [2, 1, ["Spawn1","Spawn2"], ["Spawn3","Spawn4"], 0, "targetmark" , 2, 5] call IP_WAVE; player commandchat format ["%1" ,testcount]; testcount is returned as the correct number of spawned units... tricky that "side" has to be a number btw ;) Edited July 13, 2013 by Mad_Cheese Share this post Link to post Share on other sites
IndeedPete 1038 Posted July 14, 2013 Yeah, it's all still in Beta state, so i don't expect everything to run smoothly. With my solution, i am now able to get accurate numbers. Since they are only needed to calculate when the next wave of enemies arrives (e.g. by 20% of actual count) i don't need 100% accuracy. Five more or ten less - doesn't affect the atmosphere. However, my good old system goes down to it's knees when around 100 BLUFOR guys shoot at a spawned helicopter who is playing SAD above my camp but it looks quite awesome... :) Anyway, maybe i just call my waves wrong. If someone cares, i have a "waveController.sqf" which, well... controlls the amount of enemies storming the camp etc. _countMenGroupsMin = 3; _countMenGroupsMax = 5; _countVehicleGroupsMin = 1; _countVehicleGroupsMax = 3; _menSpawnPoints = IP_MENSPAWNPOINTS; _vehicleSpawnPoints = IP_VEHICLESPAWNPOINTS; _side = 1; //EAST _target = "mMaxwell"; _menCountMin = 5; _menCountMax = 10; _iniBLUFORCount = {(side _x) == west} count allUnits; _waveCount = 3; _waveIntensity = 2; _waveIntensityInc = (-0.5); _waveRestRatio = 0.2; private ["_countMenGroupsMin", "_countMenGroupsMax", "_countVehicleGroupsMin", "_countVehicleGroupsMax", "_menSpawnPoints", "_vehicleSpawnPoints", "_side", "_target", "_menCountMin", "_menCountMax", "_iniBLUFORCount", "_waveCount", "_waveIntensity", "_waveIntensityInc", "_waveRestRatio"]; if ((IP_tLittlebirdCompleted)) then {_waveIntensity = _waveIntensity * 0.75}; for [{_i = 0}, {_i < _waveCount}, {_i = _i + 1}] do { _countMenGroups = round (_waveIntensity * (_countMenGroupsMin + random (_countMenGroupsMax - _countMenGroupsMin))); _countVehicleGroups = round (_waveIntensity * (_countVehicleGroupsMin + random (_countVehicleGroupsMax - _countVehicleGroupsMin))); _c = [_countMenGroups, _countVehicleGroups, _menSpawnPoints, _vehicleSpawnPoints, _side, _target, _menCountMin, _menCountMax, 1] execVM "scripts\wave.sqf"; // call IP_WAVE; //_unitCount = _unitCount + _c; _OPFORCount = {(side _x) == east} count allUnits; _iniOPFORCount = _OPFORCount; while {_OPFORCount >= (round(_iniOPFORCount * _waveRestRatio))} do { _BLUFORCount = {(side _x) == west} count allUnits; _OPFORCount = {(side _x) == east} count allUnits; if (_OPFORCount > _iniOPFORCount) then {_iniOPFORCount = _OPFORCount}; if (IP_TESTMODE) then {hintSilent format ["DEBUG\nWave: %1/%2\nBLUFOR: %5/%6\nOPFOR: %3/%4\nNext Wave by: %7 OPFOR", (_i + 1), _waveCount, _OPFORCount, _iniOPFORCount, _BLUFORCount, _iniBLUFORCount, (round(_iniOPFORCount * _waveRestRatio))]}; }; _waveIntensity = _waveIntensity + _waveIntensityInc; saveGame; }; sleep 60; nul = [] execVM "scenes\end.sqf"; Share this post Link to post Share on other sites