#pragma semicolon 1 #define DEBUG #define PLUGIN_AUTHOR "jenz" #define PLUGIN_VERSION "1.5" #define generic_length 256 #include #include #include #include #include //#pragma newdecls required int targethuman[MAXPLAYERS + 1]; int target_enemy[MAXPLAYERS + 1]; int buttons_old[MAXPLAYERS + 1]; int flags_old[MAXPLAYERS + 1]; bool surf_cooldown = false; float client_old_coords[MAXPLAYERS + 1][3]; float targethuman_teleported[MAXPLAYERS + 1][3]; bool chat_cooldown = 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() { for (int i = 1; i <= MaxClients; i++) if (IsValidClient(i)) { targethuman[i] = 0; target_enemy[i] = 0; reset_target_human_tp_coord(i); } //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); //UDP connection connect_socket(); chat_cooldown = false; } public void reset_target_human_tp_coord(int client) { targethuman_teleported[client][0] = 0.0; targethuman_teleported[client][1] = 0.0; targethuman_teleported[client][2] = 0.0; } public void trigger_teleport(const char[] output, int entity_index, int client, float delay) { if (IsValidEdict(entity_index)) for (int i = 1; i <= MaxClients; i++) if (IsValidClient(i)) { if (targethuman[i] == client) { GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported[i]); CreateTimer(6.0, reset_target_tp, client); } else if (is_bot_player(i) && i == client) CreateTimer(0.1, reset_target_tp, client); } } public void Trigger_Multiple(const char[] output, int entity_index, int client, float delay) { if (IsValidEdict(entity_index) && origin_command_check(entity_index)) { for (int i = 1; i <= MaxClients; i++) if (IsValidClient(i)) { if (targethuman[i] == client) { GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported[i]); CreateTimer(6.0, reset_target_tp, client); } else if (is_bot_player(i) && i == client) CreateTimer(0.1, reset_target_tp, client); } } } 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, int client) { reset_target_human_tp_coord(client); return Plugin_Continue; } public bool distance_check(int client) { float dist_target = get_power_distance(client, targethuman_teleported[client]); float min_required_distance = 50000.0; if (dist_target > min_required_distance) return false; return true; } public Action cmd_talk(int client, int args) { char msg[generic_length * 5]; 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; } if (chat_cooldown) { PrintToChat(client, "spamming bot too much, applying cooldown"); return Plugin_Handled; } bool bot_found = false; for (int i = 1; i <= MaxClients; i++) if (IsValidClient(i) && !IsFakeClient(i)) { char auth[50]; GetClientAuthId(i, AuthId_Engine, auth, sizeof(auth)); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { 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); bot_found = true; } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { 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_msg1(msg, strlen(msg)); CreateTimer(2.0, bot_chat_cooldown); bot_found = true; } } if (!bot_found) PrintToChat(client, "bot not connected to server"); return Plugin_Handled; } public Action bot_chat_cooldown(Handle timer, any data) { chat_cooldown = false; return Plugin_Continue; } public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast) { for (int i = 1; i <= MaxClients; i++) if (IsValidClient(i) && !IsFakeClient(i)) { targethuman[i] = 0; target_enemy[i] = 0; reset_target_human_tp_coord(i); } } public void OnMapStart() { //0.2 too spammmy, 1.5 too slow chat_cooldown = false; CreateTimer(0.30, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); CreateTimer(15.0, bot_check_connect, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); } 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 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) { 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)) { if (client_count > 61) { found_bot_1 = true; found_bot_2 = true; char msg[generic_length]; if (is_bot_player(i)) { KickClient(i, "server full you need to leave"); Format(msg, sizeof(msg), "bot kicked server full"); send_socket_msg(msg, strlen(msg)); } } else { char auth[50]; GetClientAuthId(i, AuthId_Engine, auth, sizeof(auth)); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { found_bot_1 = true; } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { 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)); if (!found_bot_2) send_socket_msg1(msg, strlen(msg)); 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 (is_bot_player(client)) { int flags = GetEntityFlags(client); if (!(flags & FL_ONGROUND) && (flags_old[client] & FL_ONGROUND) && !(buttons_old[client] & IN_JUMP) && !(buttons & IN_JUMP) && (GetEntityMoveType(client) != MOVETYPE_LADDER)) { float Vel[3], feet_origin[3], ground_pos[3], downwards[3]; //TODO float velocity_addition_z_axis = 300.0; GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel); Vel[2] += velocity_addition_z_axis; GetClientAbsOrigin(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, client); if (TR_DidHit()) { TR_GetEndPosition(ground_pos); feet_origin[2] -= 10.0; float ground_distance = GetVectorDistance(feet_origin, ground_pos); if (ground_distance > 80) { float angles_eye[3]; GetClientEyeAngles(client, angles_eye); feet_origin[2] += 10.0; TR_TraceRayFilter(feet_origin, angles_eye, MASK_ALL, RayType_Infinite, TraceRayDontHitSelf, client); if (TR_DidHit()) { TR_GetEndPosition(ground_pos); feet_origin[2] -= 10.0; float forward_distance = GetVectorDistance(feet_origin, ground_pos); if (forward_distance > 280) { if (IsValidClient(targethuman[client])) { float feet_origin_pre[3], human_feet_origin[3]; GetClientAbsOrigin(client, feet_origin_pre); GetClientAbsOrigin(targethuman[client], human_feet_origin); //target human is below, get down to them //TODO maybe? if (feet_origin_pre[2] - 200 > human_feet_origin[2]) { buttons_old[client] = buttons; flags_old[client] = flags; return; } } float velocity[3]; GetEntPropVector(client, Prop_Data, "m_vecVelocity", velocity); velocity[2] += 30.0; NegateVector(velocity); for (int y = 0; y < 10; y++) TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, velocity); } } } } TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel); } buttons_old[client] = buttons; flags_old[client] = flags; } } public bool is_bot_player(int client) { char auth[50]; GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth)); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { return true; } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { return true; } return false; } public Action recursive_pressing(Handle timer, any data) { for (int client = 1; client <= MaxClients; client++) { if (!IsValidClient(client)) continue; if (is_bot_player(client)) { if (GetClientTeam(client) == 1 || GetClientTeam(client) == 0) { ChangeClientTeam(client, 2); continue; } if (IsPlayerAlive(client)) { if (GetEntityMoveType(client) == MOVETYPE_LADDER) continue; int targeteam = 0; if (GetClientTeam(client) != 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; } if (targethuman_teleported[client][0] != 0.0) { float ClientPos[3]; float Result[3]; GetClientEyePosition(client, ClientPos); MakeVectorFromPoints(ClientPos, targethuman_teleported[client], Result); GetVectorAngles(Result, Result); TeleportEntity(client, NULL_VECTOR, Result, NULL_VECTOR); if (!distance_check(client)) reset_target_human_tp_coord(client); continue; } target_enemy[client] = GetClosestClient_option1(targeteam == 2 ? 3 : 2, client); targethuman[client] = GetClosestClient_option1(targeteam == 2 ? 2 : 3, client); float enemy_distance = -1.0; float dist_target = -1.0; float pos[3]; if (IsValidClient(targethuman[client])) { GetEntPropVector(targethuman[client], Prop_Send, "m_vecOrigin", pos); dist_target = get_power_distance(client, pos); } //TODO maybe disable if requested if (IsValidClient(target_enemy[client])) { GetEntPropVector(target_enemy[client], Prop_Send, "m_vecOrigin", pos); enemy_distance = get_power_distance(client, pos); } if ((0 < enemy_distance && targeteam == 2) || dist_target < 0 < enemy_distance) { /* 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); } else if (0 < dist_target) face_call(targethuman[client], client); trace_hulling_bot(client); char message[generic_length * 7]; if (IsValidClient(targethuman[client])) Format(message, sizeof(message), "dist_target: %f targethuman: %N enemy_distance: %f targeteam: %i", dist_target, targethuman[client], enemy_distance, targeteam); else Format(message, sizeof(message), "dist_target: %f targethuman: none enemy_distance: %f targeteam: %i", dist_target, enemy_distance, targeteam); if (IsValidClient(target_enemy[client])) Format(message, sizeof(message), "%s target_enemy: %N", message, target_enemy[client]); else Format(message, sizeof(message), "%s target_enemy: none", message); char auth[50]; GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth)); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { send_socket_msg(message, strlen(message)); } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { send_socket_msg1(message, strlen(message)); } } } } return Plugin_Continue; } //https://developer.valvesoftware.com/wiki/Dimensions public void trace_hulling_bot(int client) { char message[generic_length * 3]; float step_cap = 18.0; float crouch_min = 48.0; float stand_min = 63.0; float feet_origin[3], mins[3], maxs[3], eye_position[3]; int BOUNDINGBOX_INFLATION_OFFSET = 3; GetClientEyePosition(client, eye_position); GetClientAbsOrigin(client, feet_origin); GetClientMins(client, mins); GetClientMaxs(client, maxs); //increasing boxes sizes for (int ij = 0; ij < sizeof(mins) - 1; ij++) { mins[ij] -= BOUNDINGBOX_INFLATION_OFFSET; maxs[ij] += BOUNDINGBOX_INFLATION_OFFSET; } //acts as full body check feet_origin[2] += BOUNDINGBOX_INFLATION_OFFSET; TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf); if (TR_DidHit()) { //check 0.0 to 48.0 units starting from feet feet_origin[2] -= BOUNDINGBOX_INFLATION_OFFSET; mins[2] = 0.0; maxs[2] = crouch_min; TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf); if (!(TR_DidHit())) { //can crouch Format(message, sizeof(message), "hull info:crouch"); char auth[50]; GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth)); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { send_socket_msg(message, strlen(message)); } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { send_socket_msg1(message, strlen(message)); } return; } //something blocks floor crouch eye_position[2] += 5.0; TR_TraceHullFilter(eye_position, eye_position, mins, maxs, MASK_ALL, TraceRayDontHitSelf); if (!(TR_DidHit())) { //should not block jump level Format(message, sizeof(message), "hull info:jump"); char auth[50]; GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth)); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { send_socket_msg(message, strlen(message)); } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { send_socket_msg1(message, strlen(message)); } return; } else { //still potentially crouch hole in wall or one side jumpable mins[2] = step_cap; float iterator = step_cap; while (iterator < stand_min) { maxs[2] = iterator; iterator += step_cap; for (int jj = 0; jj < 2; jj++) for (int ij = 0; ij < 2; ij++) { if (jj == 0) mins[ij] += BOUNDINGBOX_INFLATION_OFFSET; else maxs[ij] -= BOUNDINGBOX_INFLATION_OFFSET; TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf); if (!(TR_DidHit())) { Format(message, sizeof(message), "hull info:jump"); char auth[50]; GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth)); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { send_socket_msg(message, strlen(message)); } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { send_socket_msg1(message, strlen(message)); } return; } TR_TraceHullFilter(eye_position, eye_position, mins, maxs, MASK_ALL, TraceRayDontHitSelf); if (!(TR_DidHit())) { Format(message, sizeof(message), "hull info:jump"); char auth[50]; GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth)); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { send_socket_msg(message, strlen(message)); } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { send_socket_msg1(message, strlen(message)); } return; } if (jj == 0) mins[ij] -= BOUNDINGBOX_INFLATION_OFFSET; else maxs[ij] += BOUNDINGBOX_INFLATION_OFFSET; } } //currently detects when two walls meet and create a corner float move_angles[3]; if (GetEntityMoveType(client) != MOVETYPE_LADDER && GetEntProp(client, Prop_Data, "m_nWaterLevel") == 0) { GetClientEyeAngles(client, move_angles); move_angles[0] = 0.0; move_angles[1] += 35.0; move_angles[2] = 0.0; TeleportEntity(client, NULL_VECTOR, move_angles, NULL_VECTOR); } return; } } } //TODO implement surfing again but differently //check_bot_surfing(); /* public void check_bot_surfing() { float vPos[3]; float vMins[3]; float vMaxs[3]; GetEntPropVector(, Prop_Data, "m_vecOrigin", vPos); GetEntPropVector(, Prop_Send, "m_vecMins", vMins); GetEntPropVector(, 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, ); if (TR_DidHit()) { //< 0.7 = surf ramp float surf_ramp = 0.6; char keyinput[generic_length * 3]; float vPlane[3]; TR_GetPlaneNormal(INVALID_HANDLE, vPlane); if (0.0 < vPlane[2] < surf_ramp) { vPlane[0] *= 100; vPlane[1] *= 100; vPlane[2] *= 100; if (!surf_cooldown) { surf_cooldown = true; TeleportEntity(, NULL_VECTOR, vPlane, NULL_VECTOR); Format(keyinput, sizeof(keyinput), "surfing: %f %f %f", vPlane[0], vPlane[1], vPlane[2]); char auth[50]; GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth)); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { send_socket_msg(keyinput, strlen(keyinput)); } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { send_socket_msg1(keyinput, strlen(keyinput)); } CreateTimer(0.5, surf_cooldown_timer); } } } } */ public Action surf_cooldown_timer(Handle timer, any data) { surf_cooldown = false; return Plugin_Continue; } public bool TraceRayDontHitSelf(int entity, int mask, any data) { return entity != data && !(0 < entity <= MaxClients); } public void face_call(int client, int selfclient) { for (int j = 0; j < 5; j++) faceclient(client, selfclient); } public void faceclient(int target_human, int client) { if (IsValidClient(client) && IsValidClient(target_human)) { float TargetPos[3]; float ClientPos[3]; float Result[3]; GetClientEyePosition(target_human, TargetPos); GetClientEyePosition(client, ClientPos); MakeVectorFromPoints(ClientPos, TargetPos, Result); GetVectorAngles(Result, Result); TeleportEntity(client, 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) { float min_distance_cap = 5.0; float client_own_distance = get_power_distance(client, client_old_coords[client]); GetEntPropVector(client, Prop_Send, "m_vecOrigin", client_old_coords[client]); return client_own_distance < min_distance_cap; } int target_human_afk_counter = 0; public int GetClosestClient_option1(int targeteam, int client) { float nearestdistance = -1.0; int nearest = -1; bool bot_alternative = false; for (int i = 1; i <= MaxClients; i++) if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && !is_bot_player(i)) { if (!IsAbleToSee(client, i)) continue; if (is_client_stuck_or_afk(i)) continue; bot_alternative = true; break; } for (int i = 1; i <= MaxClients; i++) if (IsValidClient(i) && IsPlayerAlive(i) && i != client && GetClientTeam(i) == targeteam) { if (!IsAbleToSee(client, i)) continue; if (is_client_stuck_or_afk(i)) { if (i != targethuman[client]) continue; target_human_afk_counter++; int afk_cap = 9; if (target_human_afk_counter > afk_cap) { target_human_afk_counter = 0; continue; } } if (bot_alternative && targethuman[client] == i && is_bot_player(i)) continue; if (i == targethuman[client]) return targethuman[client]; float pos[3]; GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); float dist_target = get_power_distance(client, pos); if (admins[i] || vips[i] || i == target_enemy[client]) dist_target /= 5; if (GetClientTeam(client) == 3 && targeteam == 3) { for (int j = 1; j <= MaxClients; j++) if (IsValidClient(j) && IsPlayerAlive(j) && GetClientTeam(j) == 2) { if (!IsAbleToSee(i, j)) continue; if (is_client_stuck_or_afk(j)) continue; dist_target += 250.0; } } 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); return GetVectorDistance(vec, pos); } 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)); char msg[generic_length]; Format(msg, sizeof(msg), "autismo connected"); if (StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false)) { send_socket_msg(msg, strlen(msg)); } if (StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false)) { send_socket_msg1(msg, strlen(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; } public OnSocketError(Handle socket, const int errorType, const int errorNum, any args) { CloseHandle(socket); LogError("[MR] Socket error: %d (errno %d)", errorType, errorNum); CreateTimer(10.0, TimerConnect, INVALID_HANDLE, TIMER_HNDL_CLOSE); } stock void connect_socket() { if (global_socket == INVALID_HANDLE || !SocketIsConnected(global_socket)) { //socket otherwise declare in public OnConfigsExecuted(){} global_socket = SocketCreate(SOCKET_UDP, OnSocketError); SocketSetOption(global_socket, SocketReuseAddr, 1); SocketBind(global_socket, "127.0.0.1", 48475); SocketConnect(global_socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 48475); } } public void OnClientDisconnect(int client) { 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; } //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(10.0, TimerConnect, INVALID_HANDLE, TIMER_HNDL_CLOSE); } public Action TimerConnect(Handle timer, any arg) { connect_socket(); 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_ALL, 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; }