minor surf changes and targeting
This commit is contained in:
parent
cf08a56abf
commit
8aad46e08a
@ -34,17 +34,37 @@ def joinTeam():
|
||||
time.sleep(4.5)
|
||||
print('jointeam func: ')
|
||||
|
||||
def bot_process_surf(input_line):
|
||||
bot_surf_plane = input_line[input_line.index("surfing:") + len("surfing:"):]
|
||||
bot_surf_plane = bot_surf_plane.strip()
|
||||
bot_surf_plane = [float(i.replace('\U00002013', '-')) for i in bot_surf_plane.split(' ')]
|
||||
#X axis positive = hold A
|
||||
#X axis negative = hold D
|
||||
#if Y axis = 0.0 use X instead
|
||||
#Y axis negative = hold A
|
||||
#Y axis positive = hold D
|
||||
strInput = "-forward; wait 3; "
|
||||
if bot_surf_plane[1] < 0.0:
|
||||
strInput += "+moveleft; wait 3; "
|
||||
elif bot_surf_plane[1] > 0.0:
|
||||
strInput += "+moveright; wait 3;"
|
||||
elif bot_surf_plane[0] < 0.0:
|
||||
strInput += "+moveleft; wait 3; "
|
||||
elif bot_surf_plane[0] > 0.0:
|
||||
strInput += "+moveright; wait 3; "
|
||||
print('bot surfing bot_surf_plane: ', bot_surf_plane)
|
||||
writeCfgInput(strInput)
|
||||
time.sleep(0.3)
|
||||
writeCfgInput("wait 5;")
|
||||
|
||||
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 = ""
|
||||
for _ in range(2):
|
||||
strInput += f"""{movement_input}; wait 5; """
|
||||
strInput += "-jump; wait 5; -duck; wait 5;"
|
||||
strInput = f"""{movement_input}; wait 5; -jump; wait 5; -duck; wait 5; """
|
||||
writeCfgInput(strInput)
|
||||
print('dist_target: ', dist_target, ' movement strinput: ', strInput)
|
||||
time.sleep(0.2)
|
||||
time.sleep(0.3)
|
||||
writeCfgInput("wait 5;")
|
||||
|
||||
def bot_process_movement(input_line):
|
||||
@ -61,11 +81,12 @@ def bot_process_movement(input_line):
|
||||
bot_on_type = int(bot_on_type)
|
||||
bot_stuck = int(bot_stuck)
|
||||
targeteam = int(targeteam)
|
||||
min_distance_target_human = 0.8
|
||||
#maybe 0.8 instead
|
||||
min_distance_target_human = 1.6
|
||||
strInput = "-attack; wait 2; -use; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; "
|
||||
if bot_stuck:
|
||||
print('bot stuck')
|
||||
strInput += "+jump; wait 15; +duck; wait 15; -jump; wait 15; -duck; wait 3;"
|
||||
strInput += "+jump; wait 5; +duck; wait 5; -jump; wait 15; -duck; wait 3;"
|
||||
if dist_target > min_distance_target_human:
|
||||
strInput += "use weapon_elite; wait 3; "
|
||||
elif targeteam == 3:
|
||||
@ -79,14 +100,13 @@ def bot_process_movement(input_line):
|
||||
ladder_counter += 1
|
||||
elif bot_on_type == 2:
|
||||
print('bot surfing')
|
||||
strInput += "-forward; wait 3;"
|
||||
strInput = strinput_append(strInput, 10)
|
||||
else:
|
||||
strInput += "-moveright; wait 3; -moveleft; wait 3;"
|
||||
ladder_counter = 0
|
||||
min_enemy_distance = 100.0
|
||||
if bot_on_type == 1 or bot_on_type == 3:
|
||||
print('bot_on_type 1 = water | 3 = downhill: ', bot_on_type)
|
||||
for _ in range(10):
|
||||
for _ in range(5):
|
||||
strInput += "+jump; wait 5;"
|
||||
if message_counter > 10:
|
||||
print('target human: ', targethuman, ' dist_target: ', dist_target, ' enemy distance: ', enemy_distance)
|
||||
@ -165,6 +185,8 @@ if __name__ == '__main__':
|
||||
print('sent databyte: ', databyte)
|
||||
elif data.startswith("dist_target:"):
|
||||
bot_process_movement(data)
|
||||
elif data.startswith("surfing:"):
|
||||
bot_process_surf(data)
|
||||
elif data.startswith("keyinput:"):
|
||||
bot_process_keyinput(data)
|
||||
except KeyboardInterrupt:
|
||||
|
@ -3,7 +3,7 @@
|
||||
#define DEBUG
|
||||
|
||||
#define PLUGIN_AUTHOR "jenz"
|
||||
#define PLUGIN_VERSION "1.3"
|
||||
#define PLUGIN_VERSION "1.4"
|
||||
#define generic_length 256
|
||||
|
||||
#include <sourcemod>
|
||||
@ -17,17 +17,18 @@ int present = 0;
|
||||
int targethuman = 0;
|
||||
int buttons_old;
|
||||
int flags_old;
|
||||
bool client_stuck_g[MAXPLAYERS + 1];
|
||||
bool round_start_stuck = false;
|
||||
int surf_delay = 0;
|
||||
float bot_old_coords[3];
|
||||
bool bot_stuck_g = false;
|
||||
float client_old_coords[MAXPLAYERS + 1][3];
|
||||
float targethuman_teleported[3];
|
||||
float g_vCurrent[3];
|
||||
float g_vLast[3];
|
||||
bool g_bOnGround[MAXPLAYERS + 1];
|
||||
bool g_bLastOnGround[MAXPLAYERS + 1];
|
||||
float g_vCurrent[MAXPLAYERS + 1][3];
|
||||
float g_vLast[MAXPLAYERS + 1][3];
|
||||
bool client_stuck_g[MAXPLAYERS + 1];
|
||||
bool round_start_stuck = false;
|
||||
bool cmdpost_run_cooldown = false;
|
||||
bool bot_surf_plane = false;
|
||||
|
||||
//admins & vips
|
||||
bool admins[MAXPLAYERS + 1];
|
||||
@ -65,7 +66,9 @@ public void OnPluginStart()
|
||||
global_socket = socket;
|
||||
round_start_stuck = true;
|
||||
cmdpost_run_cooldown = false;
|
||||
bot_surf_plane = false;
|
||||
reset_target_human_tp_coord();
|
||||
reset_bot_old_coords();
|
||||
targethuman = 0;
|
||||
}
|
||||
|
||||
@ -80,7 +83,10 @@ public void trigger_teleport(const char[] output, int entity_index, int client,
|
||||
{
|
||||
if (IsValidEdict(entity_index))
|
||||
if (IsValidClient(targethuman) && client == targethuman)
|
||||
{
|
||||
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported);
|
||||
CreateTimer(6.0, reset_target_tp);
|
||||
}
|
||||
else if (IsValidClient(present) && client == present)
|
||||
CreateTimer(0.1, reset_target_tp);
|
||||
}
|
||||
@ -92,7 +98,10 @@ public void Trigger_Multiple(const char[] output, int entity_index, int client,
|
||||
if (IsValidClient(targethuman) && client == targethuman)
|
||||
{
|
||||
if (origin_command_check(entity_index))
|
||||
{
|
||||
GetEntPropVector(client, Prop_Send, "m_vecOrigin", targethuman_teleported);
|
||||
CreateTimer(6.0, reset_target_tp);
|
||||
}
|
||||
}
|
||||
else if (IsValidClient(present) && client == present)
|
||||
{
|
||||
@ -132,7 +141,7 @@ public Action reset_target_tp(Handle timer, any data)
|
||||
public bool distance_check()
|
||||
{
|
||||
float dist_target = get_power_distance(present, targethuman_teleported);
|
||||
float min_required_distance = 800.0;
|
||||
float min_required_distance = 500.0;
|
||||
if (dist_target > min_required_distance)
|
||||
return false;
|
||||
return true;
|
||||
@ -157,8 +166,8 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast
|
||||
{
|
||||
round_start_stuck = false;
|
||||
targethuman = 0;
|
||||
bot_stuck_g = false;
|
||||
cmdpost_run_cooldown = false;
|
||||
bot_surf_plane = false;
|
||||
reset_target_human_tp_coord();
|
||||
CreateTimer(7.0, permitStuck);
|
||||
}
|
||||
@ -183,8 +192,6 @@ public Action clients_coordinates(Handle timer, any data)
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && i != present && !client_stuck_g[i])
|
||||
GetEntPropVector(i, Prop_Send, "m_vecOrigin", client_old_coords[i]);
|
||||
if (!bot_stuck_g)
|
||||
GetEntPropVector(present, Prop_Send, "m_vecOrigin", bot_old_coords);
|
||||
}
|
||||
return Plugin_Continue;
|
||||
}
|
||||
@ -205,7 +212,7 @@ public Action bot_check_connect(Handle timer, any data)
|
||||
send_socket_msg(msg, strlen(msg));
|
||||
}
|
||||
else if (IsValidClient(present) && GetClientCount(false) >= 63)
|
||||
KickClient(present);
|
||||
KickClient(present, "server full you need to leave");
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
@ -235,22 +242,23 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
|
||||
Format(keyinput, sizeof(keyinput), "keyinput: %s dist_target: %f", keyinput, dist_target);
|
||||
send_socket_msg(keyinput, strlen(keyinput));
|
||||
cmdpost_run_cooldown = true;
|
||||
CreateTimer(1.0, runcmd_cooldown);
|
||||
CreateTimer(0.5, runcmd_cooldown);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (client == present)
|
||||
{
|
||||
int flags = GetEntityFlags(client);
|
||||
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP))
|
||||
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP) && !(buttons & IN_JUMP))
|
||||
{
|
||||
float Vel[3];
|
||||
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
|
||||
Vel[2] = 300.0;
|
||||
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
|
||||
Vel[2] += 300.0;
|
||||
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel);
|
||||
}
|
||||
buttons_old = buttons;
|
||||
flags_old = flags;
|
||||
check_bot_surfing();
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,8 +290,10 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
int ilevel = GetEntProp(present, Prop_Data, "m_nWaterLevel");
|
||||
if (ilevel >= 2)
|
||||
bot_on_type = 1;
|
||||
if (bot_surf_plane)
|
||||
bot_on_type = 2;
|
||||
if (bot_on_type == -1)
|
||||
bot_on_type = check_bot_surfing_or_downhill();
|
||||
bot_on_type = check_bot_downhill();
|
||||
if (targethuman_teleported[0] != 0.0)
|
||||
{
|
||||
bot_on_type = 4;
|
||||
@ -296,7 +306,8 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
if (!distance_check())
|
||||
reset_target_human_tp_coord();
|
||||
}
|
||||
if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman) && bot_on_type != 0 && bot_on_type != 4)
|
||||
if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman) && bot_on_type != 0 && bot_on_type != 2
|
||||
&& bot_on_type != 4)
|
||||
{
|
||||
face_call(targethuman);
|
||||
find_closest_match = is_client_stuck_or_afk(targethuman);
|
||||
@ -306,7 +317,7 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
find_closest_match = IsAbleToSee(present, targethuman) ? false : true;
|
||||
}
|
||||
}
|
||||
if (find_closest_match && bot_on_type != 0 && bot_on_type != 4)
|
||||
if (find_closest_match && bot_on_type != 0 && bot_on_type != 2 && bot_on_type != 4)
|
||||
{
|
||||
targethuman = 0;
|
||||
targethuman = GetClosestClient_option1(present, targeteam);
|
||||
@ -315,7 +326,7 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
int target_enemy = find_closest_enemy(present, targeteam);
|
||||
bool chasing_enemy = false;
|
||||
float dist_target = -1.0;
|
||||
if (bot_on_type != 0 && bot_on_type != 4)
|
||||
if (bot_on_type != 0 && bot_on_type != 2 && bot_on_type != 4)
|
||||
{
|
||||
float pos[3];
|
||||
if (IsValidClient(targethuman))
|
||||
@ -329,7 +340,7 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", 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 = 0.8;
|
||||
float min_distance_target_human = 1.6;
|
||||
//human aiming for zombie
|
||||
if (targeteam == 3)
|
||||
{
|
||||
@ -345,7 +356,7 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
}
|
||||
}
|
||||
//zombie aiming for human
|
||||
if (targeteam == 2 && 0 < enemy_distance <= min_enemy_distance * 5)
|
||||
if (targeteam == 2 && 0 < enemy_distance <= min_enemy_distance * 10)
|
||||
{
|
||||
chasing_enemy = true;
|
||||
face_call(target_enemy);
|
||||
@ -357,30 +368,78 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
bot_stuck = is_bot_stuck();
|
||||
}
|
||||
//TODO in some cases prevent bot from jumping over edge
|
||||
if (IsValidClient(targethuman))
|
||||
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);
|
||||
else
|
||||
Format(message, sizeof(message), "dist_target: %f targethuman: none bot_on_type: %i enemy_distance: %f bot_stuck: %i targeteam: %i", dist_target, bot_on_type, enemy_distance, bot_stuck, targeteam);
|
||||
send_socket_msg(message, strlen(message));
|
||||
|
||||
//TODO in some cases crouch under obstacles? maybe trace raying all
|
||||
if (bot_on_type != 2)
|
||||
{
|
||||
if (IsValidClient(targethuman))
|
||||
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);
|
||||
else
|
||||
Format(message, sizeof(message), "dist_target: %f targethuman: none bot_on_type: %i enemy_distance: %f bot_stuck: %i targeteam: %i", dist_target, bot_on_type, enemy_distance, bot_stuck, targeteam);
|
||||
send_socket_msg(message, strlen(message));
|
||||
}
|
||||
}
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public int check_bot_surfing_or_downhill()
|
||||
public void check_bot_surfing()
|
||||
{
|
||||
float vPos[3];
|
||||
float vMins[3];
|
||||
float vMaxs[3];
|
||||
GetEntPropVector(present, Prop_Data, "m_vecOrigin", vPos);
|
||||
GetEntPropVector(present, Prop_Send, "m_vecMins", vMins);
|
||||
GetEntPropVector(present, Prop_Send, "m_vecMaxs", vMaxs);
|
||||
float vEndPos[3];
|
||||
vEndPos[0] = vPos[0];
|
||||
vEndPos[1] = vPos[1];
|
||||
vEndPos[2] = vPos[2] - FindConVar("sv_maxvelocity").FloatValue;
|
||||
TR_TraceHullFilter(vPos, vEndPos, vMins, vMaxs, MASK_PLAYERSOLID_BRUSHONLY, TraceRayDontHitSelf, present);
|
||||
if (TR_DidHit())
|
||||
{
|
||||
//< 0.7 = surf ramp
|
||||
float surf_ramp = 0.7;
|
||||
char keyinput[generic_length * 3];
|
||||
float vPlane[3];
|
||||
TR_GetPlaneNormal(INVALID_HANDLE, vPlane);
|
||||
if (0.0 < vPlane[2] < surf_ramp)
|
||||
{
|
||||
//TODO this is very experimental
|
||||
vPlane[0] *= 100;
|
||||
vPlane[1] *= 100;
|
||||
vPlane[2] *= 100;
|
||||
surf_delay++;
|
||||
bot_surf_plane = true;
|
||||
if (surf_delay > 50)
|
||||
{
|
||||
surf_delay = 0;
|
||||
TeleportEntity(present, NULL_VECTOR, vPlane, NULL_VECTOR);
|
||||
Format(keyinput, sizeof(keyinput), "surfing: %f %f %f", vPlane[0], vPlane[1], vPlane[2]);
|
||||
send_socket_msg(keyinput, strlen(keyinput));
|
||||
}
|
||||
}
|
||||
else
|
||||
bot_surf_plane = false;
|
||||
}
|
||||
else
|
||||
bot_surf_plane = false;
|
||||
}
|
||||
|
||||
public int check_bot_downhill()
|
||||
{
|
||||
g_bLastOnGround[present] = g_bOnGround[present];
|
||||
if (GetEntityFlags(present) & FL_ONGROUND)
|
||||
g_bOnGround[present] = true;
|
||||
else
|
||||
g_bOnGround[present] = false;
|
||||
g_vLast[present][0] = g_vCurrent[present][0];
|
||||
g_vLast[present][1] = g_vCurrent[present][1];
|
||||
g_vLast[present][2] = g_vCurrent[present][2];
|
||||
g_vCurrent[present][0] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[0]");
|
||||
g_vCurrent[present][1] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[1]");
|
||||
g_vCurrent[present][2] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[2]");
|
||||
if (g_bOnGround[present] && !g_bLastOnGround[present])
|
||||
{
|
||||
g_vLast[0] = g_vCurrent[0];
|
||||
g_vLast[1] = g_vCurrent[1];
|
||||
g_vLast[2] = g_vCurrent[2];
|
||||
g_vCurrent[0] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[0]");
|
||||
g_vCurrent[1] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[1]");
|
||||
g_vCurrent[2] = GetEntPropFloat(present, Prop_Send, "m_vecVelocity[2]");
|
||||
float vPos[3];
|
||||
float vMins[3];
|
||||
float vMaxs[3];
|
||||
@ -394,21 +453,17 @@ public int check_bot_surfing_or_downhill()
|
||||
TR_TraceHullFilter(vPos, vEndPos, vMins, vMaxs, MASK_PLAYERSOLID_BRUSHONLY, TraceRayDontHitSelf, present);
|
||||
if (TR_DidHit())
|
||||
{
|
||||
//(1.0 = flat ground, < 0.7 = surf ramp)
|
||||
//1.0 = flat ground
|
||||
float vPlane[3];
|
||||
float vLast[3];
|
||||
float surf_ramp = 0.7;
|
||||
float flat_ground = 1.0;
|
||||
TR_GetPlaneNormal(INVALID_HANDLE, vPlane);
|
||||
//TODO figure out moveright or moveleft on surf ramps
|
||||
if (vPlane[2] < surf_ramp)
|
||||
return 2;
|
||||
if (vPlane[2] < flat_ground)
|
||||
if (0 < vPlane[2] < flat_ground)
|
||||
{
|
||||
vLast[0] = g_vLast[present][0];
|
||||
vLast[1] = g_vLast[present][1];
|
||||
vLast[2] = g_vLast[present][2];
|
||||
vLast[2] -= (FindConVar("sv_gravity").FloatValue * GetTickInterval() * 0.5);
|
||||
vLast[0] = g_vLast[0];
|
||||
vLast[1] = g_vLast[1];
|
||||
vLast[2] = g_vLast[2];
|
||||
vLast[2]-= (FindConVar("sv_gravity").FloatValue * GetTickInterval() * 0.5);
|
||||
float fBackOff = GetVectorDotProduct(vLast, vPlane);
|
||||
float change;
|
||||
float vVel[3];
|
||||
@ -427,7 +482,6 @@ public int check_bot_surfing_or_downhill()
|
||||
}
|
||||
vVel[2] = 0.0;
|
||||
vLast[2] = 0.0;
|
||||
// Make sure the player is going down a ramp by checking if they actually will gain speed from the boost
|
||||
if (GetVectorLength(vVel) > GetVectorLength(vLast))
|
||||
return 3;
|
||||
}
|
||||
@ -445,10 +499,10 @@ public bool is_bot_stuck()
|
||||
{
|
||||
if (!round_start_stuck)
|
||||
return false;
|
||||
float min_distance_cap = 0.1;
|
||||
float min_distance_cap = 0.05;
|
||||
float bot_own_distance = get_power_distance(present, bot_old_coords);
|
||||
bot_stuck_g = bot_own_distance < min_distance_cap;
|
||||
return bot_stuck_g;
|
||||
GetEntPropVector(present, Prop_Send, "m_vecOrigin", bot_old_coords);
|
||||
return bot_own_distance <= min_distance_cap;
|
||||
}
|
||||
|
||||
public void face_call(int client)
|
||||
@ -569,6 +623,13 @@ public float get_power_distance(int target_player, float [3]pos)
|
||||
return power_distance / defaultcap;
|
||||
}
|
||||
|
||||
public void reset_bot_old_coords()
|
||||
{
|
||||
bot_old_coords[0] = 0.0;
|
||||
bot_old_coords[1] = 0.0;
|
||||
bot_old_coords[2] = 0.0;
|
||||
}
|
||||
|
||||
public void OnClientPostAdminCheck(int client)
|
||||
{
|
||||
//STEAM_0:1:34783317
|
||||
@ -580,17 +641,13 @@ public void OnClientPostAdminCheck(int client)
|
||||
if (StrEqual("[U:1:120378081]", auth, false))
|
||||
{
|
||||
present = client;
|
||||
bot_old_coords[0] = 0.0;
|
||||
bot_old_coords[1] = 0.0;
|
||||
bot_old_coords[2] = 0.0;
|
||||
reset_bot_old_coords();
|
||||
bot_send_connected_msg();
|
||||
}
|
||||
else if (StrEqual("STEAM_0:1:60189040", auth, false))
|
||||
{
|
||||
present = client;
|
||||
bot_old_coords[0] = 0.0;
|
||||
bot_old_coords[1] = 0.0;
|
||||
bot_old_coords[2] = 0.0;
|
||||
reset_bot_old_coords();
|
||||
bot_send_connected_msg();
|
||||
}
|
||||
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
|
||||
|
Loading…
Reference in New Issue
Block a user