From 7e03b2cf8be8505d29348dc1267ea75e229362bc Mon Sep 17 00:00:00 2001 From: jenzur Date: Mon, 27 Jul 2020 00:34:15 +0200 Subject: [PATCH] added checks for surfing and bot going downhill --- AutismBotIngame/python/ingamefollowct.py | 32 ++-- AutismBotIngame/scripting/autism_bot_info.sp | 161 +++++++++++++------ 2 files changed, 129 insertions(+), 64 deletions(-) diff --git a/AutismBotIngame/python/ingamefollowct.py b/AutismBotIngame/python/ingamefollowct.py index 48d00e3c..724ccbce 100644 --- a/AutismBotIngame/python/ingamefollowct.py +++ b/AutismBotIngame/python/ingamefollowct.py @@ -72,39 +72,47 @@ def bot_process_movement(input_line): elif targeteam == 2: strInput += "use weapon_knife; wait 5; " global ladder_counter - if bot_on_type == 0 and ladder_counter < 500: + if bot_on_type == 0 and ladder_counter < 100: print('bot_on_type ladder, ladder_counter: ', ladder_counter) strInput += "setang -90 90 0; wait 5; -back; wait 3; -moveleft; wait 3; -moveright; wait 5; -jump; wait 3; -duck; wait 3; +forward; wait 5;" ladder_counter += 1 elif bot_on_type == 2: print('bot surfing') - #make some setup to allow surfing/mimic + strInput += "-forward; wait 3;" + strInput = strinput_append(strInput, 10) else: ladder_counter = 0 - min_distance_target_human = 0.3 + min_distance_target_human = 0.2 min_enemy_distance = 10.0 - if bot_on_type == 1: - print('bot_on_type water') - strInput += "+jump; wait 5;" + if bot_on_type == 1 or bot_on_type == 3: + print('bot_on_type 1 = water | 3 = downhill: ', bot_on_type) + for _ in range(10): + 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 enemy_distance < min_enemy_distance or targeteam == 2: strInput += "+forward; wait 5; " - for _ in range(10): - boolean_val = random.choice([True, False]) - if boolean_val: - strInput += "+moveleft; wait 15; -moveleft; " - else: - strInput += "+moveright; wait 15; -moveright; " + strInput = strinput_append(strInput, 1) else: strInput += "-forward; wait 5;" + print('-forward!') #print('strInput final:', strInput) writeCfgInput(strInput) time.sleep(0.2) writeCfgInput("wait 5;") +def strinput_append(strInput, nth): + for _ in range(10 * nth): + boolean_val = random.choice([True, False]) + if boolean_val: + strInput += "+moveleft; wait 15; -moveleft; " + else: + strInput += "+moveright; wait 15; -moveright; " + return strInput + def bot_connect_ze(): #use whatever ip you want here to connect with strdev = "connect 151.80.230.149:27019/test132;" diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index eda28716..c94ae15a 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -18,7 +18,11 @@ bool round_start_stuck = false; float bot_old_coords[3]; bool bot_stuck_g = false; float client_old_coords[MAXPLAYERS + 1][3]; -float bot_presumed_endpoint[3]; +bool bot_forward = false; +bool g_bOnGround[MAXPLAYERS + 1]; +bool g_bLastOnGround[MAXPLAYERS + 1]; +float g_vCurrent[MAXPLAYERS + 1][3]; +float g_vLast[MAXPLAYERS + 1][3]; //admins & vips bool admins[MAXPLAYERS + 1]; @@ -51,10 +55,8 @@ public void OnPluginStart() connect(socket); global_socket = socket; round_start_stuck = true; + bot_forward = false; targethuman = 0; - bot_presumed_endpoint[0] = 0.0; - bot_presumed_endpoint[1] = 0.0; - bot_presumed_endpoint[2] = 0.0; } public Action cmd_talk(int client, int args) @@ -77,9 +79,7 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast round_start_stuck = false; targethuman = 0; bot_stuck_g = false; - bot_presumed_endpoint[0] = 0.0; - bot_presumed_endpoint[1] = 0.0; - bot_presumed_endpoint[2] = 0.0; + bot_forward = false; CreateTimer(7.0, permitStuck); } @@ -91,9 +91,7 @@ public Action permitStuck(Handle timer, any data) public Action bot_reached_endpoint(Handle timer, any data) { - bot_presumed_endpoint[0] = 0.0; - bot_presumed_endpoint[1] = 0.0; - bot_presumed_endpoint[2] = 0.0; + bot_forward = false; return Plugin_Continue; } @@ -165,6 +163,8 @@ public Action recursive_pressing(Handle timer, any data) { if (IsValidClient(present) && IsPlayerAlive(present)) { + if (bot_forward) + return Plugin_Continue; char message[generic_length * 7]; float present_bot_coords[3]; GetClientAbsOrigin(present, present_bot_coords); @@ -183,57 +183,36 @@ public Action recursive_pressing(Handle timer, any data) bool bot_stuck = false; if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman)) { - if (bot_presumed_endpoint[0] != 0.0) - { - find_closest_match = false; - float ClientPos[3]; - float Result[3]; - float min_distance = 0.2; - GetClientEyePosition(present, ClientPos); - MakeVectorFromPoints(ClientPos, bot_presumed_endpoint, Result); - GetVectorAngles(Result, Result); - TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR); - bot_stuck = is_bot_stuck(); - float dist_target = get_power_distance(present, bot_presumed_endpoint); - if (dist_target <= min_distance) - { - bot_presumed_endpoint[0] = 0.0; - bot_presumed_endpoint[1] = 0.0; - bot_presumed_endpoint[2] = 0.0; - } - } - else + face_call(targethuman); + find_closest_match = is_client_stuck_or_afk(targethuman); + if (!find_closest_match) { face_call(targethuman); - find_closest_match = is_client_stuck_or_afk(targethuman); - if (!find_closest_match) + find_closest_match = IsAbleToSee(present, targethuman) ? false : true; + if (find_closest_match) { - 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]); + float min_required_distance = 1500.0; + if (dist_target > min_required_distance) { - float dist_target = get_power_distance(targethuman, client_old_coords[targethuman]); - float min_required_distance = 1500.0; - if (dist_target > min_required_distance) - { - bot_presumed_endpoint[0] = client_old_coords[targethuman][0]; - bot_presumed_endpoint[1] = client_old_coords[targethuman][1]; - bot_presumed_endpoint[2] = client_old_coords[targethuman][2]; - find_closest_match = false; - CreateTimer(4.0, bot_reached_endpoint); - } + bot_forward = true; + find_closest_match = false; + CreateTimer(4.0, bot_reached_endpoint); } } } + } - //check ladder = 0, water = 1, in air(surfing) = 2 TODO + //check ladder = 0, water = 1, in air(surfing) = 2, downhill = 3 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 == -1) + bot_on_type = check_bot_surfing_or_downhill(); if (find_closest_match && bot_on_type != 0) { targethuman = 0; @@ -243,7 +222,7 @@ 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; - if (bot_on_type != 0 && bot_on_type != 2 && bot_presumed_endpoint[0] == 0.0) + if (bot_on_type != 0 && bot_on_type != 2) { float pos[3]; if (IsValidClient(targethuman)) @@ -254,9 +233,10 @@ public Action recursive_pressing(Handle timer, any data) if (IsValidClient(target_enemy)) { float min_enemy_distance = 10.0; + int min_distance_mult = 6; GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos); enemy_distance = get_power_distance(present, pos); - float min_distance_target_human = 0.3; + float min_distance_target_human = 0.2; //human aiming for zombie if (targeteam == 3 && dist_target > 0 && dist_target < min_distance_target_human && enemy_distance > min_enemy_distance) { @@ -264,7 +244,9 @@ public Action recursive_pressing(Handle timer, any data) face_call(target_enemy); } //zombie aiming for human - if (targeteam == 2 && min_enemy_distance * 3 > enemy_distance && enemy_distance > 0) + if (0 < enemy_distance <= dist_target) + min_enemy_distance = min_enemy_distance * min_distance_mult; + if (targeteam == 2 && min_enemy_distance * min_distance_mult > enemy_distance && enemy_distance > 0) { chasing_enemy = true; face_call(target_enemy); @@ -275,7 +257,8 @@ public Action recursive_pressing(Handle timer, any data) if (round_start_stuck) bot_stuck = is_bot_stuck(); } - //TODO detect gaps and jump perfectly over them, trace maybe to judge if avoiding gap or jumpable distance + //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 @@ -285,6 +268,80 @@ public Action recursive_pressing(Handle timer, any data) return Plugin_Continue; } +public int check_bot_surfing_or_downhill() +{ + g_bLastOnGround[present] = g_bOnGround[present]; + if (GetEntityFlags(present) & FL_ONGROUND) + g_bOnGround[present] = true; + else + g_bOnGround[present] = false; + g_vLast[present][0] = g_vCurrent[present][0]; + g_vLast[present][1] = g_vCurrent[present][1]; + g_vLast[present][2] = g_vCurrent[present][2]; + g_vCurrent[present][0] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[0]"); + g_vCurrent[present][1] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[1]"); + g_vCurrent[present][2] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[2]"); + if (g_bOnGround[present] && !g_bLastOnGround[present]) + { + 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, < 0.7 = surf ramp) + float vPlane[3]; + float vLast[3]; + float surf_ramp = 0.7; + float flat_ground = 1.0; + TR_GetPlaneNormal(INVALID_HANDLE, vPlane); + if (vPlane[2] < surf_ramp) + return 2; + if (vPlane[2] < flat_ground) + { + vLast[0] = g_vLast[present][0]; + vLast[1] = g_vLast[present][1]; + vLast[2] = g_vLast[present][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; + // Make sure the player is going down a ramp by checking if they actually will gain speed from the boost + 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 bool is_bot_stuck() { if (!round_start_stuck) @@ -347,7 +404,7 @@ public int find_closest_enemy(int entity, int targeteam) bool traceable = false; if (IsAbleToSee(present, i)) traceable = true; - float trace_advantage = 2.5; + float trace_advantage = 5.5; if (traceable) dist_target = dist_target / trace_advantage; if (is_client_stuck_or_afk(i)) @@ -396,7 +453,7 @@ public int GetClosestClient_option1(int entity, int targeteam) } float pos[3]; GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); - float trace_advantage = 2.5; + float trace_advantage = 5.5; float dist_target = get_power_distance(entity, pos); if (traceable) dist_target = dist_target / trace_advantage;