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

Code:
private["_ai","_magazinetype","_entity_array","_humanity","_humanitylimit","_sleeptime","_detectrange"];
_ai = _this select 0;
//_weapons = weapons _ai;
//_weapon = _weapons select 0;
//_magazinetype = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select 0;
 
_detectrange=300;
_humanitylimit=2499;
_humanity=0;
_sleeptime=0.5;
 
while {alive _ai} do {
    //diag_log "heartbeat";
    _entity_array = (position _ai) nearEntities [["zZombieBase","Bandit1_DZ","BanditW1_DZ"],_detectrange];
    {
        if(vehicle _ai != _ai) then { // NPC in a vehicle
            if(isPlayer _x) then {
                _humanity= _x getVariable ["humanity",0];
                If (_humanity < _humanitylimit && rating _x > -10000) then {
                    diag_log format["reducing rating for player: %1",name _x];
                    _x addrating -10000;
                } else {
                    if (_humanity > _humanitylimit && rating _x <= -10000) then {
                        _x addRating 10000;
                    };               
                };
            };
        } else { //NPC on foot
            if(isPlayer _x) then {
                _humanity= _x getVariable ["humanity",0];
                if (_humanity < _humanitylimit && rating _x > -10000) then {
                    diag_log format["reducing rating for player: %1",name _x];
                    _x addrating -10000;
                } else {
                    if (_humanity > _humanitylimit && rating _x <= -10000) then {
                        _x addRating 10000;
                    };
                };
            } else {
                if (typeOf _x == "zZombieBase") then {
                    _x addRating -10000;
                };
            };
        };
 
    } forEach _entity_array;
 
//    // refresh ammo
//    if !(someAmmo _ai) then {
//        {_ai removeMagazine _x} forEach magazines _ai;
//        _ai addMagazine _magazinetype;
//    };
 
    sleep _sleeptime;
};

Aside from the commented out code, which I think I just figured out my problem and those wont be commented out in a sec, does this code look right?
 
This isn't working for either bandits or zombies.

Code:
case 3 : {
    _ailoadout=[_resistanceMilitiaRifle,_resistanceMilitiaAmmo];
    _aiwep = _ailoadout select 0;
    _aiammo = _ailoadout select 1;
   
    _resistanceMilitiaSkin createUnit [_unitpos, _aiGroup,"_aiunit=this",1,"Private"];
                               
    _aiunit enableAI "TARGET";
    _aiunit enableAI "AUTOTARGET";
    _aiunit enableAI "MOVE";
    _aiunit enableAI "ANIM";
    _aiunit enableAI "FSM";
    _aiunit allowDammage true;
    _aiunit setCombatMode "RED";
    _aiunit setBehaviour "COMBAT";
    _aiunit addMPEventHandler ["MPkilled", {Null = _this execVM "scripts\unit_killed.sqf";}];
    _aiunit setVehicleInit "null = [this] execVM 'scripts\unit_init.sqf'";
   
    //clear default weapons / ammo
    removeAllWeapons _aiunit;
    removeAllItems _aiunit;
    //add weapon
    _aiunit addMagazine _aiammo;
    _aiunit addweapon _aiwep;                       
    _gearCount = count _resistanceMilitiaGear;
    for [{z = 0},{z < _gearCount},{z = z + 1}] do {
        _currentItem = _resistanceMilitiaGear select z;
        _aiunit addMagazine _currentItem;
    };
    //set skills
    for [{_i=0},{_i<10},{_i=_i+1}] do {
        _totalSkill = (floor(random _skillRemainder)+_baseSkill)/10;
        _aiunit setSkill [_aiSkills select _i,_totalSkill];
    };                   
};
That's where I create the unit.
Code:
private["_ai","_magazinetype","_entity_array","_humanity","_humanitylimit","_sleeptime","_detectrange"];
_ai = _this select 0;
_weapons = weapons _ai;
_weapon = _weapons select 0;
_magazinetype = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select 0;
 
_detectrange=300;
_humanitylimit=2499;
_humanity=0;
_sleeptime=0.5;
 
while {alive _ai} do {
    //diag_log "heartbeat";
    _entity_array = (position _ai) nearEntities [["zZombieBase","Bandit1_DZ","BanditW1_DZ"],_detectrange];
    {
        if(vehicle _ai != _ai) then { // NPC in a vehicle
            if(isPlayer _x) then {
                _humanity= _x getVariable ["humanity",0];
                If (_humanity < _humanitylimit && rating _x > -10000) then {
                    diag_log format["reducing rating for player: %1",name _x];
                    _x addrating -10000;
                } else {
                    if (_humanity > _humanitylimit && rating _x <= -10000) then {
                        _x addRating 10000;
                    };               
                };
            };
        } else { //NPC on foot
            if(isPlayer _x) then {
                _humanity= _x getVariable ["humanity",0];
                if (_humanity < _humanitylimit && rating _x > -10000) then {
                    diag_log format["reducing rating for player: %1",name _x];
                    _x addrating -10000;
                } else {
                    if (_humanity > _humanitylimit && rating _x <= -10000) then {
                        _x addRating 10000;
                    };
                };
            } else {
                if (typeOf _x == "zZombieBase") then {
                    _x addRating -10000;
                };
            };
        };
 
    } forEach _entity_array;
 
    // refresh ammo
    if !(someAmmo _ai) then {
        {_ai removeMagazine _x} forEach magazines _ai;
        _ai addMagazine _magazinetype;
    };
 
    sleep _sleeptime;
};
That's the script run from the setVehicleInit
 
Code:
private["_ai","_magazinetype","_entity_array","_humanity","_humanitylimit","_sleeptime","_detectrange"];
_ai = _this select 0;
_weapons = weapons _ai;
_weapon = _weapons select 0;
_magazinetype = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select 0;
 
_detectrange=300;
_humanitylimit=2499;
_humanity=0;
_sleeptime=0.5;
 
while {alive _ai} do {
    _entity_array = (position _ai) nearEntities [["zZombieBase","Bandit1_DZ","BanditW1_DZ","Survivor1_DZ","SurvivorW1_DZ","Survivor2_DZ","SurvivorW2_DZ","Citizen1_DZ","Citizen2_DZ","Citizen3_DZ","Citizen4_DZ","police1_DZ","Camo1_DZ","Sniper1_DZ"],_detectrange];
    {
        if(vehicle _ai != _ai) then { // NPC in a vehicle
            if(isPlayer _x) then {
                _humanity= _x getVariable ["humanity",0];
                If (_humanity < _humanitylimit && rating _x > -10000) then {
                    diag_log format["reducing rating for player: %1",name _x];
                    _x addrating -10000;
                } else {
                    if (_humanity > _humanitylimit && rating _x <= -10000) then {
                        _x addRating 10000;
                    };               
                };
            };
        } else { //NPC on foot
            if(isPlayer _x) then {
                _humanity= _x getVariable ["humanity",0];
                if (_humanity < _humanitylimit && rating _x > -10000) then {
                    diag_log format["reducing rating for player: %1",name _x];
                    _x addrating -10000;
                } else {
                    if (_humanity > _humanitylimit && rating _x <= -10000) then {
                        _x addRating 10000;
                    };
                };
            };
        };
        if (typeOf _x == "zZombieBase") then {
            _x addRating -10000;
        };       
 
    } forEach _entity_array;
 
    // refresh ammo
    if !(someAmmo _ai) then {
        {_ai removeMagazine _x} forEach magazines _ai;
        _ai addMagazine _magazinetype;
    };
 
    sleep _sleeptime;
};

This code doesn't make them attack zombies. It's working for Bandits however.
 
any output in the rpt? I recommend to add a couple of diag_logs and see where it fails.
 
ok i have the files sorted, its all in an additional scripts folder. Working on the random spawn logic now.

One thing i realized is that i have a heli and infantry Ai in the same area, Zeds get tagged by the inf as enemy - which leads to the heli attacking zeds as well. No way around this one as far as i can see.

I might release my complete pack later on this week, called SAR_AI. some tuning still necessary though, especially the random patrol setup based on the players position.

Need to figure out a way how to do this, worst case it will need to be via predefined triggers. I dont want to change any original pbo's, neither client nor serverside. The only one i adjust serverside atm is the init.sqf in the missions.pbo, which is fine.
 
sorted the ammo bug ... damn typo ...

Code:
_magazinetype = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select 0;

make this

Code:
_magazintype = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select 0;

whic if statement ? theres a ton of em :)
 
sorted the ammo bug ... damn typo ...

Code:
_magazinetype = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select 0;

make this

Code:
_magazintype = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select 0;

whic if statement ? theres a ton of em :)
The zZombieBase if at the end where I set the zombie rating. It's saying that none of the zombies are zZombieBase
 
are you working on the stndard Chernarus map ? zZombie_Base is defined in CfgVehicles.hpp in the dayz_code.pbo.
 
The reload portion isn't working, but at least I have the zombie part working again. I gave them each 1 mag since your script gives them more, but once that clip is empty they never get more.

edit: That's not true. When I log out and back in and more zombies spawn, they start shooting again, but they never kill all of the zombies. There are always some floaters that they don't kill, as if not ALL of the zombies are getting marked as hated.
Code:
private["_ai","_magazinetype","_entity_array","_humanity","_humanitylimit","_sleeptime","_detectrange"];
_ai = _this select 0;
_weapons = weapons _ai;
_weapon = _weapons select 0;
_magazinetype = getArray (configFile >> "CfgWeapons" >> _weapon >> "magazines") select 0;
 
_detectrange=300;
_humanitylimit=2499;
_humanity=0;
_sleeptime=5;
 
while {alive _ai} do {
    _entity_array = (position _ai) nearEntities [["zZombie_Base","Bandit1_DZ","BanditW1_DZ","Survivor1_DZ","SurvivorW1_DZ","Survivor2_DZ","SurvivorW2_DZ","Citizen1_DZ","Citizen2_DZ","Citizen3_DZ","Citizen4_DZ","police1_DZ","Camo1_DZ","Sniper1_DZ"],_detectrange];
    {
                    diag_log format["player type: %1",typeOf _x];
        if(vehicle _ai != _ai) then { // NPC in a vehicle
            if(isPlayer _x) then {
                _humanity= _x getVariable ["humanity",0];
                If (_humanity < _humanitylimit && rating _x > -10000) then {
                    diag_log format["reducing rating for player: %1",name _x];
                    _x addrating -10000;
                } else {
                    if (_humanity > _humanitylimit && rating _x <= -10000) then {
                        _x addRating 10000;
                    };             
                };
            };
        } else { //NPC on foot
            if(isPlayer _x) then {
                _humanity= _x getVariable ["humanity",0];
                if (_humanity < _humanitylimit && rating _x > -10000) then {
                    diag_log format["reducing rating for player: %1",name _x];
                    _x addrating -10000;
                } else {
                    if (_humanity > _humanitylimit && rating _x <= -10000) then {
                        _x addRating 10000;
                    };
                };
            } else {
                if (typeOf _x == "zZombie_Base") then {
                    diag_log format["reducing rating for player: %1",name _x];
                    _x addRating -10000;
                };                 
            };
        };
 
    } forEach _entity_array;
 
    // refresh ammo
    if !(someAmmo _ai) then {
        {_ai removeMagazine _x} forEach magazines _ai;
        _ai addMagazine _magazinetype;
    };
 
    sleep _sleeptime;
};

there's the full file
 
see above, i fixed the typo.They should never have more than 1 mag in my logic (correct -> 1 mag in the weapon, 1 mag spare).
 
great script, excellent work :)

does anyone have a list of skins one could use as skins for the AI troops?
BAF Soldiers and Takistani Insurgents dont really fit one my Taviana server :/
 
seems the Zeds that are not being shot at are somehow bugged ... i had a full squad cleaning nwaf, they refused to attack the last 2 zeds.
 
Back
Top