Simple AI Tutorial (no rMod or DayZ_Factions)

Sycosis

Valued Member!
First off, special thanks to Axeman, ButtFace, and 3djoker. This is all code that either they wrote, helped with, or inspired.

scripts.txt:
So with the new respawn ability, you encounter a battleeye error when you kill a unit. To correct this you need to edit your scripts.txt file, which is located on your server. The error is #8, which is on line #10. Find this code:
Code:
5 addWaypoint
and change the 5 to a 1.
You also get error #53, which is on line #55. Find this code:
Code:
5 addMPEventHandler
and change the 5 to a 1.
You also get error #112, which is on line #114. So find this code:
Code:
5 addWeapon
and change the 5 to a 1.
I've been to lazy to find out how exactly to only exlude your specific instance of the code, instead of just exluding all uses of the code, but if someone else knows how, I will add it to the tutorial.

add_unit_server.sqf:
I've attached this file to the post.
1) Create a folder called scripts inside your mission folder.
2) Put the file into your scripts folder.

There is some configuration in this folder that you have to deal with. I will cover it real quick. If you have any more detailed questions, feel free to ask.

Find this line:
Code:
switch (_gearSet) do {
Below this line is a series of variables with self explanatory names. There is a case for each gearSet. 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. That should be the extent of your interaction with that file.

set_unit_faction.sqf:
I've also attached this file to the post. Load this into the same folder. Inside this file is where you set the reaction your troops have to other factions. There is a little bit of configuration in this file as well.

Simply put, 0 is absolute hate, .6 is hate a little, .7 is like a little, and 1 is love. You are WEST!!! You can set EAST and RESISTANCE to hate each other, but love you. You can set them to love each other but hate you. You an also set everyone to hate everyone. Set this however you want.

zombie_generate.sqf:
Pull this file from your Dayz_code.pbo and then add the following code at the very bottom.

Code:
{ _x addRating -20000; } forEach allMissionObjects "zZombie_Base";

To find your zombie_generate file you have to go into your dayz_code.pbo which is located inside of your arma 2 install folder, inside of the map you're editing, which for me is @DayZOring. Just open the pbo and it's inside of the compile folder.

If you want to get rid of zombies entirely (for deathmatch server purposes) find this line:
Code:
if (!_isNoone) exitWith {};
and replace it with:
Code:
if (!_isNoone || _isNoone) exitWith {};
I wouldn't edit anything else in the file. Thanks to ButtFace for this.

mission/init.sqf:
Based on your map, this is going to be different, so i'm just going to post the changes here instead of the file. Below your pre-process loading, add the following lines:
Code:
zombie_generate = compile preprocessFileLineNumbers "scripts\zombie_generate.sqf";
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";
};

Worldspace:
Tto get your worldspace you can do this a couple different ways. the way that i do it is that i go into the map editor and set some markers for where i want them to spawn, and then save the mission and steal the worldspace for those markers, but you could just as easily put your character where you want them to spawn and then go into your database and steal your current worldspace.

Patrol Radius:
Just set this to however far you want your units to roam from their starting location, in meters.

Waypoints:
This is however many points you want them to travel to within the radius that you set. So the more spots you choose, the more thorough they will be with covering that ground.

Units:
The number of units that you want to spawn. Keep in mind that if you choose squad, that you are getting multiples of three.

Type:
0: Random, 1: Sniper, 2: Gunner, 3: Militiaman, 4: Squad (all 3 types together)

Faction:
0: RESISTANCE, 1: EAST, 2: WEST

Base Skill:
The lowest potential skill that your unit can have.

Potential Skill:
The highest potential skill that your unit can have.

Gear Set:
This coordinates to the gearSet case located in your add_unit_server file.

Respawn:
The amount of time to wait until your unit respawns. This number counts in seconds. So for 30 minutes, put 1800.

I made this as user friendly as possible. I hope you enjoy.

So in the end you have the following files:
"Mission\Init.sqf" Which is now modified.
"Mission\Scripts\unit_killed.sqf"
"Mission\Scripts\add_unit_server.sqf"
"Mission\Scripts\set_unit_faction.sqf"
"Mission\Scripts\zombie_generate.sqf"
 

Attachments

  • add_unit_server.sqf
    13 KB · Views: 674
  • set_unit_faction.sqf
    298 bytes · Views: 580
  • unit_killed.sqf
    1.4 KB · Views: 496
Back
Top