diff --git a/AutismBotIngame/python/ingamefollowct.py b/AutismBotIngame/python/ingamefollowct.py index 797dd0fd..23ee0103 100644 --- a/AutismBotIngame/python/ingamefollowct.py +++ b/AutismBotIngame/python/ingamefollowct.py @@ -54,6 +54,8 @@ def bot_process_movement(input_line): strInput += "wait 2; use weapon_elite; wait 3; +forward; wait 2;" elif state == 2: strInput += "-forward; wait 2; use weapon_elite; wait 3;" + elif state == 8: + strInput += "use weapon_knife; wait 5; +forward; wait 2;" print('dist_target: ', dist_target, ' enemy distance: ', enemy_distance, ' targetteam: ', targeteam, ' state:', state) if state not in [0, 2, 5, 7, 8]: @@ -127,15 +129,16 @@ def launch_css_process(): subprocess.getoutput([f"/home/{whoami}/.steam/debian-installation/steam.sh -applaunch 240 -textmode -novid -nosound -noipx -nojoy -noshaderapi -port {data_ports['steam_port']}"]) print('finished starting game') -def bot_connect(server, connected_to_other): +def bot_connect(data): #use whatever ip you want here to connect with str1 = "" - if "connect to ze" == server: + if "connect to ze" == data: str1 = f"connect {data_ports['server_ip_port_ze']}" - connected_to_other = False - elif "connect to ze2" == server and not connected_to_other: + elif "connect to ze2" == data: str1 = f"connect {data_ports['server_ip_port_ze2']}" writeCfgInput(str1) + time.sleep(0.5) + writeCfgInput("") print('not yet connected') if __name__ == '__main__': @@ -149,7 +152,7 @@ if __name__ == '__main__': restart_sdl_and_steam() else: kill_owned_process("pidof hl2_linux") - connected_to_other = False + is_bot_connected_to_ze2 = False launch_css_process() sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) @@ -177,28 +180,31 @@ if __name__ == '__main__': writeCfgInput(response_msg) if ip != data_ports['ovh_ip']: continue - if data == "autismo connected": - print('Bot connected!') - connection_issue_counter = 0 elif data == "rtv": response_msg = "say rtv" writeCfgInput(response_msg) elif data == "bot kicked server full": print('bot kicked server full: ', datetime.datetime.now().time()) - elif "connected to" in data: - connected_to_other = True - elif "not connected" in data: - connected_to_other = False - elif "connect to" in data: + elif "autismo connected to ze" == data: + print('Bot connected to ze!') + connection_issue_counter = 0 + is_bot_connected_to_ze2 = False + elif "not connected to ze2" == data: + is_bot_connected_to_ze2 = False + elif "autismo connected to ze2" == data: + print('Bot connected to ze2!') + connection_issue_counter = 0 + is_bot_connected_to_ze2 = True + elif "connect to ze" == data or ("connect to ze2" == data and not is_bot_connected_to_ze2): if connection_issue_counter == 20: kill_owned_process("pidof hl2_linux") print('exiting') sys.exit(1) - if not connected_to_other or "connect to ze" == data: + else: print('data: ', data) connection_issue_counter += 1 print('connection_issue_counter: ', connection_issue_counter) - bot_connect(data, connected_to_other) + bot_connect(data) elif "clientmessage:" in data: messager_name = data.split("clientmessage:", 1)[1].split(" 72DqZ84")[0] databyte_send_message = messager_name + data.split("72DqZ84")[1] diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index 02c07224..7464858a 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -16,13 +16,15 @@ int target_friend_afk_counter[MAXPLAYERS][MAXPLAYERS + 1]; int target_friend[MAXPLAYERS + 1]; int target_enemy[MAXPLAYERS + 1]; +bool human_too_close[MAXPLAYERS + 1]; +bool bot_follow_tp[MAXPLAYERS + 1]; int buttons_old[MAXPLAYERS + 1]; int flags_old[MAXPLAYERS + 1]; int ports[7] = {48470, 48471, 48472, 48473, 48474, 48479, 48480}; //last three indexes are ports its sending udp from in plugin int server_ports[2] = {27015, 27035}; //server ports: ze, ze2 int bot_avoid_edge[MAXPLAYERS + 1]; float client_old_coords[MAXPLAYERS + 1][3]; -float targethuman_self_teleported[MAXPLAYERS + 1][3]; +float targetfriend_prev_coords[MAXPLAYERS + 1][3]; bool chat_cooldown = false; //socket for bot input @@ -53,6 +55,7 @@ public void OnPluginStart() //talking RegConsoleCmd("sm_autism", cmd_talk, "talking to the bot through java application"); RegConsoleCmd("sm_botrtv", cmd_botrtv, "making bots rtv"); + HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy); //UDP connection connect_socket(); @@ -74,22 +77,34 @@ public void OnPluginEnd() } } -public void reset_target_tp(int client) +public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast) { - if (IsValidClient(client) && is_bot_player(client)) + for (int i = 1; i <= MaxClients; i++) { - targethuman_self_teleported[client][0] = 0.0; - targethuman_self_teleported[client][1] = 0.0; - targethuman_self_teleported[client][2] = 0.0; + if (IsValidClient(i)) + { + if (is_bot_player(i)) + { + bot_avoid_edge[i] = -1; + target_friend[i] = -1; + target_enemy[i] = -1; + human_too_close[i] = false; + bot_follow_tp[i] = false; + targetfriend_prev_coords[i][0] = 0.0; + targetfriend_prev_coords[i][1] = 0.0; + targetfriend_prev_coords[i][2] = 0.0; + for (int j = 1; j <= MaxClients; j++) + { + if (IsValidClient(j) && j != i) + { + target_friend_afk_counter[i][j] = 0; + } + } + } + } } } -public Action reset_target_tp_timer(Handle timer, int client) -{ - reset_target_tp(client); - return Plugin_Continue; -} - public bool distance_check(int client, int botclient, bool nowpos) { float dist_target = 0.0; @@ -101,7 +116,6 @@ public bool distance_check(int client, int botclient, bool nowpos) } else { - dist_target = get_power_distance(client, targethuman_self_teleported[botclient]); } float min_required_distance = 50000.0; if (dist_target > min_required_distance) @@ -238,19 +252,6 @@ public Action bot_chat_cooldown(Handle timer, any data) return Plugin_Continue; } -public void did_target_tp(int client, int bot_client) -{ - if (client == bot_client && targethuman_self_teleported[client][0] != 0.0 && !distance_check(client, bot_client, false)) - { - reset_target_tp(client); - } - else if (client != bot_client && targethuman_self_teleported[bot_client][0] == 0.0 && !distance_check(client, bot_client, true)) - { - GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_self_teleported[bot_client]); - CreateTimer(6.0, reset_target_tp_timer, bot_client); - } -} - public void OnMapStart() { chat_cooldown = false; @@ -265,143 +266,66 @@ public void send_socket_msg(char[] query_msg, int len, int port) public Action bot_check_connect(Handle timer, any data) { - //this is designed for being ran from several css servers - int client_count = GetClientCount(false); - char msg[generic_length]; - int i_port = GetConVarInt(FindConVar("hostport")); - bool is_host_ze = false; - if (i_port == server_ports[0]) - { - is_host_ze = true; - } - bool found_bot1 = false; - bool found_bot2 = false; - bool found_bot3 = false; - bool found_bot4 = false; - for (int i = 1; i <= MaxClients; i++) - if (IsValidClient(i) && !IsFakeClient(i)) - { - if (client_count > 60) - { - found_bot1 = true; - found_bot2 = true; - found_bot3 = true; - found_bot4 = true; - if (is_bot_player(i)) - { - KickClient(i, "server full you need to leave"); - } - } - if (is_host_ze) - { - if (client_count < 50) - { - Format(msg, sizeof(msg), "connect to ze"); - if (is_autism_bot1(i)) - { - found_bot1 = true; - } - if (is_autism_bot2(i)) - { - found_bot2 = true; - } - if (is_autism_bot3(i)) - { - found_bot3 = true; - } - if (is_autism_bot4(i)) - { - found_bot4 = true; - } - } - else if (client_count > 55) - { - found_bot1 = true; - found_bot2 = true; - found_bot3 = true; - found_bot4 = true; - Format(msg, sizeof(msg), "connect to ze2"); - send_socket_msg(msg, strlen(msg), ports[0]); - send_socket_msg(msg, strlen(msg), ports[1]); - send_socket_msg(msg, strlen(msg), ports[2]); - send_socket_msg(msg, strlen(msg), ports[3]); - break; - } - } - else - { - if (is_bot_player(i)) - { - Format(msg, sizeof(msg), "connected to ze2"); - } + //this is designed for being ran from several css servers + int client_count = GetClientCount(false); + char msg[generic_length]; + int i_port = GetConVarInt(FindConVar("hostport")); + bool bot1_connected = false; + bool bot2_connected = false; + bool bot3_connected = false; + bool bot4_connected = false; + for (int i = 1; i <= MaxClients; i++) + if (IsValidClient(i) && !IsFakeClient(i)) + { + if (is_autism_bot1(i)) + bot1_connected = true; + if (is_autism_bot2(i)) + bot2_connected = true; + if (is_autism_bot3(i)) + bot3_connected = true; + if (is_autism_bot4(i)) + bot4_connected = true; + } - if (is_autism_bot1(i)) - { - send_socket_msg(msg, strlen(msg), ports[0]); - found_bot1 = true; - } - if (is_autism_bot2(i)) - { - send_socket_msg(msg, strlen(msg), ports[1]); - found_bot2 = true; - } - if (is_autism_bot3(i)) - { - send_socket_msg(msg, strlen(msg), ports[2]); - found_bot3 = true; - } - if (is_autism_bot4(i)) - { - send_socket_msg(msg, strlen(msg), ports[3]); - found_bot4 = true; - } - } - } - //this check ensures servers dont overlap each other regarding not connected messages - if (!is_host_ze) - { - Format(msg, sizeof(msg), "not connected"); - if (!found_bot1 && i_port == server_ports[1]) - { - //ze2 - send_socket_msg(msg, strlen(msg), ports[0]); - } - if (!found_bot2 && i_port == server_ports[1]) - { - //ze2 - send_socket_msg(msg, strlen(msg), ports[1]); - } - if (!found_bot3 && i_port == server_ports[1]) - { - //ze2 - send_socket_msg(msg, strlen(msg), ports[2]); - } - if (!found_bot4 && i_port == server_ports[1]) - { - //ze2 - send_socket_msg(msg, strlen(msg), ports[3]); - } - } - else - { - if (!found_bot1) - { - send_socket_msg(msg, strlen(msg), ports[0]); - } - if (!found_bot2) - { - send_socket_msg(msg, strlen(msg), ports[1]); - } - if (!found_bot3) - { - send_socket_msg(msg, strlen(msg), ports[2]); - } - if (!found_bot4) - { - send_socket_msg(msg, strlen(msg), ports[3]); - } - } - return Plugin_Continue; + if (i_port == server_ports[0]) + { + //revert again to either 10 or 55 + int max_allowed_players = 55; + if (client_count > max_allowed_players) + { + Format(msg, sizeof(msg), "connect to ze2"); + send_socket_msg(msg, strlen(msg), ports[0]); + send_socket_msg(msg, strlen(msg), ports[1]); + send_socket_msg(msg, strlen(msg), ports[2]); + send_socket_msg(msg, strlen(msg), ports[3]); + } + else if (client_count < 50) + { + Format(msg, sizeof(msg), "connect to ze"); + if (!bot1_connected) + send_socket_msg(msg, strlen(msg), ports[0]); + if (!bot2_connected) + send_socket_msg(msg, strlen(msg), ports[1]); + if (!bot3_connected) + send_socket_msg(msg, strlen(msg), ports[2]); + if (!bot4_connected) + send_socket_msg(msg, strlen(msg), ports[3]); + } + } + else + { + //in case the bot is not connected to ze2 anymore make sure that is_bot_connected_to_ze2 is set to false again + Format(msg, sizeof(msg), "not connected to ze2"); + if (!bot1_connected) + send_socket_msg(msg, strlen(msg), ports[0]); + if (!bot2_connected) + send_socket_msg(msg, strlen(msg), ports[1]); + if (!bot3_connected) + send_socket_msg(msg, strlen(msg), ports[2]); + if (!bot4_connected) + send_socket_msg(msg, strlen(msg), ports[3]); + } + return Plugin_Continue; } public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype, @@ -411,10 +335,9 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float 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) && GetEntProp(client, Prop_Data, "m_nWaterLevel") <= 2) + if (!(flags & FL_ONGROUND) && (flags_old[client] & FL_ONGROUND) && !(buttons_old[client] & IN_JUMP) && !(buttons & IN_JUMP) && (GetEntityMoveType(client) != MOVETYPE_LADDER) && GetEntProp(client, Prop_Data, "m_nWaterLevel") == 0) { float Vel[3], feet_origin[3], ground_pos[3], downwards[3]; - //TODO prevent bot from falling off edge if nothing infront float velocity_addition_z_axis = 300.0; //300.0 GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel); Vel[2] += velocity_addition_z_axis; @@ -527,31 +450,12 @@ public Action recursive_pressing(Handle timer, any data) //3 = autismo is human and should follow closest moving ct targeteam = 3; } - if (IsValidClient(target_friend[client])) - { - did_target_tp(target_friend[client], client); - } - else if (IsValidClient(target_enemy[client])) - { - did_target_tp(target_enemy[client], client); - } - if (targethuman_self_teleported[client][0] != 0.0) - { - float ClientPos[3]; - float Result[3]; - GetClientEyePosition(client, ClientPos); - MakeVectorFromPoints(ClientPos, targethuman_self_teleported[client], Result); - GetVectorAngles(Result, Result); - TeleportEntity(client, NULL_VECTOR, Result, NULL_VECTOR); - if (!distance_check(client, client, false)) - reset_target_tp(client); - continue; - } - //no target in water somehow + int previous_friend = target_friend[client]; target_enemy[client] = GetClosestClient_option1(false, client); target_friend[client] = GetClosestClient_option1(true, client); + + float pos[3]; - did_target_tp(client, client); float enemy_distance = -1.0; float dist_target = -1.0; if (IsValidClient(target_friend[client])) @@ -564,27 +468,80 @@ public Action recursive_pressing(Handle timer, any data) GetEntPropVector(target_enemy[client], Prop_Send, "m_vecOrigin", pos); enemy_distance = get_power_distance(client, pos); } - float max_range_dist = 150.0; - int state = -1; - if (GetEntityMoveType(client) == MOVETYPE_LADDER) + float max_range_dist = 65.0; + //here we put into consideration if the human is leaving or standing around. If the bots already catched up to the human they can have a larger distance between the player and themselves so they dont constantly follow him. If the player is leaving the bots needs to follow him much closer. + if (targeteam == 3 && human_too_close[client]) { + max_range_dist = 200.0; + } + + + int state = -1; + //the friend just moved an probably impossible distance so is most likely teleported + if (targetfriend_prev_coords[client][0] != 0.0 && IsValidClient(previous_friend)) + { + //how far from old coords did our previous friend move, teleports sometimes dont move one very far, + //has to be further than what noclip/surfing/speed might do. Not using hooking on trigger_multiple or trigger_teleport as origin also may be used + float distance_between_prev_coord_and_new_coord = get_power_distance(previous_friend, targetfriend_prev_coords[client]); + float min_required_distance = 1000.0; + if (distance_between_prev_coord_and_new_coord > min_required_distance) + { + bot_follow_tp[client] = true; + } + } + if (IsValidClient(target_friend[client]) && !bot_follow_tp[client]) + { + GetEntPropVector(target_friend[client], Prop_Send, "m_vecOrigin", targetfriend_prev_coords[client]); + } + if (bot_follow_tp[client]) + { + float ClientPos[3]; + float Result[3]; + GetClientEyePosition(client, ClientPos); + MakeVectorFromPoints(ClientPos, targetfriend_prev_coords[client], Result); + GetVectorAngles(Result, Result); + float distance_between_bot_and_tp = get_power_distance(client, targetfriend_prev_coords[client]); + //when we are close enough to teleport just run forward without facing the tp + if (distance_between_bot_and_tp > 250.0) + { + TeleportEntity(client, NULL_VECTOR, Result, NULL_VECTOR); + } + if (!IsPointVisible(ClientPos, targetfriend_prev_coords[client])) + { + targetfriend_prev_coords[client][0] = 0.0; + targetfriend_prev_coords[client][1] = 0.0; + targetfriend_prev_coords[client][2] = 0.0; + bot_follow_tp[client] = false; + } + state = 8; //if its walking into a TP or up/down a ladder it matters to use +forward; + } + //if the bot or its target is on the ladder just use forward to reach the ladder + else if (GetEntityMoveType(client) == MOVETYPE_LADDER || (IsValidClient(target_friend[client]) && GetEntityMoveType(target_friend[client]) == MOVETYPE_LADDER)) + { + if (IsValidClient(target_friend[client])) + { + face_call(target_friend[client], client); + } state = 8; } //if bot is ct: is close enough to friend, can stop following friend and focus on shooting zombies else if (targeteam == 3 && 0 < dist_target < max_range_dist && IsValidClient(target_enemy[client])) { + human_too_close[client] = true; face_call(target_enemy[client], client); state = 0; } - //if bot is ct: if bot is not close enough to friend follow him + //if bot is ct: if bot is not close enough to friend follow him, //dist_target being larger than max_range_dist means a friend was found to follow else if (targeteam == 3 && dist_target > max_range_dist) { + human_too_close[client] = false; face_call(target_friend[client], client); state = 1; } //if bot is ct and close enough to friend then just do nothing in case of there being no enemy to shoot at else if (targeteam == 3) { + human_too_close[client] = true; state = 2; } //if bot is zm follow enemy sometimes @@ -616,7 +573,7 @@ public Action recursive_pressing(Handle timer, any data) { state = 7; } - if (GetEntProp(client, Prop_Data, "m_nWaterLevel") <= 2 && GetEntityMoveType(client) != MOVETYPE_LADDER) + if (GetEntProp(client, Prop_Data, "m_nWaterLevel") == 0 && GetEntityMoveType(client) != MOVETYPE_LADDER) trace_hulling_bot(client); char message[generic_length * 7]; Format(message, sizeof(message), "dist_target: %f enemy_distance: %f targeteam: %i state: %i", dist_target, enemy_distance, targeteam, state); @@ -666,155 +623,174 @@ public Action recursive_pressing(Handle timer, any data) //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"); - if (is_autism_bot1(client)) - { - send_socket_msg(message, strlen(message), ports[0]); - } - if (is_autism_bot2(client)) - { - send_socket_msg(message, strlen(message), ports[1]); - } - if (is_autism_bot3(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"); + if (is_autism_bot1(client)) + { + send_socket_msg(message, strlen(message), ports[0]); + } + if (is_autism_bot2(client)) + { + send_socket_msg(message, strlen(message), ports[1]); + } + if (is_autism_bot3(client)) { - send_socket_msg(message, strlen(message), ports[2]); + send_socket_msg(message, strlen(message), ports[2]); } - if (is_autism_bot4(client)) - { - send_socket_msg(message, strlen(message), ports[3]); + if (is_autism_bot4(client)) + { + send_socket_msg(message, strlen(message), ports[3]); } - 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"); - if (is_autism_bot1(client)) - { - send_socket_msg(message, strlen(message), ports[0]); - } - if (is_autism_bot2(client)) - { - send_socket_msg(message, strlen(message), ports[1]); - } - if (is_autism_bot3(client)) + 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"); + if (is_autism_bot1(client)) + { + send_socket_msg(message, strlen(message), ports[0]); + } + if (is_autism_bot2(client)) + { + send_socket_msg(message, strlen(message), ports[1]); + } + if (is_autism_bot3(client)) + { + send_socket_msg(message, strlen(message), ports[2]); + } + if (is_autism_bot4(client)) + { + send_socket_msg(message, strlen(message), ports[3]); + } + 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; + + float eyes_down[3]; + eyes_down[0] = eye_position[0]; + eyes_down[1] = eye_position[1] + 10.0; + eyes_down[2] = eye_position[2]; + + float eyes_forward[3]; + eyes_forward[0] = eye_position[0]; + eyes_forward[1] = eye_position[1] + 10.0; + eyes_forward[2] = eye_position[2]; + + float maxs_new[3]; + maxs_new[0] = maxs[0] - 8.0; + maxs_new[1] = maxs[1] - 8.0; + maxs_new[2] = maxs[2]; + + TR_TraceHullFilter(eye_position, eye_position, mins, maxs_new, MASK_ALL, TraceRayDontHitSelf); + if ((TR_DidHit())) { - send_socket_msg(message, strlen(message), ports[2]); + bool should_jump = true; + TR_TraceHullFilter(eyes_down, eyes_forward, mins, maxs, MASK_ALL, TraceRayDontHitSelf); + if (!(TR_DidHit())) + { + should_jump = false; + } + + eyes_down[0] = eye_position[0] + 10.0; + eyes_forward[0] = eye_position[0] + 10.0; + TR_TraceHullFilter(eyes_down, eyes_forward, mins, maxs, MASK_ALL, TraceRayDontHitSelf); + if ((TR_DidHit())) + { + should_jump = false; + } + + if (should_jump) + { + Format(message, sizeof(message), "hull info:jump"); + if (is_autism_bot1(client)) + { + send_socket_msg(message, strlen(message), ports[0]); + } + if (is_autism_bot2(client)) + { + send_socket_msg(message, strlen(message), ports[1]); + } + if (is_autism_bot3(client)) + { + send_socket_msg(message, strlen(message), ports[2]); + } + if (is_autism_bot4(client)) + { + send_socket_msg(message, strlen(message), ports[3]); + } + return; + } } - if (is_autism_bot4(client)) + + TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf); + if (!(TR_DidHit())) { - send_socket_msg(message, strlen(message), ports[3]); + //hit wall on one side, no need to jump just run forward + return; } - 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"); - if (is_autism_bot1(client)) - { - send_socket_msg(message, strlen(message), ports[0]); - } - if (is_autism_bot2(client)) - { - send_socket_msg(message, strlen(message), ports[1]); - } - if (is_autism_bot3(client)) - { - send_socket_msg(message, strlen(message), ports[2]); - } - if (is_autism_bot4(client)) - { - send_socket_msg(message, strlen(message), ports[3]); - } - return; - } - TR_TraceHullFilter(eye_position, eye_position, mins, maxs, MASK_ALL, TraceRayDontHitSelf); - if (!(TR_DidHit())) - { - Format(message, sizeof(message), "hull info:jump"); - if (is_autism_bot1(client)) - { - send_socket_msg(message, strlen(message), ports[0]); - } - if (is_autism_bot2(client)) - { - send_socket_msg(message, strlen(message), ports[1]); - } - if (is_autism_bot3(client)) - { - send_socket_msg(message, strlen(message), ports[2]); - } - if (is_autism_bot4(client)) - { - send_socket_msg(message, strlen(message), ports[3]); - } - 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]; - 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; - } - } + 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]; + 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; + } + } } public bool TraceRayDontHitSelf(int entity, int mask, any data) @@ -852,51 +828,54 @@ stock bool IsValidClient(int client) stock bool is_client_stuck_or_afk(int client, int i) { - //triggers between 6-8 times per second - target_friend_afk_counter[client][i]++; - if (target_friend_afk_counter[client][i] >= 24) - { - float min_distance_cap = 1.0; - float i_own_distance = get_power_distance(i, client_old_coords[i]); - GetEntPropVector(i, Prop_Send, "m_vecOrigin", client_old_coords[i]); - bool not_moved = i_own_distance < min_distance_cap; - if (!not_moved) - { - target_friend_afk_counter[client][i] = 0; - } - return not_moved; - } - return false; + //triggers between 6-8 times per second + target_friend_afk_counter[client][i]++; + int human_idle_steps = 12; + if (target_friend_afk_counter[client][i] >= human_idle_steps) + { + float min_distance_cap = 1.0; + float i_own_distance = get_power_distance(i, client_old_coords[i]); + GetEntPropVector(i, Prop_Send, "m_vecOrigin", client_old_coords[i]); + bool not_moved = i_own_distance < min_distance_cap; + if (!not_moved) + { + target_friend_afk_counter[client][i] = 0; + } + return not_moved; + } + return false; } public int GetClosestClient_option1(bool finding_friend, int client) { - float nearestdistance = -1.0; - int nearest = -1; - for (int i = 1; i <= MaxClients; i++) - if (IsValidClient(i) && IsPlayerAlive(i) && i != client && !is_bot_player(i)) - { - if (!IsAbleToSee(client, i) || is_client_stuck_or_afk(client, i)) - { - continue; - } - float pos[3]; - GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); - float dist_target = get_power_distance(client, pos); - if ((finding_friend && GetClientTeam(i) != GetClientTeam(client)) || (!finding_friend && GetClientTeam(i) == GetClientTeam(client))) - { - continue; - } - /* - if (i == target_friend[client]) - dist_target /= 5; */ - if (nearestdistance < 0 || dist_target < nearestdistance) - { - nearest = i; - nearestdistance = dist_target; - } - } - return nearest; + float nearestdistance = -1.0; + int nearest = -1; + for (int i = 1; i <= MaxClients; i++) + if (IsValidClient(i) && IsPlayerAlive(i) && i != client) + { + if (!IsAbleToSee(client, i) || is_client_stuck_or_afk(client, i)) + { + continue; + } + float pos[3]; + GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); + float dist_target = get_power_distance(client, pos); + if ((finding_friend && GetClientTeam(i) != GetClientTeam(client)) || (!finding_friend && GetClientTeam(i) == GetClientTeam(client))) + { + continue; + } + if (is_bot_player(i)) + { + //just making sure bots have lowest priority + dist_target = 9000000.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) @@ -908,36 +887,51 @@ public float get_power_distance(int target_player, float [3]pos) public void OnClientPostAdminCheck(int client) { - for (int i = 1; i <= MaxClients; i++) - { - if (IsValidClient(i) && is_bot_player(i) && i != client) - target_friend_afk_counter[i][client] = 0; - } - bot_avoid_edge[client] = -1; - char auth[64]; - GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth)); - char msg[generic_length]; - Format(msg, sizeof(msg), "autismo connected"); - if (is_autism_bot1(client)) - { - send_socket_msg(msg, strlen(msg), ports[0]); - } - if (is_autism_bot2(client)) - { - send_socket_msg(msg, strlen(msg), ports[1]); - } - if (is_autism_bot3(client)) - { - send_socket_msg(msg, strlen(msg), ports[2]); - } - if (is_autism_bot4(client)) - { - send_socket_msg(msg, strlen(msg), ports[3]); - } - client_old_coords[client][0] = 0.0; - client_old_coords[client][1] = 0.0; - client_old_coords[client][2] = 0.0; - reset_target_tp(client); + for (int i = 1; i <= MaxClients; i++) + { + if (IsValidClient(i) && is_bot_player(i) && i != client) + { + target_friend_afk_counter[i][client] = 0; + } + } + //checks if ze or ze2 + int i_port = GetConVarInt(FindConVar("hostport")); + char msg[generic_length]; + if (i_port == server_ports[0]) + { + Format(msg, sizeof(msg), "autismo connected to ze"); + } + else + { + Format(msg, sizeof(msg), "autismo connected to ze2"); + } + targetfriend_prev_coords[client][0] = 0.0; + targetfriend_prev_coords[client][1] = 0.0; + targetfriend_prev_coords[client][2] = 0.0; + human_too_close[client] = false; + bot_follow_tp[client] = false; + bot_avoid_edge[client] = -1; + char auth[64]; + GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth)); + if (is_autism_bot1(client)) + { + send_socket_msg(msg, strlen(msg), ports[0]); + } + if (is_autism_bot2(client)) + { + send_socket_msg(msg, strlen(msg), ports[1]); + } + if (is_autism_bot3(client)) + { + send_socket_msg(msg, strlen(msg), ports[2]); + } + if (is_autism_bot4(client)) + { + send_socket_msg(msg, strlen(msg), ports[3]); + } + client_old_coords[client][0] = 0.0; + client_old_coords[client][1] = 0.0; + client_old_coords[client][2] = 0.0; } public void OnSocketError(Handle socket, const int errorType, const int errorNum, any args) @@ -968,16 +962,22 @@ stock void connect_socket() public void OnClientDisconnect(int client) { - bot_avoid_edge[client] = -1; - client_old_coords[client][0] = 0.0; - client_old_coords[client][1] = 0.0; - client_old_coords[client][2] = 0.0; - for (int i = 1; i <= MaxClients; i++) + bot_avoid_edge[client] = -1; + client_old_coords[client][0] = 0.0; + client_old_coords[client][1] = 0.0; + client_old_coords[client][2] = 0.0; + targetfriend_prev_coords[client][0] = 0.0; + targetfriend_prev_coords[client][1] = 0.0; + targetfriend_prev_coords[client][2] = 0.0; + human_too_close[client] = false; + bot_follow_tp[client] = false; + for (int i = 1; i <= MaxClients; i++) { if (IsValidClient(i) && is_bot_player(i) && i != client) + { target_friend_afk_counter[i][client] = 0; + } } - reset_target_tp(client); } //Socket callback