Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Yea that worked. the AI wont attack any vehicles though? im using "militia man" only with L85A2Varsyn,
Try this init.sqf and let me know if it works
_aispawn = [[2758.7144,5304.3457,0],100,5,1,2,1,7,10,4,60]//Zelenogorsk test NPC
EAST setFriend [CIVILIAN,1];
//clear default weapons / ammo
removeAllWeapons _player;
removeAllItems _player;
_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)
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.
};
// 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...
...
...
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![]()
Gorri56,
Please try this init.sqf.
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.
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