more bot updates along the way, needs some more adjustsments and included new way of calculating distances
This commit is contained in:
parent
f624dc238c
commit
fe87151bed
@ -34,18 +34,15 @@ def joinTeam():
|
||||
|
||||
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("xyz:")]
|
||||
xyz_difference = input_line[input_line.index("xyz:") + len("xyz:"):input_line.index("dist_target:")]
|
||||
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:"):]
|
||||
dist_target = float(dist_target)
|
||||
xyz_difference = xyz_difference.strip()
|
||||
xyz_difference = [float(i.replace('\U00002013', '-')) for i in xyz_difference.split(' ')]
|
||||
bot_on_type = int(bot_on_type)
|
||||
strInput = ""
|
||||
if dist_target < 100.0:
|
||||
strInput += "-forward; wait 3; -back; wait 3; -moveleft; wait 3; -moveright; wait 3; "
|
||||
if dist_target < 3000.0:
|
||||
strInput += "-forward; wait 3; -back; wait 3; -moveleft; waii 3; -moveright; wait 3; "
|
||||
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:
|
||||
@ -63,25 +60,16 @@ def bot_process_movement(input_line):
|
||||
strInput += "+jump; wait 5;"
|
||||
print('target human: ', targethuman, ' dist_target: ', dist_target)
|
||||
#print('movemenet_input: ', movement_input)
|
||||
if dist_target < 400.0:
|
||||
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 > 400:
|
||||
strInput += f""" setang 0 180 0; wait 5; """
|
||||
#print('xyz_difference: ', xyz_difference)
|
||||
axis_distance = 25.0
|
||||
if xyz_difference[0] > axis_distance:
|
||||
strInput += " -back; wait 5; +forward; wait 5;"
|
||||
elif xyz_difference[0] < axis_distance * -1:
|
||||
strInput += " -forward; wait 5; +back; wait 5;"
|
||||
|
||||
if xyz_difference[1] < axis_distance * -1:
|
||||
strInput += " -moveleft; wait 5; +moveright; wait 5;"
|
||||
elif xyz_difference[1] > axis_distance:
|
||||
strInput += " -moveright; wait 5; +moveleft; wait 5;"
|
||||
if not movement_input or dist_target > distance_cap:
|
||||
strInput += "+forward; wait 5; "
|
||||
#angle set by sourcemod plugin
|
||||
|
||||
#print('strInput final:', strInput)
|
||||
writeCfgInput(strInput)
|
||||
time.sleep(0.1)
|
||||
time.sleep(0.2)
|
||||
writeCfgInput("wait 5;")
|
||||
|
||||
def bot_connect_ze():
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include <socket>
|
||||
|
||||
//#pragma newdecls required
|
||||
|
||||
int present = 0;
|
||||
int targethuman = 0;
|
||||
int stuck_counter[MAXPLAYERS + 1];
|
||||
|
||||
//admins & vips
|
||||
int admins[MAXPLAYERS + 1];
|
||||
@ -22,7 +22,6 @@ int vips[MAXPLAYERS + 1];
|
||||
//socket for bot input
|
||||
Handle global_socket;
|
||||
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "coordinates for the bot",
|
||||
@ -70,7 +69,7 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
CreateTimer(0.1, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(0.2, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(10.0, bot_check_connect, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
}
|
||||
|
||||
@ -101,7 +100,6 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
{
|
||||
if (IsValidClient(present) && IsPlayerAlive(present))
|
||||
{
|
||||
float flVel[3];
|
||||
char message[generic_length * 7];
|
||||
float present_bot_coords[3];
|
||||
GetClientAbsOrigin(present, present_bot_coords);
|
||||
@ -117,87 +115,52 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
targeteam = 3;
|
||||
}
|
||||
bool find_closest_match = true;
|
||||
float distance_limit = 100.0;
|
||||
if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman))
|
||||
{
|
||||
float pos[3];
|
||||
GetClientAbsOrigin(targethuman, 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]);
|
||||
float dist_target = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
GetEntPropVector(targethuman, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
float distance_limit = 10000.0;
|
||||
if (admins[targethuman])
|
||||
distance_limit = distance_limit * 5;
|
||||
else if (vips[targethuman])
|
||||
distance_limit = distance_limit * 2.5;
|
||||
if (flVel[0] < 100.0 && flVel[1] < 100.0)
|
||||
find_closest_match = false;
|
||||
if (dist_target < distance_limit)
|
||||
find_closest_match = false;
|
||||
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);
|
||||
find_closest_match = dist_target < distance_limit ? false : true;
|
||||
}
|
||||
}
|
||||
if (find_closest_match)
|
||||
{
|
||||
float lowest_distance = 1000000.0;
|
||||
bool adminpresent = false;
|
||||
bool vippresent = false;
|
||||
float dist_target = 0.0;
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
||||
{
|
||||
float pos[3];
|
||||
GetClientAbsOrigin(i, 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]);
|
||||
dist_target = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
|
||||
if (admins[i] == 1 && dist_target < distance_limit * 5)
|
||||
{
|
||||
adminpresent = true;
|
||||
vippresent = false;
|
||||
}
|
||||
else if (vips[i] == 1 && !adminpresent && dist_target < distance_limit * 2.5)
|
||||
{
|
||||
vippresent = true;
|
||||
}
|
||||
if (adminpresent)
|
||||
{
|
||||
if (admins[i] == 0)
|
||||
continue;
|
||||
}
|
||||
else if (vippresent)
|
||||
{
|
||||
if (vips[i] == 0)
|
||||
continue;
|
||||
}
|
||||
GetEntPropVector(i, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
if (flVel[0] < 100.0 && flVel[1] < 100.0)
|
||||
continue;
|
||||
if (dist_target < lowest_distance)
|
||||
{
|
||||
lowest_distance = dist_target;
|
||||
targethuman = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
targethuman = GetClosestClient_option1(present, targeteam);
|
||||
|
||||
if (IsValidClient(targethuman))
|
||||
{
|
||||
float dx = 0.0;
|
||||
float dy = 0.0;
|
||||
float dz = 0.0;
|
||||
float dist_target = 0.0;
|
||||
float target_human_original_coord[3];
|
||||
GetClientAbsOrigin(targethuman, target_human_original_coord);
|
||||
dx = present_bot_coords[0] - target_human_original_coord[0];
|
||||
dy = present_bot_coords[1] - target_human_original_coord[1];
|
||||
dz = FloatAbs(present_bot_coords[2] - target_human_original_coord[2]);
|
||||
dist_target = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
{ //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;
|
||||
if (IsValidClient(target_enemy))
|
||||
{
|
||||
float enemy_distance = get_power_distance(target_enemy, pos);
|
||||
if (enemy_distance < 2500)
|
||||
faceclient(target_enemy);
|
||||
else if (dist_target > dist_cap)
|
||||
faceclient(targethuman);
|
||||
}
|
||||
else if (dist_target > dist_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
|
||||
//check ladder = 0, water = 1, in air(surfing) = 2 TODO
|
||||
|
||||
int bot_on_type = -1;
|
||||
if (GetEntityMoveType(present) == MOVETYPE_LADDER)
|
||||
bot_on_type = 0;
|
||||
@ -222,14 +185,25 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
}
|
||||
float clientangles[3];
|
||||
GetClientAbsAngles(targethuman, clientangles);
|
||||
//PrintToChatAll("targethuman: %N", targethuman);
|
||||
Format(message, sizeof(message), "keyinput: %s clientangles: %f %f %f xyz: %f %f %f dist_target: %f targethuman: %N bot_on_type: %i", keyinput, clientangles[0], clientangles[1], clientangles[2], dx, dy, dz, dist_target, targethuman, bot_on_type);
|
||||
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));
|
||||
}
|
||||
}
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public void faceclient(int target_human)
|
||||
{
|
||||
float TargetPos[3];
|
||||
float ClientPos[3];
|
||||
float Result[3];
|
||||
GetClientEyePosition(targethuman, TargetPos);
|
||||
GetClientEyePosition(present, ClientPos);
|
||||
MakeVectorFromPoints(ClientPos, TargetPos, Result);
|
||||
GetVectorAngles(Result, Result);
|
||||
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
|
||||
}
|
||||
|
||||
stock bool IsValidClient(int client)
|
||||
{
|
||||
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
|
||||
@ -237,6 +211,107 @@ stock bool IsValidClient(int client)
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public int find_closest_enemy(int entity, int targeteam)
|
||||
{
|
||||
float pos[3];
|
||||
float nearestdistance = -1.0;
|
||||
int nearest = -1;
|
||||
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", pos);
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) != targeteam)
|
||||
{
|
||||
float dist_target = get_power_distance(i, pos);
|
||||
if (nearestdistance < 0 || dist_target < nearestdistance)
|
||||
{
|
||||
nearest = i;
|
||||
nearestdistance = dist_target;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
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;
|
||||
GetEntPropVector(entity, Prop_Send, "m_vecOrigin", pos);
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
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)
|
||||
{
|
||||
adminpresent = true;
|
||||
vippresent = false;
|
||||
}
|
||||
else if (vips[i] == 1 && !adminpresent && dist_target < distance_limit * 2.5)
|
||||
{
|
||||
vippresent = true;
|
||||
}
|
||||
if (adminpresent)
|
||||
{
|
||||
if (admins[i] == 0)
|
||||
continue;
|
||||
}
|
||||
else if (vippresent)
|
||||
{
|
||||
if (vips[i] == 0)
|
||||
continue;
|
||||
}
|
||||
if (is_client_stuck_or_afk(i))
|
||||
continue;
|
||||
if (nearestdistance < 0 || dist_target < nearestdistance)
|
||||
{
|
||||
nearest = i;
|
||||
nearestdistance = dist_target;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public bool FilterClient(int entity, int contentsMask, int client)
|
||||
{
|
||||
if (entity == client)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void OnClientPostAdminCheck(int client)
|
||||
{
|
||||
//STEAM_0:1:34783317
|
||||
@ -259,6 +334,7 @@ public void OnClientPostAdminCheck(int client)
|
||||
admins[client] = 1;
|
||||
else if (CheckCommandAccess(client, "sm_reserved", ADMFLAG_RESERVATION))
|
||||
vips[client] = 1;
|
||||
stuck_counter[client] = 0;
|
||||
}
|
||||
|
||||
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
||||
@ -281,6 +357,7 @@ public void OnClientDisconnect(int client)
|
||||
}
|
||||
admins[client] = 0;
|
||||
vips[client] = 0;
|
||||
stuck_counter[client] = 0;
|
||||
}
|
||||
|
||||
public void bot_send_connected_msg()
|
||||
|
Loading…
Reference in New Issue
Block a user