Simple AI Tutorial (no rMod or DayZ_Factions)

Spike,

On the vanishing AI thing, change the addMPEventhandler and the MPKilled lines in add_unit_server.sqf to addEventHandler and Killed, bit more about this on page 26.

On the no weapon thing, I would need to see you add_unit_server.sqf to determine has loadouts you are assigning and if there are any errors.

I believe grenades are equivalent to ammo but I have not tried to insert them so I'm not 100% sure.

4th, I would again have to see your add_unit_server.sqf and faction.sqf to determine what's up with that.

5th, As far as I know Sarge AI is the most complete in terms of vehicle patrol.
 
Just went to save them into my Favourites\ToDo folder and they are both already there lol

Found Sarges last week when I started having issues with this one, discounted Axemans right at the beginning as this seemed a better thread (more active at the time) might be worth revisiting I guess
 
I'm working on using some of the axeman code along with this one, I also recently grabbed Sarge and will take a look as well. Both are too far in the wrong direction for me so I am really gonna put together a patchwork, but in the process I am really looking into all things so if I can help out in anyway let me know. If you want post your pbo or sqf's I can take a look and see.
 
Code:
private
switch (_gearSet) do {
    case 0 : {
        _sniperSkin = "BAF_Soldier_L_DDPM";
        _sniperRifle = "RH_mp7RFX";
        _sniperAmmo = "RH_46x30mm_40RND_Mag";
        _sniperAmmoCount = 5;
        _sniperGear = ["ItemBandage","HandGrenade"];
        _sniperWeapons = ["ItemMatchbox"];
        _gunnerSkin = "BAF_Soldier_L_DDPM";
        _gunnerRifle = "RH_M16A2sgl";
        _gunnerAmmo = "30Rnd_556x45_Stanag";
        _gunnerAmmoCount = 5;
        _gunnerGear = ["ItemBandage","SmokeShellRed","HandGrenade"];
        _gunnerWeapons = ["ItemMatchbox"];
        _militiaSkin = "BAF_Soldier_L_DDPM";
        _militiaRifle = "RH_HK53";
        _militiaAmmo = "30Rnd_556x45_Stanag";
        _militiaAmmoCount = 5;
        _militiaGear = ["ItemBandage","SmokeShellRed","HandGrenade"]; // Additional gear (does not include tools or guns)
        _militiaWeapons = ["ItemMatchbox"]; //Additional Guns and Tools
    };
//    case 1 and 2 as above for testing
};

I set case 0 - 3 the same to test it and cut it out to save space for post, happens on all groups regardless.

Guessed it was due to me using added weapons (RH pack) but they work in game normally (spawn and survivors can relog etc no issues) tested with both rmod and rmod2. No doubt a simple fix but missing it each time I browse the code, probably cos I'm in a rush and have peeps on TS whining about it all the time :(

Figured the non engaging thing was an issue with skins but seemed to work with most ai, although as soon as in a vehicle we get shot at. Thats why I thiought it may have been an ai skill thing (set between 2 and 10 so nobody knows skill of ais and doest try to farm them for gear at new spawn)

Will try the addMPEventhandler at home later (work atm) but looks promising so have high hopes for that. To be honest, if I can fix this then the weapons I can work around by just using certain ones and nades arent such a big issue I dont think.

Cheers for the replies though chaps, really thankful for any and all support I can get. Normally its me helping through silly questions but I think I'm just overloaded with stress atm (insert pathetic sad face here)
 
I changed the respawn again.
After the NPC is killed, and after respawn time, i delete the npc.
I think if not excluded, can cause lag on the server.

In add_unit_server.sqf:
Code:
_aiunit addMPEventHandler["MPKilled",{null=_this+[aispawnpos,wpradius,wpnum,1,1,globalFaction,baseSkill,potentialSkill,gearSet,respawnTime] execVM "scripts\unit_killed.sqf";}];

changed to:
Code:
_aiunit addEventHandler["Killed",{null=_this+[wpradius,wpnum,1,1,globalFaction,baseSkill,potentialSkill,gearSet,respawnTime] execVM "scripts\unit_killed.sqf";}];

In unit_killed.sqf:
Code:
private ["_aiobj","_killer","_wpradius","_wpnum","_numUnits","_unitType","_faction","_baseSkill","_potentialSkill","_gearSet","_respawnTime","_zombieKills","_humanity"];
_aiobj = _this select 0;
_killer = _this select 1;
//_aispawnpos = _this select 2;
_wpradius = _this select 2;
_wpnum = _this select 3;
_numUnits = _this select 4;
_unitType = _this select 5;
_faction = _this select 6;
_baseSkill = _this select 7;
_potentialSkill = _this select 8;
_gearSet = _this select 9;
_respawnTime = _this select 10;
_zombieKills = 0;
_humanity = 0;
 
_zombieKills = _killer getVariable["zombieKills",0];
_zombieKills = _zombieKills + 1;
_killer setVariable["zombieKills",_zombieKills,true];
_humanity = _killer getVariable["humanity",0];
_humanity = _humanity + 100;
_killer setVariable["humanity",_humanity,true];
 
diag_log format["NPC dead! Respawning in %1",_respawnTime];
sleep _respawnTime;
 
aispawnpos = getPosATL _aiobj;
wpradius = _wpradius;
wpnum = _wpnum;
numUnits = _numUnits;
unitType = _unitType;
globalFaction = _faction;
baseSkill = _baseSkill;
potentialSkill = _potentialSkill;
gearSet = _gearSet;
respawnTime = _respawnTime;
 
diag_log format["Respawning NPC at %1",_aispawnpos];
deleteVehicle _aiobj; //AI dead, delete. Reduce server lag??
_aispawn = [aispawnpos,wpradius,wpnum,numUnits,unitType,globalFaction,baseSkill,potentialSkill,gearSet,respawnTime] execVM "scripts\add_unit_server.sqf";
 
Jomine,

Yeah, deleting the npc does reduce lag, you are leaving them around for the respawn time which should allow for looting etc. - I see you moved the logic into the unit_killed.sqf for getting the position, I have thought about doing that as well, I manged to solve the inheritance issue for the faction. Gearset I think will be the hardest. Only thing, update your log line to read aispawnpos instead of _aispawnpos, they are not the same thing.
 
Right away I see two issues

case 3 : {
_sniperGear = ["ItemBandage","NVGoggles"];
case 5 : {
_sniperGear = ["ItemBandage","NVGoggles","ItemHeatPack"];

NVGoogles should be in weapons section not gear
okay thank you that is what I was unsure of which items go in which section.
 
Pretty sure they are both Gear as far as AI load goes

class FoodMRE : FoodEdible {
scope = public;
count = 1;
bloodRegen = 800;

class ItemTrashToiletpaper : CA_Magazine {
scope = public;
count = 1;
 
I'm working on using some of the axeman code along with this one, I also recently grabbed Sarge and will take a look as well. Both are too far in the wrong direction for me so I am really gonna put together a patchwork, but in the process I am really looking into all things so if I can help out in anyway let me know. If you want post your pbo or sqf's I can take a look and see.
Combining the random weapon spawn would be really cool to add IMO.
 
http://opendayz.net/index.php?threads/dayz-npc-ai-units-troops-add-to-server.8002/ & http://opendayz.net/index.php?threads/sarge-ai-framework-public-release.8391/
I personally think Sarge AI is super hard i have no idea at all how to add severel spawns? they use some kind of grid system

Did you even read the documentation ? I spent lots of time to make my framework as easy to configure as possible - and it is. People run it out of the box with the gridsystem, people adjust it to have infantry and heli patrols in areas that they define, you can do whatever your imagination allows with this framework. - random AI spawns on the whole map ? use the grid, and adjust the gridsize to your liking. Want a bandit cherno ? defina an area around Cherbo and spawn 10 bandit groups in there.

I would recommend rereading the docs, and ask in the thread, lots of people will help you out (if you bothered to read and understand the documentation :) )
 
Sarge, looking through your code I see the random unit types get random weapon types, but do you have a way to load them with custom item's and gear? Am I just not seeing the spot where this happens?
 
Code:
/*   
    INITILIZATION
*/
startLoadingScreen ["","RscDisplayLoadCustom"];
cutText ["","BLACK OUT"];
enableSaving [false, false];
 
//REALLY IMPORTANT VALUES
dayZ_instance = 2582;                    //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
call compile preprocessFileLineNumbers "debug\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";
playerstats = compile preprocessFileLineNumbers "debug\playerstats.sqf";
 
if ((!isServer) && (isNull player) ) then
{
waitUntil {!isNull player};
waitUntil {time > 3};
};
 
if ((!isServer) && (player != player)) then
{
  waitUntil {player == player};
  waitUntil {time > 3};
};
 
zombie_generate = compile preprocessFileLineNumbers "scripts\zombie_generate.sqf";
 
if (isServer) then {
// For settings involving the factions, go to scripts\add_unit_server.sqf and adjust the settings at the top of the file
    _factions = [] execVM "scripts\set_unit_faction.sqf";
//_aispawnpos - Worldspace location
//_wpradius - Distance you want units to be able to travel
//_wpnum - Number of waypoints to place withing that distance. The higher the number, the more extensively the units will travel
//_numunits - Number of units to place. Keep in mind that squads will be placed in multiples of this number
//_unitType - Type of unit to place. 0: Random, 1: Sniper, 2: Gunner, 3: Militia, 4: Squad of the previous 3 types
//_faction - The type of faction you want this unit to adhere to. 0: RESISTANCE, 1: EAST, 2: WEST. Factions loyalties are set in scripts\set_unit_faction.sqf
//_baseSkill - Lowest possible skill that the units can posess from 1 to 10
//_potentialSkill - Highes possible skill that the units can posess from 1 to 10
//_gearSet - Which set of gear your units will use. To set the types of gear, edit the variables at the top of scripts\add_units_server.sqf
//_respawnTime - How long to wait until NPCs respawn (in seconds)
    _aispawn = [[3873.47,68,1721.85],300,5,2,1,1,9,10,0,1200] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[3238.02,5,1124.9],300,5,2,0,0,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[1006.8,17,1890.34],200,5,1,0,1,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[2208.6,15,4959.97],500,5,1,0,2,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[6510.68,17,6759.33],300,5,1,0,0,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[3218.7,44,7964.37],600,5,2,0,1,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
};
 
if (isServer) then {
//===================piXel 15-02-2013===========
    dogOwner = [];
//=========================end==================   
    _serverMonitor =    [] execVM "\z\addons\dayz_code\system\server_monitor.sqf";
};
 
if (!isDedicated) then {
    //Conduct map operations
    0 fadeSound 0;
    waitUntil {!isNil "dayz_loadScreenMsg"};
    dayz_loadScreenMsg = (localize "STR_AUTHENTICATING");
   
    //Run the player monitor
   
//===================piXel 15-02-2013===========
    _id = player addEventHandler ["Respawn", {_id = [] spawn player_death; _nul = [] execVM "addin\plrInit.sqf";}];
    //dayZ original _id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
    _playerMonitor =    [] execVM "\z\addons\dayz_code\system\player_monitor.sqf";
    _nul = [] execVM "addin\plrInit.sqf";
//=========================end==================
};
have inserted this in init. but get wait for host. what have i do wrong? pls help me out of this
 
ray,

You have a bunch of stuff in there not related to the AI that I can't speak to, if you remove the AI stuff though, everything works fine?
 
Best guess I would say try this
Code:
/*   
    INITILIZATION
*/
startLoadingScreen ["","RscDisplayLoadCustom"];
cutText ["","BLACK OUT"];
enableSaving [false, false];
 
//REALLY IMPORTANT VALUES
dayZ_instance = 2582;                    //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
call compile preprocessFileLineNumbers "debug\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";
playerstats = compile preprocessFileLineNumbers "debug\playerstats.sqf";

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

if (isServer) then {
//===================piXel 15-02-2013===========
    dogOwner = [];
//=========================end==================   
    _serverMonitor =    [] execVM "\z\addons\dayz_code\system\server_monitor.sqf";

// For settings involving the factions, go to scripts\add_unit_server.sqf and adjust the settings at the top of the file
    _factions = [] execVM "scripts\set_unit_faction.sqf";
//_aispawnpos - Worldspace location
//_wpradius - Distance you want units to be able to travel
//_wpnum - Number of waypoints to place withing that distance. The higher the number, the more extensively the units will travel
//_numunits - Number of units to place. Keep in mind that squads will be placed in multiples of this number
//_unitType - Type of unit to place. 0: Random, 1: Sniper, 2: Gunner, 3: Militia, 4: Squad of the previous 3 types
//_faction - The type of faction you want this unit to adhere to. 0: RESISTANCE, 1: EAST, 2: WEST. Factions loyalties are set in scripts\set_unit_faction.sqf
//_baseSkill - Lowest possible skill that the units can posess from 1 to 10
//_potentialSkill - Highes possible skill that the units can posess from 1 to 10
//_gearSet - Which set of gear your units will use. To set the types of gear, edit the variables at the top of scripts\add_units_server.sqf
//_respawnTime - How long to wait until NPCs respawn (in seconds)
    _aispawn = [[3873.47,68,1721.85],300,5,2,1,1,9,10,0,1200] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[3238.02,5,1124.9],300,5,2,0,0,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[1006.8,17,1890.34],200,5,1,0,1,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[2208.6,15,4959.97],500,5,1,0,2,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[6510.68,17,6759.33],300,5,1,0,0,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
    _aispawn = [[3218.7,44,7964.37],600,5,2,0,1,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
};


 
if ((!isServer) && (isNull player) ) then
{
waitUntil {!isNull player};
waitUntil {time > 3};
};
 
if ((!isServer) && (player != player)) then
{
  waitUntil {player == player};
  waitUntil {time > 3};
};
 

  
 
if (!isDedicated) then {
    //Conduct map operations
    0 fadeSound 0;
    waitUntil {!isNil "dayz_loadScreenMsg"};
    dayz_loadScreenMsg = (localize "STR_AUTHENTICATING");
   
    //Run the player monitor
   
//===================piXel 15-02-2013===========
    _id = player addEventHandler ["Respawn", {_id = [] spawn player_death; _nul = [] execVM "addin\plrInit.sqf";}];
    //dayZ original _id = player addEventHandler ["Respawn", {_id = [] spawn player_death;}];
    _playerMonitor =    [] execVM "\z\addons\dayz_code\system\player_monitor.sqf";
    _nul = [] execVM "addin\plrInit.sqf";
//=========================end==================

};
 
yes it worked fine ;)what do you do? and they spawn in. but he had a as50 and i was dead
hehe. think i should change that.
 
I think there is a specific order for the loading of things all I did was rearrange the order of you code, and grouped the is(server) code above the is(!server) code, to adjust the As50 stuff use the add_unit_server.sqf to change loadout.
 
Could someone tell me if there is a way to make a faction of AI only friendly to me and my group?
 
Back
Top