From ff489404852bc48612a3363e4d6cd365576f138a Mon Sep 17 00:00:00 2001 From: jenzur Date: Sun, 30 Aug 2020 20:00:02 +0200 Subject: [PATCH] some updates added timestamp logging and redid most logging messages. added some extra informations in regards to crouching/jumping over obstacles that need to be checked further (dot_product). added cooldowns and finally fixed bot being stuck in spectate hopefully. also changed cooldown timers to span less UDP packets. --- AutismBotIngame/python/ingamefollowct.py | 67 ++++---- AutismBotIngame/scripting/autism_bot_info.sp | 162 ++++++++++--------- 2 files changed, 125 insertions(+), 104 deletions(-) diff --git a/AutismBotIngame/python/ingamefollowct.py b/AutismBotIngame/python/ingamefollowct.py index cf93cfa9..9a598c4a 100644 --- a/AutismBotIngame/python/ingamefollowct.py +++ b/AutismBotIngame/python/ingamefollowct.py @@ -9,11 +9,11 @@ import signal import time import socket import codecs +import datetime looptestPath = '/home/gameservers/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg' chatmsg = "" ladder_counter = 0 -message_counter = 0 def writeCfgInput(Input): with open(looptestPath, 'w') as f: @@ -30,10 +30,10 @@ def exit_handler(): resetCfgInputShortWait() def joinTeam(): - str = "jointeam 2; wait 2; zspawn; wait 1; wait 5;" - writeCfgInput(str) - time.sleep(4.5) - print('jointeam func: ') + str = "jointeam 2; joinclass 3; zspawn;" + writeCfgInput(str) + time.sleep(4.5) + print('jointeam func: ') def bot_process_surf(input_line): bot_surf_plane = input_line[input_line.index("surfing:") + len("surfing:"):] @@ -64,33 +64,39 @@ def bot_process_keyinput(input_line): dist_target = float(dist_target) strInput = f"""{movement_input}; wait 5; -jump; wait 5; -duck; wait 5; """ writeCfgInput(strInput) - print('dist_target: ', dist_target, ' movement strinput: ', strInput) + print('MIMIC datetime: ', datetime.datetime.now().time(), ' dist_target: ', dist_target, ' movement strinput: ', strInput) time.sleep(0.3) writeCfgInput("wait 5;") def bot_process_movement(input_line): - global message_counter - message_counter += 1 dist_target = input_line[input_line.index("dist_target:") + len("dist_target:"):input_line.index("targethuman:")] targethuman = input_line[input_line.index("targethuman:") + len("targethuman:"):input_line.index("bot_on_type:")] bot_on_type = input_line[input_line.index("bot_on_type:") + len("bot_on_type:"):input_line.index("enemy_distance:")] - enemy_distance = input_line[input_line.index("enemy_distance:") + len("enemy_distance:"):input_line.index("crouch_or_jump:")] - crouch_or_jump = input_line[input_line.index("crouch_or_jump:") + len("crouch_or_jump:"):input_line.index("targeteam:")] - targeteam = input_line[input_line.index("targeteam:") + len("targeteam:"):] + enemy_distance = input_line[input_line.index("enemy_distance:") + len("enemy_distance:"):input_line.index("dot_product:")] + dot_product = input_line[input_line.index("dot_product:") + len("dot_product:"):input_line.index("targeteam:")] + targeteam = input_line[input_line.index("targeteam:") + len("targeteam:"):input_line.index("target_enemy:")] + target_enemy = input_line[input_line.index("target_enemy:") + len("target_enemy:"):input_line.index("z_axis:")] + z_axis = input_line[input_line.index("z_axis:") + len("z_axis:"):] dist_target = float(dist_target) + z_axis = float(z_axis) enemy_distance = float(enemy_distance) bot_on_type = int(bot_on_type) - crouch_or_jump = int(crouch_or_jump) + dot_product = float(dot_product) targeteam = int(targeteam) - #maybe 0.8 instead - min_distance_target_human = 0.1 + min_distance_target_human = 800.0 strInput = "-attack; wait 2; -use; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; +forward; wait 2; " - if crouch_or_jump == 2: - print('crouching') - strInput += "+duck; wait 1500; -duck; wait 50;" - if crouch_or_jump == 3: - print('jumping') - strInput += "+jump; wait 750; +duck; wait 750; -jump; wait 500; -duck; wait 500; +jump; wait 1000; -jump; " + if dot_product > 0.0: + print('dot_product: ', dot_product) + if z_axis > 0.0: + print('z_axis: ', z_axis) + crouch_cap = 5000.0 + jump_cap = 100000.0 + if 0.0 < dot_product <= crouch_cap: + print('crouching', datetime.datetime.now().time()) + strInput += "+duck; wait 1500; +jump; -duck; wait 250; -jump; wait 50;" + elif 0.0 < dot_product <= jump_cap: + print('jumping', datetime.datetime.now().time()) + strInput += "+jump; wait 350; +duck; wait 250; -jump; -duck; wait 50;" if dist_target > min_distance_target_human: strInput += "use weapon_elite; wait 3; " elif targeteam == 3: @@ -102,18 +108,17 @@ def bot_process_movement(input_line): print('bot_on_type ladder, ladder_counter: ', ladder_counter) strInput += "setang -90 0 0; wait 5; -back; wait 3; -moveleft; wait 3; -moveright; wait 5; -jump; wait 3; -duck; wait 3; " ladder_counter += 1 - elif bot_on_type == 2: - print('bot surfing') else: ladder_counter = 0 min_enemy_distance = 100.0 - if bot_on_type == 1 or bot_on_type == 3: - print('bot_on_type 1 = water | 3 = downhill: ', bot_on_type) + if bot_on_type == 3: + print('3 = downhill: ', bot_on_type) for _ in range(5): 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: + print('date: ', datetime.datetime.now().time(), ' target_enemy: ', target_enemy, ' enemy distance: ', enemy_distance) + else: + print('date: ', datetime.datetime.now().time(), ' target human: ', targethuman, ' dist_target: ', dist_target,) strInput = strinput_append(strInput, 2) #print('strInput final:', strInput) writeCfgInput(strInput) @@ -138,7 +143,7 @@ def kill_css_process(): time.sleep(15) print('preparing to launch game....') os.chdir('/home/gameservers/.steam/debian-installation/') - subprocess.check_call("./steam.sh %s" % ("-applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi +exec looptest.cfg"), shell=True) + subprocess.check_call("./steam.sh %s" % ("-applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi"), shell=True) print('finished starting game') def bot_connect_ze(): @@ -187,6 +192,8 @@ if __name__ == '__main__': connection_issue_counter = 0 time.sleep(2) joinTeam() + elif data == "bot kicked server full": + print('bot kicked server full: ', datetime.datetime.now().time()) elif data == "connect to ze": if connection_issue_counter == 5: kill_css_process() @@ -206,13 +213,11 @@ if __name__ == '__main__': pass #/home/gameservers/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg: -#/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg: #alias loop "exec looptest.cfg; wait 5; loop;"; wait 5; loop; #-condebug -#cd /home/nonroot/.steam/ #cd /home/gameservers/.steam/debian-installation/ -#./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi +exec looptest.cfg +#./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi #cd /home/gameservers/ze_runner_files #./play.sh diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index d8c65780..3b157290 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -17,17 +17,15 @@ int present = 0; int targethuman = 0; int buttons_old; int flags_old; -int surf_delay = 0; +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 g_bOnGround[MAXPLAYERS + 1]; -bool g_bLastOnGround[MAXPLAYERS + 1]; bool client_stuck_g[MAXPLAYERS + 1]; bool round_start_stuck = false; bool cmdpost_run_cooldown = false; -bool bot_surf_plane = false; //admins & vips bool admins[MAXPLAYERS + 1]; @@ -65,7 +63,6 @@ public void OnPluginStart() global_socket = socket; round_start_stuck = true; cmdpost_run_cooldown = false; - bot_surf_plane = false; reset_target_human_tp_coord(); targethuman = 0; } @@ -139,7 +136,7 @@ public Action reset_target_tp(Handle timer, any data) public bool distance_check() { float dist_target = get_power_distance(present, targethuman_teleported); - float min_required_distance = 500.0; + float min_required_distance = 500000.0; if (dist_target > min_required_distance) return false; return true; @@ -155,8 +152,13 @@ public Action cmd_talk(int client, int args) PrintToChat(client, "Add a message to the command if autism bot is ingame and running on discord"); return Plugin_Handled; } - Format(msg, sizeof(msg), "clientmessage: %s", info); - send_socket_msg(msg, strlen(msg)); + 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; } @@ -165,7 +167,6 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast round_start_stuck = false; targethuman = 0; cmdpost_run_cooldown = false; - bot_surf_plane = false; reset_target_human_tp_coord(); CreateTimer(7.0, permitStuck); } @@ -178,8 +179,8 @@ public Action permitStuck(Handle timer, any data) public void OnMapStart() { - //0.2 - CreateTimer(0.5, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); + //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); } @@ -211,7 +212,12 @@ public Action bot_check_connect(Handle timer, any data) 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; } @@ -235,13 +241,13 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float float pos[3]; GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos); float dist_target = get_power_distance(present, pos); - float dist_cap = 1.5; + 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.25, runcmd_cooldown); + CreateTimer(0.5, runcmd_cooldown); } } } @@ -276,17 +282,13 @@ public Action recursive_pressing(Handle timer, any data) { if (IsValidClient(present)) { - if (GetClientTeam(present) == 1) + if (GetClientTeam(present) == 1 || GetClientTeam(present) == 0) { - //prevent him being stuck afk in spec bot_send_connected_msg(); return Plugin_Continue; } if (IsPlayerAlive(present)) { - char message[generic_length * 7]; - float present_bot_coords[3]; - GetClientAbsOrigin(present, present_bot_coords); int targeteam = 0; if (GetClientTeam(present) != 3) { @@ -300,16 +302,11 @@ public Action recursive_pressing(Handle timer, any data) } bool find_closest_match = true; - //check ladder = 0, water = 1, in air(surfing) = 2, downhill = 3, teleporter = 4 + //check ladder = 0, downhill = 3, teleporter = 4 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_surf_plane) - bot_on_type = 2; - if (bot_on_type == -1) + else bot_on_type = check_bot_downhill(); if (targethuman_teleported[0] != 0.0) { @@ -323,8 +320,7 @@ public Action recursive_pressing(Handle timer, any data) if (!distance_check()) reset_target_human_tp_coord(); } - if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman) && bot_on_type != 0 && bot_on_type != 2 - && bot_on_type != 4) + 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); @@ -334,7 +330,7 @@ public Action recursive_pressing(Handle timer, any data) find_closest_match = IsAbleToSee(present, targethuman) ? false : true; } } - if (find_closest_match && bot_on_type != 0 && bot_on_type != 2 && bot_on_type != 4) + if (find_closest_match && bot_on_type != 0 && bot_on_type != 4) { targethuman = 0; targethuman = GetClosestClient_option1(present, targeteam); @@ -343,8 +339,9 @@ public Action recursive_pressing(Handle timer, any data) int target_enemy = find_closest_enemy(present, targeteam); bool chasing_enemy = false; float dist_target = -1.0; - int crouch_or_jump = 0; - if (bot_on_type != 0 && bot_on_type != 2 && bot_on_type != 4) + 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)) @@ -354,13 +351,13 @@ public Action recursive_pressing(Handle timer, any data) } if (IsValidClient(target_enemy)) { - float min_enemy_distance = 100.0; + 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 = 0.1; + float min_distance_target_human = 800.0; if (0 < dist_target <= min_distance_target_human && enemy_distance > min_enemy_distance) { chasing_enemy = true; @@ -371,9 +368,18 @@ public Action recursive_pressing(Handle timer, any data) chasing_enemy = true; face_call(target_enemy); } + else + { + target_enemy = 0; + enemy_distance = -1.0; + } } //zombie aiming for human - if (targeteam == 2 && 0 < enemy_distance) + 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); @@ -381,23 +387,25 @@ public Action recursive_pressing(Handle timer, any data) } if (IsValidClient(targethuman) && !chasing_enemy) face_call(targethuman); - //0: nothing, 2: crouch, 3: jump - crouch_or_jump = wall_circle(); - } - if (bot_on_type != 2) - { - if (IsValidClient(targethuman)) - Format(message, sizeof(message), "dist_target: %f targethuman: %N bot_on_type: %i enemy_distance: %f crouch_or_jump: %i targeteam: %i", dist_target, targethuman, bot_on_type, enemy_distance, crouch_or_jump, targeteam); - else - Format(message, sizeof(message), "dist_target: %f targethuman: none bot_on_type: %i enemy_distance: %f crouch_or_jump: %i targeteam: %i", dist_target, bot_on_type, enemy_distance, crouch_or_jump, targeteam); - send_socket_msg(message, strlen(message)); + //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 int wall_circle() +public float wall_circle() { //Circle: for (int iterator = 0; iterator < 3; iterator++) @@ -421,19 +429,18 @@ public int wall_circle() float distance = GetVectorDistance(StartOrigin, EndOrigin); float crouch_cap = 5000.0; float jump_cap = 100000.0; - float distance_cap = 50.0; + //TODO maybe 50.0 again + float distance_cap = 60.0; if (distance <= distance_cap) { - if (dot_product <= crouch_cap) - return 2; - else if (dot_product <= jump_cap) - return 3; + if (dot_product <= crouch_cap || dot_product <= jump_cap) + return dot_product; } } } } - return 0; + return 0.0; } public void check_bot_surfing() @@ -451,8 +458,8 @@ public void check_bot_surfing() TR_TraceHullFilter(vPos, vEndPos, vMins, vMaxs, MASK_PLAYERSOLID_BRUSHONLY, TraceRayDontHitSelf, present); if (TR_DidHit()) { - //< 0.7 = surf ramp - float surf_ramp = 0.7; + //< 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); @@ -462,31 +469,29 @@ public void check_bot_surfing() vPlane[0] *= 100; vPlane[1] *= 100; vPlane[2] *= 100; - surf_delay++; - bot_surf_plane = true; - if (surf_delay > 50) + + if (!surf_cooldown) { - surf_delay = 0; + 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); } } - else - bot_surf_plane = false; } - else - bot_surf_plane = false; +} + +public Action surf_cooldown_timer(Handle timer, any data) +{ + surf_cooldown = false; + return Plugin_Continue; } public int check_bot_downhill() { - g_bLastOnGround[present] = g_bOnGround[present]; + //TODO experimental if (GetEntityFlags(present) & FL_ONGROUND) - g_bOnGround[present] = true; - else - g_bOnGround[present] = false; - if (g_bOnGround[present] && !g_bLastOnGround[present]) { g_vLast[0] = g_vCurrent[0]; g_vLast[1] = g_vCurrent[1]; @@ -581,7 +586,7 @@ stock bool is_client_stuck_or_afk(int client) { if (!round_start_stuck) return false; - float min_distance_cap = 0.02; + 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]; @@ -679,12 +684,12 @@ 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)); - float power_distance = SquareRoot(x_axis * x_axis + y_axis * y_axis + z_axis * z_axis); - float defaultcap = 1000.0; - return power_distance / defaultcap; + //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) @@ -745,7 +750,18 @@ public void bot_send_connected_msg() { char msg[generic_length]; Format(msg, sizeof(msg), "autismo connected"); - send_socket_msg(msg, strlen(msg)); + 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