updated to handle stuff multiple clients but might need further edits

This commit is contained in:
christian 2021-03-27 00:57:40 +01:00
parent 41e2e524d9
commit 646a81151a

View File

@ -3,7 +3,7 @@
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "1.4"
#define PLUGIN_VERSION "1.5"
#define generic_length 256
#include <sourcemod>
@ -13,7 +13,7 @@
#include <socket>
//#pragma newdecls required
int present = 0;
int present[MAXPLAYERS + 1];
int targethuman = 0;
int target_enemy = 0;
int buttons_old;
@ -42,6 +42,9 @@ public Plugin myinfo =
public void OnPluginStart()
{
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i))
present[i] = 0;
//talking
RegConsoleCmd("sm_autism", cmd_talk, "talking to the bot through java application");
@ -75,7 +78,7 @@ public void trigger_teleport(const char[] output, int entity_index, int client,
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported);
CreateTimer(6.0, reset_target_tp);
}
else if (IsValidClient(present) && client == present)
else if (IsValidClient(client) && client == present[client])
CreateTimer(0.1, reset_target_tp);
}
@ -91,7 +94,7 @@ public void Trigger_Multiple(const char[] output, int entity_index, int client,
CreateTimer(6.0, reset_target_tp);
}
}
else if (IsValidClient(present) && client == present)
else if (IsValidClient(client) && client == present[client])
{
if (origin_command_check(entity_index))
CreateTimer(0.1, reset_target_tp);
@ -126,9 +129,9 @@ public Action reset_target_tp(Handle timer, any data)
return Plugin_Continue;
}
public bool distance_check()
public bool distance_check(int client)
{
float dist_target = get_power_distance(present, targethuman_teleported);
float dist_target = get_power_distance(present[client], targethuman_teleported);
float min_required_distance = 50000.0;
if (dist_target > min_required_distance)
return false;
@ -150,17 +153,26 @@ public Action cmd_talk(int client, int args)
PrintToChat(client, "spamming bot too much, applying cooldown");
return Plugin_Handled;
}
if (IsValidClient(present))
{
chat_cooldown = true;
char magic_code[16];
Format(magic_code, sizeof(magic_code), "72DqZ84");
Format(msg, sizeof(msg), "clientmessage:%N %s %s", client, magic_code, info);
send_socket_msg(msg, strlen(msg));
CreateTimer(2.0, bot_chat_cooldown);
}
else
PrintToChat(client, "bot not connected to server");
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && !IsFakeClient(i))
{
char ip_addr[generic_length];
GetClientIP(i, ip_addr, sizeof(ip_addr));
if (present[i] == i)
{
if (StrContains(ip_addr, "127.0.0.1"))
{
chat_cooldown = true;
char magic_code[16];
Format(magic_code, sizeof(magic_code), "72DqZ84");
Format(msg, sizeof(msg), "clientmessage:%N %s %s", client, magic_code, info);
send_socket_msg(msg, strlen(msg));
CreateTimer(2.0, bot_chat_cooldown);
return Plugin_Handled;
}
}
}
PrintToChat(client, "bot not connected to server");
return Plugin_Handled;
}
@ -191,24 +203,57 @@ public void send_socket_msg(char[] query_msg, int len)
SocketSendTo(global_socket, query_msg, len, "127.0.0.1", 48477); //udp
}
public void send_socket_msg1(char[] query_msg, int len)
{
if (global_socket != INVALID_HANDLE && SocketIsConnected(global_socket))
SocketSendTo(global_socket, query_msg, len, "127.0.0.1", 48478); //udp
}
public Action bot_check_connect(Handle timer, any data)
{
if (!IsValidClient(present) && GetClientCount(false) <= 61)
{
char msg[generic_length];
//PrintToChatAll("sending UDP message...");
Format(msg, sizeof(msg), "connect to ze");
int client_count = GetClientCount(false);
bool found_bot_1 = false;
bool found_bot_2 = false;
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && !IsFakeClient(i))
{
char ip_addr[generic_length];
GetClientIP(i, ip_addr, sizeof(ip_addr));
if (i == present[i])
{
if (client_count > 61)
{
char msg[generic_length];
if (StrContains(ip_addr, "127.0.0.1"))
{
KickClient(i, "server full you need to leave");
Format(msg, sizeof(msg), "bot kicked server full");
send_socket_msg(msg, strlen(msg));
}
else if (StrContains(ip_addr, "164.132.201.173"))
{
KickClient(i, "server full you need to leave");
Format(msg, sizeof(msg), "bot kicked server full");
send_socket_msg1(msg, strlen(msg));
}
}
else
{
if (StrContains(ip_addr, "127.0.0.1"))
found_bot_1 = true;
else if (StrContains(ip_addr, "164.132.201.173"))
found_bot_2 = true;
}
}
}
char msg[generic_length];
//PrintToChatAll("sending UDP message...");
Format(msg, sizeof(msg), "connect to ze");
if (!found_bot_1)
send_socket_msg(msg, strlen(msg));
}
/*
else if (IsValidClient(present) && GetClientCount(false) >= 63)
{
char msg[generic_length];
KickClient(present, "server full you need to leave");
Format(msg, sizeof(msg), "bot kicked server full");
send_socket_msg(msg, strlen(msg));
}
*/
if (!found_bot_2)
send_socket_msg1(msg, strlen(msg));
return Plugin_Continue;
}
@ -216,10 +261,10 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
int cmdnum, int tickcount, int seed, const int mouse[2])
{
if (!IsClientInGame(client)) return;
if (client == present)
if (client == present[client])
{
int flags = GetEntityFlags(client);
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP) && !(buttons & IN_JUMP) && (GetEntityMoveType(present) != MOVETYPE_LADDER))
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP) && !(buttons & IN_JUMP) && (GetEntityMoveType(present[client]) != MOVETYPE_LADDER))
{
float Vel[3], feet_origin[3], ground_pos[3], downwards[3];
//TODO
@ -227,11 +272,11 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
Vel[2] += velocity_addition_z_axis;
GetClientAbsOrigin(present, feet_origin);
GetClientAbsOrigin(present[client], feet_origin);
downwards[0] = 90.0;
downwards[1] = 0.0;
downwards[2] = 0.0;
TR_TraceRayFilter(feet_origin, downwards, MASK_ALL, RayType_Infinite, TraceRayDontHitSelf, present);
TR_TraceRayFilter(feet_origin, downwards, MASK_ALL, RayType_Infinite, TraceRayDontHitSelf, present[client]);
if (TR_DidHit())
{
TR_GetEndPosition(ground_pos);
@ -240,9 +285,9 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
if (ground_distance > 80)
{
float angles_eye[3];
GetClientEyeAngles(present, angles_eye);
GetClientEyeAngles(present[client], angles_eye);
feet_origin[2] += 10.0;
TR_TraceRayFilter(feet_origin, angles_eye, MASK_ALL, RayType_Infinite, TraceRayDontHitSelf, present);
TR_TraceRayFilter(feet_origin, angles_eye, MASK_ALL, RayType_Infinite, TraceRayDontHitSelf, present[client]);
if (TR_DidHit())
{
TR_GetEndPosition(ground_pos);
@ -253,7 +298,7 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
if (IsValidClient(targethuman))
{
float feet_origin_pre[3], human_feet_origin[3];
GetClientAbsOrigin(present, feet_origin_pre);
GetClientAbsOrigin(present[client], feet_origin_pre);
GetClientAbsOrigin(targethuman, human_feet_origin);
//target human is below, get down to them
//TODO maybe?
@ -265,11 +310,11 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
}
}
float velocity[3];
GetEntPropVector(present, Prop_Data, "m_vecVelocity", velocity);
GetEntPropVector(present[client], Prop_Data, "m_vecVelocity", velocity);
velocity[2] += 30.0;
NegateVector(velocity);
for (int y = 0; y < 10; y++)
TeleportEntity(present, NULL_VECTOR, NULL_VECTOR, velocity);
TeleportEntity(present[client], NULL_VECTOR, NULL_VECTOR, velocity);
}
}
}
@ -283,19 +328,20 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
public Action recursive_pressing(Handle timer, any data)
{
if (IsValidClient(present))
for (int client = 1; client <= MaxClients; client++)
if (IsValidClient(client) && present[client] == client)
{
if (GetClientTeam(present) == 1 || GetClientTeam(present) == 0)
if (GetClientTeam(present[client]) == 1 || GetClientTeam(present[client]) == 0)
{
ChangeClientTeam(present, 2);
ChangeClientTeam(present[client], 2);
return Plugin_Continue;
}
if (IsPlayerAlive(present))
if (IsPlayerAlive(present[client]))
{
if (GetEntityMoveType(present) == MOVETYPE_LADDER)
if (GetEntityMoveType(present[client]) == MOVETYPE_LADDER)
return Plugin_Continue;
int targeteam = 0;
if (GetClientTeam(present) != 3)
if (GetClientTeam(present[client]) != 3)
{
//2 = autismo is zm and should follow closest moving zm
targeteam = 2;
@ -309,42 +355,42 @@ public Action recursive_pressing(Handle timer, any data)
{
float ClientPos[3];
float Result[3];
GetClientEyePosition(present, ClientPos);
GetClientEyePosition(present[client], ClientPos);
MakeVectorFromPoints(ClientPos, targethuman_teleported, Result);
GetVectorAngles(Result, Result);
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
if (!distance_check())
TeleportEntity(present[client], NULL_VECTOR, Result, NULL_VECTOR);
if (!distance_check(client))
reset_target_human_tp_coord();
return Plugin_Continue;
}
//target_enemy = GetClosestClient_option1(targeteam == 2 ? 3 : 2);
targethuman = GetClosestClient_option1(targeteam == 2 ? 2 : 3);
target_enemy = GetClosestClient_option1(targeteam == 2 ? 3 : 2, client);
targethuman = GetClosestClient_option1(targeteam == 2 ? 2 : 3, client);
float enemy_distance = -1.0;
float dist_target = -1.0;
float pos[3];
if (IsValidClient(targethuman))
{
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
dist_target = get_power_distance(present, pos);
dist_target = get_power_distance(present[client], pos);
}
/*
//TODO maybe disable if requested
if (IsValidClient(target_enemy))
{
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
enemy_distance = get_power_distance(present, pos);
enemy_distance = get_power_distance(present[client], pos);
}
*/
if ((0 < enemy_distance && targeteam == 2) || dist_target < 0 < enemy_distance)
{
float feet_origin[3], enemy_feet_origin[3];
GetClientAbsOrigin(present, feet_origin);
GetClientAbsOrigin(present[client], feet_origin);
GetClientAbsOrigin(target_enemy, enemy_feet_origin);
if (feet_origin[2] + 100 > enemy_feet_origin[2])
face_call(target_enemy);
face_call(target_enemy, client);
}
else if (0 < dist_target)
face_call(targethuman);
trace_hulling_bot();
face_call(targethuman, client);
trace_hulling_bot(client);
char message[generic_length * 7];
if (IsValidClient(targethuman))
Format(message, sizeof(message), "dist_target: %f targethuman: %N enemy_distance: %f targeteam: %i", dist_target, targethuman, enemy_distance, targeteam);
@ -361,7 +407,7 @@ public Action recursive_pressing(Handle timer, any data)
}
//https://developer.valvesoftware.com/wiki/Dimensions
public void trace_hulling_bot()
public void trace_hulling_bot(int client)
{
char message[generic_length * 3];
float step_cap = 18.0;
@ -369,10 +415,10 @@ public void trace_hulling_bot()
float stand_min = 63.0;
float feet_origin[3], mins[3], maxs[3], eye_position[3];
int BOUNDINGBOX_INFLATION_OFFSET = 3;
GetClientEyePosition(present, eye_position);
GetClientAbsOrigin(present, feet_origin);
GetClientMins(present, mins);
GetClientMaxs(present, maxs);
GetClientEyePosition(present[client], eye_position);
GetClientAbsOrigin(present[client], feet_origin);
GetClientMins(present[client], mins);
GetClientMaxs(present[client], maxs);
//increasing boxes sizes
for (int ij = 0; ij < sizeof(mins) - 1; ij++)
{
@ -444,13 +490,13 @@ public void trace_hulling_bot()
}
//currently detects when two walls meet and create a corner
float move_angles[3];
if (GetEntityMoveType(present) != MOVETYPE_LADDER)
if (GetEntityMoveType(present[client]) != MOVETYPE_LADDER)
{
GetClientEyeAngles(present, move_angles);
GetClientEyeAngles(present[client], move_angles);
move_angles[0] = 0.0;
move_angles[1] += 35.0;
move_angles[2] = 0.0;
TeleportEntity(present, NULL_VECTOR, move_angles, NULL_VECTOR);
TeleportEntity(present[client], NULL_VECTOR, move_angles, NULL_VECTOR);
}
return;
}
@ -459,19 +505,20 @@ public void trace_hulling_bot()
//TODO implement surfing again but differently
//check_bot_surfing();
/*
public void check_bot_surfing()
{
float vPos[3];
float vMins[3];
float vMaxs[3];
GetEntPropVector(present, Prop_Data, "m_vecOrigin", vPos);
GetEntPropVector(present, Prop_Send, "m_vecMins", vMins);
GetEntPropVector(present, Prop_Send, "m_vecMaxs", vMaxs);
GetEntPropVector(present[client], Prop_Data, "m_vecOrigin", vPos);
GetEntPropVector(present[client], Prop_Send, "m_vecMins", vMins);
GetEntPropVector(present[client], Prop_Send, "m_vecMaxs", vMaxs);
float vEndPos[3];
vEndPos[0] = vPos[0];
vEndPos[1] = vPos[1];
vEndPos[2] = vPos[2] - FindConVar("sv_maxvelocity").FloatValue;
TR_TraceHullFilter(vPos, vEndPos, vMins, vMaxs, MASK_ALL, TraceRayDontHitSelf, present);
TR_TraceHullFilter(vPos, vEndPos, vMins, vMaxs, MASK_ALL, TraceRayDontHitSelf, present[client]);
if (TR_DidHit())
{
//< 0.7 = surf ramp
@ -488,7 +535,7 @@ public void check_bot_surfing()
if (!surf_cooldown)
{
surf_cooldown = true;
TeleportEntity(present, NULL_VECTOR, vPlane, NULL_VECTOR);
TeleportEntity(present[client], NULL_VECTOR, vPlane, NULL_VECTOR);
Format(keyinput, sizeof(keyinput), "surfing: %f %f %f", vPlane[0], vPlane[1], vPlane[2]);
send_socket_msg(keyinput, strlen(keyinput));
CreateTimer(0.5, surf_cooldown_timer);
@ -496,6 +543,7 @@ public void check_bot_surfing()
}
}
}
*/
public Action surf_cooldown_timer(Handle timer, any data)
{
@ -508,24 +556,24 @@ public bool TraceRayDontHitSelf(int entity, int mask, any data)
return entity != data && !(0 < entity <= MaxClients);
}
public void face_call(int client)
public void face_call(int client, int selfclient)
{
for (int j = 0; j < 5; j++)
faceclient(client);
faceclient(client, selfclient);
}
public void faceclient(int target_human)
public void faceclient(int target_human, int client)
{
if (IsValidClient(present) && IsValidClient(target_human))
if (IsValidClient(client) && IsValidClient(target_human))
{
float TargetPos[3];
float ClientPos[3];
float Result[3];
GetClientEyePosition(target_human, TargetPos);
GetClientEyePosition(present, ClientPos);
GetClientEyePosition(client, ClientPos);
MakeVectorFromPoints(ClientPos, TargetPos, Result);
GetVectorAngles(Result, Result);
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
TeleportEntity(client, NULL_VECTOR, Result, NULL_VECTOR);
}
}
@ -545,14 +593,14 @@ stock bool is_client_stuck_or_afk(int client)
}
int target_human_afk_counter = 0;
public int GetClosestClient_option1(int targeteam)
public int GetClosestClient_option1(int targeteam, int client)
{
float nearestdistance = -1.0;
int nearest = -1;
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present[client])
{
if (!IsAbleToSee(present, i))
if (!IsAbleToSee(present[client], i))
continue;
if (is_client_stuck_or_afk(i))
{
@ -570,8 +618,8 @@ public int GetClosestClient_option1(int targeteam)
return targethuman;
float pos[3];
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(present, pos);
if (GetClientTeam(present) == 3 && IsValidClient(target_enemy) && targeteam == 3)
float dist_target = get_power_distance(present[client], pos);
if (GetClientTeam(present[client]) == 3 && IsValidClient(target_enemy) && targeteam == 3)
{
float enemey_cap = 1500.0;
float enemy_dist = get_power_distance(target_enemy, pos);
@ -603,16 +651,17 @@ public void OnClientPostAdminCheck(int client)
//[U:1:120378081]
//[U:1:69566635]
char auth[50];
present[client] = 0;
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
if (StrEqual("[U:1:120378081]", auth, false))
if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false))
{
present = client;
bot_send_connected_msg();
present[client] = client;
bot_send_connected_msg(0);
}
else if (StrEqual("STEAM_0:1:60189040", auth, false))
if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false))
{
present = client;
bot_send_connected_msg();
present[client] = client;
bot_send_connected_msg(1);
}
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
admins[client] = true;
@ -644,10 +693,7 @@ stock void connect_socket()
public void OnClientDisconnect(int client)
{
if (present == client)
{
present = 0;
}
present[client] = 0;
admins[client] = false;
vips[client] = false;
client_old_coords[client][0] = 0.0;
@ -655,14 +701,17 @@ public void OnClientDisconnect(int client)
client_old_coords[client][2] = 0.0;
}
public void bot_send_connected_msg()
public void bot_send_connected_msg(int bot_specified)
{
char msg[generic_length];
Format(msg, sizeof(msg), "autismo connected");
if (!connected_cooldown)
{
connected_cooldown = true;
send_socket_msg(msg, strlen(msg));
if (!bot_specified)
send_socket_msg(msg, strlen(msg));
else
send_socket_msg1(msg, strlen(msg));
CreateTimer(5.0, connect_cooldown);
}
}