921 lines
26 KiB
SourcePawn
921 lines
26 KiB
SourcePawn
#pragma semicolon 1
|
|
|
|
#define DEBUG
|
|
|
|
#define PLUGIN_AUTHOR "jenz"
|
|
#define PLUGIN_VERSION "1.4"
|
|
#define generic_length 256
|
|
|
|
#include <sourcemod>
|
|
#include <sdktools>
|
|
#include <sdkhooks>
|
|
#include <outputinfo>
|
|
#include <socket>
|
|
|
|
//#pragma newdecls required
|
|
int present = 0;
|
|
int targethuman = 0;
|
|
int buttons_old;
|
|
int flags_old;
|
|
int surf_delay = 0;
|
|
float client_old_coords[MAXPLAYERS + 1][3];
|
|
float targethuman_teleported[3];
|
|
float g_vCurrent[3];
|
|
float g_vLast[3];
|
|
bool g_bOnGround[MAXPLAYERS + 1];
|
|
bool g_bLastOnGround[MAXPLAYERS + 1];
|
|
bool client_stuck_g[MAXPLAYERS + 1];
|
|
bool round_start_stuck = false;
|
|
bool cmdpost_run_cooldown = false;
|
|
bool bot_surf_plane = false;
|
|
|
|
//admins & vips
|
|
bool admins[MAXPLAYERS + 1];
|
|
bool vips[MAXPLAYERS + 1];
|
|
|
|
//socket for bot input
|
|
Handle global_socket;
|
|
|
|
public Plugin myinfo =
|
|
{
|
|
name = "coordinates for the bot",
|
|
author = PLUGIN_AUTHOR,
|
|
description = "hello ",
|
|
version = PLUGIN_VERSION,
|
|
url = ""
|
|
};
|
|
|
|
public void OnPluginStart()
|
|
{
|
|
//talking
|
|
RegConsoleCmd("sm_autism", cmd_talk, "talking to the bot through java application");
|
|
|
|
//hooks
|
|
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
|
|
HookEntityOutput("trigger_multiple", "OnTrigger", Trigger_Multiple);
|
|
HookEntityOutput("trigger_multiple", "OnStartTouch", Trigger_Multiple);
|
|
HookEntityOutput("trigger_teleport", "OnTrigger", trigger_teleport);
|
|
HookEntityOutput("trigger_teleport", "OnStartTouch", trigger_teleport);
|
|
|
|
//socket otherwise declare in public OnConfigsExecuted(){}
|
|
Handle socket = SocketCreate(SOCKET_UDP, OnSocketError);
|
|
SocketSetOption(socket, SocketReuseAddr, 1);
|
|
SocketBind(socket, "127.0.0.1", 48475);
|
|
connect(socket);
|
|
global_socket = socket;
|
|
round_start_stuck = true;
|
|
cmdpost_run_cooldown = false;
|
|
bot_surf_plane = false;
|
|
reset_target_human_tp_coord();
|
|
targethuman = 0;
|
|
}
|
|
|
|
public void reset_target_human_tp_coord()
|
|
{
|
|
targethuman_teleported[0] = 0.0;
|
|
targethuman_teleported[1] = 0.0;
|
|
targethuman_teleported[2] = 0.0;
|
|
}
|
|
|
|
public void trigger_teleport(const char[] output, int entity_index, int client, float delay)
|
|
{
|
|
if (IsValidEdict(entity_index))
|
|
if (IsValidClient(targethuman) && client == targethuman)
|
|
{
|
|
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported);
|
|
CreateTimer(6.0, reset_target_tp);
|
|
}
|
|
else if (IsValidClient(present) && client == present)
|
|
CreateTimer(0.1, reset_target_tp);
|
|
}
|
|
|
|
public void Trigger_Multiple(const char[] output, int entity_index, int client, float delay)
|
|
{
|
|
if (IsValidEdict(entity_index))
|
|
{
|
|
if (IsValidClient(targethuman) && client == targethuman)
|
|
{
|
|
if (origin_command_check(entity_index))
|
|
{
|
|
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported);
|
|
CreateTimer(6.0, reset_target_tp);
|
|
}
|
|
}
|
|
else if (IsValidClient(present) && client == present)
|
|
{
|
|
if (origin_command_check(entity_index))
|
|
CreateTimer(0.1, reset_target_tp);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool origin_command_check(int entity_index)
|
|
{
|
|
int count_trigger = GetOutputCount(entity_index, "m_OnTrigger");
|
|
int count_starttouch = GetOutputCount(entity_index, "m_OnStartTouch");
|
|
for (int i = 0; i < count_trigger; i++)
|
|
{
|
|
char buffer[generic_length];
|
|
GetOutputParameter(entity_index, "m_OnTrigger", i, buffer, sizeof(buffer));
|
|
if (StrContains(buffer, "origin", true) != -1)
|
|
return true;
|
|
}
|
|
for (int i = 0; i < count_starttouch; i++)
|
|
{
|
|
char buffer[generic_length];
|
|
GetOutputParameter(entity_index, "m_OnStartTouch", i, buffer, sizeof(buffer));
|
|
if (StrContains(buffer, "origin", true) != -1)
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public Action reset_target_tp(Handle timer, any data)
|
|
{
|
|
reset_target_human_tp_coord();
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public bool distance_check()
|
|
{
|
|
float dist_target = get_power_distance(present, targethuman_teleported);
|
|
float min_required_distance = 500.0;
|
|
if (dist_target > min_required_distance)
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
public Action cmd_talk(int client, int args)
|
|
{
|
|
char msg[generic_length];
|
|
char info[generic_length];
|
|
GetCmdArgString(info, sizeof(info));
|
|
if (strlen(info) == 0)
|
|
{
|
|
PrintToChat(client, "Add a message to the command if autism bot is ingame and running on discord");
|
|
return Plugin_Handled;
|
|
}
|
|
Format(msg, sizeof(msg), "clientmessage: %s", info);
|
|
send_socket_msg(msg, strlen(msg));
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
|
|
{
|
|
round_start_stuck = false;
|
|
targethuman = 0;
|
|
cmdpost_run_cooldown = false;
|
|
bot_surf_plane = false;
|
|
reset_target_human_tp_coord();
|
|
CreateTimer(7.0, permitStuck);
|
|
}
|
|
|
|
public Action permitStuck(Handle timer, any data)
|
|
{
|
|
round_start_stuck = true;
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public void OnMapStart()
|
|
{
|
|
//0.2
|
|
CreateTimer(0.5, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
|
CreateTimer(1.0, clients_coordinates, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
|
CreateTimer(10.0, bot_check_connect, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
|
}
|
|
|
|
public Action clients_coordinates(Handle timer, any data)
|
|
{
|
|
if (IsValidClient(present) && IsPlayerAlive(present))
|
|
{
|
|
for (int i = 1; i <= MaxClients; i++)
|
|
if (IsValidClient(i) && IsPlayerAlive(i) && i != present && !client_stuck_g[i])
|
|
GetEntPropVector(i, Prop_Send, "m_vecOrigin", client_old_coords[i]);
|
|
}
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public void send_socket_msg(char[] query_msg, int len)
|
|
{
|
|
if (global_socket != INVALID_HANDLE && SocketIsConnected(global_socket))
|
|
SocketSendTo(global_socket, query_msg, len, "127.0.0.1", 48477); //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");
|
|
send_socket_msg(msg, strlen(msg));
|
|
}
|
|
else if (IsValidClient(present) && GetClientCount(false) >= 63)
|
|
KickClient(present, "server full you need to leave");
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public Action runcmd_cooldown(Handle timer, any data)
|
|
{
|
|
cmdpost_run_cooldown = false;
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype,
|
|
int cmdnum, int tickcount, int seed, const int mouse[2])
|
|
{
|
|
if (!IsClientInGame(client)) return;
|
|
if (client == targethuman && round_start_stuck && IsValidClient(present) && !cmdpost_run_cooldown)
|
|
{
|
|
char keyinput[generic_length * 5];
|
|
if (buttons & IN_JUMP || buttons & IN_DUCK)
|
|
Format(keyinput, sizeof(keyinput), "+jump; wait 5; +duck; wait 5; ", keyinput);
|
|
if (strlen(keyinput) > 0)
|
|
{
|
|
float pos[3];
|
|
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
|
|
float dist_target = get_power_distance(present, pos);
|
|
float dist_cap = 1.5;
|
|
if (dist_target < dist_cap)
|
|
{
|
|
Format(keyinput, sizeof(keyinput), "keyinput: %s dist_target: %f", keyinput, dist_target);
|
|
send_socket_msg(keyinput, strlen(keyinput));
|
|
cmdpost_run_cooldown = true;
|
|
CreateTimer(0.25, runcmd_cooldown);
|
|
}
|
|
}
|
|
}
|
|
else if (client == present)
|
|
{
|
|
int flags = GetEntityFlags(client);
|
|
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP) && !(buttons & IN_JUMP))
|
|
{
|
|
float Vel[3];
|
|
float velocity_addition_z_axis = 300.0;
|
|
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
|
|
if (IsValidClient(targethuman))
|
|
{
|
|
//TODO maybe?
|
|
/*
|
|
{
|
|
Vel[0] -= velocity_addition_z_axis / 10;
|
|
Vel[1] -= velocity_addition_z_axis / 10;
|
|
}
|
|
*/
|
|
}
|
|
Vel[2] += velocity_addition_z_axis;
|
|
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel);
|
|
check_bot_surfing();
|
|
}
|
|
buttons_old = buttons;
|
|
flags_old = flags;
|
|
}
|
|
}
|
|
|
|
public Action recursive_pressing(Handle timer, any data)
|
|
{
|
|
if (IsValidClient(present) && IsPlayerAlive(present))
|
|
{
|
|
if (GetClientTeam(present) == 1)
|
|
{
|
|
//prevent him being stuck afk in spec
|
|
bot_send_connected_msg();
|
|
return Plugin_Continue;
|
|
}
|
|
char message[generic_length * 7];
|
|
float present_bot_coords[3];
|
|
GetClientAbsOrigin(present, present_bot_coords);
|
|
int targeteam = 0;
|
|
if (GetClientTeam(present) != 3)
|
|
{
|
|
//2 = autismo is zm and should follow closest moving zm
|
|
targeteam = 2;
|
|
}
|
|
else
|
|
{
|
|
//3 = autismo is human and should follow closest moving ct
|
|
targeteam = 3;
|
|
}
|
|
bool find_closest_match = true;
|
|
|
|
//check ladder = 0, water = 1, in air(surfing) = 2, downhill = 3, teleporter = 4
|
|
int bot_on_type = -1;
|
|
if (GetEntityMoveType(present) == MOVETYPE_LADDER)
|
|
bot_on_type = 0;
|
|
int ilevel = GetEntProp(present, Prop_Data, "m_nWaterLevel");
|
|
if (ilevel >= 2)
|
|
bot_on_type = 1;
|
|
if (bot_surf_plane)
|
|
bot_on_type = 2;
|
|
if (bot_on_type == -1)
|
|
bot_on_type = check_bot_downhill();
|
|
if (targethuman_teleported[0] != 0.0)
|
|
{
|
|
bot_on_type = 4;
|
|
float ClientPos[3];
|
|
float Result[3];
|
|
GetClientEyePosition(present, ClientPos);
|
|
MakeVectorFromPoints(ClientPos, targethuman_teleported, Result);
|
|
GetVectorAngles(Result, Result);
|
|
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
|
|
if (!distance_check())
|
|
reset_target_human_tp_coord();
|
|
}
|
|
if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman) && bot_on_type != 0 && bot_on_type != 2
|
|
&& bot_on_type != 4)
|
|
{
|
|
face_call(targethuman);
|
|
find_closest_match = is_client_stuck_or_afk(targethuman);
|
|
if (!find_closest_match || admins[targethuman] || vips[targethuman])
|
|
{
|
|
face_call(targethuman);
|
|
find_closest_match = IsAbleToSee(present, targethuman) ? false : true;
|
|
}
|
|
}
|
|
if (find_closest_match && bot_on_type != 0 && bot_on_type != 2 && bot_on_type != 4)
|
|
{
|
|
targethuman = 0;
|
|
targethuman = GetClosestClient_option1(present, targeteam);
|
|
}
|
|
float enemy_distance = -1.0;
|
|
int target_enemy = find_closest_enemy(present, targeteam);
|
|
bool chasing_enemy = false;
|
|
float dist_target = -1.0;
|
|
int crouch_or_jump = 0;
|
|
if (bot_on_type != 0 && bot_on_type != 2 && bot_on_type != 4)
|
|
{
|
|
float pos[3];
|
|
if (IsValidClient(targethuman))
|
|
{
|
|
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
|
|
dist_target = get_power_distance(present, pos);
|
|
}
|
|
if (IsValidClient(target_enemy))
|
|
{
|
|
float min_enemy_distance = 100.0;
|
|
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
|
|
enemy_distance = get_power_distance(present, pos);
|
|
//human aiming for zombie
|
|
if (targeteam == 3)
|
|
{
|
|
float min_distance_target_human = 0.1;
|
|
if (0 < dist_target <= min_distance_target_human && enemy_distance > min_enemy_distance)
|
|
{
|
|
chasing_enemy = true;
|
|
face_call(target_enemy);
|
|
}
|
|
else if (!IsValidClient(targethuman))
|
|
{
|
|
chasing_enemy = true;
|
|
face_call(target_enemy);
|
|
}
|
|
}
|
|
//zombie aiming for human
|
|
if (targeteam == 2 && 0 < enemy_distance)
|
|
{
|
|
chasing_enemy = true;
|
|
face_call(target_enemy);
|
|
}
|
|
}
|
|
if (IsValidClient(targethuman) && !chasing_enemy)
|
|
face_call(targethuman);
|
|
//0: nothing, 2: crouch, 3: jump
|
|
crouch_or_jump = wall_circle();
|
|
}
|
|
if (bot_on_type != 2)
|
|
{
|
|
if (IsValidClient(targethuman))
|
|
Format(message, sizeof(message), "dist_target: %f targethuman: %N bot_on_type: %i enemy_distance: %f crouch_or_jump: %i targeteam: %i", dist_target, targethuman, bot_on_type, enemy_distance, crouch_or_jump, targeteam);
|
|
else
|
|
Format(message, sizeof(message), "dist_target: %f targethuman: none bot_on_type: %i enemy_distance: %f crouch_or_jump: %i targeteam: %i", dist_target, bot_on_type, enemy_distance, crouch_or_jump, targeteam);
|
|
send_socket_msg(message, strlen(message));
|
|
}
|
|
}
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
public int wall_circle()
|
|
{
|
|
//Circle:
|
|
for (int iterator = 0; iterator < 3; iterator++)
|
|
{
|
|
float angle_start = -360.0; //should be -180.0 ofc
|
|
float angle_end = 360.0;
|
|
for (float AngleRotate = angle_start; AngleRotate <= angle_end; AngleRotate += 10.0)
|
|
{
|
|
float StartOrigin[3];
|
|
float Angles[3];
|
|
GetClientEyeAngles(present, Angles);
|
|
Angles[iterator] = AngleRotate;
|
|
GetClientEyePosition(present, StartOrigin);
|
|
TR_TraceRayFilter(StartOrigin, Angles, MASK_SOLID, RayType_Infinite, TraceRayDontHitSelf, present);
|
|
if (TR_DidHit())
|
|
{
|
|
float EndOrigin[3];
|
|
TR_GetEndPosition(EndOrigin, INVALID_HANDLE);
|
|
float dot_product = GetVectorDotProduct(StartOrigin, EndOrigin);
|
|
dot_product = dot_product / 1000;
|
|
float distance = GetVectorDistance(StartOrigin, EndOrigin);
|
|
float crouch_cap = 5000.0;
|
|
float jump_cap = 100000.0;
|
|
float distance_cap = 50.0;
|
|
if (distance <= distance_cap)
|
|
{
|
|
if (dot_product <= crouch_cap)
|
|
return 2;
|
|
else if (dot_product <= jump_cap)
|
|
return 3;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
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);
|
|
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_PLAYERSOLID_BRUSHONLY, TraceRayDontHitSelf, present);
|
|
if (TR_DidHit())
|
|
{
|
|
//< 0.7 = surf ramp
|
|
float surf_ramp = 0.7;
|
|
char keyinput[generic_length * 3];
|
|
float vPlane[3];
|
|
TR_GetPlaneNormal(INVALID_HANDLE, vPlane);
|
|
if (0.0 < vPlane[2] < surf_ramp)
|
|
{
|
|
//TODO this is very experimental
|
|
vPlane[0] *= 100;
|
|
vPlane[1] *= 100;
|
|
vPlane[2] *= 100;
|
|
surf_delay++;
|
|
bot_surf_plane = true;
|
|
if (surf_delay > 50)
|
|
{
|
|
surf_delay = 0;
|
|
TeleportEntity(present, 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));
|
|
}
|
|
}
|
|
else
|
|
bot_surf_plane = false;
|
|
}
|
|
else
|
|
bot_surf_plane = false;
|
|
}
|
|
|
|
public int check_bot_downhill()
|
|
{
|
|
g_bLastOnGround[present] = g_bOnGround[present];
|
|
if (GetEntityFlags(present) & FL_ONGROUND)
|
|
g_bOnGround[present] = true;
|
|
else
|
|
g_bOnGround[present] = false;
|
|
if (g_bOnGround[present] && !g_bLastOnGround[present])
|
|
{
|
|
g_vLast[0] = g_vCurrent[0];
|
|
g_vLast[1] = g_vCurrent[1];
|
|
g_vLast[2] = g_vCurrent[2];
|
|
g_vCurrent[0] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[0]");
|
|
g_vCurrent[1] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[1]");
|
|
g_vCurrent[2] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[2]");
|
|
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);
|
|
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_PLAYERSOLID_BRUSHONLY, TraceRayDontHitSelf, present);
|
|
if (TR_DidHit())
|
|
{
|
|
//1.0 = flat ground
|
|
float vPlane[3];
|
|
float vLast[3];
|
|
float flat_ground = 1.0;
|
|
TR_GetPlaneNormal(INVALID_HANDLE, vPlane);
|
|
if (0 < vPlane[2] < flat_ground)
|
|
{
|
|
vLast[0] = g_vLast[0];
|
|
vLast[1] = g_vLast[1];
|
|
vLast[2] = g_vLast[2];
|
|
vLast[2]-= (FindConVar("sv_gravity").FloatValue * GetTickInterval() * 0.5);
|
|
float fBackOff = GetVectorDotProduct(vLast, vPlane);
|
|
float change;
|
|
float vVel[3];
|
|
for (int i; i < 2; i++)
|
|
{
|
|
change = vPlane[i] * fBackOff;
|
|
vVel[i] = vLast[i] - change;
|
|
}
|
|
float fAdjust = GetVectorDotProduct(vVel, vPlane);
|
|
if (fAdjust < 0.0)
|
|
{
|
|
for(int i; i < 2; i++)
|
|
{
|
|
vVel[i] -= (vPlane[i] * fAdjust);
|
|
}
|
|
}
|
|
vVel[2] = 0.0;
|
|
vLast[2] = 0.0;
|
|
if (GetVectorLength(vVel) > GetVectorLength(vLast))
|
|
return 3;
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public bool TraceRayDontHitSelf(int entity, int mask, any data)
|
|
{
|
|
return entity != data && !(0 < entity <= MaxClients);
|
|
}
|
|
|
|
public void face_call(int client)
|
|
{
|
|
for (int j = 0; j < 5; j++)
|
|
faceclient(client);
|
|
}
|
|
|
|
public void faceclient(int target_human)
|
|
{
|
|
if (IsValidClient(present) && IsValidClient(target_human) && GetEntityMoveType(present) != MOVETYPE_LADDER)
|
|
{
|
|
float TargetPos[3];
|
|
float ClientPos[3];
|
|
float Result[3];
|
|
GetClientEyePosition(target_human, TargetPos);
|
|
GetClientEyePosition(present, ClientPos);
|
|
MakeVectorFromPoints(ClientPos, TargetPos, Result);
|
|
GetVectorAngles(Result, Result);
|
|
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
|
|
}
|
|
}
|
|
|
|
stock bool IsValidClient(int client)
|
|
{
|
|
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
stock bool is_client_stuck_or_afk(int client)
|
|
{
|
|
if (!round_start_stuck)
|
|
return false;
|
|
float min_distance_cap = 0.02;
|
|
float client_own_distance = get_power_distance(client, client_old_coords[client]);
|
|
client_stuck_g[client] = client_own_distance < min_distance_cap;
|
|
return client_stuck_g[client];
|
|
}
|
|
|
|
public int find_closest_enemy(int entity, int targeteam)
|
|
{
|
|
float pos[3];
|
|
float nearestdistance = -1.0;
|
|
int nearest = -1;
|
|
|
|
for (int i = 1; i <= MaxClients; i++)
|
|
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) != targeteam)
|
|
{
|
|
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
|
|
float dist_target = get_power_distance(entity, pos);
|
|
if (!IsAbleToSee(present, i))
|
|
continue;
|
|
if (is_client_stuck_or_afk(i))
|
|
continue;
|
|
if (nearestdistance < 0 || dist_target < nearestdistance)
|
|
{
|
|
nearest = i;
|
|
nearestdistance = dist_target;
|
|
}
|
|
}
|
|
return nearest;
|
|
}
|
|
|
|
public int GetClosestClient_option1(int entity, int targeteam)
|
|
{
|
|
bool adminpresent = false;
|
|
bool vippresent = false;
|
|
float nearestdistance = -1.0;
|
|
int nearest = -1;
|
|
int priority_targets[MAXPLAYERS + 1];
|
|
int targets = 0;
|
|
for (int i = 1; i <= MaxClients; i++)
|
|
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
|
if (admins[i] || vips[i])
|
|
{
|
|
priority_targets[targets] = i;
|
|
targets++;
|
|
}
|
|
|
|
for (int i = 1; i <= MaxClients; i++)
|
|
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
|
{
|
|
if (!IsAbleToSee(present, i))
|
|
continue;
|
|
if (is_client_stuck_or_afk(i))
|
|
continue;
|
|
if (admins[i])
|
|
{
|
|
adminpresent = true;
|
|
vippresent = false;
|
|
}
|
|
else if (vips[i] && !adminpresent)
|
|
{
|
|
vippresent = true;
|
|
}
|
|
if (adminpresent)
|
|
{
|
|
if (!admins[i])
|
|
continue;
|
|
}
|
|
else if (vippresent)
|
|
{
|
|
if (!vips[i])
|
|
continue;
|
|
}
|
|
float pos[3];
|
|
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
|
|
float dist_target = get_power_distance(entity, pos);
|
|
//focuses on group of priority to determine while still ignoring non vip/admins
|
|
if (admins[i] || vips[i])
|
|
{
|
|
for (int j = 0; j <= targets; j++)
|
|
{
|
|
float pos_priority[3];
|
|
GetEntPropVector(priority_targets[j], Prop_Send, "m_vecOrigin", pos_priority);
|
|
dist_target += get_power_distance(i, pos_priority);
|
|
}
|
|
}
|
|
if (nearestdistance < 0 || dist_target < nearestdistance)
|
|
{
|
|
nearest = i;
|
|
nearestdistance = dist_target;
|
|
}
|
|
}
|
|
return nearest;
|
|
}
|
|
|
|
public float get_power_distance(int target_player, float [3]pos)
|
|
{
|
|
float vec[3];
|
|
GetClientAbsOrigin(target_player, vec);
|
|
float x_axis = Pow(vec[0] - pos[0], 2.0);
|
|
float y_axis = Pow(vec[1] - pos[1], 2.0);
|
|
float z_axis = FloatAbs(Pow(vec[2] - pos[2], 1.4));
|
|
float power_distance = SquareRoot(x_axis * x_axis + y_axis * y_axis + z_axis * z_axis);
|
|
float defaultcap = 1000.0;
|
|
return power_distance / defaultcap;
|
|
}
|
|
|
|
public void OnClientPostAdminCheck(int client)
|
|
{
|
|
//STEAM_0:1:34783317
|
|
//STEAM_0:1:60189040
|
|
//[U:1:120378081]
|
|
//[U:1:69566635]
|
|
char auth[50];
|
|
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
|
|
if (StrEqual("[U:1:120378081]", auth, false))
|
|
{
|
|
present = client;
|
|
bot_send_connected_msg();
|
|
}
|
|
else if (StrEqual("STEAM_0:1:60189040", auth, false))
|
|
{
|
|
present = client;
|
|
bot_send_connected_msg();
|
|
}
|
|
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
|
|
admins[client] = true;
|
|
else if (CheckCommandAccess(client, "sm_reserved", ADMFLAG_RESERVATION))
|
|
vips[client] = true;
|
|
client_old_coords[client][0] = 0.0;
|
|
client_old_coords[client][1] = 0.0;
|
|
client_old_coords[client][2] = 0.0;
|
|
client_stuck_g[client] = false;
|
|
}
|
|
|
|
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
|
{
|
|
LogError("[MR] Socket error: %d (errno %d)", errorType, errorNum);
|
|
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
|
|
}
|
|
|
|
stock void connect(Handle socket)
|
|
{
|
|
if (!SocketIsConnected(socket))
|
|
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 48475);
|
|
}
|
|
|
|
public void OnClientDisconnect(int client)
|
|
{
|
|
if (present == client)
|
|
{
|
|
present = 0;
|
|
}
|
|
admins[client] = false;
|
|
vips[client] = false;
|
|
client_old_coords[client][0] = 0.0;
|
|
client_old_coords[client][1] = 0.0;
|
|
client_old_coords[client][2] = 0.0;
|
|
client_stuck_g[client] = false;
|
|
}
|
|
|
|
public void bot_send_connected_msg()
|
|
{
|
|
char msg[generic_length];
|
|
Format(msg, sizeof(msg), "autismo connected");
|
|
send_socket_msg(msg, strlen(msg));
|
|
}
|
|
|
|
//Socket callback
|
|
public OnSocketConnected(Handle socket, any arg)
|
|
{
|
|
|
|
}
|
|
|
|
//manage message
|
|
public OnSocketReceive(Handle socket, char[] receiveData, const dataSize, any hFile)
|
|
{
|
|
//PrintToChatAll("receiveData: %s", receiveData);
|
|
}
|
|
|
|
public OnSocketDisconnected(Handle socket, any arg)
|
|
{
|
|
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
|
|
}
|
|
|
|
public Action TimerConnect(Handle timer, any arg)
|
|
{
|
|
connect(arg);
|
|
return Plugin_Handled;
|
|
}
|
|
|
|
public bool IsAbleToSee(int entity, int client)
|
|
{
|
|
float vecorigin[3];
|
|
float vecEyePos[3];
|
|
GetClientAbsOrigin(entity, vecorigin);
|
|
GetClientEyePosition(client, vecEyePos);
|
|
// Check if centre is visible.
|
|
if (IsPointVisible(vecEyePos, vecorigin))
|
|
return true;
|
|
float vecEyePos_ent[3];
|
|
float vecEyeAng[3];
|
|
GetClientEyeAngles(entity, vecEyeAng);
|
|
GetClientEyePosition(entity, vecEyePos_ent);
|
|
// Check if weapon tip is visible.
|
|
if (IsFwdVecVisible(vecEyePos, vecEyeAng, vecEyePos_ent))
|
|
return true;
|
|
float mins[3];
|
|
float maxs[3];
|
|
GetClientMins(client, mins);
|
|
GetClientMaxs(client, maxs);
|
|
// Check outer 4 corners of player.
|
|
if (IsRectangleVisible(vecEyePos, vecorigin, mins, maxs, 1.30))
|
|
return true;
|
|
// Check inner 4 corners of player.
|
|
if (IsRectangleVisible(vecEyePos, vecorigin, mins, maxs, 0.65))
|
|
return true;
|
|
return false;
|
|
}
|
|
|
|
public bool Filter_NoPlayers(int entity, int mask)
|
|
{
|
|
return (entity > MaxClients && !(0 < GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity") <= MaxClients));
|
|
}
|
|
|
|
public bool IsPointVisible(const float start[3], const float end[3])
|
|
{
|
|
TR_TraceRayFilter(start, end, MASK_SOLID, RayType_EndPoint, Filter_NoPlayers);
|
|
return TR_GetFraction() == 1.0;
|
|
}
|
|
|
|
public bool IsFwdVecVisible(const float start[3], const float angles[3], const float end[3])
|
|
{
|
|
float fwd[3];
|
|
GetAngleVectors(angles, fwd, NULL_VECTOR, NULL_VECTOR);
|
|
ScaleVector(fwd, 50.0);
|
|
AddVectors(end, fwd, fwd);
|
|
return IsPointVisible(start, fwd);
|
|
}
|
|
|
|
public bool IsRectangleVisible(const float start[3], const float end[3], const float mins[3], const float maxs[3], float scale)
|
|
{
|
|
float ZpozOffset = maxs[2];
|
|
float ZnegOffset = mins[2];
|
|
float WideOffset = ((maxs[0] - mins[0]) + (maxs[1] - mins[1])) / 4.0;
|
|
// This rectangle is just a point!
|
|
if (ZpozOffset == 0.0 && ZnegOffset == 0.0 && WideOffset == 0.0)
|
|
return IsPointVisible(start, end);
|
|
// Adjust to scale.
|
|
ZpozOffset *= scale;
|
|
ZnegOffset *= scale;
|
|
WideOffset *= scale;
|
|
// Prepare rotation matrix.
|
|
float angles[3];
|
|
float fwd[3];
|
|
float right[3];
|
|
SubtractVectors(start, end, fwd);
|
|
NormalizeVector(fwd, fwd);
|
|
GetVectorAngles(fwd, angles);
|
|
GetAngleVectors(angles, fwd, right, NULL_VECTOR);
|
|
float vRectangle[4][3];
|
|
float vTemp[3];
|
|
// If the player is on the same level as us, we can optimize by only rotating on the z-axis.
|
|
if (FloatAbs(fwd[2]) <= 0.7071)
|
|
{
|
|
ScaleVector(right, WideOffset);
|
|
|
|
// Corner 1, 2
|
|
vTemp = end;
|
|
vTemp[2] += ZpozOffset;
|
|
AddVectors(vTemp, right, vRectangle[0]);
|
|
SubtractVectors(vTemp, right, vRectangle[1]);
|
|
|
|
// Corner 3, 4
|
|
vTemp = end;
|
|
vTemp[2] += ZnegOffset;
|
|
AddVectors(vTemp, right, vRectangle[2]);
|
|
SubtractVectors(vTemp, right, vRectangle[3]);
|
|
|
|
}
|
|
else if (fwd[2] > 0.0) // Player is below us.
|
|
{
|
|
fwd[2] = 0.0;
|
|
NormalizeVector(fwd, fwd);
|
|
ScaleVector(fwd, scale);
|
|
ScaleVector(fwd, WideOffset);
|
|
ScaleVector(right, WideOffset);
|
|
// Corner 1
|
|
vTemp = end;
|
|
vTemp[2] += ZpozOffset;
|
|
AddVectors(vTemp, right, vTemp);
|
|
SubtractVectors(vTemp, fwd, vRectangle[0]);
|
|
// Corner 2
|
|
vTemp = end;
|
|
vTemp[2] += ZpozOffset;
|
|
SubtractVectors(vTemp, right, vTemp);
|
|
SubtractVectors(vTemp, fwd, vRectangle[1]);
|
|
// Corner 3
|
|
vTemp = end;
|
|
vTemp[2] += ZnegOffset;
|
|
AddVectors(vTemp, right, vTemp);
|
|
AddVectors(vTemp, fwd, vRectangle[2]);
|
|
// Corner 4
|
|
vTemp = end;
|
|
vTemp[2] += ZnegOffset;
|
|
SubtractVectors(vTemp, right, vTemp);
|
|
AddVectors(vTemp, fwd, vRectangle[3]);
|
|
}
|
|
else // Player is above us.
|
|
{
|
|
fwd[2] = 0.0;
|
|
NormalizeVector(fwd, fwd);
|
|
ScaleVector(fwd, scale);
|
|
ScaleVector(fwd, WideOffset);
|
|
ScaleVector(right, WideOffset);
|
|
// Corner 1
|
|
vTemp = end;
|
|
vTemp[2] += ZpozOffset;
|
|
AddVectors(vTemp, right, vTemp);
|
|
AddVectors(vTemp, fwd, vRectangle[0]);
|
|
// Corner 2
|
|
vTemp = end;
|
|
vTemp[2] += ZpozOffset;
|
|
SubtractVectors(vTemp, right, vTemp);
|
|
AddVectors(vTemp, fwd, vRectangle[1]);
|
|
// Corner 3
|
|
vTemp = end;
|
|
vTemp[2] += ZnegOffset;
|
|
AddVectors(vTemp, right, vTemp);
|
|
SubtractVectors(vTemp, fwd, vRectangle[2]);
|
|
// Corner 4
|
|
vTemp = end;
|
|
vTemp[2] += ZnegOffset;
|
|
SubtractVectors(vTemp, right, vTemp);
|
|
SubtractVectors(vTemp, fwd, vRectangle[3]);
|
|
}
|
|
// Run traces on all corners.
|
|
for (new i = 0; i < 4; i++)
|
|
if (IsPointVisible(start, vRectangle[i]))
|
|
return true;
|
|
return false;
|
|
} |