Simple AI Tutorial (no rMod or DayZ_Factions)

Rhythmnz,

Checked out your files, biggest issue I find is your variables.sqf, it seems to me that unless you wanted the changes that you made in there it causes most of the issues you describe(zed respawn time trippled in length and loot spawn). I simply removed the line to it in the init.sqf and used the original one and it solved the zombie and loot spawn issues. I checked the ai and the fast rope and everything worked, I don't know/use what the mv22 thing is so I could not test that. But it does not seem there is much reason for using your custom file.

On the AI stuff there is some issues with your _aispawn lines, some of the lines refer to a gearset 2 which does not exist - so I would update those. Also in the add_unit_server.sqf you don't have any of the changes I talk about throughout this forum for to stop the AI disappearing, respawning in a diff place or in a diff faction.

I would say try these two files and see if it works for you. Note I commented our the _aispawn lines with the bad gearset in the init.sqf so you can update and uncomment.
 

Attachments

  • add_unit_server.sqf
    13.2 KB · Views: 5
  • init.sqf
    5.6 KB · Views: 6
Hey

Am trying to do this but nothing is spawning, added the files and such as per page 1 psot 1
 

Attachments

  • dayz_mission.pbo
    449.1 KB · Views: 3
Varsyn,

Try this init.sqf and let me know if it works
Yea that worked. the AI wont attack any vehicles though? im using "militia man" only with L85A2

Also is there anyway to make it so they dont always drop gun only a chance
 
Hi.

Gonna start to say thx for a really nice work with AI/NPC thread, using it on my server.

My NPCs are spawning and they drop loot so players can loot them. But have some small problems if someone can help me?

1. They dont respawn. Seems to be the problem with they respawning at the position they died in i think? If u check my test NPC have this spawn point in my init.sqf. I have tried it at airfields to and they dont respawn (had 10 mins timer at the time for them).


Code:
_aispawn = [[2758.7144,5304.3457,0],100,5,1,2,1,7,10,4,60]//Zelenogorsk test NPC

And here is a copy from my .rpt log when he dies (60 sec timer for the test). Notice now NPC dont spawn as same unit type either.

11:08:41 "DEBUG FPS : 49.6894"
11:09:18 "NPC dead! Respawning in 60"
11:10:18 "Position: [2776.42,5381.1,0.00143433], Radius: 100, Waypoints: 5, Units: 1, Unit Type: 1, Faction: EAST, Base Skill: 7, Potential Skill: 10, Gear Set: 4, Respawn Time: 60"
11:10:18 "globalFaction is EAST"
11:11:42 "DEBUG FPS : 49.8442"

2. Is it possible to NOT make them attack zombies? All my NPCs attack zombies so if you hide in a good place you can wait for them to run out of ammo (like control tower at airfields, i just want them to attack players). I have tried this in the set_unit_faction.sqf.

Code:
EAST setFriend [CIVILIAN,1];

3. Their body dosent hide/delete at respawn. But maybe its connected to the thing with they dont spawn at same point and not same unit type?

If someone could help me it would be nice. Im having a Dayz.st server so u know so cant change every configs myself. :)

Thx for the good work with the NPCs and helping ppl out. Really love to bring more action to my server. ;)
 

Attachments

  • set_unit_faction.sqf
    297 bytes · Views: 1
  • unit_killed.sqf
    1.6 KB · Views: 2
  • zombie_generate.sqf
    3 KB · Views: 5
  • add_unit_server.sqf
    16.7 KB · Views: 2
  • init.sqf
    4.5 KB · Views: 4
Villko05,

This was solved, I think it is talked about on page 3 by OrcThrasher

Varsyn,

The best way to go about it in my opinion would be to mod the unit_killed.sqf add a random chance that the following happens

Code:
//clear default weapons / ammo
removeAllWeapons _player;
removeAllItems _player;

Onaabys, looking through your files now.
 
Onaabys,

Actually the issue you describe is a "fix" for the larger issue that most people have. The OP files pass the _aispawnpos to the unit_killed.sqf and this is used as the location of the respawn - the problem with this is that if you have more than 1 _aispawn line in your init.sqf you are overwriting this variable so by the time an NPC dies, they end up respawning at the location set in the last _aispawn line, the solution to this was to grab the NPC current position at the time of death and pass that to the unit_killed.sqf hence the (getPosATL (_this Select 0)) part of the event handler line. At the moment this is the best way to keep them roughly in the right place on respawn.

However this speaks to a larger problem which your debug line illustrates - all the info passed to the unit_killed.sqf faces the same issue (why they respawn as diff unit type) - we were able to solve the faction issue by using the (side (group (_this Select 0))), there is however currently no fix for the rest of the variables, it may not seem obvious in your test because you tested with the last line but had you used your first line, and left the last line in.

Code:
_aispawn = [[7622.51,7912.7,0],5000,20,1,4,1,8,10,0,5400] execVM "scripts\add_unit_server.sqf";//Chernaurs (Whole map) Militia Nato(Squad)

The log would have showed:
"Position: [where NPC died], Radius: 100, Waypoints: 5, Units: 1, Unit Type: 1, Faction: EAST, Base Skill: 7, Potential Skill: 10, Gear Set: 4, Respawn Time: 60"

This is an issue I have been working on, I don't have tons of time to dedicate to it, while working on other things.

2. If you remove the line from the bottom of the zombie_generate.sqf they will not attack zombies, in fact as this is the only modified bit of this file, you could simply not use it and leave the reference to it out of the init.sqf

3. I don't think the position respawn should effect the vanishing, the time they stick around should be directly tied to the respawn timer as set in the unit_killed.sqf, eventually the built in server_cleanup.fsm should remove them if there are to many dead bodies on the map, but that limit is default 300.
 
Would like if some one could look at my File and see if it is done correctly I have tried a lot of different things and cannot get it to work I feel like an idiot even asking because i know its something simple
 

Attachments

  • dayz_1.Chernarus.pbo
    61.7 KB · Views: 2
This line
// -----------------------------------------------
// respawning of groups & vehicles that are dynamically spawned in the grid system
// -----------------------------------------------
SAR_dynamic_group_respawn = true;

// time after which AI are respawned if configured
SAR_respawn_waittime = 900; // default 30 seconds

Does it means i enabled automatic respawns after 900 seconds after NPC dies?
I want to be sure.
 
Sorry, am asking another favour. Not so good at english as it foreign language which i use rarely.
Does
If somebody wants to take a stab at having zombies attack AI, then by all means pitch in - i'm currently looking through all of the dayz_code.pbo and I have some ideas, but I haven't implemented it yet.

Here's a first step though - have the zeds go after your ai gunfire like they would a player.

Add this code in your add_unit_server.sqf (I have mulitple copies of this file to generate different unit types).

Code:
// Alert zombies if a weapon is fired
_aiunit addEventHandler ["Fired", {[(_this Select 0),100,true,(getPosATL (_this Select 0))] execvm "units\NPC_AlertZombies.sqf";}];
 
//_aiunit addEventHandler ["Fired", {diag_log format ["AIUNIT: Alert - unit is shooting shit - %1",_this];}]; // for testing eventhandler
diag_log format ["AIUNIT: Creating MPEvent Handler for %1 ",_aiunit];

It should be within the "for [{ x=1 },{ x < _numunits+1 },{ x = x + 1; }] do " loop near the top.

Where i have to drop it?

Should look like??

Code:
};
// Alert zombies if a weapon is fired
_aiunit addEventHandler ["Fired", {[(_this Select 0),100,true,(getPosATL (_this Select 0))] execvm "units\NPC_AlertZombies.sqf";}];
 
//_aiunit addEventHandler ["Fired", {diag_log format ["AIUNIT: Alert - unit is shooting shit - %1",_this];}]; // for testing eventhandler
diag_log format ["AIUNIT: Creating MPEvent Handler for %1 ",_aiunit];
diag_log format["globalFaction is %1",globalFaction];
for [{ x=1 },{ x < _numunits+1 },{ x = x + 1; }] do {
_unitpos = [_xpos+x,_ypos+x,0];
switch (_unitType) do {
case 1 : {
_ailoadout=[_sniperRifle,_sniperAmmo];
_sniperSkin createUnit [_unitpos, _aigroup, "_aiunit=this;",1,"Private"];
_aiunit enableAI "TARGET";
_aiunit enableAI "AUTOTARGET";
_aiunit enableAI "MOVE";
_aiunit enableAI "ANIM";
_aiunit enableAI "FSM";
_aiunit allowDammage true;
_aiunit setCombatMode "RED";
_aiunit setBehaviour "COMBAT";
_aiunit addMPEventHandler["MPKilled",{null=_this+[aispawnpos,wpradius,wpnum,1,1,globalFaction,baseSkill,potentialSkill,gearSet,respawnTime] execVM "scripts\unit_killed.sqf";}];
//clear default weapons / ammo
removeAllWeapons _aiunit;
removeAllItems _aiunit;
  //add weapon...
...
...
[/quote]

Confusing. Can't understand where exactly i should paste that. :/

And last question
Then put this sqf file in your units\ directory:

Code:
//NPC_AlertZombies.sqf
 
private["_unit","_distance","_i","_listTalk","_zombie","_targets","_pos"];
//Alert Zed's to noise of shot
_unit =_this select 0;
_distance = _this select 1;
_doRun =_this select 2;
_pos =_this select 3;
_listTalk = _pos nearEntities ["zZombie_Base",_distance * 2];
 
 
// post to the RPT file if an npc alerts a zed
diag_log format ["NPC_AlertZombies: %1, %2, %3, %4",_unit,_distance,_dorun,_pos];
 
 
//hint str(_listTalk);
 
{
_zombie = _x;
if (_doRun) then {
_targets = _zombie getVariable ["targets",[]];
if (!(_unit in _targets)) then {
_targets set [count _targets,_unit];
_zombie setVariable ["targets",_targets,true];
};
} else {
_zombie setVariable ["myDest",_pos,true];
};
} forEach _listTalk;

That's pretty much the same code that alerts the zombies to a player gunshot, but the dayz code passes some ranges based upon the fired weapon, which I'm sure could be added pretty easily - baby steps :)

I can't find units\ directory :( Where exactly? Everything working fine, i just need only this script for perfection.
 
Onaabys,

Actually the issue you describe is a "fix" for the larger issue that most people have. The OP files pass the _aispawnpos to the unit_killed.sqf and this is used as the location of the respawn - the problem with this is that if you have more than 1 _aispawn line in your init.sqf you are overwriting this variable so by the time an NPC dies, they end up respawning at the location set in the last _aispawn line, the solution to this was to grab the NPC current position at the time of death and pass that to the unit_killed.sqf hence the (getPosATL (_this Select 0)) part of the event handler line. At the moment this is the best way to keep them roughly in the right place on respawn.

However this speaks to a larger problem which your debug line illustrates - all the info passed to the unit_killed.sqf faces the same issue (why they respawn as diff unit type) - we were able to solve the faction issue by using the (side (group (_this Select 0))), there is however currently no fix for the rest of the variables, it may not seem obvious in your test because you tested with the last line but had you used your first line, and left the last line in.

Code:
_aispawn = [[7622.51,7912.7,0],5000,20,1,4,1,8,10,0,5400] execVM "scripts\add_unit_server.sqf";//Chernaurs (Whole map) Militia Nato(Squad)

The log would have showed:
"Position: [where NPC died], Radius: 100, Waypoints: 5, Units: 1, Unit Type: 1, Faction: EAST, Base Skill: 7, Potential Skill: 10, Gear Set: 4, Respawn Time: 60"

This is an issue I have been working on, I don't have tons of time to dedicate to it, while working on other things.

2. If you remove the line from the bottom of the zombie_generate.sqf they will not attack zombies, in fact as this is the only modified bit of this file, you could simply not use it and leave the reference to it out of the init.sqf

3. I don't think the position respawn should effect the vanishing, the time they stick around should be directly tied to the respawn timer as set in the unit_killed.sqf, eventually the built in server_cleanup.fsm should remove them if there are to many dead bodies on the map, but that limit is default 300.

1. Maybe they didnt show up after respawn because of some of the weird places they died in and bugged out or something (was alot of obstacles in the area when i tested it). Seems like you have to choose how you want the NPCs to end up (as the last line respawn or the same place they died with a chance to spawn not correctly). I have to make the best of it as i can when. :)

2. Thanks gonna test it today how it works.

3. Yeah thanks checked the file and noticed as you said 300 dead bodies before it start to clean up.

Thanks for taking you time, helped alot with you answers! ;)
 
Call me a derp. But i actually had someone from the dayz forums talk me slowly through the install on my Teamspeak for this script.

I am using the original script from the first post.

First thing is it works. AI spawn Own the place up. They are carrying the load out i wan them to carry. My players were over the moon!

But then we found out when you killed them the insta Vanish :S No Loot no nothing. and with them on a Half hour re spawn i haven't tested if they will come back or not, but i read a-lot that people are not getting them re spawn.

Any help on making these Loot-able and making sure they kind of spawn back in the right area. would be fantastic.
Also maybe making them react to the zombies and the zombies react to them would be great!

I never expect anything for free so if someone can take the time to get the files for me or to talk me through it like the last gentleman I would happily throw a donation their way. I know scripting can be time consuming and doing it just because people ask and getting no reward seems wrong. Please get in touch! need this fixing.

Regards
Vori
*Edit* fixed the vanish act via page 26 thanks, still need them alerting and re spawning tho will keep looking
 

Attachments

  • init.sqf
    4.3 KB · Views: 4
  • add_unit_server.sqf
    13.7 KB · Views: 4
  • set_unit_faction.sqf
    298 bytes · Views: 2
  • unit_killed.sqf
    1.4 KB · Views: 2
  • zombie_generate.sqf
    2.8 KB · Views: 2
How would I get my solider NPCs to fight players only if a player shoots another solider because people are just shooting the soilders NPCs to get good gear
 
Bloodtype,

Glad you ssolved the vanish issue, as far as the respawn stuff look at my posts on the last few pages, I describe the code for both the location and faction fix, the NPC attacking zombie is handled by the addition of the line in the OP to the zombie_generate.sqf. to have the zombies attack NPC like a player check out or thrashers post on page 3. Currently on my mobile so can't check out you'd files.

Tiger,

If you set the soldiers to faction 0 and set resistance friendly to .6 then if you shoot one of the group the others should attack you, if you set the faction to 2 or west then this does not work.
 
Back
Top