#pragma semicolon 1 #define DEBUG #define PLUGIN_AUTHOR "jenz" #define PLUGIN_VERSION "1.4" #define generic_length 256 #include #include #include #include #include //#pragma newdecls required int present = 0; 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]; //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); //UDP connection connect_socket(); 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 = 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 (IsValidClient(present)) { 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)); } else PrintToChat(client, "bot not connected to server"); return Plugin_Handled; } public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast) { targethuman = 0; reset_target_human_tp_coord(); } public void OnMapStart() { //0.2 too spammmy, 1.5 too slow CreateTimer(0.60, 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 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) { 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)); } 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 == 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); Vel[2] += velocity_addition_z_axis; TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel); } buttons_old = buttons; flags_old = flags; } } public Action recursive_pressing(Handle timer, any data) { if (IsValidClient(present)) { if (GetClientTeam(present) == 1 || GetClientTeam(present) == 0) { ChangeClientTeam(present, 2); return Plugin_Continue; } if (IsPlayerAlive(present)) { if (GetEntityMoveType(present) == MOVETYPE_LADDER) return Plugin_Continue; 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; if (targethuman_teleported[0] != 0.0) { 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(); return Plugin_Continue; } if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman)) { face_call(targethuman); find_closest_match = is_client_stuck_or_afk(targethuman); if (!find_closest_match) { face_call(targethuman); find_closest_match = IsAbleToSee(present, targethuman) ? false : true; } } if (find_closest_match) targethuman = GetClosestClient_option1(targeteam); float enemy_distance = -1.0; int target_enemy = find_closest_enemy(present, targeteam); 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); } if (IsValidClient(target_enemy)) { GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos); enemy_distance = get_power_distance(present, pos); } float enemey_cap = 900.0; if ((0 < enemy_distance < enemey_cap && targeteam == 2) || dist_target < 0 < enemy_distance) face_call(target_enemy); else if (0 < dist_target) face_call(targethuman); trace_hulling_bot(); 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); else Format(message, sizeof(message), "dist_target: %f targethuman: none enemy_distance: %f targeteam: %i", dist_target, enemy_distance, targeteam); if (IsValidClient(target_enemy)) Format(message, sizeof(message), "%s target_enemy: %N", message, target_enemy); else Format(message, sizeof(message), "%s target_enemy: none", message); send_socket_msg(message, strlen(message)); } } return Plugin_Continue; } public void trace_hulling_bot() { float feet_origin[3]; float eye_angles[3]; GetClientAbsOrigin(present, feet_origin); GetClientEyeAngles(present, eye_angles); //RayType_Infinite || RayType_EndPoint (Less performance intensive) TR_TraceRayFilter(feet_origin, eye_angles, MASK_SOLID, RayType_Infinite, TraceRayDontHitSelf, present); if (TR_DidHit()) { float EndOrigin[3]; TR_GetEndPosition(EndOrigin, INVALID_HANDLE); float mins[3], maxs[3]; int BOUNDINGBOX_INFLATION_OFFSET = 3; GetClientMins(present, mins); GetClientMaxs(present, maxs); //increasing boxes sizes for (int i = 0; i < sizeof(mins); i++) { mins[i] -= BOUNDINGBOX_INFLATION_OFFSET; maxs[i] += BOUNDINGBOX_INFLATION_OFFSET; } TR_TraceHullFilter(EndOrigin, EndOrigin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf, present); if (TR_DidHit()) { float end_origin_hud[3]; float forward_origin[3]; float plane[3]; TR_GetEndPosition(end_origin_hud, INVALID_HANDLE); //TODO GetVectorDotProduct failing GetAngleVectors(end_origin_hud, forward_origin, NULL_VECTOR, NULL_VECTOR); SubtractVectors(feet_origin, eye_angles, plane); NormalizeVector(plane, plane); float smallest_dot_product = GetVectorDotProduct(plane, forward_origin); float smallest_distance = GetVectorDistance(feet_origin, end_origin_hud); char message[generic_length * 5]; Format(message, sizeof(message), "smallest_dot_product: %f smallest_distance: %f end_origin_hud: %f %f %f", smallest_dot_product, smallest_distance, end_origin_hud[0], end_origin_hud[1], end_origin_hud[2]); send_socket_msg(message, strlen(message)); } } } //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); 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.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(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); } } } } 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) { 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) { 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; } 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 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 && i != targethuman) { 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(present, pos); 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)); 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; } 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) { 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; } public void bot_send_connected_msg() { 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; } //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_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; }