dayZ NPC (AI) Units / Troops | Add to Server.

axeman

OpenDayZ Rockstar!
After playing on a server where I stumbled across some AI troops roaming the server I thought I would add them to my server. So far reports back have been good, apparently is quite surprising to find random bands of troops roaming the server.

This script will spawn groups of AI NPCs, set random waypoints, tool them up with a random selection of weapon & ammo and then send them on their way, attacking zeds as they go.

This mission script allows you to specify the following:
  • Centre point where troops spawn
  • Radius of waypoint creation (how far troops can travel)
  • Number of waypoints
  • Number of troops created.
Have also created some admin in-game options to spawn groups of three troops and to take 'leadership of them', so they join your player group.. (These are not part of this release, PM me for the code if you are happy with applying and testing code)

init.sqf (in your mission folder)
Code:
if (isServer) then {
    _dayzFactions = [] execVM "Dayz_Factions\init.sqf";
    //diag_log format["Dayz Factions executed: %1",_dayzFactions];
    //Array to pass to .sqf: [[<worldspace>],radius of waypoints (in metres),number of waypoints,number of ai units]
    _aispawn = [[6689.49,2623.59,0],160,8,4] execVM "units\add_unit_server.sqf";//Chernogorsk
    _aispawn = [[7622.51,7912.7,0],5000,20,6] execVM "units\add_unit_server.sqf";//Chernaurs (Whole map)
    _aispawn = [[7625.51,7915.7,0],5000,20,6] execVM "units\add_unit_server.sqf";//Chernaurs (Whole map)
    _aispawn = [[4598.66,10197.7,0],650,12,4] execVM "units\add_unit_server.sqf";//NW Airfield
    _aispawn = [[10447.5,2246.96,0],180,3,3] execVM "units\add_unit_server.sqf";//Electrozavodsk
    _aispawn = [[13253.3,6406.53,0],180,4,3] execVM "units\add_unit_server.sqf";//Solnichniy
};

This is creating 6 groups of troops (one per each line). The array infront of the execVM command consists of the following (in order):

  1. [<worldspace>] (Array of X,Y,Z worldspace coordinates where troops start)
  2. Radius (in metres) that the waypoints are randomly created within. These are the points that the troops run between)
  3. The number of waypoints (Generally create more for a larger radius)
  4. Number of AI units to create
So to create a group of 4 troops, in Cherno (with a 160m random patrol radius from centre of town), with a random route around 6 points do this:
Code:
_aispawn = [[6689.49,2623.59,0],160,6,4] execVM "units\add_unit_server.sqf";

You can call this same command as many times as you feel is necessary, a new 'AI group' is generated each time, keeping them as separate groups..

The main code: <Mission Folder>\units\add_unit_server.sqf
Code:
    private["_aiunit","_xpos","_ypos","_unitpos","_aiGroup","_wppos","_wpradius","_wpnum","_numunits","_rndLOut","_ailoadout","_aiwep","_aiammo","_wp","_aispawnpos"];
    _aiunit = objNull;
    _aiGroup = createGroup resistance;
    _aispawnpos =_this select 0;
    _wpradius = _this select 1;
    _wpnum = _this select 2;
    _numunits = _this select 3;
 
    _xpos = _aispawnpos select 0;
    _ypos = _aispawnpos select 1;
 
    diag_log format ["AIUNIT: Spawn initiated: Centre:%1 | Radius in m:%2 | Waypoint number:%3",_aispawnpos,_wpradius,_wpnum];
 
    for [{ x=1 },{ x < _numunits+1 },{ x = x + 1; }] do {
    _unitpos = [_xpos+x,_ypos+x,0];
 
    _rndLOut=floor(random 3);
    _ailoadout=
    switch (_rndLOut) do
    {
      case 0: {["AK_47_M","30Rnd_762x39_AK47"]};
      case 1: {["M4A1_AIM_SD_camo","30Rnd_556x45_StanagSD"]};
      case 2: {["Remington870_lamp","8Rnd_B_Beneli_74Slug"]};
    };
 
    "BAF_Soldier_L_DDPM" createUnit [_unitpos, _aiGroup, "_aiunit=this;",0.6,"Private"];
 
    diag_log format ["AIUNIT: Creating BAF_Soldier_L_DDPM by %1 at %2. Result:%3 | Loadout:%4 / Num:%5",player,_unitpos,_aiunit,_ailoadout,_rndLOut];
 
    _aiunit enableAI "TARGET";
    _aiunit enableAI "AUTOTARGET";
    _aiunit enableAI "MOVE";
    _aiunit enableAI "ANIM";
    _aiunit enableAI "FSM";
    _aiunit allowDammage true;
 
    _aiunit setCombatMode "RED";
    _aiunit setBehaviour "COMBAT";
 
    //clear default weapons / ammo
    removeAllWeapons _aiunit;
    //add random selection
    _aiwep = _ailoadout select 0;
    _aiammo = _ailoadout select 1;
    _aiunit addweapon _aiwep;
    _aiunit addMagazine _aiammo;
    _aiunit addMagazine _aiammo;
    _aiunit addMagazine _aiammo;
    _aiunit addMagazine _aiammo;
    _aiunit addMagazine _aiammo;
    _aiunit addMagazine _aiammo;
    _aiunit addMagazine _aiammo;
    _aiunit addMagazine _aiammo;
 
    //set skills
    _aiunit setSkill ["aimingAccuracy",1];
    _aiunit setSkill ["aimingShake",1];
    _aiunit setSkill ["aimingSpeed",1];
    _aiunit setSkill ["endurance",1];
    _aiunit setSkill ["spotDistance",1];
    _aiunit setSkill ["spotTime",1];
    _aiunit setSkill ["courage",1];
    _aiunit setSkill ["reloadSpeed",1];
    _aiunit setSkill ["commanding",1];
    _aiunit setSkill ["general",1];
    //sleep 0.5;
    } ;
 
    //generate waypoints
    for [{ x=1 },{ x < _wpnum },{ x = x + 1; }] do {
    _wppos = [_xpos+(x*20),_ypos+(x*20),_wpradius];
    _wp = _aiGroup addWaypoint [_wppos, _wpradius];
    _wp setWaypointType "MOVE";
    };
    _wp = _aiGroup addWaypoint [[_xpos,_ypos,0], _wpradius];
    _wp setWaypointType "CYCLE";
 
    diag_log format ["AIUNIT: Last Waypoint %1 at %2",_wp,_wppos];

Finally there is a bit of code from Xyberviri's dayZ Factions thread that handles the opposition / friendliness of the units, this is what gets the units attacking zeds: <Mission Folder>\Dayz_Factions\init.sqf
Code:
waitUntil{initialized};
//0Day
createCenter east;
createCenter resistance;
//Survivors
WEST setFriend [RESISTANCE,1];
WEST setFriend [EAST,0];
//Bandits
EAST setFriend [RESISTANCE,0];
EAST setFriend [WEST,0];
//AI Units
RESISTANCE setFriend [WEST,1];
RESISTANCE setFriend [EAST,0];
RESISTANCE setFriend [CIVILIAN,0];//AI Units attack zeds
 
//CIVILIAN setFriend [RESISTANCE,0];//Testing Zeds attack AI units, doesn't seem to help..

Battleye: In some cases you might get booted for a script restriction #8, try updating line #10 addWaypoint of your scripts.txt to this
Code:
5 addWaypoint !"\"addWaypoint\"," !"units\add_unit_server.sqf"

Also, edit lines #114 addWeapon and #118 addMagazine. Add:
Code:
!"units\add_unit_server.sqf"
to the end of both lines. I haven't tested this but I would think that you will only get these errors if trying to run from the client. The server should be running the commands..

The attached .pbo has the basic files required (have used the mission init.sqf from the latest Reality build) and come from the normal dayz_1.chernaurs.pbo in MPMission folder. The only lines added are: the one to initiate the Dayz_Factions init and the 6 lines to create the 6 groups..

There are ways of enhancing the AI of the troops, this uses ARMA2 AI troops. I haven't yet added anything more and am experimenting with taking leadership of the troops so they actually help you..

>> There is a lot of good content in this thread provided by others. As there are so many pages I have tried to highlight the main points here <<

>> Additional Tweaks THIS POST<<

>> Sycosis has put together a tutorial HERE<<

>> A List of un-banned soldier skins HERE (Not Tested)<<

>> Setting Sides and Different Loadouts HERE <<

>> A List of Towns and their worldspace coordinates HERE <<
>> Taking Control of AI Groups HERE <<
>> A good few pages of more advanced AI HERE from Sarge and BETA testers wanted HERE <<

>> Orcthrasher touches on the subject of vehicles HERE <<
>> Some Hero / Bandit Stuff here (Not Tested) Also Infinite Ammo HERE <<​
(There is a lot in this thread, if you have any posts you think should be mentioned or a relevant AI Troop thread elsewhere, let me know and I will add it in here)

I look forward to your feedback.. PM me if you are really stuck, after reading through the thread for any clues as how to resolve your issue..
 

Attachments

  • dayZ_AI_NPC_Units.pbo
    5.8 KB · Views: 1,006
I've been looking into AI - been toying around with UPS.. gonna do some testing with it... I'll give this a go as well.

How "good" are these AI? And how would you make them work with vehicle / heli patrols?
 
It is quite a mess to setup tho.. might wait till its more simple.
Right now you need parts from dayz factions and all that.
 
It is quite a mess to setup tho.. might wait till its more simple.
Right now you need parts from dayz factions and all that.

The factions is just a mission file / folder the rest isn't needed for the AI, Arma runs the AI troops. All that is being done is the sides being set. Maybe someone else using dayz.st can let us know if it installs ok, have not used it myself, I have a dedicated server.
 
I've been looking into AI - been toying around with UPS.. gonna do some testing with it... I'll give this a go as well.

How "good" are these AI? And how would you make them work with vehicle / heli patrols?

From what I have seen you need to add a waypoint, where the vehicle is situated and, and change it's wayPointType to Get In, they will board the vehicle and carry on to the next waypoint. Info on wayPointTypes. Not something I have tested yet..

I have seen a thread here where someone was trying to get a bus travelling around the map, he was having problems with players still being able to occupy the drivers seat. I might set up a bus route on my server and have it reset every server restart :)
 
works on dayz.st but randomly shoot

Yeh they seem to shoot at ghosts, I have seen them kill the odd zombie, was wondering if changing their guns would make them any more accurate.. I read somewhere that they will attack anything Civilian, they may be shooting at bits of junk.

Is why I linked in with the Factions thread as Xyberviri has got further with the AI intelligence, he suggested trying ASR AI to me.
 
Yeh they seem to shoot at ghosts, I have seen them kill the odd zombie, was wondering if changing their guns would make them any more accurate.. I read somewhere that they will attack anything Civilian, they may be shooting at bits of junk.

Is why I linked in with the Factions thread as Xyberviri has got further with the AI intelligence, he suggested trying ASR AI to me.

Just looked into this further, they AI troops are shooting at zeds they just might be miles away, behind a building and a wall or two :)

Try adjusting this line down (values between zero and one)
Code:
_aiunit setSkill ["spotDistance",1];
 
Axeman, Great ai addition easy to use and very easy to apply. Thanks so much it was just what I was looking for.

Have you done any work on trying to get them to despawn after death and respawn maybe 10 minutes later? I would greatly appreciate help in that area as well. Thanks in advance
 
Ohh forgot to mention I run a dayz.st server and everything is working great had to change the resistance setfriend [west,1] to resistance setfriend [west,0] so that they attack the survivors as well as zeds.
 
It doesnt work for me, i use dayz.st as well, running taviana ALL my vehicles duplicates.


// EarthQuake:
if (!isDedicated) then {
[] execVM "earthquake.sqf";
};

// Lights:
if (!isDedicated) then {
[] execVM "fixes\change_streetlights.sqf";
};

if (isServer) then {
_serverMonitor = [] execVM "\z\addons\dayz_code\system\server_monitor.sqf";
/*
IMPORTANT STUFF STARTS HERE:
*/
_dayzFactions = [] execVM "Dayz_Factions\init.sqf";
//diag_log format["Dayz Factions executed: %1",_dayzFactions];
//Array to pass to .sqf: [[<worldspace>],radius of waypoints (in metres),number of waypoints,number of ai units]
_aispawn = [0,[10288.61,799.3477,0]] execVM "units\add_unit_server.sqf";//Chernogorsk
_aispawn = [0,[10292.9,772.8418,0]] execVM "units\add_unit_server.sqf";//Chernaurs (Whole map)
_aispawn = [0,[10455.89,852.3672,0]] execVM "units\add_unit_server.sqf";//Chernaurs (Whole map)
_aispawn = [0,[10520.22,675.6406,0]] execVM "units\add_unit_server.sqf";//NW Airfield
_aispawn = [0,[10443.02,993.75,0]] execVM "units\add_unit_server.sqf";//Electrozavodsk
_aispawn = [0,[10528.8,967.2402,0]] execVM "units\add_unit_server.sqf";//Solnichniy
/*
IMPORTANT STUFF ENDS HERE
*/
};
 
It doesnt work for me, i use dayz.st as well, running taviana ALL my vehicles duplicates.

make it look like tis loose the extra zero in first bracket. change from
_aispawn = [0,[10528.8,967.2402,0]] execVM "units\add_unit_server.sqf";//Solnichniy

to

_aispawn = [[10528.8,967.2402,0]160,6,4] execVM "units\add_unit_server.sqf";//Solnichniy

dont forget what I put in red this is from left to right radius for way points, amount of waypoints and amount of ai
 
make it look like tis loose the extra zero in first bracket. change from
_aispawn = [0,[10528.8,967.2402,0]] execVM "units\add_unit_server.sqf";//Solnichniy

to

_aispawn = [[10528.8,967.2402,0]160,6,4] execVM "units\add_unit_server.sqf";//Solnichniy

dont forget what I put in red this is from left to right radius for way points, amount of waypoints and amount of ai
Thank you, ill try that.
 
That didn't work either, i believe i've done something wrong in my init.sqf
here is the rest of the fragment

"filmic" setToneMappingParams [0.153, 0.357, 0.231, 0.1573, 0.011, 3.750, 6, 4]; setToneMapping "Filmic";

if (isServer) then {
hiveInUse = true;
_serverMonitor = [] execVM "\z\addons\dayz_server\system\server_monitor.sqf";
};

if (!isDedicated) then {
0 fadeSound 0;
0 cutText [(localize "STR_AUTHENTICATING"), "BLACK FADED",60];
_id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
_playerMonitor = [] execVM "\z\addons\dayz_code\system\player_monitor.sqf";

};

// Extra actions for Taviana:
if (!isDedicated) then {
[] execVM "kh_actions.sqf";
};

// EarthQuake:
if (!isDedicated) then {
[] execVM "earthquake.sqf";
};

// Lights:
if (!isDedicated) then {
[] execVM "fixes\change_streetlights.sqf";
};

if (isServer) then {
_serverMonitor = [] execVM "\z\addons\dayz_code\system\server_monitor.sqf";
/*
IMPORTANT STUFF STARTS HERE:
*/
_dayzFactions = [] execVM "Dayz_Factions\init.sqf";
//diag_log format["Dayz Factions executed: %1",_dayzFactions];
//Array to pass to .sqf: [[<worldspace>],radius of waypoints (in metres),number of waypoints,number of ai units]
_aispawn = [[6689.49,2623.59,0],160,8,4] execVM "units\add_unit_server.sqf";//Chernogorsk
_aispawn = [[7622.51,7912.7,0],5000,20,6] execVM "units\add_unit_server.sqf";//Chernaurs (Whole map)
_aispawn = [[7625.51,7915.7,0],5000,20,6] execVM "units\add_unit_server.sqf";//Chernaurs (Whole map)
_aispawn = [[4598.66,10197.7,0],650,12,4] execVM "units\add_unit_server.sqf";//NW Airfield
_aispawn = [[10447.5,2246.96,0],180,3,3] execVM "units\add_unit_server.sqf";//Electrozavodsk
_aispawn = [[13253.3,6406.53,0],180,4,3] execVM "units\add_unit_server.sqf";//Solnichniy
/*
IMPORTANT STUFF ENDS HERE
*/
};
 
Looking forward to deploy it on my server. However, can anyone help me out what weapons are they carry, is it lootable - and are they "hardcore" against survivors - I mean, are they gonna open fire automatically if they spot a survivor?

Thanks in advance!
 
Got it working :)
BUT getting kicked for SR #8
Changed line 8 in scripts.txt to 5 (addResources) logged in as a survivor, declared war between me and them, killed like 2-4. got kicked again #8
 
Not sure what SR #8 is but looking aat your world locations it seems you are using the same as the chernarua map. I think that might spawn some ai in the oceans in taviana. Could this be causing the SR #8?
 
Back
Top