diff --git a/AutismBotIngame/python/ingamefollowct.py b/AutismBotIngame/python/ingamefollowct.py index db80a0bd..135cc35a 100644 --- a/AutismBotIngame/python/ingamefollowct.py +++ b/AutismBotIngame/python/ingamefollowct.py @@ -64,8 +64,7 @@ def bot_process_movement(input_line): strInput = "-attack; wait 2; -use; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; " if bot_stuck: print('bot stuck') - for _ in range(2): - strInput += "+jump; wait 15; +duck; wait 15; -jump; wait 15; -duck; wait 3;" + strInput += "+jump; wait 15; +duck; wait 15; -jump; wait 15; -duck; wait 3;" if dist_target > 2.5: strInput += "use weapon_elite; wait 3; " elif targeteam == 3: @@ -83,16 +82,17 @@ def bot_process_movement(input_line): else: ladder_counter = 0 min_distance_target_human = 2.0 + min_enemy_distance = 20.0 if bot_on_type == 1: print('bot_on_type water') strInput += "+jump; wait 5;" if message_counter > 10: print('target human: ', targethuman, ' dist_target: ', dist_target, ' enemy distance: ', enemy_distance) message_counter = 0 - if enemy_distance < 0 or dist_target > min_distance_target_human or targeteam == 2: + if enemy_distance < 0 or dist_target > min_distance_target_human or enemy_distance < min_enemy_distance or targeteam == 2: strInput += "+forward; wait 5; " - boolean_val = random.choice([True, False]) for _ in range(10): + boolean_val = random.choice([True, False]) if boolean_val: strInput += "+moveleft; wait 15; -moveleft; " else: diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index 1f95b4f8..7ac2062d 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -136,27 +136,6 @@ public Action bot_check_connect(Handle timer, any data) return Plugin_Continue; } -public bool TraceRayable(int client, int target) -{ - float pos_client[3]; - float pos_target[3]; - GetClientEyePosition(client, pos_client); - GetClientEyePosition(target, pos_target); - - //Handle trace = TR_TraceRayFilterEx(pos_client, pos_target, MASK_NPCSOLID, RayType_EndPoint, FilterClient, client); - Handle trace = TR_TraceRayFilterEx(pos_client, pos_target, MASK_VISIBLE, RayType_EndPoint, FilterClient, client); - if (TR_DidHit(trace)) - { - if(TR_GetEntityIndex(trace) == target) - { - CloseHandle(trace); - return true; - } - } - CloseHandle(trace); - return false; -} - 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]) { @@ -226,16 +205,12 @@ public Action recursive_pressing(Handle timer, any data) } else { + face_call(targethuman); find_closest_match = is_client_stuck_or_afk(targethuman); if (!find_closest_match) { - int iterator_counter = 0; - while (iterator_counter < 10 && find_closest_match) - { - face_call(targethuman); - find_closest_match = TraceRayable(present, targethuman) ? false : true; - iterator_counter++; - } + face_call(targethuman); + find_closest_match = IsAbleToSee(present, targethuman) ? false : true; if (find_closest_match) { float dist_target = get_power_distance(targethuman, client_old_coords[targethuman]); @@ -246,62 +221,74 @@ public Action recursive_pressing(Handle timer, any data) bot_presumed_endpoint[1] = client_old_coords[targethuman][1]; bot_presumed_endpoint[2] = client_old_coords[targethuman][2]; find_closest_match = false; - CreateTimer(6.0, bot_reached_endpoint); + CreateTimer(4.0, bot_reached_endpoint); } } } } } - if (find_closest_match) + + //check ladder = 0, water = 1, in air(surfing) = 2 TODO + int bot_on_type = -1; + if (GetEntityMoveType(present) == MOVETYPE_LADDER) + bot_on_type = 0; + int ilevel = GetEntProp(present, Prop_Data, "m_nWaterLevel"); + if (ilevel >= 2) + bot_on_type = 1; + if (find_closest_match && bot_on_type != 0) + { + targethuman = 0; targethuman = GetClosestClient_option1(present, targeteam); - if (IsValidClient(targethuman)) + } + float enemy_distance = -1.0; + int target_enemy = find_closest_enemy(present, targeteam); + bool chasing_enemy = false; + float dist_target = -1.0; + if (bot_on_type != 0 && bot_on_type != 2 && bot_presumed_endpoint[0] == 0.0) { float pos[3]; - GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos); - float dist_target = get_power_distance(present, pos); - float enemy_distance = -1.0; - //check ladder = 0, water = 1, in air(surfing) = 2 TODO - int bot_on_type = -1; - if (GetEntityMoveType(present) == MOVETYPE_LADDER) - bot_on_type = 0; - int ilevel = GetEntProp(present, Prop_Data, "m_nWaterLevel"); - if (ilevel >= 2) - bot_on_type = 1; - if (bot_on_type != 0 && bot_on_type != 2 && bot_presumed_endpoint[0] == 0.0) + if (IsValidClient(targethuman)) { - int target_enemy = find_closest_enemy(present, targeteam); - if (IsValidClient(target_enemy)) - { - float min_distance_target_human = 2.0; - float min_enemy_distance = 100.0; - GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos); - enemy_distance = get_power_distance(present, pos); - //human aiming for zombie - if (targeteam == 3 && dist_target < min_distance_target_human && enemy_distance > min_enemy_distance) - face_call(target_enemy); - //zombie aiming for human - else if (targeteam == 2 && min_distance_target_human * min_enemy_distance > enemy_distance && enemy_distance > 0) - face_call(target_enemy); - //human aiming human && zombie aiming zombie - else - face_call(targethuman); - } - else - face_call(targethuman); - if (round_start_stuck) - bot_stuck = is_bot_stuck(); + GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos); + dist_target = get_power_distance(present, pos); } - //TODO detect gaps and jump perfectly over them - Format(message, sizeof(message), "dist_target: %f targethuman: %N bot_on_type: %i enemy_distance: %f bot_stuck: %i targeteam: %i", dist_target, targethuman, bot_on_type, enemy_distance, bot_stuck, targeteam); - send_socket_msg(message, strlen(message)); + if (IsValidClient(target_enemy)) + { + float min_enemy_distance = 20.0; + GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos); + enemy_distance = get_power_distance(present, pos); + float min_distance_target_human = 2.0; + //human aiming for zombie + if (targeteam == 3 && dist_target > 0 && dist_target < min_distance_target_human && enemy_distance > min_enemy_distance) + { + chasing_enemy = true; + face_call(target_enemy); + } + //zombie aiming for human + if (targeteam == 2 && min_enemy_distance * 3 > enemy_distance && enemy_distance > 0) + { + chasing_enemy = true; + face_call(target_enemy); + } + } + if (IsValidClient(targethuman) && !chasing_enemy) + face_call(targethuman); + if (round_start_stuck) + bot_stuck = is_bot_stuck(); } + //TODO detect gaps and jump perfectly over them + if (IsValidClient(targethuman)) + Format(message, sizeof(message), "dist_target: %f targethuman: %N bot_on_type: %i enemy_distance: %f bot_stuck: %i targeteam: %i", dist_target, targethuman, bot_on_type, enemy_distance, bot_stuck, targeteam); + else + Format(message, sizeof(message), "dist_target: %f targethuman: none bot_on_type: %i enemy_distance: %f bot_stuck: %i targeteam: %i", dist_target, bot_on_type, enemy_distance, bot_stuck, targeteam); + send_socket_msg(message, strlen(message)); } return Plugin_Continue; } public bool is_bot_stuck() { - float min_distance_cap = 0.05; + float min_distance_cap = 0.1; float bot_own_distance = get_power_distance(present, bot_old_coords); bot_stuck_g = bot_own_distance < min_distance_cap; return bot_stuck_g; @@ -337,6 +324,8 @@ stock bool IsValidClient(int client) stock bool is_client_stuck_or_afk(int client) { + if (!round_start_stuck) + return false; float min_distance_cap = 0.05; int min_cap = 15; float client_own_distance = get_power_distance(client, client_old_coords[client]); @@ -344,6 +333,8 @@ stock bool is_client_stuck_or_afk(int client) client_mini_stuck_counter[client]++; else client_mini_stuck_counter[client] = 0; + if (client == targethuman) + min_cap = min_cap * 4; return client_mini_stuck_counter[client] > min_cap; } @@ -359,11 +350,11 @@ public int find_closest_enemy(int entity, int targeteam) GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); float dist_target = get_power_distance(entity, pos); bool traceable = false; - face_call(i); - if (TraceRayable(present, i)) + if (IsAbleToSee(present, i)) traceable = true; - if (!traceable) - continue; + float trace_advantage = 2.5; + if (traceable) + dist_target = dist_target / trace_advantage; if (is_client_stuck_or_afk(i)) continue; if (nearestdistance < 0 || dist_target < nearestdistance) @@ -385,17 +376,16 @@ public int GetClosestClient_option1(int entity, int targeteam) if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present) { bool traceable = false; - face_call(i); - if (TraceRayable(present, i)) + if (IsAbleToSee(present, i)) traceable = true; if (is_client_stuck_or_afk(i)) continue; - if (admins[i]) + if (admins[i] && traceable) { adminpresent = true; vippresent = false; } - else if (vips[i] && !adminpresent) + else if (vips[i] && !adminpresent && traceable) { vippresent = true; } @@ -411,9 +401,10 @@ public int GetClosestClient_option1(int entity, int targeteam) } float pos[3]; GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); + float trace_advantage = 2.5; float dist_target = get_power_distance(entity, pos); - if (!traceable) - continue; + if (traceable) + dist_target = dist_target / trace_advantage; if (nearestdistance < 0 || dist_target < nearestdistance) { nearest = i; @@ -435,11 +426,6 @@ public float get_power_distance(int target_player, float [3]pos) return power_distance / defaultcap; } -public bool FilterClient(int entity, int contentsMask, int client) -{ - return (entity != client && 1 <= client <= MaxClients || !IsClientInGame(client)); -} - public void OnClientPostAdminCheck(int client) { //STEAM_0:1:34783317 @@ -528,4 +514,156 @@ 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_VISIBLE, 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; } \ No newline at end of file