further adjustsment to targeting, handling teleports, distance and ray tracing

This commit is contained in:
jenzur 2020-07-25 00:50:00 +02:00
parent 121301cd54
commit 45f8a4c480
2 changed files with 98 additions and 65 deletions

View File

@ -12,6 +12,7 @@ import codecs
looptestPath = '/home/gameservers/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg'
chatmsg = ""
ladder_counter = 0
message_counter = 0
def writeCfgInput(Input):
with open(looptestPath, 'w') as f:
@ -47,6 +48,8 @@ def bot_process_keyinput(input_line):
writeCfgInput("wait 5;")
def bot_process_movement(input_line):
global message_counter
message_counter += 1
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:"):input_line.index("enemy_distance:")]
@ -83,15 +86,17 @@ def bot_process_movement(input_line):
if bot_on_type == 1:
print('bot_on_type water')
strInput += "+jump; wait 5;"
if message_counter > 10:
print('target human: ', targethuman, ' dist_target: ', dist_target, ' enemy distance: ', enemy_distance)
message_counter = 0
if enemy_distance < 0 or dist_target > min_distance_target_human or targeteam == 2:
strInput += "+forward; wait 5; "
for _ in range(10):
boolean_val = random.choice([True, False])
for _ in range(10):
if boolean_val:
strInput += "+moveleft; wait 5; -moveleft; wait 5; "
strInput += "+moveleft; wait 15; -moveleft; "
else:
strInput += "+moveright; wait 5; -moveright; wait 5; "
strInput += "+moveright; wait 15; -moveright; "
else:
strInput += "-forward; wait 5;"

View File

@ -13,12 +13,12 @@
//#pragma newdecls required
int present = 0;
int targethuman = 0;
int bot_mini_count_stucker = 0;
int client_mini_stuck_counter[MAXPLAYERS + 1];
bool round_start_stuck = false;
float bot_old_coords[3];
bool bot_stuck_g = false;
float client_old_coords[MAXPLAYERS + 1][3];
bool face_teleporter = false;
float bot_presumed_endpoint[3];
//admins & vips
bool admins[MAXPLAYERS + 1];
@ -50,6 +50,11 @@ public void OnPluginStart()
SocketBind(socket, "127.0.0.1", 48475);
connect(socket);
global_socket = socket;
targethuman = 0;
bot_presumed_endpoint[0] = 0.0;
bot_presumed_endpoint[1] = 0.0;
bot_presumed_endpoint[2] = 0.0;
}
public Action cmd_talk(int client, int args)
@ -70,9 +75,11 @@ public Action cmd_talk(int client, int args)
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
round_start_stuck = false;
face_teleporter = false;
targethuman = 0;
bot_mini_count_stucker = 0;
bot_stuck_g = false;
bot_presumed_endpoint[0] = 0.0;
bot_presumed_endpoint[1] = 0.0;
bot_presumed_endpoint[2] = 0.0;
CreateTimer(7.0, permitStuck);
}
@ -82,10 +89,18 @@ public Action permitStuck(Handle timer, any data)
return Plugin_Continue;
}
public Action bot_reached_endpoint(Handle timer, any data)
{
bot_presumed_endpoint[0] = 0.0;
bot_presumed_endpoint[1] = 0.0;
bot_presumed_endpoint[2] = 0.0;
return Plugin_Continue;
}
public void OnMapStart()
{
CreateTimer(0.2, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
CreateTimer(2.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);
}
@ -93,17 +108,12 @@ public Action clients_coordinates(Handle timer, any data)
{
if (IsValidClient(present) && IsPlayerAlive(present))
{
int min_cap = 5;
int min_cap = 15;
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && IsPlayerAlive(i) && i != present && client_mini_stuck_counter[i] < min_cap)
GetEntPropVector(i, Prop_Send, "m_vecOrigin", client_old_coords[i]);
if (bot_mini_count_stucker < min_cap)
if (!bot_stuck_g)
GetEntPropVector(present, Prop_Send, "m_vecOrigin", bot_old_coords);
if (face_teleporter)
if (IsValidClient(targethuman))
face_teleporter = get_power_distance(targethuman, client_old_coords[targethuman]) <= 1.0 ? false : true;
else
face_teleporter = false;
}
return Plugin_Continue;
}
@ -133,7 +143,8 @@ public bool TraceRayable(int client, int target)
GetClientEyePosition(client, pos_client);
GetClientEyePosition(target, pos_target);
Handle trace = TR_TraceRayFilterEx(pos_client, pos_target, MASK_NPCSOLID, RayType_EndPoint, FilterClient, client);
//Handle trace = TR_TraceRayFilterEx(pos_client, pos_target, MASK_NPCSOLID, RayType_EndPoint, FilterClient, client);
Handle trace = TR_TraceRayFilterEx(pos_client, pos_target, MASK_VISIBLE, RayType_EndPoint, FilterClient, client);
if (TR_DidHit(trace))
{
if(TR_GetEntityIndex(trace) == target)
@ -162,7 +173,7 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
float pos[3];
GetEntPropVector(present, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(targethuman, pos);
float dist_cap = 3.0;
float dist_cap = 15.0;
if (dist_target <= dist_cap)
{
Format(keyinput, sizeof(keyinput), "keyinput: %s dist_target: %f", keyinput, dist_target);
@ -191,28 +202,52 @@ public Action recursive_pressing(Handle timer, any data)
targeteam = 3;
}
bool find_closest_match = true;
bool bot_stuck = false;
if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman))
{
if (bot_presumed_endpoint[0] != 0.0)
{
find_closest_match = false;
float ClientPos[3];
float Result[3];
float min_distance = 0.2;
GetClientEyePosition(present, ClientPos);
MakeVectorFromPoints(ClientPos, bot_presumed_endpoint, Result);
GetVectorAngles(Result, Result);
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
bot_stuck = is_bot_stuck();
float dist_target = get_power_distance(present, bot_presumed_endpoint);
if (dist_target <= min_distance)
{
bot_presumed_endpoint[0] = 0.0;
bot_presumed_endpoint[1] = 0.0;
bot_presumed_endpoint[2] = 0.0;
}
}
else
{
find_closest_match = is_client_stuck_or_afk(targethuman);
if (!find_closest_match)
{
int iterator_counter = 0;
while (iterator_counter < 10 && find_closest_match)
{
face_call(targethuman);
find_closest_match = TraceRayable(present, targethuman) ? false : true;
iterator_counter++;
}
if (find_closest_match)
{
//check for targethuman entering teleport maybe good enough as this
float dist_target = get_power_distance(targethuman, client_old_coords[targethuman]);
float min_required_distance = 850.0;
float min_required_distance = 1500.0;
if (dist_target > min_required_distance)
{
bot_presumed_endpoint[0] = client_old_coords[targethuman][0];
bot_presumed_endpoint[1] = client_old_coords[targethuman][1];
bot_presumed_endpoint[2] = client_old_coords[targethuman][2];
find_closest_match = false;
face_teleporter = true;
float ClientPos[3];
float Result[3];
GetClientEyePosition(present, ClientPos);
MakeVectorFromPoints(ClientPos, client_old_coords[targethuman], Result);
GetVectorAngles(Result, Result);
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
CreateTimer(6.0, bot_reached_endpoint);
}
}
}
}
@ -222,8 +257,8 @@ public Action recursive_pressing(Handle timer, any data)
if (IsValidClient(targethuman))
{
float pos[3];
GetEntPropVector(present, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(targethuman, pos);
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(present, pos);
float enemy_distance = -1.0;
//check ladder = 0, water = 1, in air(surfing) = 2 TODO
int bot_on_type = -1;
@ -232,15 +267,15 @@ public Action recursive_pressing(Handle timer, any data)
int ilevel = GetEntProp(present, Prop_Data, "m_nWaterLevel");
if (ilevel >= 2)
bot_on_type = 1;
bool bot_stuck = false;
if (bot_on_type != 0 && bot_on_type != 2)
if (bot_on_type != 0 && bot_on_type != 2 && bot_presumed_endpoint[0] == 0.0)
{
int target_enemy = find_closest_enemy(present, targeteam);
if (IsValidClient(target_enemy))
{
float min_distance_target_human = 2.0;
float min_enemy_distance = 100.0;
enemy_distance = get_power_distance(target_enemy, pos);
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
enemy_distance = get_power_distance(present, pos);
//human aiming for zombie
if (targeteam == 3 && dist_target < min_distance_target_human && enemy_distance > min_enemy_distance)
face_call(target_enemy);
@ -254,12 +289,9 @@ public Action recursive_pressing(Handle timer, any data)
else
face_call(targethuman);
if (round_start_stuck)
{
bot_stuck = is_bot_stuck();
if (bot_stuck)
bot_mini_count_stucker = 0;
}
}
//TODO detect gaps and jump perfectly over them
Format(message, sizeof(message), "dist_target: %f targethuman: %N bot_on_type: %i enemy_distance: %f bot_stuck: %i targeteam: %i", dist_target, targethuman, bot_on_type, enemy_distance, bot_stuck, targeteam);
send_socket_msg(message, strlen(message));
}
@ -269,17 +301,14 @@ public Action recursive_pressing(Handle timer, any data)
public bool is_bot_stuck()
{
float min_distance_cap = 5.0;
int min_cap = 5;
float min_distance_cap = 0.05;
float bot_own_distance = get_power_distance(present, bot_old_coords);
if (bot_own_distance < min_distance_cap)
bot_mini_count_stucker++;
return bot_mini_count_stucker > min_cap;
bot_stuck_g = bot_own_distance < min_distance_cap;
return bot_stuck_g;
}
public void face_call(int client)
{
if (!face_teleporter)
for (int j = 0; j < 5; j++)
faceclient(client);
}
@ -308,8 +337,8 @@ stock bool IsValidClient(int client)
stock bool is_client_stuck_or_afk(int client)
{
float min_distance_cap = 2.5;
int min_cap = 5;
float min_distance_cap = 0.05;
int min_cap = 15;
float client_own_distance = get_power_distance(client, client_old_coords[client]);
if (client_own_distance < min_distance_cap)
client_mini_stuck_counter[client]++;
@ -323,11 +352,12 @@ 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);
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(entity, pos);
bool traceable = false;
face_call(i);
if (TraceRayable(present, i))
@ -349,10 +379,8 @@ public int GetClosestClient_option1(int entity, int targeteam)
{
bool adminpresent = false;
bool vippresent = false;
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)
{
@ -362,12 +390,12 @@ public int GetClosestClient_option1(int entity, int targeteam)
traceable = true;
if (is_client_stuck_or_afk(i))
continue;
if (admins[i] && traceable)
if (admins[i])
{
adminpresent = true;
vippresent = false;
}
else if (vips[i] && !adminpresent && traceable)
else if (vips[i] && !adminpresent)
{
vippresent = true;
}
@ -381,9 +409,11 @@ public int GetClosestClient_option1(int entity, int targeteam)
if (!vips[i])
continue;
}
float dist_target = get_power_distance(i, pos);
float pos[3];
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(entity, pos);
if (!traceable)
dist_target = dist_target * dist_target;
continue;
if (nearestdistance < 0 || dist_target < nearestdistance)
{
nearest = i;
@ -407,9 +437,7 @@ public float get_power_distance(int target_player, float [3]pos)
public bool FilterClient(int entity, int contentsMask, int client)
{
if (entity == client)
return false;
return true;
return (entity != client && 1 <= client <= MaxClients || !IsClientInGame(client));
}
public void OnClientPostAdminCheck(int client)