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

Axeman,

Do you know if I can use this script, with DayZAI or Sarge AI. Cause what I'm trying to do is make it so that ppl can take control of the added AI.
 
The best way is to go into your 3d editor and create a group of units and give them a series of waypoints. it will be saved as a sqf file then you can add that entire sqf file into your server to create the ai and waypoints statically.
 
Ok i did try and do it in the mission file . Just like buildings true sqf
So i place the sqf in the server file and call it. In the server monitor sqf? Im new to this kinda ai spawn
Thanks

And then add the weapons and gear in the init of the ai right ? And can change the skin in the sqf ?
Sorry for al the questions
 
Yeah, it should work fine like that. I made a video about it, I think. Now if you create the sqf in the editor and save it, then copy to your server you have to delete the stuff ABOVE the actual units, and the stuff BELOW the units so you just have the createunit blocks. And your server will try and delete the AI with a message in your log "killed a hacker" so you need to use the SargeAI fix where you add _unit setvariable["sarge",1]; to EACH ai in the file and then in your server_cleanup.fsm you check for the sarge variable so they don't get deleted by the cleanup script.
AND if you add in any vehicles you will have to add in a dayz_serverobjectmonitor .
I will post example code below. This is a 'bus route' as designed by Axman. I set the AI to be invunlerable using the handledamage false, so that players couldn't kill the bus drivers. Of note is that waypoints are followed by GROUPS, not units. So it doesn't matter if the group is 1 soldier, or 10 soldiers a UH1H and bicycle, the GROUP will follow the waypoints and wait for each other.
See the variable PVDZE_serverObjectMonitor (I mentioned it above). That is for Epoch, if you are using Dayz or overwatch then that variable needs to be dayz_serverObjectMonitor and that needs to be set only for vehicles.
Code:
//_blueBus and _redBus

_this = createCenter civilian;
_center_2 = _this;

_grpBlue = createGroup _center_2;

_unit_2 = objNull;
if (true) then
{
  _this = _grpBlue createUnit ["Policeman", [1616.7765, 2233.0764, 1.4383841e-007], [], 0, "CAN_COLLIDE"];
  _unit_2 = _this;
  _this setUnitAbility 0.60000002;
  if (true) then {_grpBlue selectLeader _this;};
       _this setVariable ["Sarge",1,true];
    _this allowDammage false;
     _this addEventHandler ["HandleDamage", {false}];

     };

_unit_3 = objNull;
if (true) then
{
  _this = _grpBlue createUnit ["Policeman", [1623.1814, 2232.6938, -5.2183168e-008], [], 0, "CAN_COLLIDE"];
  _unit_3 = _this;
  _this setUnitAbility 0.60000002;
  if (false) then {_grpBlue selectLeader _this;};
       _this setVariable ["Sarge",1,true];
        _this allowDammage false;
     _this addEventHandler ["HandleDamage", {false}];

};

_vehicle_0 = objNull;
if (true) then
{
  _this = createVehicle ["Ikarus", [1599.1127, 2242.4331, -2.3079338e-008], [], 0, "CAN_COLLIDE"];
  _vehicle_0 = _this;
  _this setDir -71.269524;
  _this setPos [1599.1127, 2242.4331, -2.3079338e-008];
    _this setVariable ["Sarge",1,true];
    _this allowDammage false;
    _this addEventHandler ["HandleDamage", {false}];
    _this setVariable ["ObjectID", [_dir,getPos _this] call dayz_objectUID2, true];
    PVDZE_serverObjectMonitor set [count PVDZE_serverObjectMonitor,_this];
    [_this,"Ikarus"] spawn server_updateObject;
  _blueBus = _this;
};

_this = _grpBlue addWaypoint [[1594.5338, 2244.3137, 2.1127926e-007], 0];
_this setWaypointType "GETIN NEAREST";
_this setWaypointCombatMode "RED";
_this setWaypointSpeed "FULL";
_this setWaypointBehaviour "CARELESS";
_waypoint_0 = _this;

_this = _grpBlue addWaypoint [[732.96844, 1893.0231, -1.8595892e-007], 0];
_waypoint_1 = _this;

_this = _grpBlue addWaypoint [[678.28821, 1865.5563, 2.2065069e-007], 0];
_this setWaypointBehaviour "COMBAT";
_waypoint_2 = _this;

_this = _grpBlue addWaypoint [[650.99005, 1850.6868, 1.8210267e-007], 0];
_waypoint_3 = _this;

_this = _grpBlue addWaypoint [[690.61407, 1848.1786, 4.1011663e-007], 0];
_waypoint_4 = _this;

_this = _grpBlue addWaypoint [[790.48114, 1920.0989, 1.1124575e-007], 0];
_this setWaypointBehaviour "CARELESS";
_waypoint_5 = _this;

_this = _grpBlue addWaypoint [[1830.3545, 2214.7742, 1.029548e-007], 0];
_this setWaypointBehaviour "CARELESS";
_this setWaypointTimeout [10, 10, 10];
_waypoint_6 = _this;

_this = _grpBlue addWaypoint [[4517.0571, 2445.3359, 2.1862797e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_7 = _this;

_this = _grpBlue addWaypoint [[6348.7422, 2429.8325, 7.1187969e-008], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_8 = _this;

_this = _grpBlue addWaypoint [[6566.2964, 2864.8196, 5.2154064e-008], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_9 = _this;

_this = _grpBlue addWaypoint [[9966.5996, 2052.2791, -5.9138983e-008], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_10 = _this;

_this = _grpBlue addWaypoint [[10408.438, 2246.1348, 1.0544318e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_11 = _this;

_this = _grpBlue addWaypoint [[10800.207, 2567.8381, 0.057557106], 0];
_waypoint_12 = _this;

_this = _grpBlue addWaypoint [[12009.484, 3479.1714, 7.6106517e-008], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_13 = _this;

_this = _grpBlue addWaypoint [[13386.558, 5383.3008, 0], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_14 = _this;

_this = _grpBlue addWaypoint [[13461.66, 6236.2959, -1.139706e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_15 = _this;

_this = _grpBlue addWaypoint [[13282.458, 6982.1265, 1.7404091e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_16 = _this;

_this = _grpBlue addWaypoint [[12989.876, 8336.4756, 0], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_17 = _this;

_this = _grpBlue addWaypoint [[13100.437, 10335.808, 0], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_18 = _this;

_this = _grpBlue addWaypoint [[13072.771, 10375.53, 0], 0];
_this setWaypointBehaviour "COMBAT";
_waypoint_19 = _this;

_this = _grpBlue addWaypoint [[12998.04, 10327.238, 0], 0];
_this setWaypointBehaviour "CARELESS";
_waypoint_20 = _this;

_this = _grpBlue addWaypoint [[12832.215, 9958.292, 0], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_21 = _this;

_this = _grpBlue addWaypoint [[12308.234, 9552.7021, -2.1222513e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_22 = _this;

_this = _grpBlue addWaypoint [[12151.067, 9043.1436, -1.3522804e-006], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_23 = _this;

_this = _grpBlue addWaypoint [[12823.489, 8593.7803, -2.8405339e-008], 0];
_waypoint_24 = _this;

_this = _grpBlue addWaypoint [[12916.135, 8521.3438, -2.2631139e-007], 0];
_this setWaypointBehaviour "COMBAT";
_waypoint_25 = _this;

_this = _grpBlue addWaypoint [[13277.846, 6979.3608, -1.8641003e-007], 0];
_this setWaypointBehaviour "CARELESS";
_this setWaypointTimeout [10, 10, 10];
_waypoint_26 = _this;

_this = _grpBlue addWaypoint [[13455.297, 6232.3125, 1.2273085e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_27 = _this;

_this = _grpBlue addWaypoint [[13383.92, 5478.1475, -7.1246177e-008], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_28 = _this;

_this = _grpBlue addWaypoint [[12045.63, 3488.9026, -1.3016688e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_29 = _this;

_this = _grpBlue addWaypoint [[10888.996, 2773.6587, 1.6269041e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_30 = _this;

_this = _grpBlue addWaypoint [[10332.829, 2159.7454], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_31 = _this;

_this = _grpBlue addWaypoint [[6424.7744, 2705.928, 0], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_32 = _this;

_this = _grpBlue addWaypoint [[4570.7388, 2434.6482, -3.9755832e-008], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_33 = _this;

_this = _grpBlue addWaypoint [[3581.5159, 2454.2285, -1.2641249e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_34 = _this;

_this = _grpBlue addWaypoint [[1853.936, 2230.4497, 1.0876101e-007], 0];
_this setWaypointTimeout [10, 10, 10];
_waypoint_35 = _this;

_this = _grpBlue addWaypoint [[1657.6793, 2222.6558, -1.6621925e-007], 0];
_waypoint_36 = _this;

_this = _grpBlue addWaypoint [[1633.3134, 2230.5825, 9.9928002e-008], 0];
_this setWaypointType "CYCLE";
_waypoint_37 = _this;
 
also .. It could have just been errors on my part, but I have had issues putting AI spawn scripts into the dayz_server.pbo but they always work perfectly in the mission folder and exec them from the init.sqf (or some other file at a later point)
 
In gonna try this tomorrow.
When i am back from work
Thanks for the help
Its good to know i was thinking in the right direction
Cus i learnt all i know from this forum
 
let me know how it goes. Once you have done it a few times, the editor is wicked easy and does all the work for you. Just remember to delete the stuff before and after, just like the file I posted. And then you have to add in the 'sarge' and/or dayz_serverobjectmonitor stuff.
 
HAHA thanks alot
this gonna make my server nice and clean thanks alotmega thanks super awesome thanks
If you where a chick i would kiss you

edit i dont need the sarge thingy my server dont use that stuff...
new overpochins server :)

One more question.....maybe a stupid one :)
How can i make the ai use the vehicle's i spawn then with
Thankssssssssss
 
Last edited:
ok the ai is walking :)
I made them east is this a good thing if i want them to be bandit ?
Now the thing is afther some test they shoot ther own group till one skin remains
And in the editor the ai use a car .
But not when its on the server

Thanks for all the help
And i did a reply on @Cyanotic his post
i rent a server with one klick overpochins instal
 
Bandits are East so yes. do you have a setfriend setup anywhere for side relations? https://community.bistudio.com/wiki/setFriend
you can at the top of your AI file add
west setfriend[east,0];
east setfriendl[west,0];

Try to set them all in a skin that is east. In arma, if you use a West skin, you are west. And I have never had that issue with AI but who knows. There is some debugging that could be done. Save this code as debug.sqf in your mission folder and at the bottom of your init.sqf
execvm "debug.sqf";
Code:
while {true} do {
hint format["Target is side: %1",side cursortarget];
sleep 1;
};
Now make sure you have god mode on so they don't kill you and when you look at a target it should pop up a hint box showing you what side they are on.

As for the vehicle. I don't know, check the waypoint ... does the vehicle exist on the server where you can get into it?
 
ok there it is my ai.sqf
http://pastebin.com/mrcdKafc EDIT This a new test
i cant make a spoiler cus its more then 10000 characters
its on pastebin now :)
welcome to take a look and maybe help me out some things
i made a test they need to follow a fence and cycly trought the waipoints
the ai doing perfect in the editor
but when i upload to the server they tend to ghet lost and follow a weird route
and they dont wanne go in a car when i upload to the server

All help is welcome
and i hope to learn alot from you all
Mega thanks
 
Last edited:
I am on a day vacation and can't download to my cellphone.
For future note post the files to pastebin.com then we can just click and view it
 
I am on a day vacation and can't download to my cellphone.
For future note post the files to pastebin.com then we can just click and view it

Ok on pastebin now
http://pastebin.com/mrcdKafc EDIT this is new
i did make a new test
ai carry bp to and testting is out
they dont shoot each ather !! i fix that thanks for the help with the friend thing


EDIT i think i know how to do this
i made a few stupid mistakes with groups/static guns
Thanks for all the help if i run in to troubles i wil come back :):)
 
Last edited:
I think I see some issues.
I have never seen anyone use setvehiclevarname .. unneeded?
when setting the unit gear you assign the gear to this instead of _this. imho _this gets confusing. best to assign a name right off the bat like _aiUnit and use that. it describes what you are editing.

You are using setvehicleinit. Therefore at the end of your file you would need
processinitcommands
Easier to just not use setvehicleinit.

I took your pastebin and edited it. Untested, but should work. Being significantly smaller number of lines its easier to read. I used two variables for the units. _aiLeader and _aiUnit.
I used FOR loops to add the multiple magazines. https://community.bistudio.com/wiki/Control_Structures#for-Loop
We can add this code to randomize the skins:
_aiSkin = ["skin1","skin2","skin3"] bis_fnc_selectrandom;
and then create the unit with
_aiLeader = _group_1 createUnit [_aiSkin, [22121.715, 19438.953, 0], [], 0, "CAN_COLLIDE"];
then do the same thing for the weapon or to add in the gear. The only issue with the weapon is you want to add the correct type of ammo so you would use a 2 dimensional array
_weapon =[["m16a4","m16a4_ammo"],["ak107","ak107_ammo"]]bis_fnc_selectrandom;
and then you would substitute _weapon select 0 for the weapon and _weapon select 1 for the ammo.
Code:
_center_0= createCenter resistance;
_center_0 setFriend [east, 0];
_center_0 setFriend [west, 0];
_group_1 = createGroup _center_0;


//----------------------------------CREATE GROUP LEADER------------------------------------------------------
_aiLeader = _group_1 createUnit ["gsc_eco_stalker_head_duty", [22121.715, 19438.953, 0], [], 0, "CAN_COLLIDE"];
removeAllWeapons _aiLeader;
_aiLeader addWeapon "M16A4";
for "_counter" from 0 to 4 do//LOOP THROUGH 5 TIMES
    {_aiLeader addMagazine "30Rnd_556x45_Stanag"; };
_aiLeader addMagazine "HandGrenade_West";
_aiLeader addWeapon "Colt1911";
for "_counter" from 0 to 4 do
    {_aiLeader addMagazine "7Rnd_45ACP_1911";};
_aiLeader addWeapon "NVGoggles"; 
_aiLeader addWeapon "ItemGPS"; 
_aiLeader addbackpack "us_backpack_ep1"; 
(Unitbackpack _aiLeader) addmagazinecargo ["30Rnd_556x45_Stanag",5];
_aiLeader setUnitAbility 0.60000002;
_group_1 selectLeader _aiLeader;

//--------------------------------CREATE GROUP UNITS------------------------------------------------------------
for "_groupsize" from 0 to 4 do
{
_aiUnit = _group_1 createUnit ["gsc_eco_stalker_head_duty", [22121.715, 19438.953, 0], [], 0, "CAN_COLLIDE"];
removeAllWeapons _aiUnit;
_aiUnit addWeapon "M16A4";
for "_counter" from 0 to 4 do
    {_aiUnit addMagazine "30Rnd_556x45_Stanag"; };
_aiUnit addMagazine "HandGrenade_West";
_aiUnit addWeapon "Colt1911";
for "_counter" from 0 to 4 do
    {_aiUnit addMagazine "7Rnd_45ACP_1911";};
_aiUnit addWeapon "NVGoggles"; 
_aiUnit addWeapon "ItemGPS"; 
_aiUnit addbackpack "us_backpack_ep1"; 
(Unitbackpack _aiUnit) addmagazinecargo ["30Rnd_556x45_Stanag",5];
_aiUnit setUnitAbility 0.60000002;

};


//-------------------------------------- GROUP WAYPOINTS------------------------------------------------------
_this = _group_1 addWaypoint [[22186.225, 19310.393], 0];
_this setWaypointCombatMode "RED";
_this setWaypointFormation "COLUMN";
_this setWaypointSpeed "LIMITED";
_this setWaypointBehaviour "AWARE";
_waypoint_0 = _this;

_this = _group_1 addWaypoint [[22320.545, 19409.922, 0], 0];
_this setWaypointCombatMode "RED";
_this setWaypointFormation "COLUMN";
_this setWaypointSpeed "LIMITED";
_this setWaypointBehaviour "AWARE";
_waypoint_1 = _this;

_this = _group_1 addWaypoint [[22255.344, 19476.506, 0], 0];
_this setWaypointCombatMode "RED";
_this setWaypointFormation "COLUMN";
_this setWaypointSpeed "LIMITED";
_this setWaypointBehaviour "AWARE";
_waypoint_2 = _this;

_this = _group_1 addWaypoint [[22130.701, 19445.404, 0], 0];
_this setWaypointType "CYCLE";
_this setWaypointCombatMode "RED";
_this setWaypointFormation "COLUMN";
_this setWaypointSpeed "LIMITED";
_this setWaypointBehaviour "AWARE";
_waypoint_3 = _this;
 
Last edited:
Back
Top