Help getting AI to attack Zeds

delpi

Well-Known Member
I've tried everything I can find on the web, but I can't seem to make AI kill Zeds.

Does anyone have a working example of this they would mind sharing with me? I'm stumped.
 
You need to reduce the rating of the Zombies, so that they are flagged as enemys.
https://community.bistudio.com/wiki/addRating

it works best on the clientside that is the owner of the zombies, so the best way is a publicvariablehandler to do this. This Eventhandler has to be in the mission, so it avaible on every client.
PHP:
"RHAI_changeRating" addPublicVariableEventHandler {
    _targets = (_this select 1) select 0;
    _rating = (_this select 1) select 1;
    {
        if (local _x) then {
            if(rating _x > _rating) then {
                _x addRating _rating;
            };
        };
    } forEach _targets;
};

And running a loop for every group of Ai:
This shoud be on serverside (dayz_server.pbo) where the ai is local.
PHP:
_unitsAlive = {alive _x} count (units _this);
while {_unitsAlive > 0} do {
        _nearEntities = (leader _UnitGroup) nearEntities ["zZombie_Base",150];
        {
            if (local _x) then {
                if(rating _x > -30000) then {
                    _x addrating -30000;
                };
            } else {
                RHAI_changeRating = [[_x],(-30000)];
                (owner _x) publicVariableClient "RHAI_changeRating";
            };
        } foreach _nearEntities;
        sleep 15;
        _unitsAlive = {alive _x} count (units _UnitGroup);
    };

ps.: look into DZAI there is a good example.
 
THANKS!!!!

That was the peice i was missing. I was changing the rating on the server and it wouldn't take. I couldn't figure out why.

Tried tons of oddball ways to get it to work and they all failed.
 
Got that part working.

AI still are not attacking though.

I tried following DZAI but couldn't.

Do i need to set a certain type of waypoint other than MOVE in order to get them to attack?

Actually at the point that I'm looking for them to attack i dont' think there are any waypoints.

EDIT

I'm trying to set up a loop of SAD waypoints and having some success. Wondering if I can just have them attack after they move to destination instead of having to keep cycling it.
 
Last edited:
Ok, could use some more guidance here. I did manage to setup a set of SAD waypoints, but the AI never seem to get past the first one.

After some time I want to get them in a vehicle and leave. They get in, but then go back to the very first SAD.

Anybody able to point me to the right way to do this?
 
yes.

Basically they just get done with a move waypoint, get out of vehicle and I delete the waypoint

then they sit there.

If I give them a new waypoing of SAD, they attack all the zeds nearby at that point.

Then things go to hell and I can't really get them to rejoin the script.
 
Zombies are Agents and independent (has no faction), so you have to reduce the rating of them, to tag them as enemy for the AI.
Zombies spawned Clientside, so it works best to reduce to rating on clientside.

For me it works great.
S&D Waypoints for the AI has no influence on the Zombies.

Note the loop on serverside that searches for Zombies in a range around the AI, runs only every 15 secounds.

ps.: waypoints only work if the units are not in combat, at a point the ai changes in danger mode, that is a fsm file that describes the behaviour of the Ai after different events, from this point on all waypoints are not working.

ps2.: S&D waypoints only let the leader search the area for danger, if the area of the waypoint is huge the leader needs more time to search through
 
Last edited:
I got the client/server part working and I can tell the zombies have the right rating now.

However, the ai are not attacking. they just stand there. I assumed i needed to tell them to go into combat or something.

I must have setup the AI or the groups wrong and done something that is keeping them out of combat.
 
I think i just spotted my error. When i want them to attack, i need to move them to 'combat'

  • Careless - Careless behaviour will cause the group move and behave in a very non-combat manner. The group will form into a Compact Column like formation, where each unit will directly follow the man in front rather than moving in a formation. Soldiers will carry their weapons in safe position (rifles across body, pistols holstered) and walk slowly. Infantry will not fire on enemy targets (unless they have wounded legs), but vehicles will still fire on enemies. Groups in careless mode do not switch to a more alert mode if enemies are encountered. All unit types show preference moving along roads whenever possible.

In careless, it suggests they will not attack.
 
Still no real success. I assign one of them the leader. After they reach waypoint, I delete the waypoint and make sure their behavior is set to combat.

Would someone please point out what i'm messing up?

Group code

_CDcenter = createCenter RESISTANCE;
_CD_BusUnitGroup = createGroup _CDcenter;

// Set Friend Status
_CDcenter setFriend [CIVILIAN,0];
CIVILIAN setFriend [_CDcenter,0];

// Set Group characteristics
_CD_BusUnitGroup setBehaviour "COMBAT";
_CD_BusUnitGroup setSpeedMode "NORMAL";
_CD_BusUnitGroup setCombatMode "RED";
_CD_BusUnitGroup enableAttack true;

Unit code

_CD_BusUnit enableAI "TARGET";
_CD_BusUnit enableAI "AUTOTARGET";
_CD_BusUnit enableAI "MOVE";
_CD_BusUnit enableAI "ANIM";
_CD_BusUnit enableAI "FSM";
_CD_BusUnit setCombatMode "RED";
_CD_BusUnit setBehaviour "COMBAT";
_CD_BusUnit enableAttack true;
{
_CD_BusUnit setSkill [_x, 1];

} forEach ["aimingAccuracy","aimingShake","aimingSpeed","endurance","spotDistance","spotTime","courage","reloadSpeed","commanding","general"];
 
Could you post the whole code of the serverside loop to set the rating and the publicvariableeventhandler on client-/missionside?
so i can't find any failure
 
Sure I will tonight, but the Zed have rating below-2000.

from diag messages, the client gets it, sees it, and then the server sees the rating is set the next time I check the zed.

It will be tonight when I can post it. At work now.


Also, they are now attacking Zeds most of the time. However, they alos seems to shoot themselves and their vehicle half the time too. Seems by accident.
 
Last edited:
Two things.

The first is a bit of a guess bit I was feeding them awareness if all the Zeds at start so the would shoot at things without line of sight.

The second is that largely doe to the first they ran out of ammo. I thought they just were not shooting,

They are still a little wonky on when they attack and don't, but that seems to be the norm for this.

Do you have an easy manner for infinite ammo? The only thing I could find was to add a magazine each Tim the fired.
 
Last edited:
i use an eventhandler "fired" for every unit
PHP:
fnc_eh_fired = {
    private ["_unit","_weapon","_muzzle","_mode","_ammo","_magazine","_projectile","_magcnt"];
    _unit =         _this select 0; //unit: Object - Object the event handler is assigned to
    _weapon =         _this select 1; //weapon: String - Fired weapon
    //_muzzle =     _this select 2; //muzzle: String - Muzzle that was used
    //_mode =         _this select 3; //mode: String - Current mode of the fired weapon
    _ammo =         _this select 4; //ammo: String - Ammo used
    _magazine =     _this select 5; //magazine: String - magazine name which was used
    //_projectile =     _this select 6; //projectile: object - Object of the projectile that was shot
 
    // *** Munition nachfüllen ***
            _magcnt = {_x == _magazine} count (magazines _unit);
            if ( (_unit ammo _weapon == 0) OR _magcnt <= 2) then {
                //_unit removeMagazines _magazine;
                _unit addMagazine _magazine;
            };
};

and at this to every unit:
PHP:
_unit addEventHandler ["Fired", {_this call fnc_eh_fired;}];

ps.: this is the short variante of my eventhandler, i also do this max. every 5 seconds
 
Very handy. I was using the event, but I was just adding a magazine each time it was fired. I was wondering just how full they would be at the end. HA!

I'll impliment yours tonight. Thanks.
 
Back
Top