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

I have added the add_unit_server_bandit.sqf, and now when i assign units they all start attacking eachother, how can i fix this?

The AI troops in Cherno started to kill eachother, but they are all resistance last i checked.
 
I have good guys and bad guys - with TK skins and BAF skins (and different weapons and skill levels). They all shoot zombies. This is how I hacked it together (and it can be imporoved, but I was trying to just go for basic function testing).

Add this line to your init.sqf under factions:

Then, you can either modify your add_unit_server to accept a bandit/hero parameter to change the center, or just (like I did for testing) duplicate it.

*Deleted code from quote to save space*

Now, call them from your chernarus mission init.sqf the same way, and choose if you want to spawn a bandit or soldier.
Code:
_aispawn = [[4780.92,2500.74,0.001],20,1,5] execVM "units\add_unit_server.sqf";//Balota
_aispawn = [[4703.12,2525.5,0.001],20,1,5] execVM "units\add_unit_server_Bandit.sqf";//Balota

I created a new file called add_unit_server_bandit.sqf with the code you provided. I put it in the units folder. I then added these lines to init.sqf, below the lines for the AI soldiers. The AI soldiers are spawning fine. The bandits are not:

Code:
_aispawn = [[4185.1543,3678.1938,0.001],5000,20,4] execVM "units\add_unit_server_bandit.sqf";//Bandit spawn Pancho
_aispawn = [[2334.2578,8068.2959,0.001],50,8,15] execVM "units\add_unit_server_bandit.sqf";//Bandit spawn Villa Oscura
 
EDIT2. I was pointed out to me that I made some screw ups in the code. This has been updated below and now should work ok.


EDIT. So I have updated the server and this seems to be working ok... it seems to not spawn in weapons for the Bandit AI tho..

The NPCs are also spawning in with radios and watches, is this just a standard loadout for the NPCs? Anyway to remove it?



Hey folks,

I've been playing around with the code found in this post and thought I would post my work here in case anyone wanted to use it, and to see if you can spot and stupid mistakes before I go live with it.

So I am using the Hero/Bandit option, using a separate file to call each one. I have set up what I hope are boring standard load-outs with the Hero AI having a moderate chance of a good gun, but being harder to kill and the Bandit AI having a very small chance of a good gun, but easy slightly easier to kill. I have also given them infinite ammo with one clip.

So for the Hero (the soldiers patrolling some of my bases):

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 30);
    _ailoadout=
    switch (_rndLOut) do
    {
      case 0: {["DMR","20Rnd_762x51_DMR"]};
      case 1: {["G36K_camo","30Rnd_556x45_Stanag"]};
      case 2: {["m16a4_acg","30Rnd_556x45_Stanag"]};
      case 3: {["M4A1_HWS_GL_CAMO","30Rnd_556x45_Stanag"]};
 
      default: {["M4A1","30Rnd_556x45_Stanag"]};
    };
       
    //Generate what the sidearm and ammo will be
    _rndLOut=floor(random 3);
    _aiside=
    switch (_rndLOut) do
    {
      case 0: {["M9","15Rnd_9x19_M9"]};
      case 1: {["M9 Silenced","15Rnd_9x19_M9SD"]};
      case 2: {["glock17_EP1","17Rnd_9x19_glock17"]};
 
    };
 
    //Generate what the equipment will be - it's likely to be a map, but maybe.... :)
    _rndLOut=floor(random 30);
    _aiequipspawn=
    switch (_rndLOut) do
        {
        case 0: {["Binocular_Vector"]};
        case 1: {["ItemGPS"]};
        case 2: {["ItemCompass"]};
        case 3: {["NVGoggles"]};
        case 4: {["Binocular"]};
 
        default: {["ItemMap"]};
    };
 
    "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;
 
    // Add sidearm and mags
    _aiunit addweapon _aisidearm;
    _aiunit addMagazine _aisidearmammo;
 
    // add gear
    _aiunit addWeapon _aigear;
    //_aiunit addMagazine _aigear;
 
    //set skills
    _aiunit setSkill ["aimingAccuracy",0.9];
    _aiunit setSkill ["aimingShake",0.9];
    _aiunit setSkill ["aimingSpeed",0.9];
    _aiunit setSkill ["endurance",1];
    _aiunit setSkill ["spotDistance",0.9];
    _aiunit setSkill ["spotTime",0.9];
    _aiunit setSkill ["courage",0.9];
    _aiunit setSkill ["reloadSpeed",0.9];
    _aiunit setSkill ["commanding",1];
    _aiunit setSkill ["general",1];
    //sleep 0.5;
    } ;
    //infinite ammo
 
    _aiunit addEventHandler ["Fired", {(_this select 0) setvehicleammo 1}];
 
    //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];

and for the Bandits:

Code:
private["_aiunit","_xpos","_ypos","_unitpos","_aiGroup","_wppos","_wpradius","_wpnum","_numunits","_rndLOut","_ailoadout","_aiwep","_aiammo","_wp","_aispawnpos"];
    _aiunit = objNull;
    _aiGroup = createGroup EAST;
    _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 50);
    _ailoadout=
    switch (_rndLOut) do
    {
      case 0: {["huntingrifle","5x_22_LR_17_HMR"]};
      case 1: {["Sa58V_RCO_EP1","30Rnd_762x39_AK47"]};
      case 2: {["SVD_Camo","10Rnd_762x54_SVD"]};
      case 3: {["Sa58V_CCO_EP1","30Rnd_762x39_AK47"]};
 
      default: {["AK_47","30Rnd_762x39_AK47"]};
    };
 
    //Generate what the sidearm and ammo will be
    _rndLOut=floor(random 3);
    _aiside=
    switch (_rndLOut) do
    {
      case 0: {["M1911","7Rnd_45ACP_1911"]};
      case 1: {["revolver_EP1","6Rnd_45ACP"]};
      case 2: {["Makarov","8Rnd_9x18_Makarov"]};
    };
 
    //Generate what the equipment will be - it's likely to be a map, but maybe.... :)
    _rndLOut=floor(random 50);
    _aiequipspawn=
    switch (_rndLOut) do
        {
        case 0: {["Binocular_Vector"]};
        case 1: {["ItemGPS"]};
        case 2: {["ItemCompass"]};
        case 3: {["NVGoggles"]};
        case 4: {["Binocular"]};
 
        default: {["ItemMap"]};
    };
 
    "TK_INS_Soldier_EP1" createUnit [_unitpos, _aiGroup, "_aiunit=this;",0.6,"Private"];
 
    diag_log format ["AIUNIT: Creating TK_INS_Soldier_EP1 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;
 
    // Add sidearm and mags
    _aiunit addweapon _aisidearm;
    _aiunit addMagazine _aisidearmammo;
 
 
    // add gear
    _aiunit addWeapon _aigear;
    //_aiunit addMagazine _aigear;
 
    //set skills
    _aiunit setSkill ["aimingAccuracy",0.9];
    _aiunit setSkill ["aimingShake",0.9];
    _aiunit setSkill ["aimingSpeed",0.8];
    _aiunit setSkill ["endurance",1];
    _aiunit setSkill ["spotDistance",0.8];
    _aiunit setSkill ["spotTime",0.7];
    _aiunit setSkill ["courage",0.9];
    _aiunit setSkill ["reloadSpeed",0.9];
    _aiunit setSkill ["commanding",1];
    _aiunit setSkill ["general",1];
    //sleep 0.5;
    } ;
 
    _aiunit addEventHandler ["Fired", {(_this select 0) setvehicleammo 1}];
 
    //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];


So I'm hoping this will work, and will update the thread later. Meantime, if you spot any glaring mistakes in my code, please let me know.
 
So would I be right or wrong by saying I can my AI have unlimited ammo by adding the following code below the setskill code snippet?

Code:
_aiunit addEventHandler ["Fired", {(_this select 0) setvehicleammo 1}];
 
i saw a post earlier that say's that works, my AI guys don't seem to be running out of ammo, i just can't get the zeds to react to their shots.......lol
 
I hope it works, Ive been trying to figurew that out for a week now. I just dont know if I put the code in the correct place :/
 
I have been using this for awhile now, and did not notice it initially. But I keep getting the AI troops next to a wall, sitting there.

I thought at first this was just a timer thing between waypoints, but I sat watching them from a distance for about 30 minutes and they all seem to just be stuck.

So I restarted the server and watched. It seems that after they finish their waypoints, they just stop. They do not move anymore unless they see a target, at which point they will go after it (until they lose interest) and then return to the wall, stop and stay there.

Is there a way to make the waypoints cycle? I currently have 10 waypoints set in a 75m radius. I notice them stop 9 or 10 times before they get to the wall, then they sit at the wall. So I'm thinking that they are completing the defined number of waypoints and just stopping there.
 
Hey guys would this work
Code:
      case 0: {["Binocular","G36K_camo","30Rnd_556x45_G36","DZ_CivilBackpack_EP1"]};
      case 1: {["NVGoggles","BAF_L85A2_RIS_Holo","30Rnd_556x45_Stanag","DZ_CivilBackpack_EP1"]};
      case 2: {["ItemGPS","Mk_48_DZ","100Rnd_762x51_M240","DZ_CivilBackpack_EP1"]};
      case 3: {["Binocular_Vector","BAF_AS50_scoped","10Rnd_127x99_m107","DZ_CivilBackpack_EP1"]};
     
      default {["ItemMap"]};
Everything else is just working great, i love it!
 
You can spawn them with what ever you want but from experience..all that will happen is the players will discover the AI are well equiped and kill them all for the loot they carry:(

up to you!
 
You can spawn them with what ever you want but from experience..all that will happen is the players will discover the AI are well equiped and kill them all for the loot they carry:(

up to you!
TuBz, i'm stuck on top of a building.. lol.. I landed here with a heli the other day, and now my heli's gone and im stuck.. Help me out ;D
 
I have been using this for awhile now, and did not notice it initially. But I keep getting the AI troops next to a wall, sitting there.

I thought at first this was just a timer thing between waypoints, but I sat watching them from a distance for about 30 minutes and they all seem to just be stuck.

So I restarted the server and watched. It seems that after they finish their waypoints, they just stop. They do not move anymore unless they see a target, at which point they will go after it (until they lose interest) and then return to the wall, stop and stay there.

Is there a way to make the waypoints cycle? I currently have 10 waypoints set in a 75m radius. I notice them stop 9 or 10 times before they get to the wall, then they sit at the wall. So I'm thinking that they are completing the defined number of waypoints and just stopping there.
Placing a 'cycle' waypoint directly over the first 'move' waypoint should get them looping..
 
Hey guys would this work
Code:
      case 0: {["Binocular","G36K_camo","30Rnd_556x45_G36","DZ_CivilBackpack_EP1"]};
      case 1: {["NVGoggles","BAF_L85A2_RIS_Holo","30Rnd_556x45_Stanag","DZ_CivilBackpack_EP1"]};
      case 2: {["ItemGPS","Mk_48_DZ","100Rnd_762x51_M240","DZ_CivilBackpack_EP1"]};
      case 3: {["Binocular_Vector","BAF_AS50_scoped","10Rnd_127x99_m107","DZ_CivilBackpack_EP1"]};
   
      default {["ItemMap"]};
Everything else is just working great, i love it!
Not with the current code, it picks the first item as the weapon and the second as the ammo. Though there are some good additions on this thread, one for infinite ammo and am sure there are some tweaks for changing the equipment.

I have tested giving them NVGs but want to make them react to being attacked as they are just getting harvested..

Have been a bit distracted updating the website this week with an in-game registration confirmation system that I am testing and tweaking.

I plan to pick these back up this week and make a few changes from the feedback so far..
 
i saw a post earlier that say's that works, my AI guys don't seem to be running out of ammo, i just can't get the zeds to react to their shots.......lol
The problem seems to be that the AI Units are created by the server whereas the zeds are created by the client and as such 'can't see' each other.

I might test this out as I can create AI Units from my menu in-game, just need to get them angry toward civilians.

Sarge has an AI package going, he goes into more detail.
 
TuBz, i'm stuck on top of a building.. lol.. I landed here with a heli the other day, and now my heli's gone and im stuck.. Help me out ;D
Let us know when you want to re-spawn and we will attack with a fleet of Apache's :) That will sort your re-spawn problem..

Or, go register on the website and you can move yourself with the player tools. I would be interested in your feedback on the registration process. Been smooth mostly, couple of people have got lost..

I haven't set up player moving yet, not really something we need. If you really want I can go in and change your worldspace later..
 
Hey @axeman did you ever get the Bus Route working? Thats something I would be very interested in trying to implement as well
 
Greetings,

I am added with Editor a few WEST patrol's and i use now this ;

waitUntil{initialized};
//0Day
createCenter east;
createCenter resistance;
//Survivors
WEST setFriend [RESISTANCE,1];
WEST setFriend [EAST,0];
WEST setFriend [CIVILAN,0]; (i added this, but its not work)
//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..

I dont want Bandit AI's, i only want WEST protected Safe Camp's for newbies. This is possible?
WEST added with Editor and set them fire zombies and bandits (i think they already attack bandits).

Thanks for answers..

EDÄ°T : By the way i use RMod and my some patrols "FAC Operator" and "Saboteur".
 
Greetings again, i fixed issue. But now my units is dissapear, i dont understand this problem. Normally unit limit is very huge. I am added 11 unit and save the mission, then i am converting the sqm. And take the biedi in new.Chernarus, and i am enter the game open the Multiplayer and press the new. Load/Merge.. and my 11. unit is dissappear, my only 10 unit in here. What is this? Help me please..
 
Back
Top