mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-06 03:03:21 +00:00
Cleanup and remove V1 logic
This commit is contained in:
parent
4b9dd06256
commit
8154c97ea2
2 changed files with 17 additions and 75 deletions
Binary file not shown.
|
@ -7,7 +7,7 @@
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
|
|
||||||
static bool bEscapeReady = false;
|
static bool bEscapeReady = false;
|
||||||
static int TankClient, iAliveTanks;
|
static int iAliveTanks;
|
||||||
static bool bIsTank[MAXPLAYERS+1];
|
static bool bIsTank[MAXPLAYERS+1];
|
||||||
|
|
||||||
public Plugin myinfo =
|
public Plugin myinfo =
|
||||||
|
@ -52,11 +52,10 @@ public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Event_TankSpawn(Event event, const char[] name, bool dontBroadcast) {
|
public void Event_TankSpawn(Event event, const char[] name, bool dontBroadcast) {
|
||||||
iAliveTanks++;
|
|
||||||
int userID = GetClientOfUserId(GetEventInt(event, "userid"));
|
int userID = GetClientOfUserId(GetEventInt(event, "userid"));
|
||||||
|
iAliveTanks++;
|
||||||
bIsTank[userID] = true;
|
bIsTank[userID] = true;
|
||||||
if(iAliveTanks < 1) {
|
if(iAliveTanks < 1) {
|
||||||
TankClient = GetClientOfUserId(GetEventInt(event, "userid"));
|
|
||||||
CreateTimer(0.1, BotControlTimerV2, _, TIMER_REPEAT);
|
CreateTimer(0.1, BotControlTimerV2, _, TIMER_REPEAT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,81 +68,28 @@ public void Event_PlayerHurt(Event event, const char[] name, bool dontBroadcast)
|
||||||
char attackerName[16];
|
char attackerName[16];
|
||||||
GetClientName(attacker, attackerName, sizeof(attackerName));
|
GetClientName(attacker, attackerName, sizeof(attackerName));
|
||||||
if(StrContains(attackerName, "Tank", true) > -1) {
|
if(StrContains(attackerName, "Tank", true) > -1) {
|
||||||
|
bIsTank[targetPlayer] = false;
|
||||||
|
iAliveTanks = 0;
|
||||||
PrintToChatAll("%N (%d) was hit by tank %s (%d)", targetPlayer, targetPlayer, attackerName, attacker);
|
PrintToChatAll("%N (%d) was hit by tank %s (%d)", targetPlayer, targetPlayer, attackerName, attacker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
Logic overview:
|
|
||||||
1. Check If there is a tank (will be last spawned tank)
|
|
||||||
2. Check that the tank has a target (not waiting)
|
|
||||||
3. Loop all valid players (bots, alive, survivors)
|
|
||||||
4. If they are being targetted by tank OR health < 40:
|
|
||||||
always run away
|
|
||||||
5. Else if less than 200 units away:
|
|
||||||
run away
|
|
||||||
else:
|
|
||||||
attack tank
|
|
||||||
*/
|
|
||||||
public Action BotControlTimer(Handle timer)
|
|
||||||
{
|
|
||||||
//remove timer once tank no longer exists, is dead, or finale escape vehicle arrived
|
|
||||||
//temp improvement: disable if more than one tank.
|
|
||||||
|
|
||||||
if(bEscapeReady || iAliveTanks == 0) {
|
|
||||||
//Check if there is any existing bots, if escape NOT ready
|
|
||||||
if(!bEscapeReady) FindExistingTank();
|
|
||||||
return Plugin_Stop;
|
|
||||||
}
|
|
||||||
//Once an AI tank is awakened, m_lookatPlayer is set to a player ID
|
|
||||||
//Possible props: m_lookatPlayer, m_zombieState (if 1), m_hasVisibleThreats
|
|
||||||
int tank_target = GetEntPropEnt(TankClient, Prop_Send, "m_lookatPlayer", 0);
|
|
||||||
if(tank_target > -1) {
|
|
||||||
ShowHintToAll("TankClient#: %d | AliveTanks: %d | TankTarget: %N", TankClient, iAliveTanks, tank_target);
|
|
||||||
}else{
|
|
||||||
ShowHintToAll("TankClient#: %d | AliveTanks: %d | TankTarget: n/a", TankClient, iAliveTanks);
|
|
||||||
}
|
|
||||||
if(tank_target > -1) {
|
|
||||||
//grab tank position outside loop, only calculate bot
|
|
||||||
float TankPosition[3];
|
|
||||||
GetClientAbsOrigin(TankClient, TankPosition);
|
|
||||||
for (int i = 1; i <= MaxClients; i++)
|
|
||||||
{
|
|
||||||
if (IsClientInGame(i) && IsPlayerAlive(i) && GetClientTeam(i) == 2 && IsFakeClient(i))
|
|
||||||
{
|
|
||||||
//If distance between bot and tank is less than 200IQBots_TankDangerRange's float value
|
|
||||||
//if not tank target, and tank != visible threats, then attack. OR if health low, flee
|
|
||||||
int health = GetClientHealth(i);
|
|
||||||
if(tank_target == i || health <= 40) {
|
|
||||||
L4D2_RunScript("CommandABot({cmd=2,bot=GetPlayerFromUserID(%i),target=GetPlayerFromUserID(%i)})", GetClientUserId(i), GetClientUserId(TankClient));
|
|
||||||
}else {
|
|
||||||
|
|
||||||
float BotPosition[3];
|
|
||||||
GetClientAbsOrigin(i, BotPosition);
|
|
||||||
//Compare the distance between tank and the survivor bot, attack if far, run if too close.
|
|
||||||
float distance = GetVectorDistance(BotPosition, TankPosition);
|
|
||||||
if(distance < 200) {
|
|
||||||
L4D2_RunScript("CommandABot({cmd=2,bot=GetPlayerFromUserID(%i),target=GetPlayerFromUserID(%i)})", GetClientUserId(i), GetClientUserId(TankClient));
|
|
||||||
//do not attack if super close.
|
|
||||||
} else {
|
|
||||||
L4D2_RunScript("CommandABot({cmd=0,bot=GetPlayerFromUserID(%i),target=GetPlayerFromUserID(%i)})", GetClientUserId(i), GetClientUserId(TankClient));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Plugin_Continue;
|
|
||||||
}
|
|
||||||
/*
|
|
||||||
New logic overview:
|
New logic overview:
|
||||||
Either: Loop all tanks, check for any survivors.
|
1. Loop all valid survivors
|
||||||
Or: Loop any survivors, check for a nearby tank?
|
2. Loop all tanks per survivor
|
||||||
|
3. Find the closest tank
|
||||||
|
4. Retreat if in close range (~300 units)
|
||||||
|
|
||||||
|
CommandABot:
|
||||||
|
0 -> ATTACK
|
||||||
|
1 -> MOVETO
|
||||||
|
2 -> RUN AWAY
|
||||||
|
3 -> RESET
|
||||||
*/
|
*/
|
||||||
public Action BotControlTimerV2(Handle timer)
|
public Action BotControlTimerV2(Handle timer)
|
||||||
{
|
{
|
||||||
//remove timer once tank no longer exists, is dead, or finale escape vehicle arrived
|
//remove timer once tank no longer exists, is dead, or finale escape vehicle arrived
|
||||||
if(bEscapeReady || TankClient == -1 || !IsClientInGame(TankClient) || !IsPlayerAlive(TankClient)) {
|
if(bEscapeReady || iAliveTanks == 0) {
|
||||||
//Check if there is any existing bots, if escape NOT ready
|
//Check if there is any existing bots, if escape NOT ready
|
||||||
if(!bEscapeReady) FindExistingTank();
|
if(!bEscapeReady) FindExistingTank();
|
||||||
return Plugin_Stop;
|
return Plugin_Stop;
|
||||||
|
@ -171,7 +117,6 @@ public Action BotControlTimerV2(Handle timer)
|
||||||
GetClientAbsOrigin(tankID, TankPosition);
|
GetClientAbsOrigin(tankID, TankPosition);
|
||||||
//Get distance to survivor, and compare to get closest tank
|
//Get distance to survivor, and compare to get closest tank
|
||||||
float distanceFromSurvivor = GetVectorDistance(BotPosition, TankPosition);
|
float distanceFromSurvivor = GetVectorDistance(BotPosition, TankPosition);
|
||||||
PrintHintTextToAll("[Survivor: %N (%d)] | Tank: %d | Distance: %f", i, i, tankID, distanceFromSurvivor);
|
|
||||||
if(distanceFromSurvivor <= 1000 && smallestDistance > distanceFromSurvivor || smallestDistance == 0.0) {
|
if(distanceFromSurvivor <= 1000 && smallestDistance > distanceFromSurvivor || smallestDistance == 0.0) {
|
||||||
smallestDistance = distanceFromSurvivor;
|
smallestDistance = distanceFromSurvivor;
|
||||||
closestTank = tankID;
|
closestTank = tankID;
|
||||||
|
@ -180,10 +125,9 @@ public Action BotControlTimerV2(Handle timer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//If the closest tank exists (-1 means no tank.) and is close, avoid.
|
//If the closest tank exists (-1 means no tank.) and is close, avoid.
|
||||||
if(closestTank > -1 && smallestDistance <= 1000) {
|
//TODO: Possibly only run if they have an item in the pill shot, or have medkit.
|
||||||
if(smallestDistance <= 300) {
|
if(closestTank > -1 && smallestDistance <= 300 && botHealth >= 40) {
|
||||||
L4D2_RunScript("CommandABot({cmd=2,bot=GetPlayerFromUserID(%i),target=GetPlayerFromUserID(%i)})", GetClientUserId(i), GetClientUserId(closestTank));
|
L4D2_RunScript("CommandABot({cmd=2,bot=GetPlayerFromUserID(%i),target=GetPlayerFromUserID(%i)})", GetClientUserId(i), GetClientUserId(closestTank));
|
||||||
}
|
|
||||||
}else{
|
}else{
|
||||||
L4D2_RunScript("CommandABot({cmd=3,bot=GetPlayerFromUserID(%i)", GetClientUserId(i));
|
L4D2_RunScript("CommandABot({cmd=3,bot=GetPlayerFromUserID(%i)", GetClientUserId(i));
|
||||||
}
|
}
|
||||||
|
@ -192,7 +136,6 @@ public Action BotControlTimerV2(Handle timer)
|
||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
}
|
}
|
||||||
void resetPlugin() {
|
void resetPlugin() {
|
||||||
TankClient = -1;
|
|
||||||
bEscapeReady = false;
|
bEscapeReady = false;
|
||||||
iAliveTanks = 0;
|
iAliveTanks = 0;
|
||||||
for(int i = 0; i < sizeof(bIsTank); i++) {
|
for(int i = 0; i < sizeof(bIsTank); i++) {
|
||||||
|
@ -212,7 +155,6 @@ public void FindExistingTank() {
|
||||||
bIsTank[i] = true;
|
bIsTank[i] = true;
|
||||||
PrintToChatAll("Found existing tank: %N (%i)", i, i);
|
PrintToChatAll("Found existing tank: %N (%i)", i, i);
|
||||||
if(iAliveTanks == 0) {
|
if(iAliveTanks == 0) {
|
||||||
TankClient = i;
|
|
||||||
CreateTimer(0.1, BotControlTimerV2, _, TIMER_REPEAT);
|
CreateTimer(0.1, BotControlTimerV2, _, TIMER_REPEAT);
|
||||||
}
|
}
|
||||||
iAliveTanks++;
|
iAliveTanks++;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue