AdmiralKarlDonuts 0 Posted May 2, 2004 Hi all, I was wondering if anybody knew of a script I could use to remove units too far away for the player to see in a single player mission. The idea is that you put all the units you want in the editor and the script will remove them if they're too far away and replace them when you get closer. Â Hopefully this will cut down lag because I want to not only have enemy troops but civvies running around all over Malden. Â I saw one over at OFPEC that claimed to do this ("trigger enemy spawn" by Dootlittle), but it came with no documentation whatsoever and obviously that doesn't help at all. Anybody have any ideas? Â I'm in no way capable of writing one myself, so.....help me out here guys Share this post Link to post Share on other sites
bn880 5 Posted May 3, 2004 My advice is figure out the one by Doolittle, there is also some thread or two out here about his replacement scripts. I have created a system named EnemyStack at CoC but it functions differently than what you need. AFAIK one of Doolittles scripts does just what you are looking for. Share this post Link to post Share on other sites
@cero 0 Posted May 3, 2004 If you open the script with notepad, can you post it in here to have a look? we may be able to work out how it works then. All you have to do is copy it and then paste it in here. I work out a cuple of scripts like that before. @CERO. Share this post Link to post Share on other sites
-=BT=- Matty R 0 Posted May 3, 2004 Well there is a lot of scripts but here they are anyways... -captive Quote[/b] ]?not alive _this : exit?damage _this < 0.75 : exit ?vehicle _this != _this : exit ?random 1 < 0.3 : exit _this removeAllEventHandlers "Hit" _this setCaptive true _this switchMove "FXStandSurDown" _this removeAllEventHandlers "Killed" _this addEventHandler ["Killed", {_this select 0 switchMove "FXStandSurDead"; _this exec "killed.sqs"}] -delete Quote[/b] ]~1_this setPos [0, 0, 0] deleteVehicle _this -Init Quote[/b] ]requiredVersion "1.91"unitcreate = loadFile "unitcreate.sqf" -Killed Quote[/b] ]?not local Server : exit_obj = _this select 0 ~300 _obj removeAllEventHandlers "Killed" _obj setPos [0, 0, 0] deleteVehicle _obj -Mg Quote[/b] ]#gunner~10 ?not canFire _this : exit ?not isNull gunner _this : goto "gunner" _obj = nearestObject [getPos _this, "SoldierEG"] ?alive _obj : goto "assign" _obj = nearestObject [getPos _this, "SoldierESaboteurPipe"] ?alive _obj : goto "assign" _obj = nearestObject [getPos _this, "SoldierEMG"] ?alive _obj : goto "assign" _obj = nearestObject [getPos _this, "SoldierELAW"] ?alive _obj : goto "assign" goto "gunner" #assign _obj assignAsGunner _this [_obj] orderGetIn true goto "gunner" -Units Quote[/b] ]?not local Server : exit~1 _list = _this select 0 _trigger = _this select 1 _vehicletype = [] _crewtype = [] _pos = [] _group = [] _i = 0 #load _obj = _list select _i _vehicletype = _vehicletype + [typeOf vehicle _obj] _crew = [] "_crew = _crew + [typeOf _x]" forEach crew _obj _crewtype = _crewtype + [_crew] _pos = _pos + [[getPos _obj select 0, getPos _obj select 1, 0]] _group = _group + [group _obj] "_x exec ""delete.sqs""" forEach crew _obj vehicle _obj exec "delete.sqs" _i = _i + 1 ?_i < count _list : goto "load" _count = count list _trigger #empty ~2 ?count list _trigger == _count : goto "empty" _i = 0 #create _vtype = _vehicletype select _i _ctype = _crewtype select _i ?_vtype == _ctype select 0 : [_vtype, _pos select _i, _group select _i] call unitcreate; goto "next" _vehicle = _vtype createVehicle (_pos select _i) _vehicle addEventHandler ["Killed", {_this exec "killed.sqs"}] ?_vtype == "ParachuteEast" : _vehicle setPos [getPos _vehicle select 0, getPos _vehicle select 1, 135] ~0.1 _j = 0 #move _unit = [_ctype select _j, _pos select _i, _group select _i] call unitcreate ?isNull _unit : goto "next" ?_vtype == "M2StaticMG" or _vtype == "M2StaticMGE" : _vehicle exec "mg.sqs"; _unit moveInGunner _vehicle; goto "next" ?_j == 0 : _unit moveInDriver _vehicle; goto "continue" ?_j == 1 and (_ctype select _j == "SoldierECrew" or _ctype select _j == "SoldierEPilot") : _unit moveInGunner _vehicle; goto "continue" ?_j == 2 and _ctype select _j == "SoldierECrew" : _unit moveInCommander _vehicle; goto "continue" _unit moveInCargo _vehicle #continue _j = _j + 1 ?_j < count _ctype : goto "move" #next ~0.1 _i = _i + 1 ?_i < count _vehicletype : goto "create" Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted May 3, 2004 [snip] just taking up space... Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted May 3, 2004 Heh d'oh! But you forgot the unitcreate function Share this post Link to post Share on other sites
@cero 0 Posted May 3, 2004 Thanks SEAL84, that's more than I can do right now @CERO. Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted May 3, 2004 Heh heh, everyone was thinking "we'll hold his hand and walk him through the script," and then I slammed that down and everyone goes "holy crap, I'm not touching that!" Share this post Link to post Share on other sites
-=BT=- Matty R 0 Posted May 4, 2004 hmm its easy to use though Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted May 4, 2004 Well, I'm messing around with this and trimming the fat myself, so....it looks like I might be okay after all. So much of this is specific to his demo mission (parachutes, custom loadouts, eye-candy surrending and sitting down animations) - it would have been nice to get the bare-bones scripts and add to them if need be instead of having to rip out whole parts because I don't need them Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted May 5, 2004 Okay well I think I've got the creation part down to the point where I can implement it, but I've realized that this only works one way - it deletes initially, re-creates when you get close, and that's that. Â There seems to be no way to delete again if you move too far away, re-re-create, etc. Here's what I've pared it down to: init.sqs - going to check if this really needs to be in the init file. Quote[/b] ]requiredVersion "1.91"unitcreate = loadFile "unitcreate.sqf" the slimmed-down unitcreate.sqf... Quote[/b] ]private ["_type", "_pos", "_group", "_magazine", "_weapon"];_type = _this select 0; _pos = _this select 1; _group = _this select 2; unit = objNull; _type createUnit [_pos, _group, "unit = this", 0.35, "MAJOR"]; if (_type != "SoldierECrew") then { unit setBehaviour "SAFE"; }; unit setCombatMode "RED"; unit setSpeedMode "LIMITED"; if (random 1 < 0.3) then { unit setFormation "COLUMN"; }; unit units.sqs - this is what's executed by the pair of triggers (one covering the units you want deleted, one detecting when you're close enough). Â I still need to sift through this and yank some of the superflous parts. Quote[/b] ]?not local Server : exit~1 _list = _this select 0 _trigger = _this select 1 _vehicletype = [] _crewtype = [] _pos = [] _group = [] _i = 0 #load _obj = _list select _i _vehicletype = _vehicletype + [typeOf vehicle _obj] _crew = [] "_crew = _crew + [typeOf _x]" forEach crew _obj _crewtype = _crewtype + [_crew] _pos = _pos + [[getPos _obj select 0, getPos _obj select 1, 0]] _group = _group + [group _obj] "_x exec ""delete.sqs""" forEach crew _obj vehicle _obj exec "delete.sqs" _i = _i + 1 ?_i < count _list : goto "load" _count = count list _trigger #empty ~2 ?count list _trigger == _count : goto "empty" _i = 0 #create _vtype = _vehicletype select _i _ctype = _crewtype select _i ?_vtype == _ctype select 0 : [_vtype, _pos select _i, _group select _i] call unitcreate; goto "next" _vehicle = _vtype createVehicle (_pos select _i) ~0.1 _j = 0 #move _unit = [_ctype select _j, _pos select _i, _group select _i] call unitcreate ?isNull _unit : goto "next" ?_vtype == "M2StaticMG" or _vtype == "M2StaticMGE" : _vehicle exec "mg.sqs"; _unit moveInGunner _vehicle; goto "next" ?_j == 0 : _unit moveInDriver _vehicle; goto "continue" ?_j == 1 and (_ctype select _j == "SoldierECrew" or _ctype select _j == "SoldierEPilot") : _unit moveInGunner _vehicle; goto "continue" ?_j == 2 and _ctype select _j == "SoldierECrew" : _unit moveInCommander _vehicle; goto "continue" _unit moveInCargo _vehicle #continue _j = _j + 1 ?_j < count _ctype : goto "move" #next ~0.1 _i = _i + 1 ?_i < count _vehicletype : goto "create" and the grand finale, delete.sqs Quote[/b] ]~1deleteVehicle _this Anyway, I've tried to rig this up to work repeatedly - no dice so far. Â Setting the default triggers to "repeatedly" and adding another pair seems to delete them, re-create them, and promptly delete them again. Does anyone see a way to make this delete them when the player moves AWAY? Not necessarily in the script itself, but maybe another snippet/trigger combo I can throw in to match up with what's already here. As it stands it's just going to keep adding more units, and by the end of the mission things are going to be just as laggy as they would be without the script I'll keep working on it but if anyone has any suggestions, I'm definitely open to them Share this post Link to post Share on other sites
ThruYerStErNuM 0 Posted May 5, 2004 Edit: i originally posted an older version that might have acted funny, this one should be good though I could probably give some help here. I made a script that will delete units of a certain side, given that they are not near units of the other side, automatically recreate them as necessary, and continue the process, you just execute it for each group. The great and complex thing about my script, is that it will remember the unit type, the units vehicles, the position of the unit in the vehicle, and even the skill of the unit. It works by removing all but the leader, who will continue to move around his waypoints, and if he is in a vehicle, his crew wont be deleted either. And also, rather than removing them, it makes temporary units in their place, so that when you want to detect the presence of men using count list trigger or something like that, you'll still get the correct number. So I made this to work in every situation, but it's fairly complex, and requires supporting scripts, one addon for the temporary man type, and also 2 triggers to detect all the east and west on the map, although most dynamic missions have something like these triggers already. to get it to work, every east group you want to be autodeleted must have this executed: [group to autodelete, distance from west side at which it will be autodeteled] exec "server\tempdeath.sqs" well the tempdeath is in my server folder in the mission directory, it might not need to be. In the init.sqs script, put this <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> tempdead = [] invisibleunits = [] emptytype = "uwar_empty" Here is tempdeath.sqs, execute for each east group <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ; single player only? _group = _this select 0 ;_mindist = 250 - vietnam default ;_mindist = _this select 1 * (viewdistance/1000) - open areas _mindist = _this select 1 ?!(_mindist > 0): _mindist = 250 ; you might want to remove this line ?_mindist > viewdistance: _mindist = viewdistance _deletedunits = [] _nobj = "<NULL-object>" _null = "scalar bool array string 0xfcffffef" ; dont go to "exit" because the group will be removed when it shouldnt ?_group in tempdead: exit tempdead = tempdead + [_group] #begin ;maybe later add check for existance of all units, rather than wait assuming time will add them ~8 + random 5 _firstunits = units _group _firstcount = count _firstunits ?_firstcount < 1: goto "exit" #l _tempdeath = false _tim = time + 30 #lead ~1 ?_tim < time: goto "exit" _leader = leader _group ?!(alive _leader)||format["%1",(typeof vehicle _leader)] == emptytype: _leader = (units _group) select 0 ?!(alive _leader)||format["%1",(typeof vehicle _leader)] == emptytype: goto "lead" _count = count units _group ?_count > 1: goto "checkfordelete" ?_firstcount < 1: goto "exit" ~7 goto "l" #checkfordelete _west = [(getpos _leader),_mindist] call loadfile "func\westtrig.sqf" ?count _west > 0: goto "l" ;minimize now ?!(count units _group > 1): goto "begin" _deletedunits = units _group - [_leader] _infoarray = [] ;_vpos = 0 - no vehicle, 1 - driver, 2 - gunner, 3 - commander, 4 - cargo ---- dang this is all one line {_vpos = 0; if(_leader in (vehicle _x)) then {_deletedunits = _deletedunits - [_x]} else {if ((typeof vehicle _x) == (typeof _x)) then {_vpos = 0} else {if (_x == driver vehicle _x) then {_vpos = 1} else {if (_x == gunner vehicle _x) then {_vpos = 2} else {if (_x == commander vehicle _x) then {_vpos = 3} else {_vpos = 4}}}}; _infoarray = _infoarray + [[typeof _x, skill _x, "private", typeof vehicle _x, _vpos]]}} foreach _deletedunits invisibleunits = invisibleunits + _deletedunits {deletevehicle vehicle _x; deletevehicle _x} foreach _deletedunits _dels = [] {emptytype createunit [getpos leader _group,_group,{tdel = this; this disableai "move";this disableai "target";this disableai "autotarget"}];_dels=_dels+[tdel];[tdel] exec "keeptolead.sqs"} foreach _deletedunits _tempdeath = true _cam = "camera" camCreate getpos leader _group ~5 #minimized _tim = time + 60 #getleader ~1 ?_tim < time: goto "exit" _leader = leader _group ?!(alive _leader)||format["%1",(typeof vehicle _leader)] == emptytype: _leader = (units _group) select 0 ?!(alive _leader)||format["%1",(typeof vehicle _leader)] == emptytype: goto "getleader" ?count (units _group)<1: goto "exit" ?(vehicle _leader) != _leader: goto "exit" _count = count units _group ;player sidechat format["leader alive status: %1",_leader] ;player sidechat format["count of units in group is: %1",_count] ;?!(alive _leader): goto "restart" ;rather than these screwey scripts, just keep trying to remove men until just one, and ; put a killed eventhandler on that guy you know has to be there. also keep his health full ;?_count != 1:player sidechat format["recreating, units are %1",units _group]; goto "restart" _west = [(getpos _leader),_mindist] call loadfile "func\westtrig.sqf" ?count _west > 0: goto "restart" ~10 goto "minimized" #restart ;reinitialize all minimized ; this should never happen ?!_tempdeath: goto "begin" ;?dev:player sidechat "UN MINIMIZING" "deletevehicle _x" foreach _dels _x = -1 _c = count _infoarray _newvehs = [] ?!(_c>(-1)):_c = 0 #l2 _x = _x + 1 ?_x >= _c: goto "return" _current = _infoarray select _x _ipos = getpos leader _group _rnd = 15 - random 30 _pos = [_ipos select 0, (_ipos select 1) + _rnd] (_current select 0) createunit [_pos,_group,{uwar_man = this},(_current select 1),(_current select 2)] _man = uwar_man ?_current select 4 == 0: goto "vdon" _n = -1 _w = 0 #vpick ;player sidechat format["stuck in vpick, vpos is %1", _current select 4] _n = _n + 1 ;add random position variation later for newly created vehicles ?_n >= count _newvehs: _v = (_current select 3) createvehicle getpos leader _group; _newvehs = _newvehs + [_v]; _w = _w + .3 ~_w ; oh so ugly but it keeps the gamestoppers away - 3 strikes to put him in a new vehicle, then forget him ?_w > .8: goto "vdon" ?typeof (_newvehs select _n) != _current select 3:goto "vpick" ?(_current select 4 == 1) && ((format["%1",(driver (_newvehs select _n))] == _nobj)||(format["%1",(driver (_newvehs select _n))] == _null)): _man moveindriver _v; goto "vdon" ?(_current select 4 == 2) && ((format["%1",(gunner (_newvehs select _n))] == _nobj)||(format["%1",(gunner (_newvehs select _n))] == _null)): _man moveingunner _v; goto "vdon" ?(_current select 4 == 3) && ((format["%1",(commander (_newvehs select _n))] == _nobj)||(format["%1",(commander (_newvehs select _n))] == _null)): _man moveincommander _v; goto "vdon" ?(_current select 4 == 4): _man moveincargo _v ; if he is supposed to be put in cargo, and hasnt been, then we ASSUME the vehicle has no more cargo space ?_man in _v: goto "vdon" ;could there be a few bugs occuring that cause extra vehicles to be randomly left over, some maybe even occupied? goto "vpick" #vdon ~.1 goto "l2" #return invisibleunits = invisibleunits - _deletedunits _tempdeath = false ;player sidechat "UNMinimized" goto "l" #exit ;player sidechat "exiting tempdeath" invisibleunits = invisibleunits - _deletedunits tempdead = tempdead - [_group] _x = 0 #deleteempty ~.1 _c = count units _group ?_x>=_c:exit ?format["%1",(units _group) select _x]==emptytype: deletevehicle ((units _group) select _x); goto "deleteempty" _x = _x + 1 goto "deleteempty" The unit: uwar_empty, is just an addon with this in the config.cpp <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> class CfgPatches { class uwar_vietnam { units[] = {uwar_empty}; } } class CfgVehicles { class All {}; class AllVehicles:All{}; class Land:AllVehicles{}; class Man:Land{}; class Soldier:Man{}; class uwar_empty: Soldier { displayName="ghost"; nameSound=""; scope=3; vehicleClass="uwar_Objects"; simulation="soldier"; side=3; icon="vlajka"; model="empty"; picture="iaston"; wounds[]={}; moves="CfgMovesMC"; } } contents of keeptolead.sqs in mission directory <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _l = _this select 0 #l ?!(alive _l): exit _a = getpos (leader (group _l)) _l setpos [_a select 0, _a select 1, (_a select 2) + 5000] ~10 goto "l" contents of func\westtrig.sqf: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> comment { Serves as artificial detect west trigger that returns all west within it. Can only be circular. Useage: [Center of trigger, Radius of trigger] call loadfile "func\westtrig.sqf" requires function "func\getdistance.sqf" and west detecting trigger within game called trig_west that covers all units }; private ["_center","_radius", "_array"]; _center = _this select 0; _radius = _this select 1; _array = []; {if (([getpos _x select 0, getpos _x select 1, _center select 0, _center select 1] call loadfile "func\getdistance.sqf") < _radius) then {_array = _array + [_x]}} foreach (list trig_west); _array contents of func\easttrig.sqf: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> comment { Serves as artificial detect east trigger that returns all east within it. Can only be circular. Useage: [Center of trigger, Radius of trigger] call loadfile "func\easttrig.sqf" requires function "func\getdistance.sqf" and east detecting trigger within game called trig_east that covers all units } private ["_center","_radius", "_array"]; _center = _this select 0; _radius = _this select 1; _array = []; {if (([getpos _x select 0, getpos _x select 1, _center select 0, _center select 1] call loadfile "func\getdistance.sqf") < _radius) then {_array = _array + [_x]}} foreach (list trig_east); _array contents of func\getdistance.sqf Quote[/b] ]comment { gets distance between 2 coordinates, in xy only }; private ["_x", "_y", "_x2", "_y2", "_c"]; _x = _this select 0; _y = _this select 1; _x2 = _this select 2; _y2 = _this select 3; _x = _x2 - _x; _y = _y2 - _y; _c = sqrt((_x*_x) + (_y*_y)); _c I think thats it I am posting partly because i too want help with this. The ai is heavily disabled by using this temp man system, and my objective was to completely remove the ai, to lessen the load on the processor, but there still is a large load when you got lots of guys "temp deleted". looks like lots of numbers up there could be tweaked, and optimizations done, obviously i'm very sloppy and working alone. I mainly want to know if i can improve that addon config to make it less of a man, so to speak, so that it will take even less processor for each guy. For me, this script works like silk for the most part though in all my crazy missions. This brings back memories... but hope it can help someone, if its too much for the average mission maker. Of course this could be easily modified to only require that the group not be near the player, rather than not being near the other side. Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted May 5, 2004 Cool, I'll give it a shot. Thx man. Share this post Link to post Share on other sites