maturin 12 Posted June 29, 2011 (edited) I am making a large, cinematic mission with my rudimentary scripting skills. All the AI I have running around are consuming a lot of resources, and I have several optimization ideas that I do not know how to implement. Any help you guys can give me with my laundry list of issues will be greatly appreciated. 1) Does having a lot of Present triggers set off by moving units affect performance? Should I try to minimize the number of relatively frivolous area triggers by using waypoint activations instead? 2) One seemingly wasteful use of present triggers is in creating simulated artillery barrages. Once the player steps in a certain area, I spawn a bunch of exploding rockets elsewhere. The problem is, I need the impacts to be staggered. How can I accomplish this with a single trigger? At the moment I use half a dozen with varying Countdown times. 3) Can I delete AI that are no longer needed? I have things like civilians fleeing a town, and once they are out of sight, they serve no purpose. I don't want their AI routines gumming up the works anymore. I could kill them, but I hear that dead AI still take system resources. Can I just make them disappear? 4) Can I disable AI entirely and effectively have statues or zombie-like entities? I have some purely cosmetic soldiers like guards at street corners, and they will never need to fight or move. Can I make it so the engine disregards theme entirely? They don't even need to be spotting anything. I have been setting AI skill to 0 in places, but I suspect this offers a very marginal improvement. 5) To prevent vehicles from rejoining their leader in the distance, I remove their fuel. But they still attempt to start the engine periodically. Is this likely to take up system AI cycles and is there a better way. DoStop and DisableAI "MOVE" do not work. 3 and 4 are probably the more important questions. Edited June 29, 2011 by maturin Share this post Link to post Share on other sites
demonized 20 Posted June 29, 2011 1: not unless you have hundreds. 3: yes, just use deleteVehicle: for example when civilians are x distance away from a marker: { if ((side _x) == civilian AND (_x distance (getMarkerPos "center")) > 1000) then {deleteVehicle _x}; } foreach allUnits; 4: not to a 100%, you can however minimize it. a) unit setskill 0; b) {unit disableAI _x} foreach ["ANIM","MOVE","TARGET","AUTOTARGET"]; 5) removing fuel is usually followed up by an automatic disembark, but i would guess no performance impact of noticable degree. Share this post Link to post Share on other sites
st_dux 26 Posted June 29, 2011 1. That depends on what you mean by "a lot." 2. Create an exterior script file that is called by the trigger and use sleep to create delays between rocket creations. 3. deleteVehicle x, where 'x' is the name of the unit you wish to delete. 4. x enableSimulation false, where 'x' is the name of the unit you wish to disable. 5. I wouldn't worry about it. Share this post Link to post Share on other sites
2nd ranger 282 Posted June 29, 2011 2. If you don't want to use a script for some reason, you can use spawn inside a trigger activation to effectively run a virtual script without the need for an sqf file. This means you can use sleeps. Example (in trigger Act): 0 = [] spawn { some code; sleep 1; morecode;}; Share this post Link to post Share on other sites
maturin 12 Posted June 29, 2011 (edited) Thanks guys. (I'm probably up to 20 triggers soon, only half of which will actually fire in any given playthrough, and they are all one-time, not repeatable.) I assume deleteVehicle can be applied to any object? Edit: Ironically, it doesn't work on vehicles too well. At least not while they are occupied. But putting deleteVehicle on the act. of a Get Out waypoint doesn't work either. And I looked up enableSimulation out of curiosity, and couldn't find it. By the way, is there some way for the default Mines to go off when struck by wheeled vehicles? Edited June 29, 2011 by maturin Share this post Link to post Share on other sites
2nd ranger 282 Posted June 29, 2011 Yeah you can deleteVehicle any object you put in the editor. enableSimulation freezes the unit, makes them a statue as you put it. They won't run any animations if you do this, but curiously they do still call out targets so you're probably better off with what Demonized suggested. Or maybe both, I guess. Share this post Link to post Share on other sites
Gunter Severloh 4071 Posted June 29, 2011 Not sure if this would help you Maturin: cB AI Unit Caching Demo http://www.armaholic.com/page.php?id=10102 Share this post Link to post Share on other sites
demonized 20 Posted June 29, 2011 to delete a vehicle wich has crew (dead or alive) inside it, you need to remove the crew first then delete the vehicle like this: {_x setPos (getPos _vehicle); deleteVehicle _x} foreach crew _vehicle; deleteVehicle _vehicle; Share this post Link to post Share on other sites
f2k sel 164 Posted June 29, 2011 The problem is that there's no easy way to test the speed of things. FPS isn't good as so many random things can effect it. I tried counting in a loop to see how many cycles it would do in ten seconds but again the results were so wild as to be useless. Share this post Link to post Share on other sites
demonized 20 Posted June 30, 2011 The biggest resource hog in any mission is amount of AI and their skill. simply test this by running say 500 AI and check FPS, then run same with alot of triggers or scripts running, youll notice no or very little difference. game engine is automatically limiting scripts running to a certain max amount, so the lag one most of the times see would be the delayed scripts not the laggy AI. ofcourse exessive looping like doing while loops with or without large conditions with no delay would create lag spikes, but that is just poor coding not the game lag. 8 of 10 times its the amount of AI and their skill wich is to blame for most lag. On deletion: a more complete code for deleting units and vehicles of any given side when x distance away from something (can be several positions together, even moving units etc), like a marker, object and unit in my example: if not marker then you can use getPos unitname or simply a position array like [0,0,0]. this will also clean up the empty groups so the 144 group limit, will work during a long mission or many spawn/despawn periods. save this below as a script and run it from init.sqf, or simply add the code to the end of init.sqf. alternatively run it from a trigger or script at a time in the mission, you can also replace the true with anothe variable and turn it on off as needed. it will wait 10 seconds so the mission can get started properly, then it will check every 5 seconds if the civilian or its vehicle is x distance away from position (the marker in this case) and then properly delete units, vehicles and empty groups. The script if (!isServer) exitWith {}; [b]_range = 1000; _sides = [civilian, east];[/b] while {true} do { { if (!isNull _x) then { _veh = vehicle _x; _grp = group _x; if ((side _x) in _sides AND ({(_veh distance _x) < _range} count [b][(getMarkerPos "center"), (getPos objectName), (getPos (vehicle unit2))][/b]) == 0) then { if (_veh isKindof "Man") then { deleteVehicle _x; } else { {_x setPos (getPos _veh); deleteVehicle _x} foreach crew _veh; deleteVehicle _veh; }; if (({alive _x} count units _grp) == 0) then {deleteGroup _grp}; }; }; } foreach allUnits; sleep 5; }; details: range and sides: [b]_range = 1000;[/b] // this is the range in meters the units or vehicles must be away from all the positions. [b]_sides = [civilian, east];[/b] // this is what side of units wich will be deleted, can be 1 or several. positions or objects: // this below is what they need to be more than [b]_range[/b] away from before being deleted, they need to be _range waway for [b]ALL[/b] in this below, can be 1 or several, for example all player units etc... [b][(getMarkerPos "center"), (getPos objectName), (getPos unit2)][/b] // so in the above array the units from east or civilian side must be: // a) 1000m away from (getMarkerPos "center") // b) 1000m away from (getPos objectName) // c) 1000m away from (getPos unit2) // these positions can be updated in mission as well since the script will check their current position at the time the check is made, so it will work for moveable objects etc dynamically. // once a, b, and c is fullfilled, it will be deleted. // you can replace the above array with this to make it so that unit must be x range away from all the playableUnits. [b]playableUnits[/b] // or for all units in a specific group [b](units groupName)[/b] // as long as its an array with either objects or positions it will work. alternative control: place a variable in init.sqf or anywhere, as long as its run before the script starts. replace while {true} with a variable for example while {RunMyDeletes} place before script is run: RunMyDeletes = true; and add this after the sleep 5 line: if (!RunMyDeletes) then {waitUntil {RunMyDeletes}}; now you can play/pause the delete script with setting RunMyDeletes to true/false - play/pause Share this post Link to post Share on other sites
maturin 12 Posted June 30, 2011 to delete a vehicle wich has crew (dead or alive) inside it, you need to remove the crew first then delete the vehicle like this: {_x setPos (getPos _vehicle); deleteVehicle _x} foreach crew _vehicle; deleteVehicle _vehicle; Ooh, that's a big help. But why do we need the setPos getPos part? And what is _x referring to? Because _vehicle is the name of the vehicle, right? Since the players are likely to take certain paths in my mission, I don't think I need a generalized distance deleting script. What I'm hung up on right now is getting a plane to chase a car with Reveal and doMove commands. _plane reveal _target; _plane doTarget _target; _plane doMove _target; Reveal doesn't appear to give full knowsabout value the way spotting with eyes or radar does. Planes won't engage, even with doTarget commands, and won't report the revealed enemy. If given a doMove command, the plane will typically make a dry pass before engaging, but they will lost track of a moving target. Is there a better way to give full knowsabout to a unit? Or some way to make it update in real time as if there was a spotter on the ground. Or could that 'every 5 seconds' language you posted be adapted to reveal a target periodically? Share this post Link to post Share on other sites
demonized 20 Posted June 30, 2011 (edited) _x is a special variable used in the function, it represents each of the things in the array, or units in the array units group. I dont think you can delete a unit while its still inside the vehicle, at least that was how it worked for me when i started scripting and i have sticked by it. just do a test yourself without and see if it works, i think not. reveal and knowsabout values cannot be forced manually. it will give the highest value the giving units side have of target. workaround could be to place a hidden unarmed unit above the target in the air, make it watch target and then reveal after unit has 4 knowsabout to the plane, then remove hidden unit. but as long as plane has only 1 or not clear enemy value, it will act ridiculusly, well since it doesnt really know it ofc. try adding in _plane dowatch _target in your code. also i asume that _plane is the pilot not the plane itself in your code right? Edited June 30, 2011 by Demonized reveal is for side not group, this forum lag is messing up stuff :( Share this post Link to post Share on other sites
maturin 12 Posted June 30, 2011 _x is a special variable used in the function, it represents each of the things in the array, or units in the array units group.I dont think you can delete a unit while its still inside the vehicle, at least that was how it worked for me when i started scripting and i have sticked by it. just do a test yourself without and see if it works, i think not. Oh well, the main thing is I was able to delete a bunch of passengers after they disembarked. workaround could be to place a hidden unarmed unit above the target in the air, make it watch target and then reveal after unit has 4 knowsabout to the plane, then remove hidden unit. Could I place an invisible unarmed spotter to a vehicle using attachTo? try adding in _plane dowatch _target in your code. also i asume that _plane is the pilot not the plane itself in your code right? I've just been referring to the name of the plane unit in triggers. Share this post Link to post Share on other sites
maturin 12 Posted July 1, 2011 Great idea with the spotter. I can place an unarmed unit traveling under the ground beneath the vehicle. The only problem is that the player hears his voice as he calls out to plane. How can I mute a unit? Share this post Link to post Share on other sites