Simple AI Tutorial (no rMod or DayZ_Factions)

I am having this exact same issue, has anyone found a fix?

Messed around with the files and ended up fixing this myself by changing two of variables in add_unit_server.sqf.

I don't know what else this effects but this is how i got it to work, I changed the line

_aiunit addMPEventHandler["MPKilled".....

to

_aiunit addEventHandler["Killed".....

everywhere in the file - on each case type, this worked for me.

Regards,
 
  • Like
Reactions: Diz
A couple issues regarding the tutorial:

1. Can you possibly include an example or explanation of "pre-process loading" and how we identify it within the init.sqf(one of the most confusing parts for a novice is proper placement of the edited lines in this file)

2. Why are the
Code:
zombie_generate = compile preprocessFileLineNumbers "scripts\zombie_generate.sqf";

and

Code:
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 = [[3993.98,4193.84,0],100,5,1,4,1,7,10,0,1800] execVM "scripts\add_unit_server.sqf";
};

listed separately and do they go in different places or should they simply be separated by a blank line in the init.sqf?

3. There's no mention of "Mission\Scripts\unit_killed.sqf" until the final summary. (nitpicky I know)This might be confusing for some complete novices.

4. Could you possibly include example code for the following: "To add more gearSets, simply follow the numbering scheme and add the next number, then go to your init and reference that number in the proper location. Keep in mind that if you create a new case, you need to keep the naming scheme the same so that the variable names matchup."

I'm a non-coder and was able to figure everything out, but these are the items I had to go over a couple times and cross reference with other sources in order to get right. Just thought i'd pass along these suggestions on possible improvements to the tutorial since I can't really contribute much to this great project any other way.
 
While I did not write the tutorial I will attempt to answer your questions, as I found this quite straight forward apart from the 2 issues I meantioned above and have since solved.

1. The placement in the init.sqf file, the pre-process statement section is pretty clear to see, mine looks like this
Code:
// Compile and call important functions
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\variables.sqf";
progressLoadingScreen 0.1;
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\publicEH.sqf";
progressLoadingScreen 0.2;
call compile preprocessFileLineNumbers "\z\addons\dayz_code\medical\setup_functions_med.sqf";
progressLoadingScreen 0.4;
call compile preprocessFileLineNumbers "\z\addons\dayz_code\init\compiles.sqf";
progressLoadingScreen 1.0;


It seems this establishes all the needed parts for later script and object calls, as such you want to add the code after this, which is where I inserted the zombie_gen line

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

The next part has to do with the game startup type, if the game is a server do "x", if it is not do "y", if it is a dedicated server do "z", the important part here is that you place the faction and aispawn lines within the isServer context, while there is no requirement to have an empty line in between the zombie_gen line and the isServer section, it may make the file easier to read, I think the main point is that you do not place the zombie_gen line within the isServer statement. Also note that all the lines with // are comments and do not affect the script itself, but aid in the understanding each of the variables within the brackets in the aispawn line.

Code:
// Run the server monitor
if (isServer) then {
_serverMonitor = [] execVM "\z\addons\dayz_server\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 = [[3993.98,4193.84,0],100,5,1,4,0,7,10,1,1800] execVM "scripts\add_unit_server.sqf";
 
}

This part speaks to your gearset question, as can be seen from the commented lines the gearset is set by the second to last variable in the set, the one before the 1800 in the aispawn line, in the vanilla add_unit_server.sqf there are currently 2 gearsets labeled case 0 and 1, the number you put in the aispawn line here corresponds to that gearset case, so if you wanted to add another called 2 you would add the following to the add_unit_server.sqf

Code:
// to add more gear sets, just add another case, and copy and paste the variables from one of the other cases into it, and then reference it in the init.
switch (_gearSet) do {
case 0 : {
_sniperSkin = "BAF_Soldier_Sniper_MTP";
_sniperRifle = "BAF_AS50_scoped";
_sniperAmmo = "5RND_127x99_as50";
_sniperAmmoCount = 10;
_sniperGear = ["ItemBandage"];
_sniperWeapons = ["ItemMatchbox"];
_gunnerSkin = "BAF_Soldier_MTP";
_gunnerRifle = "Mk_48_DZ";
_gunnerAmmo = "100Rnd_762x51_M240";
_gunnerAmmoCount = 10;
_gunnerGear = ["ItemBandage"];
_gunnerWeapons = ["ItemMatchbox"];
_militiaSkin = "BAF_Soldier_L_MTP";
_militiaRifle = "BAF_L85A2_RIS_CWS";
_militiaAmmo = "30Rnd_556x45_StanagSD";
_militiaAmmoCount = 10;
_militiaGear = ["ItemBandage"]; // Additional gear (does not include tools or guns)
_militiaWeapons = ["ItemMatchbox"]; //Additional Guns and Tools
};
case 1 : {
_sniperSkin = "Citizen3";
_sniperRifle = "LeeEnfield";
_sniperAmmo = "10x_303";
_sniperAmmoCount = 3;
_sniperGear = ["ItemBandage"];
_sniperWeapons = ["ItemMatchbox"];
_gunnerSkin = "Worker1";
_gunnerRifle = "Winchester1866";
_gunnerAmmo = "15Rnd_W1866_Slug";
_gunnerAmmoCount = 3;
_gunnerGear = ["ItemBandage"];
_gunnerWeapons = ["ItemMatchbox"];
_militiaSkin = "Villager1";
_militiaRifle = "revolver_EP1";
_militiaAmmo = "6Rnd_45ACP";
_militiaAmmoCount = 3;
_militiaGear = ["ItemBandage"]; // Additional gear (does not include tools or guns)
_militiaWeapons = ["ItemMatchbox"]; //Additional Guns and Tools
};
case 2 : {
_sniperSkin = "Citizen3";
_sniperRifle = "BAF_AS50_scoped";
_sniperAmmo = "5RND_127x99_as50";
_sniperAmmoCount = 3;
_sniperGear = ["ItemBandage"];
_sniperWeapons = ["ItemMatchbox"];
_gunnerSkin = "BAF_Soldier_Sniper_MTP";
_gunnerRifle = "Winchester1866";
_gunnerAmmo = "15Rnd_W1866_Slug";
_gunnerAmmoCount = 3;
_gunnerGear = ["ItemBandage"];
_gunnerWeapons = ["ItemMatchbox"];
_militiaSkin = "Villager1";
_militiaRifle = "revolver_EP1";
_militiaAmmo = "6Rnd_45ACP";
_militiaAmmoCount = 3;
_militiaGear = ["ItemBandage"]; // Additional gear (does not include tools or guns)
_militiaWeapons = ["ItemMatchbox"]; //Additional Guns and Tools
};
};

Here you can see I have added a case 2 - where the sniper is a citizen3 skin with an as50, the gunner a sniper skin with winchester and militia is unaltered from case 1. In order to use this gearset I would then from the init.sqf call

Code:
_aispawn = [[3993.98,4193.84,0],100,5,1,4,0,7,10,2,1800] execVM "scripts\add_unit_server.sqf";

with a 2 in place of the 1, before the 1800 as this is the variable that means which gearset to use.

Finally in regards to the unit_killed.sqf, the main tutorial does not require any modification to it, as such the only thing you need to do is to place it in the same folder as the other scripts, as far as what it does - it handles the respawn, playerstats, and logging to the server for spawn and death of an npc. If you would like more detail I can elaborate.

I realize you said you figured everything out but as I am a beggining modder myself this helped me understand things a little better an hopefully will fill the need of any others looking for the same information you requested.

By all means those experienced folks on here let me know if I have misrepresented or explained anything here and I will correct it.

Regards
 
Morox, awesome of you to break it down for everyone. I too am a beginner and did initially learn this by bugging other posters but hopefully the will save some people some time. I had my AI working wonderfully for several days but suddenly they stopped. They never did respawn either. If there's any chance you'd feel like taking a look, I posted my files a few pages back. Thanks again!
 
Morox, awesome of you to break it down for everyone. I too am a beginner and did initially learn this by bugging other posters but hopefully the will save some people some time. I had my AI working wonderfully for several days but suddenly they stopped. They never did respawn either. If there's any chance you'd feel like taking a look, I posted my files a few pages back. Thanks again!

If you remove the fast-rope script from the init does it work then?
 
It did stop working right around when I added the fast rope. I'm not sure why they would effect each other but ill try removing it.
 
What do I need to change to make it so the ai EAST soldiers (hostile to everyone), do not shoot at zeds?

I believe if you remove the zombie_gen line from your init.sqf, the AI will not attack zeds - if I have followed the thread correctly, currently rebuilding my server so I cannot test.
 
I believe if you remove the zombie_gen line from your init.sqf, the AI will not attack zeds - if I have followed the thread correctly, currently rebuilding my server so I cannot test.
Sorry didn't answer the east question, if you are using the files from the first post the factions are controlled by the set_unit_faction.sqf, mine looks like
Code:
waitUntil{initialized};
//0Day
createCenter east;
createCenter resistance;
//Survivors
WEST setFriend [RESISTANCE,.7];
WEST setFriend [EAST,0];
//AI Units
RESISTANCE setFriend [WEST,.7];
RESISTANCE setFriend [EAST,0];
//AI Units 2
EAST setFriend [WEST,0];
EAST setFriend [RESISTANCE,0];

then in your init.sqf. you want to set the 6th variable to 1

Code:
 _aispawn = [[3993.98,4193.84,0],100,5,1,4,1,7,10,1,1800] execVM "scripts\add_unit_server.sqf";

Like so, 0 would be resistance, 1 is east and 2 is west.

Regards
 
I removed fast rope, but still no AI :( I really just don't know....
If you remove the lift and tow packages does it work, I am thinking there may be an overlapping global variable that is causing the issue, I have acquired the BTC files and will try to replicate your setup.

Regards
 
I can confirm that I am using fast rope, BTC lift, and the ai. How many ai are you spawning?


If you check page 25 you can see GaryG's files FAQdaWorld, he is the one having the issue with this, I am not running these modes nor am I running it on tavi, so I have not faced this same issue.
 
Yeah, thanks. I actually remembered the bit about the line with the zombie_gen line on my own; seems to be work again now. I Figured I'd help out Gary out a bit; We would issues with players not being able to log on, and other issues etc. I removed a bunch of the ai and it all works now. We had 150 AI surrounding the NWAF; which is a probably a bit much :p Gary if you could grab some of your rpt logs and post them that would help.
 
Sorry guys, just seen these posts. Where do I grab those lines from? I'm spawning in roughly 50 AI. Something like 6 lines each spawning 4 groups. I can back it down a bit if you think that could be the problem.
 
6:54:21 Unrecognized CfgVehicles simulation in bin\config.bin/CfgVehicles/UN_CDF_Soldier_EP1/
6:54:21 "Spawned: "32" UralCivil2"
6:54:22 "Spawned: "33" V3S_Civ"
6:54:22 Unrecognized CfgVehicles simulation in bin\config.bin/CfgVehicles/Woodlander2/
6:54:22 "Spawned: "35" HMMWV_DES_EP1"
6:54:22 "Spawned: "37" datsun1_civil_3_open"
6:54:22 Unrecognized CfgVehicles simulation in bin\config.bin/CfgVehicles/Villager4/
6:54:22 "Spawned: "38" car_hatchback"
6:54:22 "Spawned: "40" datsun1_civil_3_open"
6:54:22 "Spawned: "41" Ural_INS"
6:54:22 Unrecognized CfgVehicles simulation in bin\config.bin/CfgVehicles/Ins_Soldier_2/
6:54:22 "Spawned: "42" Ural_INS"
6:54:22 "Spawned: "43" Ural_INS"
6:54:22 "Spawned: "44" Ural_INS"
6:54:22 "Spawned: "45" Old_bike_TK_INS_EP1"
6:54:22 "Spawned: "47" TT650_TK_CIV_EP1"
6:54:22 "Spawned: "48" TT650_Civ"
6:54:22 "Spawned: "50" TT650_Gue"
6:54:22 Unrecognized CfgVehicles simulation in bin\config.bin/CfgVehicles/GUE_Soldier_3/
 
Ok, here's a weird one for y'all:

So I got everything working first try using the default files from the first post.

I notice that the "militia" class is spawning in without rifles.

I open the add_unit_server.sqf and find that the militia class has L85A2AWS(banned weapon)set as it's primary(and StanagSD ammo for some reason).

I edited and replaced the BAF_L85A2_RIS_CWS(L85A2AWS)- with SCAR_L_CQC_Holo(an unbanned MK16 variant) and also edit the ammo to be standard stanag. Save/close/repack/re-upload/restart.

Ever since this change everyone joining the server gets the following error message:
"you cannot play/edit this mission its dependent on downloadable content that has been deleted. dayz.anim" - but they are still able to join and play normally.


Ok, so the weird thing is, that's the same error people used to get when picking up the L85A2AWS in-game when it was removed/glitched in a patch about 9mo. ago.

I replaced SCAR_L_CQC_Holo with G36C(100% positively for sure unbanned) but still get the error.

I went through my add_unit_server.sqf and couldn't find any other references to BAF_L85A2_RIS_CWS or any other specific weapon outside the "case sections", so I'm kind of at a loss on where to make any corrections to fix this.

Any ideas? (relevent portion of my current add_unit_server.sqf is posted below)

Code:
// to add more gear sets, just add another case, and copy and paste the variables from one of the other cases into it, and then reference it in the init.
switch (_gearSet) do {
    case 0 : {
        _sniperSkin = "BAF_Soldier_Sniper_MTP";
        _sniperRifle = "DMR";
        _sniperAmmo = "20Rnd_762x51_DMR";
        _sniperAmmoCount = 10;
        _sniperGear = ["ItemBandage"];
        _sniperWeapons = ["ItemMatchbox"];
        _gunnerSkin = "BAF_Soldier_MTP";
        _gunnerRifle = "Mk_48_DZ";
        _gunnerAmmo = "100Rnd_762x51_M240";
        _gunnerAmmoCount = 10;
        _gunnerGear = ["ItemBandage"];
        _gunnerWeapons = ["ItemMatchbox"];
        _militiaSkin = "BAF_Soldier_L_MTP";
        _militiaRifle = "G36C";
        _militiaAmmo = "30Rnd_556x45_Stanag";
        _militiaAmmoCount = 10;
        _militiaGear = ["ItemBandage"]; // Additional gear (does not include tools or guns)
        _militiaWeapons = ["ItemMatchbox"]; //Additional Guns and Tools
    };
 
6:53:50 Error in expression <[[9988,18638,0]],30,20,3,4,1,7,10,0,1000] execVM "scripts\add_unit_server.sqf";

I found this one. I deleted it. I dont see an error but oh well. Ill try it now
 
Back
Top