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

dude, I added in zomber generator and they wont shoot zeds or players, have Skype or something to help me?
Did you follow the instructions? You have to add a line of code to the bottom, and put a link to the file in your mission\init.sqf

It definitely shouldn't break anything. Especially players.
 
if you added the zombie_generator.sqf properly, and it's not shooting ANYTHING, then you're likely not giving them ammo..
 
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",.8];
    _aiunit setSkill ["aimingShake",1];
    _aiunit setSkill ["aimingSpeed",1];
    _aiunit setSkill ["endurance",1];
    _aiunit setSkill ["spotDistance",.8];
    _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];

^^ add unit server ^^

vv factions vv


Code:
waitUntil{initialized};
//0Day
createCenter east;
createCenter resistance;
//Survivors
WEST setFriend [RESISTANCE,.2];
WEST setFriend [EAST,.2];
//Bandits
EAST setFriend [RESISTANCE,.2];
EAST setFriend [WEST,.2];
//AI Units
RESISTANCE setFriend [WEST,.2];
RESISTANCE setFriend [EAST,.2];
RESISTANCE setFriend [CIVILIAN,0.2];//AI Units attack zeds
 
//CIVILIAN setFriend [RESISTANCE,.2];//Testing Zeds attack AI units, doesn't seem to help..
 
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",.8];
    _aiunit setSkill ["aimingShake",1];
    _aiunit setSkill ["aimingSpeed",1];
    _aiunit setSkill ["endurance",1];
    _aiunit setSkill ["spotDistance",.8];
    _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];

^^ add unit server ^^

vv factions vv


Code:
waitUntil{initialized};
//0Day
createCenter east;
createCenter resistance;
//Survivors
WEST setFriend [RESISTANCE,.2];
WEST setFriend [EAST,.2];
//Bandits
EAST setFriend [RESISTANCE,.2];
EAST setFriend [WEST,.2];
//AI Units
RESISTANCE setFriend [WEST,.2];
RESISTANCE setFriend [EAST,.2];
RESISTANCE setFriend [CIVILIAN,0.2];//AI Units attack zeds
 
//CIVILIAN setFriend [RESISTANCE,.2];//Testing Zeds attack AI units, doesn't seem to help..
put your mission\init up here, and zombie_generate.. you can just do the files instead of this code quote..
 
Code:
startLoadingScreen ["","DayZ_loadingScreen"];
enableSaving [false, false];
 
dayZ_instance = 2978;    //The instance
hiveInUse    =    true;
initialized = false;
dayz_previousID = 0;
 
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;
 
zombie_generate = compile preprocessFileLineNumbers "scripts\zombie_generate.sqf";
 
//BaseBuilding start
 
player_build = compile preprocessFileLineNumbers "tweaks\player_build.sqf";
player_disarmBomb = compile preprocessFileLineNumbers "tweaks\player_disarmBomb.sqf";
player_recipeBook = compile preprocessFileLineNumbers "tweaks\player_recipeBook.sqf";
player_remove = compile preprocessFileLineNumbers "tweaks\player_remove.sqf";
fnc_usec_selfActions = compile preprocessFileLineNumbers "fixes\fn_selfActions.sqf";
remProc = true;
hasBuildItem = false;
 
CODEINPUT = [];
keyCode = [];
keyValid = false;
 
//BaseBuilding end
 
player setVariable ["BIS_noCoreConversations", true];
enableRadio false;
 
"filmic" setToneMappingParams [0.153, 0.357, 0.231, 0.1573, 0.011, 3.750, 6, 4]; setToneMapping "Filmic";
 
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 = [[2645.8,6945.16,0],60,8,6] execVM "units\add_unit_server.sqf";//Chernogorsk good one
    _aispawn = [[3053.34,8034.07,0],60,8,6] execVM "units\add_unit_server.sqf";//Chernogorsk 2
_aispawn = [[3956.76,4229.46,0],60,8,6] execVM "units\add_unit_server.sqf";//Chernogorsk 3
_aispawn = [[3572.71,1374.62,0],120,8,6] execVM "units\add_unit_server.sqf";//Chernogorsk 4
};
 
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";
   
    //BaseBuilding start
    _null = [] execVM "tweaks\player_addActions.sqf";
    _null = [] execVM "tweaks\take_itemFix.sqf";
    _null = [] execVM "tweaks\player_bomb.sqf";
    //BaseBuilding end
 
};



vv zombie generate vv

Code:
private["_position","_doLoiter","_unitTypes","_isNoone","_loot","_array","_agent","_type","_radius","_method","_nearByPlayer","_attempt","_myDest","_newDest","_lootType"];
_position =    _this select 0;
_unitTypes =    _this select 1;
_doLoiter =    true;
 
_isNoone =    {isPlayer _x} count (_position nearEntities ["CAManBase",30]) == 0;
_loot =    "";
_array =    [];
_agent =    objNull;
 
//Exit if a player is nearby
if (!_isNoone) exitWith {};
 
if (count _unitTypes == 0) then {
    _unitTypes =    []+ getArray (configFile >> "CfgBuildingLoot" >> "Default" >> "zombieClass");
};
_type = _unitTypes call BIS_fnc_selectRandom;
 
//Create the Group and populate it
//diag_log ("Spawned: " + _type);
_radius = 0;
_method = "CAN_COLLIDE";
if (_doLoiter) then {
    _radius = 40;
    _method = "NONE";
};
//diag_log ("Spawned: " + str([_type, _position, [], _radius, _method]));
_agent = createAgent [_type, _position, [], _radius, _method];
 
if (_doLoiter) then {
    _agent setPosATL _position;
    //_agent setVariable ["doLoiter",true,true];
} else {
    _agent setVariable ["doLoiter",false,true];
};
dayz_spawnZombies = dayz_spawnZombies + 1;
 
//diag_log ("CREATE INFECTED: " + str(_this));
 
_position = getPosATL _agent;
_nearByPlayer = ({isPlayer _x} count (_position nearEntities ["CAManBase",30])) > 0;
 
if (random 1 > 0.7) then {
    _agent setUnitPos "Middle";
};
 
//diag_log ("CREATED: "  + str(_agent));
 
 
 
//_agent setVariable["host",player,true];
if (_doLoiter) then {
    if (_nearByPlayer) then {
        _attempt = 0;
        while {_nearByPlayer} do {
            _position = [_position,0,20,10,0,20,0] call BIS_fnc_findSafePos;
            _agent setPos _position;
            _nearByPlayer = ({isPlayer _x} count (_position nearEntities ["CAManBase",30])) > 0;
            _attempt = _attempt + 1;
            if (_attempt > 10) exitWith {};
        };
        _agent setPos _position;
    };
};
 
if (isNull _agent) exitWith {
    dayz_spawnZombies = dayz_spawnZombies - 1;
};
 
_isAlive = alive _agent;
 
_myDest = getPosATL _agent;
_newDest = getPosATL _agent;
_agent setVariable ["myDest",_myDest];
_agent setVariable ["newDest",_newDest];
 
//Add some loot
_rnd = random 1;
if (_rnd > 0.3) then {
    _lootType =        configFile >> "CfgVehicles" >> _type >> "zombieLoot";
    if (isText _lootType) then {
        _array = []+ getArray (configFile >> "cfgLoot" >> getText(_lootType));
        if (count _array > 0) then {
            _loot = _array call BIS_fnc_selectRandomWeighted;
            //diag_log ("Zed Loot: " +(_loot));
            if(!isNil "_array") then {
                _agent addMagazine _loot;
            };
        };
    };
};
 
//Start behavior
_id = [_position,_agent] execFSM "\z\AddOns\dayz_code\system\zombie_agent.fsm";
{ _x addRating -20000; } forEach allMissionObjects "zZombie_Base";
 
is zombie_generate.sqf inside of a scripts folder or a units folder, because your directory says units.. as for the code inside of zombie_generate and the link to it in your init, they are fine.

You said the zombies aren't attacking you right away?
 
zomber generate is in scripts folder, and ais wont attack anything, but if I kill like 3 of tem they will attack me
 
zomber generate is in scripts folder, and ais wont attack anything, but if I kill like 3 of tem they will attack me
where are your files located?

according to your code, you should have:
Dayz_Factions\init.sqf
units\add_unit_server.sqf
scripts\zombie_generate.sqf
 
Honestly, I would start over and do what's in my Simple AI Tutorial. Keep the worldspaces for your current spawns though. I'm almost done working on a new version of it if you want to wait. I might not finish before my server is shut down though.
 
Code:
private["_player","_killer","_aispawnpos","_wpradius","_wpnum","_numunits","_unitType","_faction","_baseSkill","_potentialSkill","_gearset","_respawnTime","_killerHumanity","_killerKills"];
_player = this select 0;
_killer = this select 1;
_aispawnpos = this select 2;
_wpradius = this select 3;
_wpnum = this select 4;
_numunits = this select 5;
_unitType = this select 6;
_faction = this select 7;
_baseSkill = this select 8;
_potentialSkill = this select 9;
_gearSet = this select 10;
_respawnTime = this select 11;
 
_killerHumanity = _killer getVariable["humanity",0];
null = _killer setVariable["humanity",_killerHumanity-1000,true];
diag_log format["dropping %1 humanity to %2",name _killer,_killerHumanity-1000];
if ((_killerHumanity-1000) < 2500) then {
    _killer addRating -10000;
};
 
_killerKills = _killer getVariable["humanKills",0];
null = _killer setVariable["humanKills",_killerKills+1,true];
diag_log format["increased %1 kills to %2",name _killer,_killerKills+1];
 
sleep _respawnTime;
_aispawn = [_aispawnpos,_wpradius,_wpnum,_numunits,_unitType,_faction,_baseSkill,_potentialSkill,_gearSet,_respawnTime] execVM "scripts\add_unit_server.sqf";
diag_log format["respawning a unit"];

If someone can tell me what's wrong with this file, then I can get the damn respawns working..

I'm passing this file MPKilled with all the extra parameters..

Code:
 6:41:18 "dropping  humanity to scalar"
6:41:18 "increased  kills to scalar"
6:41:18 "respawning a unit"

This is my rpt

Code:
_aiunit addMPEventHandler ["MPkilled", {null = _this+[_aispawnpos,_wpradius,_wpnum,1,_unitType,_faction,_baseSkill,_potentialSkill,_gearSet,_respawnTime] execVM "scripts\unit_killed.sqf";}];

and this is how i'm passing my variables, which is how bohemia says you have to do it. building the array of _this with additional positions in the array, rather than passing them as arguments separate from _this.

The error makes me think that i'm pulling the array wrong though and i'm not getting the proper data.
 
This worked perfect on my dayz.st server. Definitely went with them being unfriendly and shooting on sight at anyone they see. I made 3 different patrols in cherno each consisting of 15 units, just for fun, and I didn't survive for very long... Do the NPCs respawn? or is it a one time spawn until restart?
 
Back
Top