projects-jenz/AutismBotIngame/scripting/autism_bot_info.sp

944 lines
26 KiB
SourcePawn
Raw Normal View History

2020-01-23 23:15:26 +01:00
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
2020-08-01 01:15:39 +02:00
#define PLUGIN_VERSION "1.4"
#define generic_length 256
2020-01-23 23:15:26 +01:00
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <outputinfo>
2020-06-26 00:11:22 +02:00
#include <socket>
2020-01-23 23:15:26 +01:00
2020-06-26 00:11:22 +02:00
//#pragma newdecls required
2020-02-28 22:00:22 +01:00
int present = 0;
2020-02-09 00:26:05 +01:00
int targethuman = 0;
int buttons_old;
int flags_old;
bool surf_cooldown = false;
bool connected_cooldown = false;
float client_old_coords[MAXPLAYERS + 1][3];
float targethuman_teleported[3];
2020-08-01 01:15:39 +02:00
float g_vCurrent[3];
float g_vLast[3];
bool client_stuck_g[MAXPLAYERS + 1];
bool round_start_stuck = false;
bool cmdpost_run_cooldown = false;
2020-01-23 23:15:26 +01:00
//admins & vips
bool admins[MAXPLAYERS + 1];
bool vips[MAXPLAYERS + 1];
2020-06-26 00:11:22 +02:00
//socket for bot input
Handle global_socket;
2020-01-23 23:15:26 +01:00
public Plugin myinfo =
{
name = "coordinates for the bot",
author = PLUGIN_AUTHOR,
description = "hello ",
version = PLUGIN_VERSION,
url = ""
};
2020-02-28 22:00:22 +01:00
public void OnPluginStart()
2020-01-23 23:15:26 +01:00
{
//talking
RegConsoleCmd("sm_autism", cmd_talk, "talking to the bot through java application");
2020-02-28 22:00:22 +01:00
//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);
2020-06-26 00:11:22 +02:00
//socket otherwise declare in public OnConfigsExecuted(){}
Handle socket = SocketCreate(SOCKET_UDP, OnSocketError);
SocketSetOption(socket, SocketReuseAddr, 1);
SocketBind(socket, "127.0.0.1", 48475);
2020-06-26 00:11:22 +02:00
connect(socket);
global_socket = socket;
2020-07-26 01:13:39 +02:00
round_start_stuck = true;
cmdpost_run_cooldown = false;
reset_target_human_tp_coord();
targethuman = 0;
2020-01-23 23:15:26 +01:00
}
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)
2020-08-01 01:15:39 +02:00
{
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported);
2020-08-01 01:15:39 +02:00
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))
2020-08-01 01:15:39 +02:00
{
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported);
2020-08-01 01:15:39 +02:00
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 = 500000.0;
if (dist_target > min_required_distance)
return false;
return true;
}
public Action cmd_talk(int client, int args)
{
2020-06-26 00:11:22 +02:00
char msg[generic_length];
char info[generic_length];
GetCmdArgString(info, sizeof(info));
2020-05-06 01:24:15 +02:00
if (strlen(info) == 0)
{
2020-06-09 23:34:49 +02:00
PrintToChat(client, "Add a message to the command if autism bot is ingame and running on discord");
2020-05-06 01:24:15 +02:00
return Plugin_Handled;
}
if (IsValidClient(present))
{
Format(msg, sizeof(msg), "clientmessage: %s", info);
send_socket_msg(msg, strlen(msg));
}
else
PrintToChat(client, "bot not connected to server");
return Plugin_Handled;
}
2020-02-28 22:00:22 +01:00
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
2020-01-23 23:15:26 +01:00
{
round_start_stuck = false;
2020-02-28 22:00:22 +01:00
targethuman = 0;
cmdpost_run_cooldown = false;
reset_target_human_tp_coord();
CreateTimer(7.0, permitStuck);
}
public Action permitStuck(Handle timer, any data)
{
round_start_stuck = true;
return Plugin_Continue;
2020-01-23 23:15:26 +01:00
}
2020-02-28 22:00:22 +01:00
public void OnMapStart()
2020-02-09 00:26:05 +01:00
{
//0.2 too spammmy, 1.5 too slow
CreateTimer(0.25, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
CreateTimer(1.0, clients_coordinates, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
2020-06-26 00:11:22 +02:00
CreateTimer(10.0, bot_check_connect, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
2020-02-09 00:26:05 +01:00
}
public Action clients_coordinates(Handle timer, any data)
{
if (IsValidClient(present) && IsPlayerAlive(present))
{
for (int i = 1; i <= MaxClients; i++)
2020-07-26 01:13:39 +02:00
if (IsValidClient(i) && IsPlayerAlive(i) && i != present && !client_stuck_g[i])
GetEntPropVector(i, Prop_Send, "m_vecOrigin", client_old_coords[i]);
}
return Plugin_Continue;
}
2020-06-26 00:11:22 +02:00
public void send_socket_msg(char[] query_msg, int len)
2020-06-09 23:34:49 +02:00
{
2020-06-26 00:11:22 +02:00
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)
2020-06-26 00:11:22 +02:00
{
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)
{
char msg[generic_length];
2020-08-01 01:15:39 +02:00
KickClient(present, "server full you need to leave");
Format(msg, sizeof(msg), "bot kicked server full");
send_socket_msg(msg, strlen(msg));
}
return Plugin_Continue;
}
public Action runcmd_cooldown(Handle timer, any data)
{
cmdpost_run_cooldown = false;
2020-06-26 00:11:22 +02:00
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];
2020-07-26 01:13:39 +02:00
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(present, pos);
//prior 1500.0
//TODO
float dist_cap = 50000.0;
2020-07-26 01:13:39 +02:00
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.5, runcmd_cooldown);
}
}
}
else if (client == present)
{
int flags = GetEntityFlags(client);
2020-08-01 01:15:39 +02:00
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;
2020-08-01 01:15:39 +02:00
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
if (IsValidClient(targethuman))
{
//TODO maybe?
2020-08-21 02:30:29 +02:00
/*
{
Vel[0] -= velocity_addition_z_axis / 10;
Vel[1] -= velocity_addition_z_axis / 10;
}
2020-08-21 02:30:29 +02:00
*/
}
Vel[2] += velocity_addition_z_axis;
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel);
2020-08-21 02:30:29 +02:00
check_bot_surfing();
}
buttons_old = buttons;
flags_old = flags;
}
}
public Action recursive_pressing(Handle timer, any data)
2020-06-26 00:11:22 +02:00
{
2020-08-24 01:18:32 +02:00
if (IsValidClient(present))
2020-06-26 00:11:22 +02:00
{
if (GetClientTeam(present) == 1 || GetClientTeam(present) == 0)
{
//TODO still stuck in spectate, fuck
ChangeClientTeam(present, 2);
return Plugin_Continue;
}
2020-08-24 01:18:32 +02:00
if (IsPlayerAlive(present))
{
2020-08-24 01:18:32 +02:00
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, downhill = 3, teleporter = 4
2020-08-24 01:18:32 +02:00
int bot_on_type = -1;
if (GetEntityMoveType(present) == MOVETYPE_LADDER)
bot_on_type = 0;
else
2020-08-24 01:18:32 +02:00
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 != 4)
{
face_call(targethuman);
2020-08-24 01:18:32 +02:00
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 != 4)
{
2020-08-24 01:18:32 +02:00
targethuman = 0;
targethuman = GetClosestClient_option1(present, targeteam);
}
2020-08-24 01:18:32 +02:00
float enemy_distance = -1.0;
int target_enemy = find_closest_enemy(present, targeteam);
bool chasing_enemy = false;
float dist_target = -1.0;
float dot_product = 0.0;
float z_axis = 0.0;
if (bot_on_type != 0 && bot_on_type != 4)
2020-07-21 01:20:28 +02:00
{
2020-08-24 01:18:32 +02:00
float pos[3];
if (IsValidClient(targethuman))
2020-07-21 01:20:28 +02:00
{
2020-08-24 01:18:32 +02:00
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
dist_target = get_power_distance(present, pos);
}
if (IsValidClient(target_enemy))
{
float min_enemy_distance = 10000.0;
2020-08-24 01:18:32 +02:00
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 = 800.0;
2020-08-24 01:18:32 +02:00
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);
}
else
{
target_enemy = 0;
enemy_distance = -1.0;
}
}
2020-08-24 01:18:32 +02:00
//zombie aiming for human
float present_bot_coords[3];
GetClientAbsOrigin(present, present_bot_coords);
z_axis = FloatAbs(Pow(present_bot_coords[2] - pos[2], 5.0));
float z_axis_cap = 10.0;
if ((targeteam == 2 && 0 < enemy_distance && z_axis < z_axis_cap) || dist_target == -1.0)
{
chasing_enemy = true;
face_call(target_enemy);
}
}
2020-08-24 01:18:32 +02:00
if (IsValidClient(targethuman) && !chasing_enemy)
face_call(targethuman);
//0: nothing, dot_product = crouch_cap = 5000.0; dot_product = jump_cap = 100000.0;
dot_product = wall_circle();
2020-07-21 01:20:28 +02:00
}
char message[generic_length * 7];
if (IsValidClient(targethuman))
Format(message, sizeof(message), "dist_target: %f targethuman: %N bot_on_type: %i enemy_distance: %f dot_product: %f targeteam: %i", dist_target, targethuman, bot_on_type, enemy_distance, dot_product, targeteam);
else
Format(message, sizeof(message), "dist_target: %f targethuman: none bot_on_type: %i enemy_distance: %f dot_product: %f targeteam: %i", dist_target, bot_on_type, enemy_distance, dot_product, targeteam);
if (IsValidClient(target_enemy))
Format(message, sizeof(message), "%s target_enemy: %N z_axis: %f", message, target_enemy, z_axis);
else
Format(message, sizeof(message), "%s target_enemy: none z_axis: %f", message, z_axis);
send_socket_msg(message, strlen(message));
2020-08-01 01:15:39 +02:00
}
2020-01-23 23:15:26 +01:00
}
2020-06-26 00:11:22 +02:00
return Plugin_Continue;
2020-01-23 23:15:26 +01:00
}
public float 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)
2020-08-21 02:30:29 +02:00
{
float StartOrigin[3];
2020-08-21 02:30:29 +02:00
float Angles[3];
GetClientEyeAngles(present, Angles);
Angles[iterator] = AngleRotate;
2020-08-21 02:30:29 +02:00
GetClientEyePosition(present, StartOrigin);
//TR_TraceRayFilter(StartOrigin, Angles, MASK_SOLID, RayType_Infinite, TraceRayDontHitSelf, present);
TR_TraceRayFilter(StartOrigin, Angles, MASK_SHOT, RayType_EndPoint, TraceRayDontHitSelf, present);
2020-08-21 02:30:29 +02:00
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;
//TODO maybe 50.0 again
float distance_cap = 100.0;
if (distance <= distance_cap)
{
if (dot_product <= crouch_cap || dot_product <= jump_cap)
return dot_product;
}
2020-08-21 02:30:29 +02:00
}
}
}
return 0.0;
}
2020-08-01 01:15:39 +02:00
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, 0.6 experimental //TODO
float surf_ramp = 0.6;
2020-08-01 01:15:39 +02:00
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;
if (!surf_cooldown)
2020-08-01 01:15:39 +02:00
{
surf_cooldown = true;
2020-08-01 01:15:39 +02:00
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));
CreateTimer(0.5, surf_cooldown_timer);
2020-08-01 01:15:39 +02:00
}
}
}
}
public Action surf_cooldown_timer(Handle timer, any data)
{
surf_cooldown = false;
return Plugin_Continue;
2020-08-01 01:15:39 +02:00
}
public int check_bot_downhill()
{
//TODO experimental
if (GetEntityFlags(present) & FL_ONGROUND)
{
2020-08-01 01:15:39 +02:00
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())
{
2020-08-01 01:15:39 +02:00
//1.0 = flat ground
float vPlane[3];
float vLast[3];
float flat_ground = 1.0;
TR_GetPlaneNormal(INVALID_HANDLE, vPlane);
2020-08-01 01:15:39 +02:00
if (0 < vPlane[2] < flat_ground)
{
2020-08-01 01:15:39 +02:00
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);
}
}
2020-01-23 23:15:26 +01:00
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 = 2.0;
float client_own_distance = get_power_distance(client, client_old_coords[client]);
2020-07-26 01:13:39 +02:00
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));
//TODO
return GetVectorDistance(vec, pos, true);
//return SquareRoot(x_axis * x_axis + y_axis * y_axis + z_axis * z_axis);
}
2020-01-23 23:15:26 +01:00
public void OnClientPostAdminCheck(int client)
{
//STEAM_0:1:34783317
//STEAM_0:1:60189040
//[U:1:120378081]
//[U:1:69566635]
2020-01-23 23:15:26 +01:00
char auth[50];
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
if (StrEqual("[U:1:120378081]", auth, false))
{
2020-02-28 22:00:22 +01:00
present = client;
2020-06-26 00:11:22 +02:00
bot_send_connected_msg();
}
2020-02-28 22:00:22 +01:00
else if (StrEqual("STEAM_0:1:60189040", auth, false))
{
2020-02-28 22:00:22 +01:00
present = client;
2020-06-26 00:11:22 +02:00
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;
2020-07-26 01:13:39 +02:00
client_stuck_g[client] = false;
}
2020-06-26 00:11:22 +02:00
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
{
2020-06-26 00:11:22 +02:00
LogError("[MR] Socket error: %d (errno %d)", errorType, errorNum);
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
}
2020-06-26 00:11:22 +02:00
stock void connect(Handle socket)
{
2020-06-26 00:11:22 +02:00
if (!SocketIsConnected(socket))
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 48475);
}
2020-06-26 00:11:22 +02:00
public void OnClientDisconnect(int client)
{
2020-06-26 00:11:22 +02:00
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;
2020-07-26 01:13:39 +02:00
client_stuck_g[client] = false;
}
2020-06-26 00:11:22 +02:00
public void bot_send_connected_msg()
{
2020-06-26 00:11:22 +02:00
char msg[generic_length];
Format(msg, sizeof(msg), "autismo connected");
if (!connected_cooldown)
{
connected_cooldown = true;
send_socket_msg(msg, strlen(msg));
CreateTimer(5.0, connect_cooldown);
}
}
public Action connect_cooldown(Handle timer, any data)
{
connected_cooldown = false;
return Plugin_Continue;
}
2020-06-26 00:11:22 +02:00
//Socket callback
public OnSocketConnected(Handle socket, any arg)
{
2020-06-26 00:11:22 +02:00
}
2020-06-26 00:11:22 +02:00
//manage message
public OnSocketReceive(Handle socket, char[] receiveData, const dataSize, any hFile)
{
2020-06-26 00:11:22 +02:00
//PrintToChatAll("receiveData: %s", receiveData);
}
public OnSocketDisconnected(Handle socket, any arg)
{
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
2020-06-09 23:34:49 +02:00
}
2020-06-26 00:11:22 +02:00
public Action TimerConnect(Handle timer, any arg)
2020-06-09 23:34:49 +02:00
{
2020-06-26 00:11:22 +02:00
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])
{
2020-07-26 01:13:39 +02:00
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;
2020-01-23 23:15:26 +01:00
}