diff --git a/AutismBotIngame/python/ingamefollowct.py b/AutismBotIngame/python/ingamefollowct.py index b12ffa5d..4b142549 100644 --- a/AutismBotIngame/python/ingamefollowct.py +++ b/AutismBotIngame/python/ingamefollowct.py @@ -61,11 +61,12 @@ def bot_process_movement(input_line): bot_on_type = int(bot_on_type) bot_stuck = int(bot_stuck) targeteam = int(targeteam) + min_distance_target_human = 0.8 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') strInput += "+jump; wait 15; +duck; wait 15; -jump; wait 15; -duck; wait 3;" - if dist_target > 0.5: + if dist_target > min_distance_target_human: strInput += "use weapon_elite; wait 3; " elif targeteam == 3: strInput += "use weapon_p90; wait 3; " @@ -82,13 +83,11 @@ def bot_process_movement(input_line): strInput = strinput_append(strInput, 10) else: ladder_counter = 0 - min_distance_target_human = 0.1 - min_enemy_distance = 10.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) 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 diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index a2528135..d94a48ae 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -8,6 +8,8 @@ #include #include +#include +#include #include //#pragma newdecls required @@ -20,11 +22,12 @@ bool round_start_stuck = false; float bot_old_coords[3]; bool bot_stuck_g = false; float client_old_coords[MAXPLAYERS + 1][3]; -bool bot_forward = false; +float targethuman_teleported[3]; bool g_bOnGround[MAXPLAYERS + 1]; bool g_bLastOnGround[MAXPLAYERS + 1]; float g_vCurrent[MAXPLAYERS + 1][3]; float g_vLast[MAXPLAYERS + 1][3]; +bool cmdpost_run_cooldown = false; //admins & vips bool admins[MAXPLAYERS + 1]; @@ -49,6 +52,10 @@ public void OnPluginStart() //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); @@ -57,10 +64,80 @@ public void OnPluginStart() connect(socket); global_socket = socket; round_start_stuck = true; - bot_forward = false; + 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); + 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); + } + 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 = 800.0; + if (dist_target > min_required_distance) + return false; + return true; +} + public Action cmd_talk(int client, int args) { char msg[generic_length]; @@ -81,7 +158,8 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast round_start_stuck = false; targethuman = 0; bot_stuck_g = false; - bot_forward = false; + cmdpost_run_cooldown = false; + reset_target_human_tp_coord(); CreateTimer(7.0, permitStuck); } @@ -91,12 +169,6 @@ public Action permitStuck(Handle timer, any data) return Plugin_Continue; } -public Action bot_reached_endpoint(Handle timer, any data) -{ - bot_forward = false; - return Plugin_Continue; -} - public void OnMapStart() { CreateTimer(0.2, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); @@ -125,13 +197,21 @@ public void send_socket_msg(char[] query_msg, int len) public Action bot_check_connect(Handle timer, any data) { - if (!IsValidClient(present) && GetClientCount(false) < 63) + 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) + KickClient(present); + return Plugin_Continue; +} + +public Action runcmd_cooldown(Handle timer, any data) +{ + cmdpost_run_cooldown = false; return Plugin_Continue; } @@ -139,7 +219,7 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float int cmdnum, int tickcount, int seed, const int mouse[2]) { if (!IsClientInGame(client)) return; - if (client == targethuman && round_start_stuck && IsValidClient(present)) + if (client == targethuman && round_start_stuck && IsValidClient(present) && !cmdpost_run_cooldown) { char keyinput[generic_length * 5]; if (buttons & IN_JUMP || buttons & IN_DUCK) @@ -149,11 +229,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.0; + float dist_cap = 1.5; 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(1.0, runcmd_cooldown); } } } @@ -176,8 +258,6 @@ 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); @@ -194,29 +274,8 @@ public Action recursive_pressing(Handle timer, any data) } bool find_closest_match = true; bool bot_stuck = false; - if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman)) - { - face_call(targethuman); - find_closest_match = is_client_stuck_or_afk(targethuman); - 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) - { - bot_forward = true; - find_closest_match = false; - CreateTimer(4.0, bot_reached_endpoint); - } - } - } - } - //check ladder = 0, water = 1, in air(surfing) = 2, downhill = 3 + //check ladder = 0, water = 1, in air(surfing) = 2, downhill = 3, teleporter = 4 int bot_on_type = -1; if (GetEntityMoveType(present) == MOVETYPE_LADDER) bot_on_type = 0; @@ -225,7 +284,29 @@ public Action recursive_pressing(Handle timer, any data) 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) + 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) + { + 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); @@ -234,7 +315,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) + if (bot_on_type != 0 && bot_on_type != 4) { float pos[3]; if (IsValidClient(targethuman)) @@ -244,12 +325,11 @@ public Action recursive_pressing(Handle timer, any data) } if (IsValidClient(target_enemy)) { - float min_enemy_distance = 10.0; - int min_distance_mult = 6; + float min_enemy_distance = 100.0; GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos); enemy_distance = get_power_distance(present, pos); //important to keep min_distance_target_human in sync with the variable value in python - float min_distance_target_human = 0.1; + float min_distance_target_human = 0.8; //human aiming for zombie if (targeteam == 3) { @@ -264,13 +344,8 @@ public Action recursive_pressing(Handle timer, any data) face_call(target_enemy); } } - int zm_multiplier = 2; - if (dist_target < min_enemy_distance) - zm_multiplier = min_distance_mult; - if (0 < enemy_distance <= dist_target * zm_multiplier) - min_enemy_distance = min_enemy_distance * min_distance_mult; //zombie aiming for human - if (targeteam == 2 && min_enemy_distance * min_distance_mult > enemy_distance && enemy_distance > 0) + if (targeteam == 2 && 0 < enemy_distance <= min_enemy_distance * 5) { chasing_enemy = true; face_call(target_enemy); @@ -281,6 +356,7 @@ public Action recursive_pressing(Handle timer, any data) if (round_start_stuck) bot_stuck = is_bot_stuck(); } + //TODO in some cases prevent bot from jumping over edge 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 @@ -324,6 +400,7 @@ public int check_bot_surfing_or_downhill() float surf_ramp = 0.7; float flat_ground = 1.0; TR_GetPlaneNormal(INVALID_HANDLE, vPlane); + //TODO figure out moveright or moveleft on surf ramps if (vPlane[2] < surf_ramp) return 2; if (vPlane[2] < flat_ground) @@ -351,7 +428,7 @@ public int check_bot_surfing_or_downhill() 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)) + if (GetVectorLength(vVel) > GetVectorLength(vLast)) return 3; } } @@ -423,12 +500,8 @@ 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; - if (IsAbleToSee(present, i)) - traceable = true; - float trace_advantage = 5.5; - if (traceable) - dist_target = dist_target / trace_advantage; + if (!IsAbleToSee(present, i)) + continue; if (is_client_stuck_or_afk(i)) continue; if (nearestdistance < 0 || dist_target < nearestdistance) @@ -449,17 +522,16 @@ public int GetClosestClient_option1(int entity, int targeteam) for (int i = 1; i <= MaxClients; i++) if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present) { - bool traceable = false; - if (IsAbleToSee(present, i)) - traceable = true; + if (!IsAbleToSee(present, i)) + continue; if (is_client_stuck_or_afk(i)) continue; - if (admins[i] && traceable) + if (admins[i]) { adminpresent = true; vippresent = false; } - else if (vips[i] && !adminpresent && traceable) + else if (vips[i] && !adminpresent) { vippresent = true; } @@ -475,10 +547,7 @@ public int GetClosestClient_option1(int entity, int targeteam) } float pos[3]; GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); - float trace_advantage = 5.5; float dist_target = get_power_distance(entity, pos); - if (traceable) - dist_target = dist_target / trace_advantage; if (nearestdistance < 0 || dist_target < nearestdistance) { nearest = i;