#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]; float g_vCurrent[3]; float g_vLast[3]; bool client_stuck_g[MAXPLAYERS + 1]; bool round_start_stuck = false; bool cmdpost_run_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() { //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; 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 = 500000.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; } 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; } public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast) { round_start_stuck = false; 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; } public void OnMapStart() { //0.2 too spammmy, 1.5 too slow CreateTimer(0.50, 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) { 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 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 = 1500.0; 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); 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)) { if (GetClientTeam(present) == 1 || GetClientTeam(present) == 0) { bot_send_connected_msg(); return Plugin_Continue; } if (IsPlayerAlive(present)) { 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 int bot_on_type = -1; if (GetEntityMoveType(present) == MOVETYPE_LADDER) bot_on_type = 0; else 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); 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) { 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; float dot_product = 0.0; float z_axis = 0.0; if (bot_on_type != 0 && 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 = 10000.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 = 800.0; 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; } } //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); } } 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(); } 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)); } } return Plugin_Continue; } 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) { 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; //TODO maybe 50.0 again float distance_cap = 60.0; if (distance <= distance_cap) { if (dot_product <= crouch_cap || dot_product <= jump_cap) return dot_product; } } } } return 0.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, 0.6 experimental //TODO 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) { //TODO this is very experimental 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 int check_bot_downhill() { //TODO experimental if (GetEntityFlags(present) & FL_ONGROUND) { 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 = 2.0; 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)); //TODO return GetVectorDistance(vec, pos, true); //return SquareRoot(x_axis * x_axis + y_axis * y_axis + z_axis * z_axis); } 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"); 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(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; }