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

Discussion in 'Mission Editing' started by axeman, Feb 19, 2013.

  1. axeman

    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 (Text):
    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 (Text):
    _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 (Text):

        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 (Text):
    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 (Text):
    5 addWaypoint !"\"addWaypoint\"," !"units\add_unit_server.sqf"
    Also, edit lines #114 addWeapon and #118 addMagazine. Add:
    Code (Text):
    !"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..

    Attached Files:

    Jokaru, LarryLost, Fox and 8 others like this.
  2. Jonassm

    Jonassm Well-Known Member

    Like it. Might add it to my server at Fallujah Airfield :D
    axeman likes this.
  3. Manatee Hunter

    Manatee Hunter Valued Member!

    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?
  4. Jonassm

    Jonassm Well-Known Member

    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.
  5. axeman

    axeman OpenDayZ Rockstar!

    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.
  6. axeman

    axeman OpenDayZ Rockstar!

    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 :)
  7. danyworms

    danyworms New Member

    works on dayz.st but randomly shoot
  8. axeman

    axeman OpenDayZ Rockstar!

    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.
  9. axeman

    axeman OpenDayZ Rockstar!

    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 (Text):
    _aiunit setSkill ["spotDistance",1];
  10. kain6699

    kain6699 New Member

    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
  11. kain6699

    kain6699 New Member

    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.
  12. biokemisten

    biokemisten Well-Known Member

    It doesnt work for me, i use dayz.st as well, running taviana ALL my vehicles duplicates.


  13. kain6699

    kain6699 New Member

    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
    axeman and biokemisten like this.
  14. biokemisten

    biokemisten Well-Known Member

    Thank you, ill try that.
  15. biokemisten

    biokemisten Well-Known Member

    That didn't work either, i believe i've done something wrong in my init.sqf
    here is the rest of the fragment

  16. DonCapello

    DonCapello New Member

    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!
  17. piXel

    piXel Valued Member!

    I like this. Definitely will check it out.
    Cheers,


    .
  18. axeman

    axeman OpenDayZ Rockstar!

    You have declared _serverMonitot twice, don't know that it will stop the ai. Have you packaged the new files in your mission .pbo ?
    biokemisten likes this.
  19. biokemisten

    biokemisten Well-Known Member

    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
  20. kain6699

    kain6699 New Member

    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?

Share This Page