improved player following significiantly again
This commit is contained in:
parent
90c83dedb8
commit
1b90d90d4b
@ -13,8 +13,8 @@
|
|||||||
#include <cstrike>
|
#include <cstrike>
|
||||||
#include <socket>
|
#include <socket>
|
||||||
|
|
||||||
int target_human_afk_counter[MAXPLAYERS + 1];
|
int target_friend_afk_counter[MAXPLAYERS + 1];
|
||||||
int targethuman[MAXPLAYERS + 1];
|
int target_friend[MAXPLAYERS + 1];
|
||||||
int target_enemy[MAXPLAYERS + 1];
|
int target_enemy[MAXPLAYERS + 1];
|
||||||
int buttons_old[MAXPLAYERS + 1];
|
int buttons_old[MAXPLAYERS + 1];
|
||||||
int flags_old[MAXPLAYERS + 1];
|
int flags_old[MAXPLAYERS + 1];
|
||||||
@ -47,7 +47,7 @@ public void OnPluginStart()
|
|||||||
for (int i = 1; i <= MaxClients; i++)
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
if (IsValidClient(i))
|
if (IsValidClient(i))
|
||||||
{
|
{
|
||||||
targethuman[i] = 0;
|
target_friend[i] = 0;
|
||||||
target_enemy[i] = 0;
|
target_enemy[i] = 0;
|
||||||
reset_target_human_tp_coord(i);
|
reset_target_human_tp_coord(i);
|
||||||
OnClientPostAdminCheck(i);
|
OnClientPostAdminCheck(i);
|
||||||
@ -81,7 +81,7 @@ public void trigger_teleport(const char[] output, int entity_index, int client,
|
|||||||
for (int i = 1; i <= MaxClients; i++)
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
if (IsValidClient(i))
|
if (IsValidClient(i))
|
||||||
{
|
{
|
||||||
if (targethuman[i] == client)
|
if (target_friend[i] == client)
|
||||||
{
|
{
|
||||||
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported[i]);
|
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported[i]);
|
||||||
CreateTimer(6.0, reset_target_tp, client);
|
CreateTimer(6.0, reset_target_tp, client);
|
||||||
@ -98,7 +98,7 @@ public void Trigger_Multiple(const char[] output, int entity_index, int client,
|
|||||||
for (int i = 1; i <= MaxClients; i++)
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
if (IsValidClient(i))
|
if (IsValidClient(i))
|
||||||
{
|
{
|
||||||
if (targethuman[i] == client)
|
if (target_friend[i] == client)
|
||||||
{
|
{
|
||||||
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported[i]);
|
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported[i]);
|
||||||
CreateTimer(6.0, reset_target_tp, client);
|
CreateTimer(6.0, reset_target_tp, client);
|
||||||
@ -277,7 +277,7 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast
|
|||||||
for (int i = 1; i <= MaxClients; i++)
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
if (IsValidClient(i) && !IsFakeClient(i))
|
if (IsValidClient(i) && !IsFakeClient(i))
|
||||||
{
|
{
|
||||||
targethuman[i] = 0;
|
target_friend[i] = 0;
|
||||||
target_enemy[i] = 0;
|
target_enemy[i] = 0;
|
||||||
reset_target_human_tp_coord(i);
|
reset_target_human_tp_coord(i);
|
||||||
}
|
}
|
||||||
@ -316,11 +316,6 @@ public Action bot_check_connect(Handle timer, any data)
|
|||||||
for (int i = 1; i <= MaxClients; i++)
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
if (IsValidClient(i) && !IsFakeClient(i))
|
if (IsValidClient(i) && !IsFakeClient(i))
|
||||||
{
|
{
|
||||||
//OnClientPostAdminCheck and OnClientAuthorized forwards wont trigger on the gg server after mapchanges/reconnects, welp
|
|
||||||
if (CheckCommandAccess(i, "sm_kick", ADMFLAG_KICK))
|
|
||||||
admins[i] = true;
|
|
||||||
else if (CheckCommandAccess(i, "sm_reserved", ADMFLAG_RESERVATION))
|
|
||||||
vips[i] = true;
|
|
||||||
if (client_count > 60)
|
if (client_count > 60)
|
||||||
{
|
{
|
||||||
found_bot1 = true;
|
found_bot1 = true;
|
||||||
@ -379,25 +374,21 @@ public Action bot_check_connect(Handle timer, any data)
|
|||||||
{
|
{
|
||||||
send_socket_msg(msg, strlen(msg), ports[0]);
|
send_socket_msg(msg, strlen(msg), ports[0]);
|
||||||
found_bot1 = true;
|
found_bot1 = true;
|
||||||
CreateTimer(1.0, respawn_bot, i);
|
|
||||||
}
|
}
|
||||||
if (is_autism_bot2(i))
|
if (is_autism_bot2(i))
|
||||||
{
|
{
|
||||||
send_socket_msg(msg, strlen(msg), ports[1]);
|
send_socket_msg(msg, strlen(msg), ports[1]);
|
||||||
found_bot2 = true;
|
found_bot2 = true;
|
||||||
CreateTimer(1.0, respawn_bot, i);
|
|
||||||
}
|
}
|
||||||
if (is_autism_bot3(i))
|
if (is_autism_bot3(i))
|
||||||
{
|
{
|
||||||
send_socket_msg(msg, strlen(msg), ports[2]);
|
send_socket_msg(msg, strlen(msg), ports[2]);
|
||||||
found_bot3 = true;
|
found_bot3 = true;
|
||||||
CreateTimer(1.0, respawn_bot, i);
|
|
||||||
}
|
}
|
||||||
if (is_autism_bot4(i))
|
if (is_autism_bot4(i))
|
||||||
{
|
{
|
||||||
send_socket_msg(msg, strlen(msg), ports[3]);
|
send_socket_msg(msg, strlen(msg), ports[3]);
|
||||||
found_bot4 = true;
|
found_bot4 = true;
|
||||||
CreateTimer(1.0, respawn_bot, i);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -525,12 +516,6 @@ public bool is_bot_player(int client)
|
|||||||
|
|
||||||
public Action recursive_pressing(Handle timer, any data)
|
public Action recursive_pressing(Handle timer, any data)
|
||||||
{
|
{
|
||||||
int i_port = GetConVarInt(FindConVar("hostport"));
|
|
||||||
bool is_host_ze = false;
|
|
||||||
if (i_port == server_ports[0])
|
|
||||||
{
|
|
||||||
is_host_ze = true;
|
|
||||||
}
|
|
||||||
bool found_valid_ct = false;
|
bool found_valid_ct = false;
|
||||||
for (int client = 1; client <= MaxClients; client++)
|
for (int client = 1; client <= MaxClients; client++)
|
||||||
{
|
{
|
||||||
@ -539,39 +524,12 @@ public Action recursive_pressing(Handle timer, any data)
|
|||||||
{
|
{
|
||||||
found_valid_ct = true;
|
found_valid_ct = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_bot_player(client))
|
if (is_bot_player(client))
|
||||||
{
|
{
|
||||||
if (GetClientTeam(client) == 1 || GetClientTeam(client) == 0)
|
if (GetClientTeam(client) == 1 || GetClientTeam(client) == 0)
|
||||||
{
|
|
||||||
if (is_host_ze)
|
|
||||||
{
|
{
|
||||||
ChangeClientTeam(client, 2);
|
ChangeClientTeam(client, 2);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int T_client_count = 0;
|
|
||||||
int CT_client_count = 0;
|
|
||||||
for (int clientI = 1; clientI <= MaxClients; clientI++)
|
|
||||||
{
|
|
||||||
if (!IsValidClient(clientI)) continue;
|
|
||||||
if (GetClientTeam(clientI) == 2)
|
|
||||||
{
|
|
||||||
T_client_count++;
|
|
||||||
}
|
|
||||||
else if (GetClientTeam(clientI) == 3)
|
|
||||||
{
|
|
||||||
CT_client_count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (T_client_count > CT_client_count)
|
|
||||||
{
|
|
||||||
ChangeClientTeam(client, 3);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ChangeClientTeam(client, 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (bot_avoid_edge[client] >= 3)
|
if (bot_avoid_edge[client] >= 3)
|
||||||
@ -608,13 +566,13 @@ public Action recursive_pressing(Handle timer, any data)
|
|||||||
}
|
}
|
||||||
//no target in water somehow
|
//no target in water somehow
|
||||||
target_enemy[client] = GetClosestClient_option1(false, client);
|
target_enemy[client] = GetClosestClient_option1(false, client);
|
||||||
targethuman[client] = GetClosestClient_option1(true, client);
|
target_friend[client] = GetClosestClient_option1(true, client);
|
||||||
float enemy_distance = -1.0;
|
float enemy_distance = -1.0;
|
||||||
float dist_target = -1.0;
|
float dist_target = -1.0;
|
||||||
float pos[3];
|
float pos[3];
|
||||||
if (IsValidClient(targethuman[client]))
|
if (IsValidClient(target_friend[client]))
|
||||||
{
|
{
|
||||||
GetEntPropVector(targethuman[client], Prop_Send, "m_vecOrigin", pos);
|
GetEntPropVector(target_friend[client], Prop_Send, "m_vecOrigin", pos);
|
||||||
dist_target = get_power_distance(client, pos);
|
dist_target = get_power_distance(client, pos);
|
||||||
}
|
}
|
||||||
if (IsValidClient(target_enemy[client]))
|
if (IsValidClient(target_enemy[client]))
|
||||||
@ -622,24 +580,17 @@ public Action recursive_pressing(Handle timer, any data)
|
|||||||
GetEntPropVector(target_enemy[client], Prop_Send, "m_vecOrigin", pos);
|
GetEntPropVector(target_enemy[client], Prop_Send, "m_vecOrigin", pos);
|
||||||
enemy_distance = get_power_distance(client, pos);
|
enemy_distance = get_power_distance(client, pos);
|
||||||
}
|
}
|
||||||
if ((750 > enemy_distance > 0 && enemy_distance > dist_target && targeteam == 2) || dist_target < 0 < enemy_distance)
|
if (IsValidClient(target_friend[client]))
|
||||||
|
face_call(target_friend[client], client);
|
||||||
|
else if (IsValidClient(target_enemy[client]) && !admins[target_enemy[client]] && !vips[target_enemy[client]])
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
float feet_origin[3], enemy_feet_origin[3];
|
|
||||||
GetClientAbsOrigin(client, feet_origin);
|
|
||||||
GetClientAbsOrigin(target_enemy[client], enemy_feet_origin);
|
|
||||||
if (feet_origin[2] + 100 > enemy_feet_origin[2])
|
|
||||||
*/
|
|
||||||
face_call(target_enemy[client], client);
|
face_call(target_enemy[client], client);
|
||||||
}
|
}
|
||||||
else if (IsValidClient(targethuman[client]))
|
|
||||||
face_call(targethuman[client], client);
|
|
||||||
//might prevent bot from jumping off ladders
|
|
||||||
if (GetEntProp(client, Prop_Data, "m_nWaterLevel") <= 2 && GetEntityMoveType(client) != MOVETYPE_LADDER)
|
if (GetEntProp(client, Prop_Data, "m_nWaterLevel") <= 2 && GetEntityMoveType(client) != MOVETYPE_LADDER)
|
||||||
trace_hulling_bot(client);
|
trace_hulling_bot(client);
|
||||||
char message[generic_length * 7];
|
char message[generic_length * 7];
|
||||||
if (IsValidClient(targethuman[client]))
|
if (IsValidClient(target_friend[client]))
|
||||||
Format(message, sizeof(message), "dist_target: %f targethuman: %N enemy_distance: %f targeteam: %i", dist_target, targethuman[client], enemy_distance, targeteam);
|
Format(message, sizeof(message), "dist_target: %f targethuman: %N enemy_distance: %f targeteam: %i", dist_target, target_friend[client], enemy_distance, targeteam);
|
||||||
else
|
else
|
||||||
Format(message, sizeof(message), "dist_target: %f targethuman: none enemy_distance: %f targeteam: %i", dist_target, enemy_distance, targeteam);
|
Format(message, sizeof(message), "dist_target: %f targethuman: none enemy_distance: %f targeteam: %i", dist_target, enemy_distance, targeteam);
|
||||||
if (IsValidClient(target_enemy[client]))
|
if (IsValidClient(target_enemy[client]))
|
||||||
@ -875,15 +826,17 @@ stock bool IsValidClient(int client)
|
|||||||
|
|
||||||
stock bool is_client_stuck_or_afk(int client)
|
stock bool is_client_stuck_or_afk(int client)
|
||||||
{
|
{
|
||||||
|
//can trigger between 6-8 times per second
|
||||||
|
target_friend_afk_counter[client]++;
|
||||||
|
if (target_friend_afk_counter[client] > 24)
|
||||||
|
{
|
||||||
|
target_friend_afk_counter[client] = 0;
|
||||||
float min_distance_cap = 1.0;
|
float min_distance_cap = 1.0;
|
||||||
float client_own_distance = get_power_distance(client, client_old_coords[client]);
|
float client_own_distance = get_power_distance(client, client_old_coords[client]);
|
||||||
GetEntPropVector(client, Prop_Send, "m_vecOrigin", client_old_coords[client]);
|
GetEntPropVector(client, Prop_Send, "m_vecOrigin", client_old_coords[client]);
|
||||||
return client_own_distance < min_distance_cap;
|
return client_own_distance < min_distance_cap;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
public bool check_client_team(int client, int i, bool finding_friend)
|
|
||||||
{
|
|
||||||
return (finding_friend && GetClientTeam(client) == GetClientTeam(i)) || (!finding_friend && GetClientTeam(client) != GetClientTeam(i));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetClosestClient_option1(bool finding_friend, int client)
|
public int GetClosestClient_option1(bool finding_friend, int client)
|
||||||
@ -892,39 +845,21 @@ public int GetClosestClient_option1(bool finding_friend, int client)
|
|||||||
int nearest = -1;
|
int nearest = -1;
|
||||||
if (GetEntityMoveType(client) == MOVETYPE_LADDER)
|
if (GetEntityMoveType(client) == MOVETYPE_LADDER)
|
||||||
return nearest;
|
return nearest;
|
||||||
//are there other players than bots to follow
|
|
||||||
bool other_players_than_bots = false;
|
|
||||||
for (int i = 1; i <= MaxClients; i++)
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
if (IsValidClient(i) && IsPlayerAlive(i) && i != client && !is_bot_player(i) && IsAbleToSee(client, i) && check_client_team(client, i, finding_friend))
|
if (IsValidClient(i) && IsPlayerAlive(i) && i != client && !is_bot_player(i))
|
||||||
{
|
{
|
||||||
other_players_than_bots = true;
|
if (!IsAbleToSee(client, i) || is_client_stuck_or_afk(i))
|
||||||
break;
|
|
||||||
}
|
|
||||||
for (int i = 1; i <= MaxClients; i++)
|
|
||||||
if (IsValidClient(i) && IsPlayerAlive(i) && i != client && (!other_players_than_bots || !is_bot_player(i)) && check_client_team(client, i, finding_friend))
|
|
||||||
{
|
{
|
||||||
if (!IsAbleToSee(client, i))
|
|
||||||
continue;
|
continue;
|
||||||
if (is_client_stuck_or_afk(i))
|
|
||||||
{
|
|
||||||
if (i != targethuman[client])
|
|
||||||
continue;
|
|
||||||
target_human_afk_counter[client]++;
|
|
||||||
int afk_cap = 4;
|
|
||||||
if (target_human_afk_counter[client] > afk_cap)
|
|
||||||
{
|
|
||||||
target_human_afk_counter[client] = 0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
float pos[3];
|
float pos[3];
|
||||||
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
|
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
|
||||||
float dist_target = get_power_distance(client, pos);
|
float dist_target = get_power_distance(client, pos);
|
||||||
if (GetClientTeam(i) != GetClientTeam(client) && (admins[i] || vips[i]))
|
if ((finding_friend && GetClientTeam(i) != GetClientTeam(client)) || (!finding_friend && GetClientTeam(i) == GetClientTeam(client)))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((admins[i] || vips[i] || i == targethuman[client]))
|
if ((admins[i] || vips[i] || i == target_friend[client]))
|
||||||
dist_target /= 5;
|
dist_target /= 5;
|
||||||
if (nearestdistance < 0 || dist_target < nearestdistance)
|
if (nearestdistance < 0 || dist_target < nearestdistance)
|
||||||
{
|
{
|
||||||
@ -942,17 +877,9 @@ public float get_power_distance(int target_player, float [3]pos)
|
|||||||
return GetVectorDistance(vec, pos);
|
return GetVectorDistance(vec, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Action respawn_bot(Handle timer, int client)
|
|
||||||
{
|
|
||||||
if (IsValidClient(client) && is_bot_player(client) && !IsPlayerAlive(client) && GetClientTeam(client) > 1)
|
|
||||||
{
|
|
||||||
CS_RespawnPlayer(client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnClientPostAdminCheck(int client)
|
public void OnClientPostAdminCheck(int client)
|
||||||
{
|
{
|
||||||
target_human_afk_counter[client] = 0;
|
target_friend_afk_counter[client] = 0;
|
||||||
bot_avoid_edge[client] = -1;
|
bot_avoid_edge[client] = -1;
|
||||||
char auth[64];
|
char auth[64];
|
||||||
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
|
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
|
||||||
@ -961,22 +888,18 @@ public void OnClientPostAdminCheck(int client)
|
|||||||
if (is_autism_bot1(client))
|
if (is_autism_bot1(client))
|
||||||
{
|
{
|
||||||
send_socket_msg(msg, strlen(msg), ports[0]);
|
send_socket_msg(msg, strlen(msg), ports[0]);
|
||||||
CreateTimer(10.0, respawn_bot, client);
|
|
||||||
}
|
}
|
||||||
if (is_autism_bot2(client))
|
if (is_autism_bot2(client))
|
||||||
{
|
{
|
||||||
send_socket_msg(msg, strlen(msg), ports[1]);
|
send_socket_msg(msg, strlen(msg), ports[1]);
|
||||||
CreateTimer(10.0, respawn_bot, client);
|
|
||||||
}
|
}
|
||||||
if (is_autism_bot3(client))
|
if (is_autism_bot3(client))
|
||||||
{
|
{
|
||||||
send_socket_msg(msg, strlen(msg), ports[2]);
|
send_socket_msg(msg, strlen(msg), ports[2]);
|
||||||
CreateTimer(10.0, respawn_bot, client);
|
|
||||||
}
|
}
|
||||||
if (is_autism_bot4(client))
|
if (is_autism_bot4(client))
|
||||||
{
|
{
|
||||||
send_socket_msg(msg, strlen(msg), ports[3]);
|
send_socket_msg(msg, strlen(msg), ports[3]);
|
||||||
CreateTimer(10.0, respawn_bot, client);
|
|
||||||
}
|
}
|
||||||
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
|
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
|
||||||
admins[client] = true;
|
admins[client] = true;
|
||||||
@ -987,15 +910,6 @@ public void OnClientPostAdminCheck(int client)
|
|||||||
client_old_coords[client][2] = 0.0;
|
client_old_coords[client][2] = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//this feels pretty fucking autistic why cant the forward just trigger, am i retarded?
|
|
||||||
public void OnClientAuthorized(int client, const char[] auth)
|
|
||||||
{
|
|
||||||
if (IsValidClient(client))
|
|
||||||
{
|
|
||||||
OnClientPostAdminCheck(client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
public void OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
||||||
{
|
{
|
||||||
CloseHandle(socket);
|
CloseHandle(socket);
|
||||||
@ -1033,7 +947,7 @@ public void OnClientDisconnect(int client)
|
|||||||
client_old_coords[client][0] = 0.0;
|
client_old_coords[client][0] = 0.0;
|
||||||
client_old_coords[client][1] = 0.0;
|
client_old_coords[client][1] = 0.0;
|
||||||
client_old_coords[client][2] = 0.0;
|
client_old_coords[client][2] = 0.0;
|
||||||
target_human_afk_counter[client] = 0;
|
target_friend_afk_counter[client] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Socket callback
|
//Socket callback
|
||||||
@ -1080,10 +994,10 @@ public bool IsAbleToSee(int entity, int client)
|
|||||||
GetClientMins(client, mins);
|
GetClientMins(client, mins);
|
||||||
GetClientMaxs(client, maxs);
|
GetClientMaxs(client, maxs);
|
||||||
// Check outer 4 corners of player.
|
// Check outer 4 corners of player.
|
||||||
if (IsRectangleVisible(vecEyePos, vecorigin, mins, maxs, 1.30))
|
if (IsRectangleVisible(vecEyePos, vecorigin, mins, maxs, 1.30)) //1.30
|
||||||
return true;
|
return true;
|
||||||
// Check inner 4 corners of player.
|
// Check inner 4 corners of player.
|
||||||
if (IsRectangleVisible(vecEyePos, vecorigin, mins, maxs, 0.65))
|
if (IsRectangleVisible(vecEyePos, vecorigin, mins, maxs, 0.65)) //0.65
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user