more major updates and features removal makes it function smoother

This commit is contained in:
jenzur 2020-07-21 01:03:06 +02:00
parent fe87151bed
commit 6dfc400fbb
2 changed files with 117 additions and 93 deletions

View File

@ -32,25 +32,39 @@ def joinTeam():
time.sleep(4.5) time.sleep(4.5)
print('jointeam func: ') print('jointeam func: ')
def bot_process_keyinput(input_line):
movement_input = input_line[input_line.index("keyinput:") + len("keyinput:"):input_line.index("dist_target:")]
dist_target = input_line[input_line.index("dist_target:") + len("dist_target:"):]
dist_target = float(dist_target)
strInput = f"""{movement_input}; wait 5; """
writeCfgInput(strInput)
print('dist_target: ', dist_target, ' movement strinput: ', strInput)
time.sleep(0.1)
writeCfgInput("wait 5;")
def bot_process_movement(input_line): def bot_process_movement(input_line):
movement_input = input_line[input_line.index("keyinput:") + len("keyinput:"):input_line.index("clientangles:")]
client_angles = input_line[input_line.index("clientangles:") + len("clientangles:"):input_line.index("dist_target:")]
dist_target = input_line[input_line.index("dist_target:") + len("dist_target:"):input_line.index("targethuman:")] 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:")] 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:"):] 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("bot_stuck:")]
bot_stuck = input_line[input_line.index("bot_stuck:") + len("bot_stuck:"):]
dist_target = float(dist_target) dist_target = float(dist_target)
enemy_distance = float(enemy_distance)
bot_on_type = int(bot_on_type) bot_on_type = int(bot_on_type)
bot_stuck = int(bot_stuck)
strInput = "" strInput = ""
if dist_target < 3000.0: distance_cap = 2.5
if dist_target < distance_cap and bot_on_type not in [0, 2]:
strInput += "-forward; wait 3; -back; wait 3; -moveleft; waii 3; -moveright; wait 3; " strInput += "-forward; wait 3; -back; wait 3; -moveleft; waii 3; -moveright; wait 3; "
print('reduced movement, too close')
strInput += "-attack; wait 2; -use; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; " strInput += "-attack; wait 2; -use; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; "
if random.randint(0, 100) < 37 and random.randint(0, 100) > 63: if bot_stuck:
strInput += "wait 5; +jump; wait 5; +duck; " strInput += "wait 5; +jump; wait 5; +duck; "
if bot_on_type == 0: if bot_on_type == 0:
print('bot_on_type ladder ') print('bot_on_type ladder ')
strInput += "setang -90 90 0; wait 5; -back; wait 3; -moveleft; wait 3; -moveright; wait 5; +forward; wait 5;" 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;"
elif bot_on_type == 2: elif bot_on_type == 2:
print('bot surfing') print('bot surfing')
#make some setup to allow surfing/mimic #make some setup to allow surfing/mimic
@ -58,14 +72,8 @@ def bot_process_movement(input_line):
if bot_on_type == 1: if bot_on_type == 1:
print('bot_on_type water') print('bot_on_type water')
strInput += "+jump; wait 5;" strInput += "+jump; wait 5;"
print('target human: ', targethuman, ' dist_target: ', dist_target) print('target human: ', targethuman, ' dist_target: ', dist_target, ' enemy distance: ', enemy_distance)
#print('movemenet_input: ', movement_input)
distance_cap = 6000.0
if dist_target < distance_cap:
strInput += f"""setang {client_angles}; wait 5; {movement_input}; wait 5; """
if not movement_input or dist_target > distance_cap:
strInput += "+forward; wait 5; " strInput += "+forward; wait 5; "
#angle set by sourcemod plugin
#print('strInput final:', strInput) #print('strInput final:', strInput)
writeCfgInput(strInput) writeCfgInput(strInput)
@ -123,8 +131,10 @@ if __name__ == '__main__':
elif "clientmessage:" in data: elif "clientmessage:" in data:
sock_external.sendto(databyte, (udp_external_ip, local_port)) sock_external.sendto(databyte, (udp_external_ip, local_port))
print('sent databyte: ', databyte) print('sent databyte: ', databyte)
elif data.startswith("keyinput:"): elif data.startswith("dist_target:"):
bot_process_movement(data) bot_process_movement(data)
elif data.startswith("keyinput:"):
bot_process_keyinput(data)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass

View File

@ -13,11 +13,11 @@
//#pragma newdecls required //#pragma newdecls required
int present = 0; int present = 0;
int targethuman = 0; int targethuman = 0;
int stuck_counter[MAXPLAYERS + 1]; int client_out_balancer[MAXPLAYERS + 1];
//admins & vips //admins & vips
int admins[MAXPLAYERS + 1]; bool admins[MAXPLAYERS + 1];
int vips[MAXPLAYERS + 1]; bool vips[MAXPLAYERS + 1];
//socket for bot input //socket for bot input
Handle global_socket; Handle global_socket;
@ -73,11 +73,6 @@ public void OnMapStart()
CreateTimer(10.0, bot_check_connect, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE); CreateTimer(10.0, bot_check_connect, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
} }
public bool TraceEntityFilterPlayer(int entity, int contentsMask)
{
return (entity > GetMaxClients() || !entity);
}
public void send_socket_msg(char[] query_msg, int len) public void send_socket_msg(char[] query_msg, int len)
{ {
if (global_socket != INVALID_HANDLE && SocketIsConnected(global_socket)) if (global_socket != INVALID_HANDLE && SocketIsConnected(global_socket))
@ -96,6 +91,52 @@ public Action bot_check_connect(Handle timer, any data)
return Plugin_Continue; 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);
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])
{
if (!IsClientInGame(client)) return;
if (client == targethuman)
{
char keyinput[generic_length * 5];
if (buttons & IN_JUMP)
Format(keyinput, sizeof(keyinput), "+jump; wait 5; ", keyinput);
if (buttons & IN_DUCK)
Format(keyinput, sizeof(keyinput), "%s +duck; wait 5; ", keyinput);
if (strlen(keyinput) > 0)
{
float pos[3];
GetEntPropVector(present, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(targethuman, pos);
float dist_cap = 2.0;
if (dist_target <= dist_cap)
{
Format(keyinput, sizeof(keyinput), "keyinput: %s dist_target: %f", keyinput, dist_target);
send_socket_msg(keyinput, strlen(keyinput));
}
}
}
}
public Action recursive_pressing(Handle timer, any data) public Action recursive_pressing(Handle timer, any data)
{ {
if (IsValidClient(present) && IsPlayerAlive(present)) if (IsValidClient(present) && IsPlayerAlive(present))
@ -117,75 +158,49 @@ public Action recursive_pressing(Handle timer, any data)
bool find_closest_match = true; bool find_closest_match = true;
if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman)) if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman))
{ {
float distance_limit = 10000.0; float distance_limit = 50.0;
if (admins[targethuman]) if (admins[targethuman])
distance_limit = distance_limit * 5; distance_limit = distance_limit * 5;
else if (vips[targethuman]) else if (vips[targethuman])
distance_limit = distance_limit * 2.5; distance_limit = distance_limit * 2.5;
find_closest_match = is_client_stuck_or_afk(targethuman); find_closest_match = is_client_stuck_or_afk(targethuman);
if (!find_closest_match) if (!find_closest_match)
{ //float dist_target = get_square_distance(targethuman, present_bot_coords); {
//this is alternative approach to assume range
float pos[3]; float pos[3];
GetEntPropVector(present, Prop_Send, "m_vecOrigin", pos); GetEntPropVector(present, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(targethuman, pos); float dist_target = get_power_distance(targethuman, pos);
if (!TraceRayable(present, targethuman))
dist_target = dist_target * 2;
find_closest_match = dist_target < distance_limit ? false : true; find_closest_match = dist_target < distance_limit ? false : true;
} }
} }
if (find_closest_match) if (find_closest_match)
targethuman = GetClosestClient_option1(present, targeteam); targethuman = GetClosestClient_option1(present, targeteam);
if (IsValidClient(targethuman)) if (IsValidClient(targethuman))
{ //float dist_target = get_square_distance(targethuman, present_bot_coords); {
float pos[3]; float pos[3];
GetEntPropVector(present, Prop_Send, "m_vecOrigin", pos); GetEntPropVector(present, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(targethuman, pos); float dist_target = get_power_distance(targethuman, pos);
int target_enemy = find_closest_enemy(present, targeteam); int target_enemy = find_closest_enemy(present, targeteam);
//dist_cap matching with distance_cap in python and enemy distance float enemy_cap = 2.5;
float dist_cap = 6000.0; float enemy_distance = -1.0;
if (IsValidClient(target_enemy)) if (IsValidClient(target_enemy))
{ {
float enemy_distance = get_power_distance(target_enemy, pos); enemy_distance = get_power_distance(target_enemy, pos);
if (enemy_distance < 2500) if (enemy_distance < enemy_cap)
faceclient(target_enemy); faceclient(target_enemy);
else if (dist_target > dist_cap)
faceclient(targethuman);
} }
else if (dist_target > dist_cap) if (enemy_distance == -1.0 || enemy_distance > enemy_cap)
faceclient(targethuman); faceclient(targethuman);
int keys = GetClientButtons(targethuman);
char keyinput[generic_length * 2];
int counter = 0;
int countercap = 5;
//check ladder = 0, water = 1, in air(surfing) = 2 TODO //check ladder = 0, water = 1, in air(surfing) = 2 TODO
int bot_on_type = -1; int bot_on_type = -1;
if (GetEntityMoveType(present) == MOVETYPE_LADDER) if (GetEntityMoveType(present) == MOVETYPE_LADDER)
bot_on_type = 0; bot_on_type = 0;
int ilevel = GetEntProp(present, Prop_Data, "m_nWaterLevel"); int ilevel = GetEntProp(present, Prop_Data, "m_nWaterLevel");
if (ilevel >= 2) if (ilevel >= 2)
bot_on_type = 1; bot_on_type = 1;
while (!strlen(keyinput) && counter < countercap) bool bot_stuck = is_client_stuck_or_afk(present);
{ Format(message, sizeof(message), "dist_target: %f targethuman: %N bot_on_type: %i enemy_distance: %f bot_stuck: %i", dist_target, targethuman, bot_on_type, enemy_distance, bot_stuck);
if (keys & IN_FORWARD)
Format(keyinput, sizeof(keyinput), "-back; wait 5; +forward; wait 5; ");
else if (keys & IN_BACK)
Format(keyinput, sizeof(keyinput), "-forward; wait 5; +back; wait 5; ");
if (keys & IN_MOVELEFT)
Format(keyinput, sizeof(keyinput), "%s -moveright; wait 5; +moveleft; wait 5; ", keyinput);
else if (keys & IN_MOVERIGHT)
Format(keyinput, sizeof(keyinput), "%s -moveleft; wait 5; +moveright; wait 5; ", keyinput);
if (keys & IN_JUMP)
Format(keyinput, sizeof(keyinput), "%s +jump; wait 5; ", keyinput);
if (keys & IN_DUCK)
Format(keyinput, sizeof(keyinput), "%s +duck; wait 5; ", keyinput);
counter++;
}
float clientangles[3];
GetClientAbsAngles(targethuman, clientangles);
Format(message, sizeof(message), "keyinput: %s clientangles: %f %f %f dist_target: %f targethuman: %N bot_on_type: %i", keyinput, clientangles[0], clientangles[1], clientangles[2], dist_target, targethuman, bot_on_type);
send_socket_msg(message, strlen(message)); send_socket_msg(message, strlen(message));
} }
} }
@ -215,25 +230,13 @@ stock bool is_client_stuck_or_afk(int client)
{ {
float flVel[3]; float flVel[3];
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", flVel); GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", flVel);
if (flVel[0] < 10.0 && flVel[1] < 10.0) flVel[0] < 10.0 && flVel[1] < 10.0 ? client_out_balancer[client]++ : client_out_balancer[client]--;
stuck_counter[client]++;
else
stuck_counter[client] = 0;
if (stuck_counter[client] > 10)
{
return true;
}
return false;
}
public float get_square_distance(int client, float []present_bot_coords) if (client_out_balancer[client] < -50)
{ client_out_balancer[client] = -50;
float pos[3]; if (client_out_balancer[client] > 50)
GetClientAbsOrigin(client, pos); client_out_balancer[client] = 50;
float dx = present_bot_coords[0] - pos[0]; return client_out_balancer[client] > 25;
float dy = present_bot_coords[1] - pos[1];
float dz = FloatAbs(present_bot_coords[2] - pos[2]);
return SquareRoot(dx*dx + dy*dy + dz*dz);
} }
public int find_closest_enemy(int entity, int targeteam) public int find_closest_enemy(int entity, int targeteam)
@ -246,6 +249,8 @@ public int find_closest_enemy(int entity, int targeteam)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) != targeteam) if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) != targeteam)
{ {
float dist_target = get_power_distance(i, pos); float dist_target = get_power_distance(i, pos);
if (!TraceRayable(present, i))
dist_target = dist_target * dist_target;
if (nearestdistance < 0 || dist_target < nearestdistance) if (nearestdistance < 0 || dist_target < nearestdistance)
{ {
nearest = i; nearest = i;
@ -259,7 +264,6 @@ public int GetClosestClient_option1(int entity, int targeteam)
{ {
bool adminpresent = false; bool adminpresent = false;
bool vippresent = false; bool vippresent = false;
float distance_limit = 10000.0;
float pos[3]; float pos[3];
float nearestdistance = -1.0; float nearestdistance = -1.0;
int nearest = -1; int nearest = -1;
@ -268,27 +272,32 @@ public int GetClosestClient_option1(int entity, int targeteam)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present) if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
{ {
float dist_target = get_power_distance(i, pos); float dist_target = get_power_distance(i, pos);
if (admins[i] == 1 && dist_target < distance_limit * 5) bool traceable = false;
if (TraceRayable(present, i))
traceable = true;
if (admins[i] && traceable)
{ {
adminpresent = true; adminpresent = true;
vippresent = false; vippresent = false;
} }
else if (vips[i] == 1 && !adminpresent && dist_target < distance_limit * 2.5) else if (vips[i] && !adminpresent && traceable)
{ {
vippresent = true; vippresent = true;
} }
if (adminpresent) if (adminpresent)
{ {
if (admins[i] == 0) if (!admins[i])
continue; continue;
} }
else if (vippresent) else if (vippresent)
{ {
if (vips[i] == 0) if (!vips[i])
continue; continue;
} }
if (is_client_stuck_or_afk(i)) if (is_client_stuck_or_afk(i))
continue; continue;
if (!traceable)
dist_target = dist_target * dist_target;
if (nearestdistance < 0 || dist_target < nearestdistance) if (nearestdistance < 0 || dist_target < nearestdistance)
{ {
nearest = i; nearest = i;
@ -302,7 +311,12 @@ public float get_power_distance(int target_player, float [3]pos)
{ {
float vec[3]; float vec[3];
GetClientAbsOrigin(target_player, vec); GetClientAbsOrigin(target_player, vec);
return Pow(vec[2]-pos[2], 2.0)+Pow(vec[1]-pos[1], 2.0)+Pow(vec[0]-pos[0], 2.0); 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.0));
float power_distance = SquareRoot(x_axis * x_axis + y_axis * y_axis + z_axis * z_axis);
float defaultcap = 1000.0;
return power_distance / defaultcap;
} }
public bool FilterClient(int entity, int contentsMask, int client) public bool FilterClient(int entity, int contentsMask, int client)
@ -331,10 +345,10 @@ public void OnClientPostAdminCheck(int client)
bot_send_connected_msg(); bot_send_connected_msg();
} }
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK)) if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
admins[client] = 1; admins[client] = true;
else if (CheckCommandAccess(client, "sm_reserved", ADMFLAG_RESERVATION)) else if (CheckCommandAccess(client, "sm_reserved", ADMFLAG_RESERVATION))
vips[client] = 1; vips[client] = true;
stuck_counter[client] = 0; client_out_balancer[client] = 0;
} }
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args) public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
@ -355,9 +369,9 @@ public void OnClientDisconnect(int client)
{ {
present = 0; present = 0;
} }
admins[client] = 0; admins[client] = false;
vips[client] = 0; vips[client] = false;
stuck_counter[client] = 0; client_out_balancer[client] = 0;
} }
public void bot_send_connected_msg() public void bot_send_connected_msg()