primarily about the bot being able to kill hl2_linux and restarting it by itself
This commit is contained in:
parent
8aad46e08a
commit
d59b90c187
@ -5,6 +5,7 @@ import atexit
|
|||||||
from threading import Timer
|
from threading import Timer
|
||||||
import string
|
import string
|
||||||
import random
|
import random
|
||||||
|
import signal
|
||||||
import time
|
import time
|
||||||
import socket
|
import socket
|
||||||
import codecs
|
import codecs
|
||||||
@ -22,7 +23,7 @@ def resetCfgInputShortWait():
|
|||||||
str = "wait 5; "
|
str = "wait 5; "
|
||||||
with open(looptestPath, 'w') as f:
|
with open(looptestPath, 'w') as f:
|
||||||
f.write(str)
|
f.write(str)
|
||||||
time.sleep(0.5)
|
time.sleep(0.2)
|
||||||
|
|
||||||
def exit_handler():
|
def exit_handler():
|
||||||
print('reached exithandler')
|
print('reached exithandler')
|
||||||
@ -82,8 +83,8 @@ def bot_process_movement(input_line):
|
|||||||
bot_stuck = int(bot_stuck)
|
bot_stuck = int(bot_stuck)
|
||||||
targeteam = int(targeteam)
|
targeteam = int(targeteam)
|
||||||
#maybe 0.8 instead
|
#maybe 0.8 instead
|
||||||
min_distance_target_human = 1.6
|
min_distance_target_human = 0.1
|
||||||
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; +forward; wait 2; "
|
||||||
if bot_stuck:
|
if bot_stuck:
|
||||||
print('bot stuck')
|
print('bot stuck')
|
||||||
strInput += "+jump; wait 5; +duck; wait 5; -jump; wait 15; -duck; wait 3;"
|
strInput += "+jump; wait 5; +duck; wait 5; -jump; wait 15; -duck; wait 3;"
|
||||||
@ -96,12 +97,11 @@ def bot_process_movement(input_line):
|
|||||||
global ladder_counter
|
global ladder_counter
|
||||||
if bot_on_type == 0 and ladder_counter < 100:
|
if bot_on_type == 0 and ladder_counter < 100:
|
||||||
print('bot_on_type ladder, ladder_counter: ', ladder_counter)
|
print('bot_on_type ladder, ladder_counter: ', ladder_counter)
|
||||||
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;"
|
strInput += "setang -90 0 0; wait 5; -back; wait 3; -moveleft; wait 3; -moveright; wait 5; -jump; wait 3; -duck; wait 3; "
|
||||||
ladder_counter += 1
|
ladder_counter += 1
|
||||||
elif bot_on_type == 2:
|
elif bot_on_type == 2:
|
||||||
print('bot surfing')
|
print('bot surfing')
|
||||||
else:
|
else:
|
||||||
strInput += "-moveright; wait 3; -moveleft; wait 3;"
|
|
||||||
ladder_counter = 0
|
ladder_counter = 0
|
||||||
min_enemy_distance = 100.0
|
min_enemy_distance = 100.0
|
||||||
if bot_on_type == 1 or bot_on_type == 3:
|
if bot_on_type == 1 or bot_on_type == 3:
|
||||||
@ -111,16 +111,10 @@ def bot_process_movement(input_line):
|
|||||||
if message_counter > 10:
|
if message_counter > 10:
|
||||||
print('target human: ', targethuman, ' dist_target: ', dist_target, ' enemy distance: ', enemy_distance)
|
print('target human: ', targethuman, ' dist_target: ', dist_target, ' enemy distance: ', enemy_distance)
|
||||||
message_counter = 0
|
message_counter = 0
|
||||||
if enemy_distance < 0 or dist_target > min_distance_target_human or enemy_distance < min_enemy_distance or targeteam == 2:
|
strInput = strinput_append(strInput, 2)
|
||||||
strInput += "+forward; wait 5; "
|
|
||||||
strInput = strinput_append(strInput, 1)
|
|
||||||
else:
|
|
||||||
strInput += "-forward; wait 5;"
|
|
||||||
print('-forward!')
|
|
||||||
|
|
||||||
#print('strInput final:', strInput)
|
#print('strInput final:', strInput)
|
||||||
writeCfgInput(strInput)
|
writeCfgInput(strInput)
|
||||||
time.sleep(0.2)
|
time.sleep(0.4)
|
||||||
writeCfgInput("wait 5;")
|
writeCfgInput("wait 5;")
|
||||||
|
|
||||||
def strinput_append(strInput, nth):
|
def strinput_append(strInput, nth):
|
||||||
@ -132,6 +126,18 @@ def strinput_append(strInput, nth):
|
|||||||
strInput += "+moveright; wait 15; -moveright; "
|
strInput += "+moveright; wait 15; -moveright; "
|
||||||
return strInput
|
return strInput
|
||||||
|
|
||||||
|
def kill_css_process():
|
||||||
|
css_pid = subprocess.getoutput(["pidof hl2_linux"])
|
||||||
|
if css_pid:
|
||||||
|
print('css_pid: ', css_pid, 'shutting the bots game down....')
|
||||||
|
css_pid = int(css_pid.strip())
|
||||||
|
os.kill(css_pid, signal.SIGTERM)
|
||||||
|
time.sleep(15)
|
||||||
|
print('preparing to launch game....')
|
||||||
|
os.chdir('/home/gameservers/.steam/debian-installation/')
|
||||||
|
subprocess.check_call("./steam.sh %s" % ("-applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi +exec looptest.cfg"), shell=True)
|
||||||
|
print('finished starting game')
|
||||||
|
|
||||||
def bot_connect_ze():
|
def bot_connect_ze():
|
||||||
#use whatever ip you want here to connect with
|
#use whatever ip you want here to connect with
|
||||||
strdev = "connect 151.80.230.149:27019/test132;"
|
strdev = "connect 151.80.230.149:27019/test132;"
|
||||||
@ -139,7 +145,6 @@ def bot_connect_ze():
|
|||||||
writeCfgInput(str1)
|
writeCfgInput(str1)
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
writeCfgInput("wait 5;")
|
writeCfgInput("wait 5;")
|
||||||
time.sleep(15.50)
|
|
||||||
print('not yet connected')
|
print('not yet connected')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -149,6 +154,7 @@ if __name__ == '__main__':
|
|||||||
local_port = 48477
|
local_port = 48477
|
||||||
udp_external_ip = "62.210.110.245"
|
udp_external_ip = "62.210.110.245"
|
||||||
buffer_size = 4096 #potentially not large enough?
|
buffer_size = 4096 #potentially not large enough?
|
||||||
|
connection_issue_counter = 0;
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock_external:
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock_external:
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
@ -172,13 +178,17 @@ if __name__ == '__main__':
|
|||||||
writeCfgInput(response_msg)
|
writeCfgInput(response_msg)
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
resetCfgInputShortWait()
|
resetCfgInputShortWait()
|
||||||
time.sleep(0.2)
|
|
||||||
#print('data: ', data)
|
#print('data: ', data)
|
||||||
if data == "autismo connected":
|
if data == "autismo connected":
|
||||||
print('Bot connected!')
|
print('Bot connected!')
|
||||||
|
connection_issue_counter = 0
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
joinTeam()
|
joinTeam()
|
||||||
elif data == "connect to ze":
|
elif data == "connect to ze":
|
||||||
|
if connection_issue_counter == 5:
|
||||||
|
kill_css_process()
|
||||||
|
connection_issue_counter += 1
|
||||||
|
print('connection_issue_counter: ', connection_issue_counter)
|
||||||
bot_connect_ze()
|
bot_connect_ze()
|
||||||
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))
|
||||||
|
@ -180,7 +180,8 @@ public Action permitStuck(Handle timer, any data)
|
|||||||
|
|
||||||
public void OnMapStart()
|
public void OnMapStart()
|
||||||
{
|
{
|
||||||
CreateTimer(0.2, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
//0.2
|
||||||
|
CreateTimer(0.5, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||||
CreateTimer(1.0, clients_coordinates, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
CreateTimer(1.0, clients_coordinates, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||||
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);
|
||||||
}
|
}
|
||||||
@ -242,7 +243,7 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
|
|||||||
Format(keyinput, sizeof(keyinput), "keyinput: %s dist_target: %f", keyinput, dist_target);
|
Format(keyinput, sizeof(keyinput), "keyinput: %s dist_target: %f", keyinput, dist_target);
|
||||||
send_socket_msg(keyinput, strlen(keyinput));
|
send_socket_msg(keyinput, strlen(keyinput));
|
||||||
cmdpost_run_cooldown = true;
|
cmdpost_run_cooldown = true;
|
||||||
CreateTimer(0.5, runcmd_cooldown);
|
CreateTimer(0.25, runcmd_cooldown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,8 +253,19 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
|
|||||||
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP) && !(buttons & IN_JUMP))
|
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP) && !(buttons & IN_JUMP))
|
||||||
{
|
{
|
||||||
float Vel[3];
|
float Vel[3];
|
||||||
|
float velocity_addition_z_axis = 300.0;
|
||||||
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
|
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
|
||||||
Vel[2] += 300.0;
|
if (IsValidClient(targethuman))
|
||||||
|
{
|
||||||
|
//TODO maybe?
|
||||||
|
GetEntPropVector(present, Prop_Send, "m_vecOrigin", bot_old_coords);
|
||||||
|
if (client_old_coords[targethuman][2] != bot_old_coords[2])
|
||||||
|
{
|
||||||
|
Vel[0] -= velocity_addition_z_axis / 10;
|
||||||
|
Vel[1] -= velocity_addition_z_axis / 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Vel[2] += velocity_addition_z_axis;
|
||||||
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel);
|
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel);
|
||||||
}
|
}
|
||||||
buttons_old = buttons;
|
buttons_old = buttons;
|
||||||
@ -311,7 +323,7 @@ public Action recursive_pressing(Handle timer, any data)
|
|||||||
{
|
{
|
||||||
face_call(targethuman);
|
face_call(targethuman);
|
||||||
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 || admins[targethuman] || vips[targethuman])
|
||||||
{
|
{
|
||||||
face_call(targethuman);
|
face_call(targethuman);
|
||||||
find_closest_match = IsAbleToSee(present, targethuman) ? false : true;
|
find_closest_match = IsAbleToSee(present, targethuman) ? false : true;
|
||||||
@ -339,12 +351,11 @@ public Action recursive_pressing(Handle timer, any data)
|
|||||||
float min_enemy_distance = 100.0;
|
float min_enemy_distance = 100.0;
|
||||||
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
|
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
|
||||||
enemy_distance = get_power_distance(present, 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 = 1.6;
|
|
||||||
//human aiming for zombie
|
//human aiming for zombie
|
||||||
if (targeteam == 3)
|
if (targeteam == 3)
|
||||||
{
|
{
|
||||||
if (dist_target > 0 && dist_target < min_distance_target_human && enemy_distance > min_enemy_distance)
|
float min_distance_target_human = 0.1;
|
||||||
|
if (0 < dist_target <= min_distance_target_human && enemy_distance > min_enemy_distance)
|
||||||
{
|
{
|
||||||
chasing_enemy = true;
|
chasing_enemy = true;
|
||||||
face_call(target_enemy);
|
face_call(target_enemy);
|
||||||
@ -367,9 +378,11 @@ public Action recursive_pressing(Handle timer, any data)
|
|||||||
if (round_start_stuck)
|
if (round_start_stuck)
|
||||||
bot_stuck = is_bot_stuck();
|
bot_stuck = is_bot_stuck();
|
||||||
}
|
}
|
||||||
//TODO in some cases prevent bot from jumping over edge
|
//TODO in some cases crouch under obstacles or jump more? maybe trace raying all obstacles, maybe use TR_GetPlaneNormal
|
||||||
|
//make this replace is_bot_stuck() probably
|
||||||
|
//crouch_or_jump = 0: nothing. crouch_or_jump = 1: crouch. crouch_or_jump = 2: jump.
|
||||||
|
int crouch_or_jump = trace_geometry();
|
||||||
|
|
||||||
//TODO in some cases crouch under obstacles? maybe trace raying all
|
|
||||||
if (bot_on_type != 2)
|
if (bot_on_type != 2)
|
||||||
{
|
{
|
||||||
if (IsValidClient(targethuman))
|
if (IsValidClient(targethuman))
|
||||||
@ -382,6 +395,20 @@ public Action recursive_pressing(Handle timer, any data)
|
|||||||
return Plugin_Continue;
|
return Plugin_Continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int trace_geometry()
|
||||||
|
{
|
||||||
|
float vPos[3];
|
||||||
|
float angles[3];
|
||||||
|
//GetClientEyeAngles(client, angles);
|
||||||
|
GetEntPropVector(present, Prop_Data, "m_vecOrigin", vPos);
|
||||||
|
TR_TraceRay(vPos, angles, MASK_PLAYERSOLID_BRUSHONLY, RayType_Infinite);
|
||||||
|
if (TR_DidHit())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
public void check_bot_surfing()
|
public void check_bot_surfing()
|
||||||
{
|
{
|
||||||
float vPos[3];
|
float vPos[3];
|
||||||
@ -573,6 +600,16 @@ public int GetClosestClient_option1(int entity, int targeteam)
|
|||||||
bool vippresent = false;
|
bool vippresent = false;
|
||||||
float nearestdistance = -1.0;
|
float nearestdistance = -1.0;
|
||||||
int nearest = -1;
|
int nearest = -1;
|
||||||
|
int priority_targets[MAXPLAYERS + 1];
|
||||||
|
int targets = 0;
|
||||||
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
|
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
||||||
|
if (admins[i] || vips[i])
|
||||||
|
{
|
||||||
|
priority_targets[targets] = i;
|
||||||
|
targets++;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 1; i <= MaxClients; i++)
|
for (int i = 1; i <= MaxClients; i++)
|
||||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
||||||
{
|
{
|
||||||
@ -602,6 +639,16 @@ public int GetClosestClient_option1(int entity, int targeteam)
|
|||||||
float pos[3];
|
float pos[3];
|
||||||
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
|
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
|
||||||
float dist_target = get_power_distance(entity, pos);
|
float dist_target = get_power_distance(entity, pos);
|
||||||
|
//focuses on group of priority to determine while still ignoring non vip/admins
|
||||||
|
if (admins[i] || vips[i])
|
||||||
|
{
|
||||||
|
for (int j = 0; j <= targets; j++)
|
||||||
|
{
|
||||||
|
float pos_priority[3];
|
||||||
|
GetEntPropVector(priority_targets[j], Prop_Send, "m_vecOrigin", pos_priority);
|
||||||
|
dist_target += get_power_distance(i, pos_priority);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (nearestdistance < 0 || dist_target < nearestdistance)
|
if (nearestdistance < 0 || dist_target < nearestdistance)
|
||||||
{
|
{
|
||||||
nearest = i;
|
nearest = i;
|
||||||
@ -617,7 +664,7 @@ public float get_power_distance(int target_player, float [3]pos)
|
|||||||
GetClientAbsOrigin(target_player, vec);
|
GetClientAbsOrigin(target_player, vec);
|
||||||
float x_axis = 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 y_axis = Pow(vec[1] - pos[1], 2.0);
|
||||||
float z_axis = FloatAbs(Pow(vec[2] - pos[2], 3.0));
|
float z_axis = FloatAbs(Pow(vec[2] - pos[2], 1.4));
|
||||||
float power_distance = SquareRoot(x_axis * x_axis + y_axis * y_axis + z_axis * z_axis);
|
float power_distance = SquareRoot(x_axis * x_axis + y_axis * y_axis + z_axis * z_axis);
|
||||||
float defaultcap = 1000.0;
|
float defaultcap = 1000.0;
|
||||||
return power_distance / defaultcap;
|
return power_distance / defaultcap;
|
||||||
|
Loading…
Reference in New Issue
Block a user