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

This is my little modification. There are two types of armament troops.
init spawn groups
PHP:
    _aispawn = [[6689.49,2623.59,0],500,10,4,0] execVM "troops\add_unit_server.sqf";//Chernogorsk
    _aispawn = [[4598.66,10197.7,0],600,10,6,1] execVM "troops\add_unit_server.sqf";//NW Airfield
    _aispawn = [[10446.5,2246.96,0],400,10,4,0] execVM "troops\add_unit_server.sqf";//Electrozavodsk
add unit code
PHP:
private["_aiunit","_xpos","_ypos","_unitpos","_aiGroup","_wppos","_wpradius","_wpnum","_levelnum","_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;
    _levelnum = _this select 4;
 
    _xpos = _aispawnpos select 0;
    _ypos = _aispawnpos select 1;
 
    diag_log format ["AIUNIT: Spawn initiated: Centre:%1 | Radius in m:%2 | Waypoint number:%3 | WeaponLevel:%4",_aispawnpos,_wpradius,_wpnum,_levelnum];
 
    for [{ x=1 },{ x < _numunits+1 },{ x = x + 1; }] do
    {
        _unitpos = [_xpos+x,_ypos+x,0];
 
        if (_levelnum==0) then // in_sityes troops
        {
            if ((x == 1) || (x == 3) || (x == 5)) then //troop soldiers
            {
                "BAF_Soldier_L_DDPM" createUnit [_unitpos, _aiGroup, "_aiunit=this;",1,"PRIVATE"];
                _rndLOut=floor(random 4);
                _ailoadout=
                switch (_rndLOut) do
                {
                  case 0: {["M1014","8Rnd_B_Beneli_74Slug","revolver_EP1","6Rnd_45ACP"]};
                  case 1: {["M1014","8Rnd_B_Beneli_Pellets","revolver_EP1","6Rnd_45ACP"]};
                  case 2: {["Remington870_lamp","8Rnd_B_Beneli_74Slug","Colt1911","7Rnd_45ACP_1911"]};
                  case 3: {["Remington870_lamp","8Rnd_B_Beneli_Pellets","Colt1911","7Rnd_45ACP_1911"]};
                };
            };
            if ((x == 2) || (x == 4) || (x >= 6)) then //troops snipers
            {
                "BAF_Soldier_Sniper_MTP" createUnit [_unitpos, _aiGroup, "_aiunit=this;",1,"PRIVATE"];
                _rndLOut=floor(random 3);
                _ailoadout=
                switch (_rndLOut) do
                {
                  case 0: {["LeeEnfield","10x_303","Makarov","8Rnd_9x18_Makarov"]};
                  case 1: {["Huntingrifle","5x_22_LR_17_HMR","Makarov","8Rnd_9x18_Makarov"]};
                  case 2: {["M14_EP1","20Rnd_762x51_DMR","Makarov","8Rnd_9x18_Makarov"]};
                };
            };
        };
        if (_levelnum==1) then //in_military troops
        {
            if (x == 1) then //one troops comander
            {
                "BAF_Soldier_Officer_DDPM" createUnit [_unitpos, _aiGroup, "_aiunit=this;",1,"LIEUTENANT"];
                _rndLOut=floor(random 7);
                _ailoadout=
                switch (_rndLOut) do
                {
                  case 0: {["AK_47_M","30Rnd_762x39_AK47","UZI_SD_EP1","15Rnd_9x19_M9SD"]};
                  case 1: {["AK_47_S","30Rnd_762x39_AK47","M9SD","15Rnd_9x19_M9SD"]};
                  case 2: {["Sa58P_EP1","30Rnd_762x39_SA58","UZI_SD_EP1","15Rnd_9x19_M9SD"]};
                  case 3: {["Sa58V_CCO_EP1","30Rnd_762x39_SA58","M9SD","15Rnd_9x19_M9SD"]};
                  case 4: {["Sa58V_EP1","30Rnd_762x39_SA58","UZI_SD_EP1","15Rnd_9x19_M9SD"]};
                  case 5: {["FN_FAL","20Rnd_762x51_FNFAL","M9SD","15Rnd_9x19_M9SD"]};
                  case 6: {["FN_FAL_ANPVS4","20Rnd_762x51_FNFAL","UZI_SD_EP1","15Rnd_9x19_M9SD"]};
                };
            };
            if ((x == 2) || (x == 3)) then //troops sergeant
            {
                "BAF_Soldier_L_DDPM" createUnit [_unitpos, _aiGroup, "_aiunit=this;",1,"SERGEANT"];
                _rndLOut=floor(random 3);
                _ailoadout=
                switch (_rndLOut) do
                {
                  case 0: {["M240","100Rnd_762x51_M240","glock17_EP1","17Rnd_9x19_glock17"]};
                  case 1: {["Mk_48","100Rnd_762x51_M240","Colt1911","7Rnd_45ACP_1911"]};
                  case 2: {["M249_EP1","100Rnd_556x45_M249","M9","15Rnd_9x19_M9"]};
                };
            };
            if (x > 3) then //troops soldiers
            {
                "BAF_Soldier_Sniper_MTP" createUnit [_unitpos, _aiGroup, "_aiunit=this;",1,"CORPORAL"];
           
                _rndLOut=floor(random 4);
                _ailoadout=
                switch (_rndLOut) do
                {
                  case 0: {["SVD_NSPU_EP1","10Rnd_762x54_SVD","Sa61_EP1","20Rnd_B_765x17_Ball"]};
                  case 1: {["M24","5Rnd_762x51_M24","Sa61_EP1","20Rnd_B_765x17_Ball"]};
                  case 2: {["DMR","20Rnd_762x51_DMR","Sa61_EP1","20Rnd_B_765x17_Ball"]};
                  case 3: {["M40A3","5Rnd_762x51_M24","Sa61_EP1","20Rnd_B_765x17_Ball"]};
                };
            };
        };
        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
        _aiwep1 = _ailoadout select 0;
        _aiammo1 = _ailoadout select 1;
        _aiwep2 = _ailoadout select 2;
        _aiammo2 = _ailoadout select 3;
        _aiunit addweapon _aiwep1;
        _aiunit addMagazine _aiammo1;
        _aiunit addMagazine _aiammo1;
        _aiunit addMagazine _aiammo1;
        _aiunit addweapon _aiwep2;
        _aiunit addMagazine _aiammo2;
        _aiunit addMagazine _aiammo2;
      //add some garbage
        if (x == 1) then {
        _aiunit addMagazine "SmokeShellGreen";
        _aiunit addMagazine "HandGrenade_West";
        _aiunit addMagazine "FoodCanBakedBeans";
        _aiunit addMagazine "ItemSodaCoke";
        _aiunit addMagazine "ItemPainkiller";
        _aiunit addMagazine "ItemHeatPack";
        _aiunit addMagazine "ItemEpinephrine";
        _aiunit addMagazine "ItemMorphine";
        };
        if (x == 2) then {
        _aiunit addMagazine "ItemHeatPack";
        _aiunit addMagazine "ItemPainkiller";
        _aiunit addMagazine "ItemEpinephrine";
        _aiunit addMagazine "ItemMorphine";
        };
        if (x >= 3) then {
        _aiunit addMagazine "ItemHeatPack";
        _aiunit addMagazine "ItemBandage";
        };
        //set skills
        _aiunit setSkill ["aimingAccuracy",0.9];
        _aiunit setSkill ["aimingShake",0.9];
        _aiunit setSkill ["aimingSpeed",0.9];
        _aiunit setSkill ["endurance",0.9];
        _aiunit setSkill ["spotDistance",1];
        _aiunit setSkill ["spotTime",0.9];
        _aiunit setSkill ["courage",0.9];
        _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];
After I figure out how to do this bandit thing i working on I was going to do this. You just saved me the time and effort. Thanks man. Good work.
 
Thanks to better axeman. I just modified the code.
By the way I have a small problem - Electro spawn only - 2 boat in the squad. So use like this -
_aispawn = [[10446.5,2246.96,0], 400,10,2,0] execVM "troops \ add_unit_server.sqf" ;/ / Electrozavodsk_1
_aispawn = [[10496.5,2296.96,0], 400,10,2,0] execVM "troops \ add_unit_server.sqf" ;/ / Electrozavodsk_2
I do not know what the problem is, just use that.
 
When I make the necessary modifications, the server seems unable to connect with the mission file. I get an error, then when I hit esc, it says that it can't find the pause script. Seems the server and mission files are not talking. Here is my init file just in case it's some type of syntax error. But I'm suspecting its a bikey issue

BTW I'm running DayZ+ on dayz.st

Code:
/*   
    INITILIZATION
*/
startLoadingScreen ["","RscDisplayLoadCustom"];
cutText ["","BLACK OUT"];
enableSaving [false, false];
 
//REALLY IMPORTANT VALUES
dayZ_instance = 331;                    //The instance
dayzHiveRequest = [];
initialized = false;
dayz_previousID = 0;
 
//disable greeting menu
player setVariable ["BIS_noCoreConversations", true];
//disable radio messages to be heard and shown in the left lower corner of the screen
enableRadio false;
 
//Load in compiled functions
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\variables.sqf";                //Initilize the Variables (IMPORTANT: Must happen very early)
progressLoadingScreen 0.1;
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\publicEH.sqf";                //Initilize the publicVariable event handlers
progressLoadingScreen 0.2;
call compile preprocessFileLineNumbers "\z\addons\dayz_code\medical\setup_functions_med.sqf";    //Functions used by CLIENT for medical
progressLoadingScreen 0.4;
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\compiles.sqf";                //Compile regular functions
progressLoadingScreen 1.0;
 
"filmic" setToneMappingParams [0.153, 0.357, 0.231, 0.1573, 0.011, 3.750, 6, 4]; setToneMapping "Filmic";
 
if ((!isServer) && (isNull player) ) then
{
waitUntil {!isNull player};
waitUntil {time > 3};
};
 
if ((!isServer) && (player != player)) then
{
  waitUntil {player == player};
  waitUntil {time > 3};
};
 
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
    */
 
 
 
 
 
 
};
 
 
 
 
 
if (!isDedicated) then {
    //Conduct map operations
    0 fadeSound 0;
    waitUntil {!isNil "dayz_loadScreenMsg"};
    dayz_loadScreenMsg = (localize "STR_AUTHENTICATING");
   
    //Run the player monitor
    _id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
    _playerMonitor =    [] execVM "\z\addons\dayz_code\system\player_monitor.sqf";   
};
 
How do you get them to use vehicles... I have been looking into AI.. and been trying to implement UPS (Figured I'd give this a go as well)
 
How do you get them to use vehicles... I have been looking into AI.. and been trying to implement UPS (Figured I'd give this a go as well)
Create some waypoints for their group then get the units to load the vehicle with moveInDriver & moveInCargo
 
Code:
_aiwep = _ailoadout select 0;
_aiammo = _ailoadout select 1;>
19:59:15  Error position: <select 0;
_aiammo = _ailoadout select 1;>
19:59:15  Error select: Type Bool, expected Array,Config entry
19:59:15 File mpmissions\__cur_mp.mbg_celle2\units\add_unit_server.sqf, line 47
19:59:15 "AIUNIT: Spawn initiated: Centre:[10727.8,11095.2,0] | Radius in m:800 | Waypoint number:25"
19:59:15 Cannot create entity with abstract type BAF_Soldier_L_DDPM (scope = private?)
19:59:15 "AIUNIT: Creating BAF_Soldier_L_DDPM by <NULL-object> at [10728.8,11096.2,0]. Result:<NULL-object> | Loadout:["M4A1_AIM_SD_camo","30Rnd_556x45_StanagSD"] / Num:1"
19:59:15 Cannot create entity with abstract type BAF_Soldier_L_DDPM (scope = private?)
19:59:15 "AIUNIT: Creating BAF_Soldier_L_DDPM by <NULL-object> at [10729.8,11097.2,0]. Result:<NULL-object> | Loadout:["AK_47_M","30Rnd_762x39_AK47"] / Num:0"
19:59:15 Cannot create entity with abstract type BAF_Soldier_L_DDPM (scope = private?)
19:59:15 "AIUNIT: Creating BAF_Soldier_L_DDPM by <NULL-object> at [10730.8,11098.2,0]. Result:<NULL-object> | Loadout:["M14_EP1","20Rnd_762x51_DMR"] / Num:5"
19:59:15 Cannot create entity with abstract type BAF_Soldier_L_DDPM (scope = private?)
19:59:15 "AIUNIT: Creating BAF_Soldier_L_DDPM by <NULL-object> at [10731.8,11099.2,0]. Result:<NULL-object> | Loadout:true / Num:3"
19:59:15 Error in expression <llWeapons _aiunit;


This is what I get in the logs, is this basically telling me that it cannot produce that unit type/skin or something? I don't fully understand.
 
Code:
_aiwep = _ailoadout select 0;
_aiammo = _ailoadout select 1;>
19:59:15  Error position: <select 0;
_aiammo = _ailoadout select 1;>
19:59:15  Error select: Type Bool, expected Array,Config entry
19:59:15 File mpmissions\__cur_mp.mbg_celle2\units\add_unit_server.sqf, line 47
19:59:15 "AIUNIT: Spawn initiated: Centre:[10727.8,11095.2,0] | Radius in m:800 | Waypoint number:25"
19:59:15 Cannot create entity with abstract type BAF_Soldier_L_DDPM (scope = private?)
19:59:15 "AIUNIT: Creating BAF_Soldier_L_DDPM by <NULL-object> at [10728.8,11096.2,0]. Result:<NULL-object> | Loadout:["M4A1_AIM_SD_camo","30Rnd_556x45_StanagSD"] / Num:1"
19:59:15 Cannot create entity with abstract type BAF_Soldier_L_DDPM (scope = private?)
19:59:15 "AIUNIT: Creating BAF_Soldier_L_DDPM by <NULL-object> at [10729.8,11097.2,0]. Result:<NULL-object> | Loadout:["AK_47_M","30Rnd_762x39_AK47"] / Num:0"
19:59:15 Cannot create entity with abstract type BAF_Soldier_L_DDPM (scope = private?)
19:59:15 "AIUNIT: Creating BAF_Soldier_L_DDPM by <NULL-object> at [10730.8,11098.2,0]. Result:<NULL-object> | Loadout:["M14_EP1","20Rnd_762x51_DMR"] / Num:5"
19:59:15 Cannot create entity with abstract type BAF_Soldier_L_DDPM (scope = private?)
19:59:15 "AIUNIT: Creating BAF_Soldier_L_DDPM by <NULL-object> at [10731.8,11099.2,0]. Result:<NULL-object> | Loadout:true / Num:3"
19:59:15 Error in expression <llWeapons _aiunit;


This is what I get in the logs, is this basically telling me that it cannot produce that unit type/skin or something? I don't fully understand.
My guess would be that the soldier type you're trying to create is banned on that map.
 
My server is filling up and I have to stop testing, but I came across some fun stuff.

You can set a players side using "side player = east", or at least thats what the command description says, but everytime i try to set it, i get stuck on loading.. but theoretically you should be able to go into playerSetup and playerSync and do an if for a certain level of humanity, and set their side to east if its below a certain number, and back to west if it's above it. Can anyone test this?

http://community.bistudio.com/wiki/side
 
Has anybody tried setting the side to ENEMY. DayZ has changed a lot with sides but the wiki claims that will make them enemy of everyone..
 
Honestly, axeman you do some great work.

I'm willing to test anything you got working... My playerbase is the understanding type that enjoy toying around with new things regardless of bugs / restarts.. Message me if you have anything for me to try out (I'm on Dayz.ST)

Edit - Yes it was the unit type that was banned, I simply changed that and it was fine...
Ingame the AI didnt seem to find anything or anyone hostile.
 
Has anybody tried setting the side to ENEMY. DayZ has changed a lot with sides but the wiki claims that will make them enemy of everyone..
I tried doing this in playerUpdate and playerSync, but I got a loading screen.. I might have had some syntax problems or something, and my server started filling up before i could finish testing..

Would you mind testing the "side player = west;" approach for bandits? I think you might be able to make it work, because you're FAR better at this than me. If you can get it to work for bandits, I can make it work for zombies, and then zombies will attack AI as well.
 
Honestly, axeman you do some great work.

I'm willing to test anything you got working... My playerbase is the understanding type that enjoy toying around with new things regardless of bugs / restarts.. Message me if you have anything for me to try out (I'm on Dayz.ST)

Edit - Yes it was the unit type that was banned, I simply changed that and it was fine...
Ingame the AI didnt seem to find anything or anyone hostile.
I am on DayZ.ST as well, and I had a problem with them not attacking zombies, so I had to borrow a simple hack from Buttface that I linked earlier in this thread that makes the zombies ENEMY faction so that the AI will kill them. Zombies still don't attack the AI though. To get them to attack you, in your factions file, set "RESISTANCE setFriend [WEST,0]" I noticed that they prefer to attack you over zombies if you do that, so I set mine to "RESISTANCE setFriend [WEST,.6]" and they seem to prefer zombies to players, but once zombies are done, you're on the menu.
 
I am on DayZ.ST as well, and I had a problem with them not attacking zombies, so I had to borrow a simple hack from Buttface that I linked earlier in this thread that makes the zombies ENEMY faction so that the AI will kill them. Zombies still don't attack the AI though. To get them to attack you, in your factions file, set "RESISTANCE setFriend [WEST,0]" I noticed that they prefer to attack you over zombies if you do that, so I set mine to "RESISTANCE setFriend [WEST,.6]" and they seem to prefer zombies to players, but once zombies are done, you're on the menu.

CIVILIAN setFriend [RESISTANCE,0];//Zeds attack AI units

.. Is it possible to add a line that would make Zombies prefer attacking players over AI or is that already set up with what you've just told me?
 
CIVILIAN setFriend [RESISTANCE,0];//Zeds attack AI units

.. Is it possible to add a line that would make Zombies prefer attacking players over AI or is that already set up with what you've just told me?
That line currently does nothing for me. I don't know if it's because I'm using DayZ.ST or what.
 
CIVILIAN setFriend [RESISTANCE,0];//Zeds attack AI units

.. Is it possible to add a line that would make Zombies prefer attacking players over AI or is that already set up with what you've just told me?
This is really just a hackfix that happens to work - you'll need to add a line to your init.sqf:

Code:
zombie_generate = compile preprocessFileLineNumbers "scripts\compile\zombie_generate.sqf";

In the directory quoted above, insert an extracted copy of your zombie_generate.sqf from dayz.pbo and insert this line at the bottom of the sqf file:

Code:
{ _x addRating -20000; } forEach allMissionObjects "zZombie_Base";

This will cause all AI to become hostile to zombies as they spawn. Note that this means that the AI will continuously engage zombies on sight, so you'll end up with piles of dead corpses lying around and possibly continuous gunfire if there are enough zombies being spawned.
I had to do this, which replaces the effect that others seems to get from that line.
 
You have to go to your dayz_code.pbo, which is located in your map folder, in your arma 2 folder. You have to open the pbo and its inside of the compile folder.
 
Alright I've done as you have explained, so between these 2 changes will have AI and zombies attacking each other, and AI attacking players?

I noticed in the other thread you were looking into a way for the AI to differentiate Bandits, survivors and heroes... That would tie in perfectly with having custom bases that only people of appropriate humanity level could enter. If you manage to figure it out, hope you share.
 
Back
Top