Jump to content

Spawning military AI/friendlies


Recommended Posts

I got the idea to create a mission where bandits are attacking a military base. I want to create military AI that are friendly towards the players to fight back the bandits. Here's what I've got so far:

 

I made a copy of DZMSAISpawn.sqf and named it DZMSMilitarySpawn.sqf. The only changes I made where switching the group to West, which will presumably make them friendly:

_unitGroup = createGroup west;

I also changed the skins, also in the DZMSMilitarySpawn.sqf:

_aiskin = DZMSMilitarySkins call BIS_fnc_selectRandom;

In DZMSFunctions.sqf, I added a line:

DZMSMilitarySpawn = compile preprocessFileLineNumbers "\z\addons\dayz_server\DZMS\Scripts\DZMSMilitarySpawn.sqf";

I added this to the DZMSAiConfig.sqf:

DZMSMilitarySkins = ["Rocket_DZ","Soldier1_DZ","Camo1_DZ","FR_OHara_DZ","FR_Rodriguez_DZ","Graves Light DZ","CZ_Special_Forces_GL_DES_EP1_DZ"];

In the mission, I spawned bandits and military:

//DZMSAISpawn spawns AI to the mission.
//Usage: [_coords, count, skillLevel, unitArray]
[_coords1,2,1,"DZMSUnitsMinor"] call DZMSAISpawn;
sleep 5;
[_coords1,2,1,"DZMSUnitsMinor"] call DZMSAISpawn;
sleep 5;
[_coords1,2,1,"DZMSUnitsMinor"] call DZMSAISpawn;
sleep 5;
[_coords1,2,1,"DZMSUnitsMinor"] call DZMSAISpawn;
sleep 1;


//DZMSAISpawn spawns military to the mission.
//Usage: [_coords, count, skillLevel, unitArray]
[_coords,2,1,"DZMSUnitsMinor"] call DZMSMilitarySpawn;
sleep 5;
[_coords,2,1,"DZMSUnitsMinor"] call DZMSMilitarySpawn;
sleep 5;
[_coords,2,1,"DZMSUnitsMinor"] call DZMSMilitarySpawn;
sleep 5;
[_coords,2,1,"DZMSUnitsMinor"] call DZMSMilitarySpawn;
sleep 1;

However, the military AI are not spawning. From my RPT log:

12:37:58 Error in expression <_fnc_selectRandom;




_unit = _unitGroup createUnit [_aiskin, [(_position>
12:37:58   Error position: <createUnit [_aiskin, [(_position>
12:37:58   Error Type Any, expected String
12:37:58 File z\addons\dayz_server\DZMS\Scripts\DZMSMilitarySpawn.sqf, line 33
12:37:58 Error in expression <_fnc_selectRandom;

Obviously the error has something to do with the call for the skin to use. What am I doing wrong?

 

Link to comment
Share on other sites

<_fnc_selectRandom;  The only difference I see is this, but I'm literally just starting out. Is it supposed to be _fnc or BIS_fnc?

 

 

BIS_fnc_selectRandom;

 

That's not a line that I touched when I copied it from DZMSAISpawn.sqf to DZMSMilitarySpawn.sqf and DZMSAISpawn.sqf works fine, so I don't think that's it. I think it has something to do with the _aiskin variable. I'm sure I need to set something up additionally for the skin selection of the military units.

Link to comment
Share on other sites

Ok, I got the military AI to spawn and they are fighting with the bandits. I now have two problems:

 

1. I have DZMS configured to end a mission if 25% of the bandits are killed and the player gets within 30m of the mission. The deaths of the military AI are being counted towards this 25%. Can I make it so only the bandit AI counts towards that?

 

2. When the soldier AI's are killed, they have no weapons, magazines or backpacks, only toolbelt items.

 

*Edit* It seems that only when AI is killed by another AI, they are losing their gear. If I kill an AI, they still have their gear. Also, any way to take humanity AWAY from a player if they kill a military AI?

Link to comment
Share on other sites

I think the issue is that you are putting both the military and bandit units into the same array, DZMSUnitsMinor, and the check is if 25% of if the units in that array are killed. Not sure if creating a second array will work or how to pull that off.

Now if only I can get DZMS to work on my test server. :(

Link to comment
Share on other sites

I got the problem of the mission clearing due to military AI deaths by changing DZMSUnitsMinor to DZMSUnitsMilitary. Thanks TheFarix, I wouldn't have thought to change that array.

 

For example:

[_coords,2,1,"DZMSUnitsMilitary"] call DZMSMilitarySpawn;

What I have left to solve is:

 

1. Gear disappears (Except toolbelt items) from AI if another AI kills them (MIlitary kills bandit or bandit kills military). Player killed AI retain their gear.

2. Prevent humanity from being gained, or take away humanity for killing military AI (My server is a PVE server).

 

If anyone can help me out with these, I'll be just about ready to release this for everyone to use in their missions!

Link to comment
Share on other sites

maybe it helps you...add variables to units for later identification in aikilled.sqf - then you only need to check for vars and override the humanity/rungear-thing what is part of the aikilled-script.

 

btw. contact me if you need help - i have the next days time for it :)

Link to comment
Share on other sites

maybe it helps you...add variables to units for later identification in aikilled.sqf - then you only need to check for vars and override the humanity/rungear-thing what is part of the aikilled-script.

 

btw. contact me if you need help - i have the next days time for it :)

 

I don't understand what you are trying to say. My current skill level is on the level of editing existing code, not writing new stuff. 

 

After thinking about the gear issue, I think it might be better that way. Otherwise, players might be inclined to sit back and watch the military kill the bandits then go collect the loot for themselves. If the only loot they get is when they kill a bandit, they might be more inclined to kill the bandits themselves.

Link to comment
Share on other sites

I haven't modified DZMS's DZMSAISpawn.sqf and DZMSAIKilled.sqf.

 

DZMSKilled.sqf is not detecting a player as killing them, so if you have DZMSRunGear true in the config, DZMS assumes the AI was killed by a vehicle and clears their gear. You should be able to check if _player isKindOf "Man" to prevent the gear being cleared.

 

As for the humanity, you should be able to modify it to check the side of _unit in DZMSKilled.sqf.

Link to comment
Share on other sites

DZMSKilled.sqf is not detecting a player as killing them, so if you have DZMSRunGear true in the config, DZMS assumes the AI was killed by a vehicle and clears their gear. You should be able to check if _player isKindOf "Man" to prevent the gear being cleared.

 

As for the humanity, you should be able to modify it to check the side of _unit in DZMSKilled.sqf.

 

you can not check side of a dead unit, however you can check side of the group the unit came from, if not deleted yet ...

Link to comment
Share on other sites

  • 2 weeks later...

I sort of fixed the humanity issue.

 

I edited this line:

_unit addEventHandler ["Killed",{ [(_this select 0), (_this select 1)] ExecVM DZMSAIKilled; }];

Changed it to this:

_unit addEventHandler ["Killed",{ [(_this select 0), (_this select 1)] ExecVM DZMSMilitaryKilled; }];

I copied DZMSAIKilled and renamed it DZMSMilitaryKilled and changed these lines:

//If the player gets humanity per config, lets give it
if (DZMSMissHumanity) then {
_player setVariable ["humanity",(_humanity + DZMSCntHumanity),true];
};


//If this counts as a bandit kill, lets give it
if (DZMSCntBanditKls) then {
_player setVariable ["banditKills",(_banditkills + 1),true];
};

To this:

//If the player gets humanity per config, lets give it
if (DZMSMissHumanity) then {
_player setVariable ["humanity",(_humanity - DZMSCntHumanity),true];
};


//If this counts as a bandit kill, lets give it
if (DZMSCntBanditKls) then {
_player setVariable ["banditKills",(_banditkills - 1),true];
};

I changed _humanity + DZMSCntHumanity to _humanity - DZMSCntHumanity and _banditkills + 1 to _banditkills - 1. Instead of removing humanity and a bandit kill, the humanity and bandit kill just isn't registering when killing a military unit. I'd prefer that it remove the humanity and one kill if possible. I thought changing the + to a - would do that, but apparently not.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...