361 lines
12 KiB
C
361 lines
12 KiB
C
class BotGroupMissionC1: MissionBase
|
|
{
|
|
|
|
void BotGroupMissionC1() { StartMissionAI(); }
|
|
|
|
AIWorld world = GetGame().GetWorld().GetAIWorld();
|
|
|
|
// Bot configs
|
|
vector BotSpawnPoint = "7852.263672 6.132144 3174.178955"; // set the spawn point of the bot
|
|
|
|
int m_botAcuracy = 10; // Setting the bot's accuracy (the higher the number, the more often the bot misses)
|
|
|
|
int BotSolderCountMin = 3; // assign the minimum number of bots
|
|
int BotSolderCountMax = 4; // assign the maximum number of bots
|
|
|
|
int botLootCountMin = 5; // set the minimum amount of loot for the bot
|
|
int botLootCountMax = 15; // assign the maximum amount of loot for the bot
|
|
|
|
float Zone_Radius = 1100; // Trigger radius for the player to spawn bots
|
|
|
|
bool isUseCheckPoints = false; // set whether checkpoints are used true - used, fslse - not used
|
|
bool isBotKaratist = true; // We set whether bots will carry weapons or will be fought with fists, by default they are with weapons, if needed without a firearm, write true
|
|
bool onRespawnBot = true; // Enable or disable bot respawn (true - enabled, fslse - disabled)
|
|
bool canUseTrigger = true; // Use trigger (true - enabled, fslse - disabled), if the trigger is not used, bots will spawn immediately after starting the server
|
|
bool useKilFeed = true; // Enabling or disabling alerts when killing a bot
|
|
bool m_Frendly = true; // Friendliness :) enable or disable. If enabled, then bots will not attack you until you attack it, if you attack a bot, you will become an enemy for all bots.
|
|
bool onVoice = true; // Enable or disable bot voice (enabling this setting causes more server load)
|
|
int m_spawnBotRadius = 100; // The radius of the spawn of bots in the territory, the center of the territory is the coordinate specified in BotSpawnPoint
|
|
int m_SpeedPatrol = 3; // Setting the movement speed while patrolling (min = 1 max = 3)
|
|
|
|
|
|
int m_TargetDist = 100; // We set the distance in meters at which the bot sees the target.
|
|
|
|
bool canBotSpawned = true; // Do not change !!!!!!!
|
|
|
|
// ------------------------------- end of config ------------------------------------------ //
|
|
|
|
|
|
// Arrays with loot and clothes
|
|
// If some type is not needed, just leave empty quotes example ---> TStringArray OtherEquip = {""};
|
|
ref TStringArray Shirt = {"GorkaEJacket_Autumn", "GorkaEJacket_Flat", "GorkaEJacket_PautRev", "GorkaEJacket_Summer"}; //Add the top of the clothes
|
|
ref TStringArray Jeans = {"GorkaPants_Autumn", "GorkaPants_Flat", "GorkaPants_PautRev", "GorkaPants_Summer"}; //Add pants
|
|
ref TStringArray Shoes = {"TTSKOBoots", "WorkingBoots_Beige", "CombatBoots_Beige", "CombatBoots_Black", "CombatBoots_Brown"}; //Add boots
|
|
ref TStringArray BackPack = {"CoyoteBag_Brown", "CoyoteBag_Green", "HuntingBag", "TortillaBag", "WaterproofBag_Green"}; //Add the Backpack
|
|
ref TStringArray Vest = {"HighCapacityVest_Black", "HighCapacityVest_Olive", "HuntingVest", "PlateCarrierVest", "UKAssVest_Camo"}; //Add Vest
|
|
ref TStringArray Helm = {"GorkaHelmet", "Mich2001Helmet", "MotoHelmet_Black", "PumpkinHelmet", "SkateHelmet_Black"}; //Add a helmet or headgear
|
|
ref TStringArray Gloves = {"WorkingGloves_Beige", "WorkingGloves_Black", "NBCGlovesGray", "OMNOGloves_Brown", "SurgicalGloves_Blue"}; //Add gloves
|
|
ref TStringArray OtherEquip = {"CivilianBelt", "MilitaryBelt"}; //Add an additional item of clothing, it can be anything :)
|
|
|
|
ref TStringArray RandomLoot = {"SardinesCan", "SodaCan_Cola", "SodaCan_Kvass", "Rice", "Rope", "Screwdriver", "AmmoBox_545x39_20Rnd"}; //We add any loot to the array, the amount is not limited
|
|
ref TStringArray MeleeWeap = {"WoodAxe", "FirefighterAxe", "Shovel", "Pickaxe"}; //Add melee weapons
|
|
|
|
// -------------------------------- end -------------------------------------------------------//
|
|
|
|
EntityAI itemEnt; // Do not change !!!!
|
|
|
|
// Function for creating checkpoints (register checkpoints here)
|
|
void AddCeckPoint(SurvivorBotBase m_BotSolder)
|
|
{
|
|
m_BotSolder.SetUseCheckpoint(); // Do not touch this line!
|
|
|
|
m_BotSolder.AddCheckpoint("1724.632080 451.730408 14298.412109");
|
|
}
|
|
// ---------------------------------- end -------------------------------------- /
|
|
|
|
ref array<SurvivorBotBase> m_BotMass = new array<SurvivorBotBase>;
|
|
ref array<SurvivorBotBase> m_PlaersZoneArray = new array<SurvivorBotBase>;
|
|
|
|
// The function of creating weapons for the bot (here you can add 7 weapon wmds, enter at your discretion)
|
|
void createWeapFromBot(SurvivorBotBase m_BotSolder)
|
|
{
|
|
int randomWeapon = Math.RandomInt(1, 7);
|
|
|
|
switch( randomWeapon )
|
|
{
|
|
case 1:
|
|
{
|
|
m_BotSolder.AddWeapon("M4A1"); //Weapon
|
|
m_BotSolder.AddWeaponAtt("M4_RISHndgrd"); //Att 1
|
|
m_BotSolder.AddWeaponAtt("M4_MPBttstck"); //Att 2
|
|
m_BotSolder.AddWeaponAtt("ACOGOptic"); //Att 3
|
|
m_BotSolder.AddMagazine("Mag_STANAG_30Rnd"); //Mag
|
|
break;
|
|
//We add body kits as needed, magazines for weapons are issued automatically, no need to add them
|
|
}
|
|
|
|
case 2:
|
|
{
|
|
m_BotSolder.AddWeapon("AKM");
|
|
m_BotSolder.AddWeaponAtt("AK_WoodBttstck");
|
|
m_BotSolder.AddWeaponAtt("AK_WoodHndgrd");
|
|
m_BotSolder.AddMagazine("Mag_AKM_Drum75Rnd");
|
|
break;
|
|
}
|
|
|
|
case 3:
|
|
{
|
|
m_BotSolder.AddWeapon("AKM");
|
|
m_BotSolder.AddWeaponAtt("AK_WoodBttstck");
|
|
m_BotSolder.AddWeaponAtt("AK_WoodHndgrd");
|
|
m_BotSolder.AddMagazine("Mag_AKM_Drum75Rnd");
|
|
break;
|
|
}
|
|
|
|
case 4:
|
|
{
|
|
m_BotSolder.AddWeapon("SVD");
|
|
m_BotSolder.AddMagazine("Mag_SVD_10Rnd");
|
|
break;
|
|
}
|
|
|
|
case 5:
|
|
{
|
|
m_BotSolder.AddWeapon("M4A1");
|
|
m_BotSolder.AddWeaponAtt("M4_RISHndgrd");
|
|
m_BotSolder.AddWeaponAtt("M4_MPBttstck");
|
|
m_BotSolder.AddWeaponAtt("ACOGOptic");
|
|
m_BotSolder.AddMagazine("Mag_STANAG_30Rnd");
|
|
break;
|
|
}
|
|
|
|
case 6:
|
|
{
|
|
m_BotSolder.AddWeapon("AKM");
|
|
m_BotSolder.AddWeaponAtt("AK_WoodBttstck");
|
|
m_BotSolder.AddWeaponAtt("AK_WoodHndgrd");
|
|
m_BotSolder.AddMagazine("Mag_AKM_Drum75Rnd");
|
|
break;
|
|
}
|
|
|
|
case 7:
|
|
{
|
|
m_BotSolder.AddWeapon("AKM");
|
|
m_BotSolder.AddWeaponAtt("AK_WoodBttstck");
|
|
m_BotSolder.AddWeaponAtt("AK_WoodHndgrd");
|
|
m_BotSolder.AddMagazine("Mag_AKM_Drum75Rnd");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
// ----------------------------- end ------------------------------------- //
|
|
|
|
// Bot spawn function (we don't change anything here !!!)
|
|
void createBotUnit()
|
|
{
|
|
vector Navmesh;
|
|
vector botSpPos;
|
|
private SurvivorBotBase m_BotSolder;
|
|
|
|
ref TStringArray m_BotBody = { "BotM_Mirek", "BotM_Rolf", "BotM_Quinn", "BotM_Peter", "BotM_Oliver" };
|
|
|
|
PGFilter m_pgFilterNav = new PGFilter();
|
|
m_pgFilterNav.SetFlags(PGPolyFlags.WALK, PGPolyFlags.INSIDE, 0);
|
|
|
|
float bspX = BotSpawnPoint[0];
|
|
float bspY = BotSpawnPoint[2];
|
|
|
|
if (isUseCheckPoints)
|
|
botSpPos = Vector(bspX + Math.RandomInt(-7, 7), BotSpawnPoint[1], bspY + Math.RandomInt(-7, 7));
|
|
else
|
|
botSpPos = Vector(bspX + Math.RandomInt(-m_spawnBotRadius, m_spawnBotRadius), BotSpawnPoint[1], bspY + Math.RandomInt(-m_spawnBotRadius, m_spawnBotRadius));
|
|
|
|
bool IsNavmesh = world.SampleNavmeshPosition( botSpPos, 2, m_pgFilterNav, Navmesh );
|
|
|
|
if (IsNavmesh)
|
|
m_BotSolder = SurvivorBotBase.Cast(GetGame().CreatePlayer(null, m_BotBody.GetRandomElement(), Navmesh, 0, "NONE"));
|
|
else
|
|
m_BotSolder = SurvivorBotBase.Cast(GetGame().CreatePlayer(null, m_BotBody.GetRandomElement(), botSpPos, 0, "NONE"));
|
|
|
|
|
|
m_BotSolder.GetInventory().CreateInInventory(Shirt.GetRandomElement());
|
|
m_BotSolder.GetInventory().CreateInInventory(Jeans.GetRandomElement());
|
|
m_BotSolder.GetInventory().CreateInInventory(Shoes.GetRandomElement());
|
|
m_BotSolder.GetInventory().CreateInInventory(BackPack.GetRandomElement());
|
|
m_BotSolder.GetInventory().CreateInInventory(Vest.GetRandomElement());
|
|
m_BotSolder.GetInventory().CreateInInventory(Helm.GetRandomElement());
|
|
m_BotSolder.GetInventory().CreateInInventory(Gloves.GetRandomElement());
|
|
m_BotSolder.GetInventory().CreateInInventory(OtherEquip.GetRandomElement());
|
|
|
|
if (isBotKaratist)
|
|
m_BotSolder.GetHumanInventory().CreateInHands(MeleeWeap.GetRandomElement());
|
|
else
|
|
createWeapFromBot(m_BotSolder);
|
|
|
|
int rndLootCnt = Math.RandomInt(botLootCountMin, botLootCountMax);
|
|
|
|
for (int i = 0; i < rndLootCnt; i++)
|
|
{
|
|
itemEnt = m_BotSolder.GetInventory().CreateInInventory(RandomLoot.GetRandomElement());
|
|
if (itemEnt)
|
|
{
|
|
int rndHlt = Math.RandomInt(55,100);
|
|
itemEnt.SetHealth("","",rndHlt);
|
|
}
|
|
}
|
|
|
|
m_BotSolder.SetAcuracy(m_botAcuracy);
|
|
m_BotSolder.SetDistance(m_TargetDist);
|
|
m_BotSolder.SetUseVoice(onVoice);
|
|
m_BotSolder.SetUseKillFeed(useKilFeed);
|
|
m_BotSolder.SetFrendly(m_Frendly);
|
|
m_BotSolder.SetSpeedPatrol(m_SpeedPatrol);
|
|
|
|
|
|
if (isUseCheckPoints)
|
|
AddCeckPoint(m_BotSolder);
|
|
|
|
|
|
m_BotMass.Insert(m_BotSolder);
|
|
}
|
|
// ----------------------------- end ------------------------------------- //
|
|
|
|
// ----------------------------- Bots respawn function ----------------------------------------//
|
|
private void respawnBotUnitC1()
|
|
{
|
|
ref array<Man> players = new array<Man>;
|
|
GetGame().GetPlayers( players );
|
|
SurvivorBotBase Bot_Ar;
|
|
vector posB;
|
|
bool m_botRemoved = false;
|
|
float distB;
|
|
int m_countBot = m_BotMass.Count();
|
|
int plaersZoneCount = -1;
|
|
m_PlaersZoneArray.Clear();
|
|
if (canBotSpawned)
|
|
{
|
|
for ( int u = 0; u < players.Count(); u++ )
|
|
{
|
|
|
|
PlayerBase player;
|
|
Class.CastTo(player, players.Get(u));
|
|
vector pos = player.GetPosition();
|
|
float dist = vector.Distance( pos, BotSpawnPoint );
|
|
|
|
if ( dist < Zone_Radius && player.IsAlive() )
|
|
{
|
|
m_PlaersZoneArray.Insert(player);
|
|
// return;
|
|
}
|
|
}
|
|
Print("Players count in zone bots C1 = " + m_PlaersZoneArray.Count());
|
|
if (m_PlaersZoneArray.Count() == 0)
|
|
{
|
|
|
|
for ( int a = 0; a < m_countBot; a++ )
|
|
{
|
|
Bot_Ar = m_BotMass.Get(a);
|
|
if (Bot_Ar)
|
|
{
|
|
if (!Bot_Ar.IsAlive())
|
|
{
|
|
posB = Bot_Ar.GetPosition();
|
|
distB = vector.Distance( posB, BotSpawnPoint );
|
|
if (distB < Zone_Radius)
|
|
{
|
|
m_BotMass.Remove( a );
|
|
}
|
|
|
|
if (m_BotMass.Count() == 0)
|
|
m_botRemoved = true;
|
|
}
|
|
else
|
|
{
|
|
if (distB < Zone_Radius)
|
|
{
|
|
m_BotMass.Remove( a );
|
|
GetGame().ObjectDelete( Bot_Ar );
|
|
}
|
|
|
|
if (m_BotMass.Count() == 0)
|
|
m_botRemoved = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (m_botRemoved && m_PlaersZoneArray.Count() == 0)
|
|
{
|
|
StartMissionAI();
|
|
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(respawnBotUnitC1);
|
|
m_botRemoved = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// ----------------------------- end ----------------------------------------//
|
|
|
|
|
|
|
|
|
|
// Spawn function of a group of bots
|
|
int delaySpawn = 0;
|
|
void spawnBotGroup()
|
|
{
|
|
int rndBotGrpCnt = Math.RandomInt(BotSolderCountMin, BotSolderCountMax);
|
|
Print("Bots spawned! Count " + rndBotGrpCnt);
|
|
for (int a = 0; a < rndBotGrpCnt; a++)
|
|
{
|
|
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(createBotUnit, 500 + delaySpawn);
|
|
delaySpawn +=1000;
|
|
}
|
|
}
|
|
// --------------------------------------- end --------------------------------------- //
|
|
|
|
// Player trigger function
|
|
void TriggerPlayersC1()
|
|
{
|
|
ref array<Man> players = new array<Man>;
|
|
GetGame().GetPlayers( players );
|
|
delaySpawn = 0;
|
|
|
|
if (canBotSpawned && IsGoodSrvFps())
|
|
{
|
|
for ( int u = 0; u < players.Count(); u++ )
|
|
{
|
|
|
|
PlayerBase player;
|
|
Class.CastTo(player, players.Get(u));
|
|
vector pos = player.GetPosition();
|
|
float dist = vector.Distance( pos, BotSpawnPoint );
|
|
|
|
if ( dist < Zone_Radius && !player.IsBot() )
|
|
{
|
|
spawnBotGroup();
|
|
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(TriggerPlayersC1);
|
|
|
|
if (onRespawnBot)
|
|
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(respawnBotUnitC1, 60000, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// --------------------------------------- end --------------------------------------- //
|
|
|
|
void StartMissionAI()
|
|
{
|
|
Print("Start mission bot");
|
|
if (canUseTrigger)
|
|
{
|
|
GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(TriggerPlayersC1, 5000, true);
|
|
}
|
|
else if (IsGoodSrvFps())
|
|
{
|
|
spawnBotGroup();
|
|
}
|
|
}
|
|
|
|
bool IsGoodSrvFps()
|
|
{
|
|
float TestFpsSrv = GetGame().GetFps();
|
|
|
|
if (TestFpsSrv < 2)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
Print("Server FPS low! FPS = " + TestFpsSrv + " Bots not respawned!");
|
|
return false;
|
|
}
|
|
}
|
|
} |