[HELP] AI to shoot at zeds (willing to pay for a working fix)

3djoker

Member
I seen a post in another part of the forums about someone who got AI to interact with zeds (i.e. kill them). I cannot for the life of me get it working though. I currently have opfor AI patrols on my map as well as a big AI bandit camp at the one factory. I would like the AI to shoot any zeds they encounter but I just cannot get it to work!

Does anyone have a fix for this? one that does not break the looting rights of the game. I will paypal anyone who can walk me through getting the AI to shoot at zeds $10.00 usd

Like I said, I seen the post in the dayz mod forum here, but i just cannot get it working with my AI. I would also be willing to start with new AI if I need to do something first and then place the AI in my mission via the editor. I just need a working fix for this.

Thanks in advance.
 
This is really just a hackfix that happens to work - you'll need to add a line to your init.sqf:

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

In the directory quoted above, insert an extracted copy of your zombie_generate.sqf from dayz.pbo and insert this line at the bottom of the sqf file:

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

This will cause all AI to become hostile to zombies as they spawn. Note that this means that the AI will continuously engage zombies on sight, so you'll end up with piles of dead corpses lying around and possibly continuous gunfire if there are enough zombies being spawned.
 
ok, but what you are saying, isn't that going to happen regardless of how you make the AI hostile to zombies?

I will be trying this out tomorrow morning, if this works and the AI do in fact kill the Zeds on sight, then I will let ya know and you can send me a PM with yer email address for payment. also, with this, will they only fire on zeds they SEE or will they start firing on zeds spawning 5k meters away as well?
 
Yeah, it will happen regardless. Until someone finds a way to make AI conditionally hostile to zombies (ie: hostile if within x meters), it's kill on sight. Also, please do not worry about money, I'm only here to help out where I can.

Using the method I described in my last post, the AI will engage zombies if they're within normal sight range, no godly sight involved. And don't worry, the method works for sure. I've been using this method myself for a few weeks on my test server. Inserting the addRating command is necessary, otherwise any zombies spawned after the initial setRating command won't be targeted by AI until the command is run again. The modified zombie_generate.sqf basically says "I spawned some zombies, and all existing zombies up to the ones I just spawned are now considered enemies to everyone."
 
awesome man, I am actually working on this now and might test it soon.

i do have a question though about implementing it.

does it matter where I insert that line in the init.sqf?
 
I tried to put that line towards the beginning of the init but it doesn't seem to be working out. the AI and zeds still just ignore each other.

this is where I added it.

Code:
/*
    INITILIZATION
*/
startLoadingScreen ["","DayZ_loadingScreen"];
cutText ["","BLACK OUT"];
enableSaving [false, false];
 
//REALLY IMPORTANT VALUES
dayZ_instance = 1;                    //The instance
dayzHiveRequest = [];
initialized = false;
dayz_previousID = 0;
_logistic = execVM "=BTC=_Logistic\=BTC=_Logistic_Init.sqf";
zombie_generate = compile preprocessFileLineNumbers "Scripts\compile\zombie_generate.sqf";
 
//start spectating
execVM "initSpec.sqf";
 
I have the line inserted right before "progressLoadingScreen 1.0;" after all compiled functions are loaded. An example:

Code:
//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";
progressLoadingScreen 0.6;
zombie_generate = compile preprocessFileLineNumbers "scripts\compile\zombie_generate.sqf";
progressLoadingScreen 1.0;
 
This is really just a hackfix that happens to work - you'll need to add a line to your init.sqf:

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

In the directory quoted above, insert an extracted copy of your zombie_generate.sqf from dayz.pbo and insert this line at the bottom of the sqf file:

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

This will cause all AI to become hostile to zombies as they spawn. Note that this means that the AI will continuously engage zombies on sight, so you'll end up with piles of dead corpses lying around and possibly continuous gunfire if there are enough zombies being spawned.
I used your other script to get my AI to work, but do you know if there is a similar way to make the AI react to Bandits? Good work btw.
 
I used your other script to get my AI to work, but do you know if there is a similar way to make the AI react to Bandits? Good work btw.

I'm not sure about this part - if you assign the bandits and AI to the east and resistance sides you might be able to get away simply by using the setFriend command in the init.sqf or something.

The only reason AI-to-zombie hostility requires such a weird fix is because the zombies are considered civilians of the player side, and ArmA AI does not attack civilians by default even if they're on opposing sides. The addRating method works because once a unit or group's rating is below -2000, they are considered hostile to everyone, even units on the same side.
 
I'm not sure about this part - if you assign the bandits and AI to the east and resistance sides you might be able to get away simply by using the setFriend command in the init.sqf or something.

The only reason AI-to-zombie hostility requires such a weird fix is because the zombies are considered civilians of the player side, and ArmA AI does not attack civilians by default even if they're on opposing sides. The addRating method works because once a unit or group's rating is below -2000, they are considered hostile to everyone, even units on the same side.
How do you assign them to a group? I dont use rMod or Factions.
 
How do you assign them to a group? I dont use rMod or Factions.

Well, this part I'm not 100% sure of since I only tried assigning AI to groups a few days ago. In my init.sqf I have these lines written:

Code:
killSquadHQ = createCenter resistance;
resistance setFriend [east, 0];
resistance setFriend [west, 0];
killSquadGrp = createGroup resistance;

I have an AI group called "killSquadGrp" assigned to the Resistance side. The second and third lines are to set hostility towards East (my bandit AI side) and West (the player's side). In the sqf script I use to spawn the killSquadGrp AI, I use this:

Code:
_unit = killSquadGrp createUnit [_type, _pos, [], 0, "FORM"];

Again, I don't know if any of this code works. I'm not at all experienced with ArmA2 coding and only learn by observation. What I do know is that the AI spawned with this code work together to kill me (the player) and zombies. I haven't yet made them face off against the bandit AI.
 
Well, this part I'm not 100% sure of since I only tried assigning AI to groups a few days ago. In my init.sqf I have these lines written:

Code:
killSquadHQ = createCenter resistance;
resistance setFriend [east, 0];
resistance setFriend [west, 0];
killSquadGrp = createGroup resistance;

I have an AI group called "killSquadGrp" assigned to the Resistance side. The second and third lines are to set hostility towards East (my bandit AI side) and West (the player's side). In the sqf script I use to spawn the killSquadGrp AI, I use this:

Code:
_unit = killSquadGrp createUnit [_type, _pos, [], 0, "FORM"];

Again, I don't know if any of this code works. I'm not at all experienced with ArmA2 coding and only learn by observation. What I do know is that the AI spawned with this code work together to kill me (the player) and zombies. I haven't yet made them face off against the bandit AI.
How did you get the Bandits assigned to East? On mine Bandits and Survivors are both West. Do you use DayZ_Factions?
 
Does anyone know where the function is that makes them Bandits? Perhaps I could go in there and add a line that assigns them to east in there, or drops their friendship with resistance or something.
 
So what I'm thinking of doing is going into server\compiles\player_humanityChange.sqf and adding a line at the bottom that says
Code:
if (_humanity < 2500) then {
player setFriend [RESISTANCE,0];
player setFriend [WEST,0];
} else {
player setFriend [RESISTANCE,1];
player setFriend [WEST,1];
};

Anyone know if this should work?

I will test, but I have no expectations.
 
So what I'm thinking of doing is going into server\compiles\player_humanityChange.sqf and adding a line at the bottom that says
Code:
if (_humanity < 2500) then {
player setFriend [RESISTANCE,0];
player setFriend [WEST,0];
} else {
player setFriend [RESISTANCE,1];
player setFriend [WEST,1];
};

Anyone know if this should work?

I will test, but I have no expectations.
This did not work. I think you would have to modify a lot of files to make this approach work. like player_Death and player_Fired and stuff like that. Which would make your mission file absolutely massive.
 
Do you think if I used this same approach with player_monitor that it would work? my server is filling up so I can no longer test this.
 
How did you get the Bandits assigned to East? On mine Bandits and Survivors are both West. Do you use DayZ_Factions?

The bandits are assigned to East in a similar (but different way) that the killSquadGrp were assigned to Resistance in my earlier example. However, the spawn script that I'm borrowing from does it in a very strange way, by recreating the group each time a single bandit is spawned. What happens in the end is that the bandits are hostile to everyone, even other bandits. I do not use DayZ Factions or any other extra mods.

Also, I've read that the setFriend function has unexpected results when run in the middle of gameplay. I'm not completely sure since I haven't looked much into this.
 
The bandits are assigned to East in a similar (but different way) that the killSquadGrp were assigned to Resistance in my earlier example. However, the spawn script that I'm borrowing from does it in a very strange way, by recreating the group each time a single bandit is spawned. What happens in the end is that the bandits are hostile to everyone, even other bandits. I do not use DayZ Factions or any other extra mods.

Also, I've read that the setFriend function has unexpected results when run in the middle of gameplay. I'm not completely sure since I haven't looked much into this.
So wait, can you share the code that assigns them to east? That's all I really need. I've been testing a bunch of different ways to do it and none have worked.

My current test is in player_Sync and player_Setup, but my server just started filling up so i'm not gonna do my mass restarts right now.
 
So wait, can you share the code that assigns them to east? That's all I really need. I've been testing a bunch of different ways to do it and none have worked.

My current test is in player_Sync and player_Setup, but my server just started filling up so i'm not gonna do my mass restarts right now.

This is the entire block of code that is responsible for spawning my bandits. There are some oddities (such as the setFriend and addRating lines) since I'm building upon code that I haven't written myself, but it is functional.

Code:
for "_i" from 1 to _totalAI do {
            _pos = [getpos player, random 360, [_minspawnd,_maxspawnd], false, 2] call fnc_randomPos;
            _eastGrp = createGroup east;
            _SideHQ = createCenter east;
         
            _types = ["Survivor2_DZ", "SurvivorW2_DZ", "Bandit1_DZ", "BanditW1_DZ", "Camo1_DZ", "Sniper1_DZ"];    // AI Bandit types
            _type = _types call BIS_fnc_selectRandom;
         
            _unit = _eastGrp createUnit [_type, _pos, [], 0, "FORM"];                        // Spawn the AI bandit unit
            _unit addEventHandler ["Fired", {_this call ai_fired;}];                        // Unit firing causes zombie aggro in the area, like player
            _unit addEventHandler ["Fired", {(_this select 0) setvehicleammo 1}];            // AI bandit has unlimited ammunition (?)
            _unit addEventHandler ["HandleDamage",{_this call local_zombieDamage;}];        // AI bandit handles damage (?)
            _unit addEventHandler ["Killed",{[_this,"banditKills"] call local_eventKill;}]; // Credit player for killing the AI bandit
            _unit addEventHandler ["Killed",{_this call fnc_spawn_deathFlies;}];            // Spawn flies for AI bandit corpse
            _unit addEventHandler ["Killed",{_this setDamage 1;}];                            // New
         
            EAST setFriend [WEST, 0];                                                        // Two-way hostility with player
            WEST setFriend [EAST, 0];
         
            [_unit] call fnc_setBehaviour;                                                    // AI behavior configuration
            [_unit] call fnc_setSkills;                                                        // AI skill configuration
            [_unit] call fnc_unitBackpackTools;                                                // (Customizable rates) Bandit backpack, tools, gadgets
            [_unit, _weapongrade] call fnc_unitSelectPistol;                                // Random AI Bandit sidearm
            [_unit, _weapongrade] call fnc_unitSelectRifle;                                    // (Customizable rates) 2nd variable - AI Bandit weapon grade (0-3: Low-High)
            [_unit] call fnc_unitConsumables;                                                // AI bandit Food/Medical/Misc loot.
            null = [_eastGrp,_pos,_patrold] execVM "BIN_taskPatrol.sqf";
            { _x addRating -20000; } forEach allMissionObjects "zZombie_Base";                // Spawned unit should be immediately hostile to existing zombies
        };
 
This is the entire block of code that is responsible for spawning my bandits. There are some oddities (such as the setFriend and addRating lines) since I'm building upon code that I haven't written myself, but it is functional.

Code:
for "_i" from 1 to _totalAI do {
            _pos = [getpos player, random 360, [_minspawnd,_maxspawnd], false, 2] call fnc_randomPos;
            _eastGrp = createGroup east;
            _SideHQ = createCenter east;
     
            _types = ["Survivor2_DZ", "SurvivorW2_DZ", "Bandit1_DZ", "BanditW1_DZ", "Camo1_DZ", "Sniper1_DZ"];    // AI Bandit types
            _type = _types call BIS_fnc_selectRandom;
     
            _unit = _eastGrp createUnit [_type, _pos, [], 0, "FORM"];                        // Spawn the AI bandit unit
            _unit addEventHandler ["Fired", {_this call ai_fired;}];                        // Unit firing causes zombie aggro in the area, like player
            _unit addEventHandler ["Fired", {(_this select 0) setvehicleammo 1}];            // AI bandit has unlimited ammunition (?)
            _unit addEventHandler ["HandleDamage",{_this call local_zombieDamage;}];        // AI bandit handles damage (?)
            _unit addEventHandler ["Killed",{[_this,"banditKills"] call local_eventKill;}]; // Credit player for killing the AI bandit
            _unit addEventHandler ["Killed",{_this call fnc_spawn_deathFlies;}];            // Spawn flies for AI bandit corpse
            _unit addEventHandler ["Killed",{_this setDamage 1;}];                            // New
     
            EAST setFriend [WEST, 0];                                                        // Two-way hostility with player
            WEST setFriend [EAST, 0];
     
            [_unit] call fnc_setBehaviour;                                                    // AI behavior configuration
            [_unit] call fnc_setSkills;                                                        // AI skill configuration
            [_unit] call fnc_unitBackpackTools;                                                // (Customizable rates) Bandit backpack, tools, gadgets
            [_unit, _weapongrade] call fnc_unitSelectPistol;                                // Random AI Bandit sidearm
            [_unit, _weapongrade] call fnc_unitSelectRifle;                                    // (Customizable rates) 2nd variable - AI Bandit weapon grade (0-3: Low-High)
            [_unit] call fnc_unitConsumables;                                                // AI bandit Food/Medical/Misc loot.
            null = [_eastGrp,_pos,_patrold] execVM "BIN_taskPatrol.sqf";
            { _x addRating -20000; } forEach allMissionObjects "zZombie_Base";                // Spawned unit should be immediately hostile to existing zombies
        };
So wait, your bandits are NPCs?

I'm trying to make my NPCs kill PLAYER bandits.
 
Back
Top