more major updates and features removal makes it function smoother
This commit is contained in:
parent
fe87151bed
commit
6dfc400fbb
@ -32,25 +32,39 @@ def joinTeam():
|
||||
time.sleep(4.5)
|
||||
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):
|
||||
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:")]
|
||||
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)
|
||||
enemy_distance = float(enemy_distance)
|
||||
bot_on_type = int(bot_on_type)
|
||||
bot_stuck = int(bot_stuck)
|
||||
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; "
|
||||
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; "
|
||||
|
||||
if random.randint(0, 100) < 37 and random.randint(0, 100) > 63:
|
||||
if bot_stuck:
|
||||
strInput += "wait 5; +jump; wait 5; +duck; "
|
||||
|
||||
if bot_on_type == 0:
|
||||
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:
|
||||
print('bot surfing')
|
||||
#make some setup to allow surfing/mimic
|
||||
@ -58,14 +72,8 @@ def bot_process_movement(input_line):
|
||||
if bot_on_type == 1:
|
||||
print('bot_on_type water')
|
||||
strInput += "+jump; wait 5;"
|
||||
print('target human: ', targethuman, ' dist_target: ', dist_target)
|
||||
#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; "
|
||||
#angle set by sourcemod plugin
|
||||
print('target human: ', targethuman, ' dist_target: ', dist_target, ' enemy distance: ', enemy_distance)
|
||||
strInput += "+forward; wait 5; "
|
||||
|
||||
#print('strInput final:', strInput)
|
||||
writeCfgInput(strInput)
|
||||
@ -123,8 +131,10 @@ if __name__ == '__main__':
|
||||
elif "clientmessage:" in data:
|
||||
sock_external.sendto(databyte, (udp_external_ip, local_port))
|
||||
print('sent databyte: ', databyte)
|
||||
elif data.startswith("dist_target:"):
|
||||
bot_process_movement(data)
|
||||
elif data.startswith("keyinput:"):
|
||||
bot_process_movement(data)
|
||||
bot_process_keyinput(data)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
|
||||
|
@ -13,11 +13,11 @@
|
||||
//#pragma newdecls required
|
||||
int present = 0;
|
||||
int targethuman = 0;
|
||||
int stuck_counter[MAXPLAYERS + 1];
|
||||
int client_out_balancer[MAXPLAYERS + 1];
|
||||
|
||||
//admins & vips
|
||||
int admins[MAXPLAYERS + 1];
|
||||
int vips[MAXPLAYERS + 1];
|
||||
bool admins[MAXPLAYERS + 1];
|
||||
bool vips[MAXPLAYERS + 1];
|
||||
|
||||
//socket for bot input
|
||||
Handle global_socket;
|
||||
@ -73,11 +73,6 @@ public void OnMapStart()
|
||||
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)
|
||||
{
|
||||
if (global_socket != INVALID_HANDLE && SocketIsConnected(global_socket))
|
||||
@ -96,6 +91,52 @@ public Action bot_check_connect(Handle timer, any data)
|
||||
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)
|
||||
{
|
||||
if (IsValidClient(present) && IsPlayerAlive(present))
|
||||
@ -117,75 +158,49 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
bool find_closest_match = true;
|
||||
if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman))
|
||||
{
|
||||
float distance_limit = 10000.0;
|
||||
float distance_limit = 50.0;
|
||||
if (admins[targethuman])
|
||||
distance_limit = distance_limit * 5;
|
||||
else if (vips[targethuman])
|
||||
distance_limit = distance_limit * 2.5;
|
||||
find_closest_match = is_client_stuck_or_afk(targethuman);
|
||||
if (!find_closest_match)
|
||||
{ //float dist_target = get_square_distance(targethuman, present_bot_coords);
|
||||
//this is alternative approach to assume range
|
||||
|
||||
{
|
||||
float pos[3];
|
||||
GetEntPropVector(present, Prop_Send, "m_vecOrigin", 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;
|
||||
}
|
||||
}
|
||||
if (find_closest_match)
|
||||
targethuman = GetClosestClient_option1(present, targeteam);
|
||||
|
||||
if (IsValidClient(targethuman))
|
||||
{ //float dist_target = get_square_distance(targethuman, present_bot_coords);
|
||||
|
||||
{
|
||||
float pos[3];
|
||||
GetEntPropVector(present, Prop_Send, "m_vecOrigin", pos);
|
||||
float dist_target = get_power_distance(targethuman, pos);
|
||||
int target_enemy = find_closest_enemy(present, targeteam);
|
||||
//dist_cap matching with distance_cap in python and enemy distance
|
||||
float dist_cap = 6000.0;
|
||||
float enemy_cap = 2.5;
|
||||
float enemy_distance = -1.0;
|
||||
if (IsValidClient(target_enemy))
|
||||
{
|
||||
float enemy_distance = get_power_distance(target_enemy, pos);
|
||||
if (enemy_distance < 2500)
|
||||
enemy_distance = get_power_distance(target_enemy, pos);
|
||||
if (enemy_distance < enemy_cap)
|
||||
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);
|
||||
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
|
||||
|
||||
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;
|
||||
while (!strlen(keyinput) && counter < countercap)
|
||||
{
|
||||
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);
|
||||
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);
|
||||
send_socket_msg(message, strlen(message));
|
||||
}
|
||||
}
|
||||
@ -215,25 +230,13 @@ stock bool is_client_stuck_or_afk(int client)
|
||||
{
|
||||
float flVel[3];
|
||||
GetEntPropVector(client, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
if (flVel[0] < 10.0 && flVel[1] < 10.0)
|
||||
stuck_counter[client]++;
|
||||
else
|
||||
stuck_counter[client] = 0;
|
||||
if (stuck_counter[client] > 10)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
flVel[0] < 10.0 && flVel[1] < 10.0 ? client_out_balancer[client]++ : client_out_balancer[client]--;
|
||||
|
||||
public float get_square_distance(int client, float []present_bot_coords)
|
||||
{
|
||||
float pos[3];
|
||||
GetClientAbsOrigin(client, pos);
|
||||
float dx = present_bot_coords[0] - pos[0];
|
||||
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);
|
||||
if (client_out_balancer[client] < -50)
|
||||
client_out_balancer[client] = -50;
|
||||
if (client_out_balancer[client] > 50)
|
||||
client_out_balancer[client] = 50;
|
||||
return client_out_balancer[client] > 25;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
float dist_target = get_power_distance(i, pos);
|
||||
if (!TraceRayable(present, i))
|
||||
dist_target = dist_target * dist_target;
|
||||
if (nearestdistance < 0 || dist_target < nearestdistance)
|
||||
{
|
||||
nearest = i;
|
||||
@ -259,7 +264,6 @@ public int GetClosestClient_option1(int entity, int targeteam)
|
||||
{
|
||||
bool adminpresent = false;
|
||||
bool vippresent = false;
|
||||
float distance_limit = 10000.0;
|
||||
float pos[3];
|
||||
float nearestdistance = -1.0;
|
||||
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)
|
||||
{
|
||||
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;
|
||||
vippresent = false;
|
||||
}
|
||||
else if (vips[i] == 1 && !adminpresent && dist_target < distance_limit * 2.5)
|
||||
else if (vips[i] && !adminpresent && traceable)
|
||||
{
|
||||
vippresent = true;
|
||||
}
|
||||
if (adminpresent)
|
||||
{
|
||||
if (admins[i] == 0)
|
||||
if (!admins[i])
|
||||
continue;
|
||||
}
|
||||
else if (vippresent)
|
||||
{
|
||||
if (vips[i] == 0)
|
||||
if (!vips[i])
|
||||
continue;
|
||||
}
|
||||
if (is_client_stuck_or_afk(i))
|
||||
continue;
|
||||
if (!traceable)
|
||||
dist_target = dist_target * dist_target;
|
||||
if (nearestdistance < 0 || dist_target < nearestdistance)
|
||||
{
|
||||
nearest = i;
|
||||
@ -302,7 +311,12 @@ public float get_power_distance(int target_player, float [3]pos)
|
||||
{
|
||||
float vec[3];
|
||||
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)
|
||||
@ -331,10 +345,10 @@ public void OnClientPostAdminCheck(int client)
|
||||
bot_send_connected_msg();
|
||||
}
|
||||
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
|
||||
admins[client] = 1;
|
||||
admins[client] = true;
|
||||
else if (CheckCommandAccess(client, "sm_reserved", ADMFLAG_RESERVATION))
|
||||
vips[client] = 1;
|
||||
stuck_counter[client] = 0;
|
||||
vips[client] = true;
|
||||
client_out_balancer[client] = 0;
|
||||
}
|
||||
|
||||
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
||||
@ -355,9 +369,9 @@ public void OnClientDisconnect(int client)
|
||||
{
|
||||
present = 0;
|
||||
}
|
||||
admins[client] = 0;
|
||||
vips[client] = 0;
|
||||
stuck_counter[client] = 0;
|
||||
admins[client] = false;
|
||||
vips[client] = false;
|
||||
client_out_balancer[client] = 0;
|
||||
}
|
||||
|
||||
public void bot_send_connected_msg()
|
||||
|
Loading…
Reference in New Issue
Block a user