general bot updates for movement handling
This commit is contained in:
parent
6d58c75d12
commit
b94b79f235
@ -33,39 +33,58 @@ def joinTeam():
|
||||
print('jointeam func: ')
|
||||
|
||||
|
||||
def bot_process_movement(input_lines):
|
||||
def bot_process_movement(input_line):
|
||||
movement_list = [1, 0]
|
||||
strInput = "-attack; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; "
|
||||
for input_line in input_lines.splitlines():
|
||||
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 = input_line[input_line.index("xyz:") + len("xyz:"):input_line.index("hunt_or_mimic:")]
|
||||
hunt_or_mimic = input_line[input_line.index("hunt_or_mimic:") + len("hunt_or_mimic:"):input_line.index("stuckX:")]
|
||||
stuckx = input_line[input_line.index("stuckX:") + len("stuckX:"):input_line.index("stuckY:")]
|
||||
stucky = input_line[input_line.index("stuckY:") + len("stuckY:"):]
|
||||
if not hunt_or_mimic:
|
||||
axis_distance = 50
|
||||
if stuckX:
|
||||
strInput = "-attack; wait 2; -use; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; "
|
||||
|
||||
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("stuckX:")]
|
||||
stuckx = input_line[input_line.index("stuckX:") + len("stuckX:"):input_line.index("stuckY:")]
|
||||
stucky = input_line[input_line.index("stuckY:") + len("stuckY:"):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(' ')]
|
||||
stuckx = int(stuckx)
|
||||
stucky = int(stucky)
|
||||
bot_on_type = int(bot_on_type)
|
||||
if bot_on_type == 0:
|
||||
print('bot_on_type ladder ')
|
||||
strInput += "setang -90 0 0; wait 5; -back; wait 3; -moveleft; wait 3; -moveright; wait 5; +forward; wait 5;"
|
||||
else:
|
||||
if bot_on_type == 1:
|
||||
print('bot_on_type water')
|
||||
strInput += "+jump; wait 5;"
|
||||
if dist_target > 300.0:
|
||||
axis_distance = 150.0
|
||||
if stuckx:
|
||||
print('stuckX enabled')
|
||||
if movement_list[0] == 0:
|
||||
movement_list[0] = 1
|
||||
elif movement_list[0] == 1:
|
||||
movement_list[0] = 0
|
||||
strInput += " +jump; wait 3; +duck; wait 5;"
|
||||
if stuckY:
|
||||
if stucky:
|
||||
print('stuckY enabled')
|
||||
if movement_list[1] == 0:
|
||||
movement_list[1] = 1
|
||||
elif movement_list[1] == 1:
|
||||
movement_list[1] = 0
|
||||
strInput += " +jump; wait 3; +duck; wait 5;"
|
||||
print('hunt mode enabled')
|
||||
if not stuckX and not stuckY:
|
||||
print('hunt mode: target human: ', targethuman)
|
||||
print('stuckx: ', stuckx, ' stuckY: ', stucky)
|
||||
#print('movement_list: ', movement_list)
|
||||
if not stuckx and not stucky:
|
||||
#print('xyz_difference: ', xyz_difference)
|
||||
if xyz_difference[0] > axis_distance:
|
||||
movement_list[0] = 1
|
||||
elif xyz_difference[0] < -axis_distance:
|
||||
movement_list[0] = 0
|
||||
|
||||
|
||||
if xyz_difference[1] < -axis_distance:
|
||||
movement_list[1] = 1
|
||||
elif xyz_difference[1] > axis_distance:
|
||||
@ -79,25 +98,26 @@ def bot_process_movement(input_lines):
|
||||
strInput += " -moveleft; wait 5; +moveright; wait 5;"
|
||||
elif movement_list[1] == 0:
|
||||
strInput += " -moveright; wait 5; +moveleft; wait 5;"
|
||||
|
||||
print('xyz_difference[0]: ', xyz_difference[0])
|
||||
print('xyz_difference[1]: ', xyz_difference[1])
|
||||
print('movement_list[0]: ', movement_list[0], '0 = back. 1 = forward.')
|
||||
print('movement_list[1]: ', movement_list[1], '0 = moveleft. 1 = moveright')
|
||||
|
||||
#print('xyz_difference[0]: ', xyz_difference[0])
|
||||
#print('xyz_difference[1]: ', xyz_difference[1])
|
||||
#print('movement_list[0]: ', movement_list[0], '0 = back. 1 = forward.')
|
||||
#print('movement_list[1]: ', movement_list[1], '0 = moveleft. 1 = moveright')
|
||||
strInput += f""" setang 0 180 0; wait 5; """
|
||||
else:
|
||||
strInput += f"""setang {client_angles[0]} {client_angles[1]} {client_angles[2]}; wait 5; {movement_input}; wait 5; """
|
||||
#print('strInput final:', strInput)
|
||||
|
||||
print('mimic mode enabled! dist_target: ', dist_target, ' targethuman: ', targethuman)
|
||||
#print('movemenet_input: ', movement_input)
|
||||
strInput += f"""setang {client_angles}; wait 5; {movement_input}; wait 5; """
|
||||
print('strInput final:', strInput)
|
||||
writeCfgInput(strInput)
|
||||
time.sleep(0.4)
|
||||
time.sleep(0.2)
|
||||
writeCfgInput("wait 5;")
|
||||
|
||||
def bot_connect_ze():
|
||||
#use whatever ip you want here to connect with
|
||||
strdev = "connect 151.80.230.149:27019/test132;"
|
||||
str1 = "connect 151.80.230.149:27015;"
|
||||
writeCfgInput(strdev)
|
||||
writeCfgInput(str1)
|
||||
time.sleep(0.2)
|
||||
writeCfgInput("wait 5;")
|
||||
time.sleep(15.50)
|
||||
@ -122,7 +142,7 @@ if __name__ == '__main__':
|
||||
data = codecs.decode(data, "utf-8", "ignore")
|
||||
ip = addr[0]
|
||||
port = addr[1]
|
||||
print('port: ', port, " ip: ", ip)
|
||||
#print('port: ', port, " ip: ", ip)
|
||||
if not data:
|
||||
continue
|
||||
if ip not in [local_ip, udp_external_ip]:
|
||||
@ -134,7 +154,7 @@ if __name__ == '__main__':
|
||||
time.sleep(0.5)
|
||||
resetCfgInputShortWait()
|
||||
time.sleep(0.2)
|
||||
print('data: ', data)
|
||||
#print('data: ', data)
|
||||
if data == "autismo connected":
|
||||
print('Bot connected!')
|
||||
time.sleep(2)
|
||||
|
@ -5,7 +5,6 @@
|
||||
#define PLUGIN_AUTHOR "jenz"
|
||||
#define PLUGIN_VERSION "1.3"
|
||||
#define generic_length 256
|
||||
#define rows_entry_cap 6
|
||||
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
@ -18,16 +17,13 @@ int targethuman = 0;
|
||||
int stuckcounterx = 0;
|
||||
int stuckcountery = 0;
|
||||
|
||||
//admins & vips
|
||||
int admins[MAXPLAYERS + 1];
|
||||
int vips[MAXPLAYERS + 1];
|
||||
|
||||
//socket for bot input
|
||||
Handle global_socket;
|
||||
|
||||
//bot input
|
||||
int row_counter = 0;
|
||||
char keyinput[rows_entry_cap][generic_length];
|
||||
float clientangles[rows_entry_cap][3];
|
||||
float xyz[rows_entry_cap][3];
|
||||
float target_human_original_coord[3];
|
||||
bool hunt_or_mimic;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
@ -76,8 +72,7 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
CreateTimer(0.2, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(0.5, socket_send_msg, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(0.3, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(10.0, bot_check_connect, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
}
|
||||
|
||||
@ -104,24 +99,25 @@ public Action bot_check_connect(Handle timer, any data)
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public Action socket_send_msg(Handle timer, any data)
|
||||
public Action recursive_pressing(Handle timer, any data)
|
||||
{
|
||||
if (IsValidClient(present) && IsPlayerAlive(present))
|
||||
{
|
||||
char message[generic_length * 7];
|
||||
int iterator = 0;
|
||||
int stuckcap = 12;
|
||||
int stuckX;
|
||||
int stuckY;
|
||||
float flVel[3];
|
||||
int stuckX = 0;
|
||||
int stuckY = 0;
|
||||
GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
float minvelocity = 40.0;
|
||||
char message[generic_length * 7];
|
||||
//stuckcounterx, stuckcountery
|
||||
float mincapvelocity = 40.0;
|
||||
GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
int stuckcap = 6;
|
||||
if (flVel[0] < mincapvelocity)
|
||||
{
|
||||
if (stuckcounterx >= stuckcap)
|
||||
{
|
||||
stuckX = 1;
|
||||
stuckcounterx = 0;
|
||||
stuckX = 1;
|
||||
}
|
||||
stuckcounterx++;
|
||||
}
|
||||
@ -129,37 +125,11 @@ public Action socket_send_msg(Handle timer, any data)
|
||||
{
|
||||
if (stuckcountery >= stuckcap)
|
||||
{
|
||||
stuckY = 1;
|
||||
stuckcountery = 0;
|
||||
stuckY = 1;
|
||||
}
|
||||
stuckcountery++;
|
||||
}
|
||||
while (iterator < row_counter)
|
||||
{
|
||||
char row[generic_length];
|
||||
if (xyz[iterator][0] != 0 || xyz[iterator][1] != 0 || xyz[iterator][2] != 0)
|
||||
{
|
||||
Format(row, sizeof(row), "keyinput: %s clientangles: %f %f %f xyz: %f %f %f hunt_or_mimic: %i stuckX: %i stuckY: %i \n", keyinput[iterator], clientangles[iterator][0], clientangles[iterator][1], clientangles[iterator][2], xyz[iterator][0], xyz[iterator][1], xyz[iterator][2], hunt_or_mimic, stuckX, stuckY);
|
||||
StrCat(message, sizeof(message), row);
|
||||
Format(keyinput[iterator], sizeof(keyinput), "");
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
clientangles[iterator][i] = 0.0;
|
||||
xyz[iterator][i] = 0.0;
|
||||
}
|
||||
}
|
||||
iterator++;
|
||||
}
|
||||
row_counter = 0;
|
||||
send_socket_msg(message, strlen(message));
|
||||
}
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public Action recursive_pressing(Handle timer, any data)
|
||||
{
|
||||
if (present && IsPlayerAlive(present))
|
||||
{
|
||||
float present_bot_coords[3];
|
||||
GetClientAbsOrigin(present, present_bot_coords);
|
||||
int targeteam = 0;
|
||||
@ -173,69 +143,112 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
//3 = autismo is human and should follow closest moving ct
|
||||
targeteam = 3;
|
||||
}
|
||||
if (!IsValidClient(targethuman) || GetClientTeam(targethuman) != targeteam || !IsPlayerAlive(targethuman))
|
||||
bool find_closest_match = true;
|
||||
float dist_target = 0.0;
|
||||
float distance_limit = 500.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]);
|
||||
dist_target = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
GetEntPropVector(targethuman, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
if (dist_target < distance_limit && flVel[0] > minvelocity && flVel[1] > minvelocity)
|
||||
find_closest_match = false;
|
||||
}
|
||||
if (find_closest_match)
|
||||
{
|
||||
hunt_or_mimic = false;
|
||||
float lowest_distance = 1000000.0;
|
||||
bool adminpresent = false;
|
||||
bool vippresent = false;
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
||||
{
|
||||
float flVel[3];
|
||||
float minvelocity = 40.0;
|
||||
GetEntPropVector(i, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
if (flVel[0] < minvelocity && flVel[1] < minvelocity)
|
||||
continue;
|
||||
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]);
|
||||
float dist = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
if (dist < lowest_distance)
|
||||
dist_target = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
|
||||
if (admins[i] == 1 && dist_target < distance_limit)
|
||||
{
|
||||
lowest_distance = dist;
|
||||
adminpresent = true;
|
||||
vippresent = false;
|
||||
}
|
||||
else if (vips[i] == 1 && !adminpresent && dist_target < distance_limit)
|
||||
{
|
||||
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] < minvelocity && flVel[1] < minvelocity)
|
||||
continue;
|
||||
|
||||
|
||||
if (dist_target < lowest_distance)
|
||||
{
|
||||
lowest_distance = dist_target;
|
||||
targethuman = i;
|
||||
}
|
||||
}
|
||||
if (IsValidClient(targethuman))
|
||||
GetClientAbsOrigin(targethuman, target_human_original_coord);
|
||||
}
|
||||
if (IsValidClient(targethuman))
|
||||
{
|
||||
if (!hunt_or_mimic)
|
||||
{
|
||||
int distance_limit = 50;
|
||||
float dx = present_bot_coords[0] - target_human_original_coord[0];
|
||||
float dy = present_bot_coords[1] - target_human_original_coord[1];
|
||||
float dz = FloatAbs(present_bot_coords[2] - target_human_original_coord[2]);
|
||||
float dist = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
//PrintToChatAll("dist: %f", dist);
|
||||
if (dist < distance_limit)
|
||||
hunt_or_mimic = true;
|
||||
xyz[row_counter][0] = dx;
|
||||
xyz[row_counter][1] = dy;
|
||||
xyz[row_counter][2] = dz;
|
||||
}
|
||||
float dx = 0.0;
|
||||
float dy = 0.0;
|
||||
float dz = 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);
|
||||
int keys = GetClientButtons(targethuman);
|
||||
if (keys & IN_FORWARD)
|
||||
Format(keyinput[row_counter], sizeof(keyinput[]), "-back; wait 5; +forward; wait 5; ");
|
||||
else if (keys & IN_BACK)
|
||||
Format(keyinput[row_counter], sizeof(keyinput[]), "-forward; wait 5; +back; wait 5; ");
|
||||
|
||||
if (keys & IN_MOVELEFT && StrContains(keyinput[row_counter], "moveleft", false) == -1)
|
||||
Format(keyinput[row_counter], sizeof(keyinput[]), "%s -moveright; wait 5; +moveleft; wait 5; ", keyinput[row_counter]);
|
||||
else if (keys & IN_MOVERIGHT && StrContains(keyinput[row_counter], "moveright", false) == -1)
|
||||
Format(keyinput[row_counter], sizeof(keyinput[]), "%s -moveleft; wait 5; +moveright; wait 5; ", keyinput[row_counter]);
|
||||
if (keys & IN_JUMP && StrContains(keyinput[row_counter], "jump", false) == -1)
|
||||
Format(keyinput[row_counter], sizeof(keyinput[]), "%s +jump; wait 5; ", keyinput[row_counter]);
|
||||
if (keys & IN_DUCK && StrContains(keyinput[row_counter], "duck", false) == -1)
|
||||
Format(keyinput[row_counter], sizeof(keyinput[]), "%s +duck; wait 5; ", keyinput[row_counter]);
|
||||
GetClientAbsAngles(targethuman, clientangles[row_counter]);
|
||||
char keyinput[generic_length * 2];
|
||||
int counter = 0;
|
||||
int countercap = 5;
|
||||
//check ladder = 0, water = 1, in air = 2
|
||||
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);
|
||||
//PrintToChatAll("targethuman: %N", targethuman);
|
||||
Format(message, sizeof(message), "keyinput: %s clientangles: %f %f %f xyz: %f %f %f stuckX: %i stuckY: %i dist_target: %f targethuman: %N bot_on_type: %i", keyinput, clientangles[0], clientangles[1], clientangles[2], dx, dy, dz, stuckX, stuckY, dist_target, targethuman, bot_on_type);
|
||||
send_socket_msg(message, strlen(message));
|
||||
}
|
||||
}
|
||||
if (row_counter < rows_entry_cap - 1)
|
||||
row_counter++;
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
@ -264,6 +277,10 @@ public void OnClientPostAdminCheck(int client)
|
||||
present = client;
|
||||
bot_send_connected_msg();
|
||||
}
|
||||
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
|
||||
admins[client] = 1;
|
||||
else if (CheckCommandAccess(client, "sm_reserved", ADMFLAG_RESERVATION))
|
||||
vips[client] = 1;
|
||||
}
|
||||
|
||||
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
||||
@ -284,6 +301,8 @@ public void OnClientDisconnect(int client)
|
||||
{
|
||||
present = 0;
|
||||
}
|
||||
admins[client] = 0;
|
||||
vips[client] = 0;
|
||||
}
|
||||
|
||||
public void bot_send_connected_msg()
|
||||
|
Loading…
Reference in New Issue
Block a user