major update to detecting objects around bot but probably not done

This commit is contained in:
Christian 2020-10-18 22:54:22 +02:00
parent 8b5c002961
commit 20c19c925f

View File

@ -219,10 +219,59 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
int flags = GetEntityFlags(client);
if (!(flags & FL_ONGROUND) && (flags_old & FL_ONGROUND) && !(buttons_old & IN_JUMP) && !(buttons & IN_JUMP))
{
float Vel[3];
float Vel[3], feet_origin[3], ground_pos[3], downwards[3];
//TODO
float velocity_addition_z_axis = 300.0;
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
Vel[2] += velocity_addition_z_axis;
GetEntPropVector(client, Prop_Data, "m_vecVelocity", Vel);
Vel[2] += velocity_addition_z_axis;
GetClientAbsOrigin(present, feet_origin);
downwards[0] = 90.0;
downwards[1] = 0.0;
downwards[2] = 0.0;
TR_TraceRayFilter(feet_origin, downwards, MASK_PLAYERSOLID, RayType_Infinite, TraceRayDontHitSelf, present);
if (TR_DidHit())
{
TR_GetEndPosition(ground_pos);
feet_origin[2] -= 10.0;
float ground_distance = GetVectorDistance(feet_origin, ground_pos);
if (ground_distance > 80)
{
float angles_eye[3];
GetClientEyeAngles(present, angles_eye);
feet_origin[2] += 10.0;
TR_TraceRayFilter(feet_origin, angles_eye, MASK_PLAYERSOLID, RayType_Infinite, TraceRayDontHitSelf, present);
if (TR_DidHit())
{
TR_GetEndPosition(ground_pos);
feet_origin[2] -= 10.0;
float forward_distance = GetVectorDistance(feet_origin, ground_pos);
if (forward_distance > 280)
{
if (IsValidClient(targethuman))
{
float feet_origin_pre[3], human_feet_origin[3];
GetClientAbsOrigin(present, feet_origin_pre);
GetClientAbsOrigin(targethuman, human_feet_origin);
//target human is below, get down to them
if (feet_origin_pre[2] - 200 > human_feet_origin[2])
{
buttons_old = buttons;
flags_old = flags;
return;
}
}
float angles_abs[3];
GetClientAbsAngles(present, angles_abs);
if (angles_abs[1] < 0)
angles_abs[1] += 180.0;
else
angles_abs[1] -= 180.0;
TeleportEntity(present, NULL_VECTOR, angles_abs, NULL_VECTOR);
}
}
}
}
TeleportEntity(client, NULL_VECTOR, NULL_VECTOR, Vel);
}
buttons_old = buttons;
@ -232,82 +281,91 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
public Action recursive_pressing(Handle timer, any data)
{
if (IsValidClient(present))
{
if (GetClientTeam(present) == 1 || GetClientTeam(present) == 0)
{
ChangeClientTeam(present, 2);
return Plugin_Continue;
}
if (IsPlayerAlive(present))
{
if (GetEntityMoveType(present) == MOVETYPE_LADDER)
return Plugin_Continue;
int targeteam = 0;
if (GetClientTeam(present) != 3)
{
//2 = autismo is zm and should follow closest moving zm
targeteam = 2;
}
else
{
//3 = autismo is human and should follow closest moving ct
targeteam = 3;
}
if (targethuman_teleported[0] != 0.0)
{
float ClientPos[3];
float Result[3];
GetClientEyePosition(present, ClientPos);
MakeVectorFromPoints(ClientPos, targethuman_teleported, Result);
GetVectorAngles(Result, Result);
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
if (!distance_check())
reset_target_human_tp_coord();
return Plugin_Continue;
}
targethuman = GetClosestClient_option1(targeteam == 2 ? 2 : 3);
float enemy_distance = -1.0;
target_enemy = GetClosestClient_option1(targeteam == 2 ? 3 : 2);
float dist_target = -1.0;
float pos[3];
if (IsValidClient(targethuman))
{
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
dist_target = get_power_distance(present, pos);
}
if (IsValidClient(target_enemy))
{
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
enemy_distance = get_power_distance(present, pos);
}
float enemey_cap = 900.0;
if ((0 < enemy_distance < enemey_cap && targeteam == 2) || dist_target < 0 < enemy_distance)
face_call(target_enemy);
else if (0 < dist_target)
face_call(targethuman);
trace_hulling_bot();
char message[generic_length * 7];
if (IsValidClient(targethuman))
Format(message, sizeof(message), "dist_target: %f targethuman: %N enemy_distance: %f targeteam: %i", dist_target, targethuman, enemy_distance, targeteam);
else
Format(message, sizeof(message), "dist_target: %f targethuman: none enemy_distance: %f targeteam: %i", dist_target, enemy_distance, targeteam);
if (IsValidClient(target_enemy))
Format(message, sizeof(message), "%s target_enemy: %N", message, target_enemy);
else
Format(message, sizeof(message), "%s target_enemy: none", message);
send_socket_msg(message, strlen(message));
}
}
return Plugin_Continue;
if (IsValidClient(present))
{
if (GetClientTeam(present) == 1 || GetClientTeam(present) == 0)
{
ChangeClientTeam(present, 2);
return Plugin_Continue;
}
if (IsPlayerAlive(present))
{
if (GetEntityMoveType(present) == MOVETYPE_LADDER)
return Plugin_Continue;
int targeteam = 0;
if (GetClientTeam(present) != 3)
{
//2 = autismo is zm and should follow closest moving zm
targeteam = 2;
}
else
{
//3 = autismo is human and should follow closest moving ct
targeteam = 3;
}
if (targethuman_teleported[0] != 0.0)
{
float ClientPos[3];
float Result[3];
GetClientEyePosition(present, ClientPos);
MakeVectorFromPoints(ClientPos, targethuman_teleported, Result);
GetVectorAngles(Result, Result);
TeleportEntity(present, NULL_VECTOR, Result, NULL_VECTOR);
if (!distance_check())
reset_target_human_tp_coord();
return Plugin_Continue;
}
target_enemy = GetClosestClient_option1(targeteam == 2 ? 3 : 2);
targethuman = GetClosestClient_option1(targeteam == 2 ? 2 : 3);
float enemy_distance = -1.0;
float dist_target = -1.0;
float pos[3];
if (IsValidClient(targethuman))
{
GetEntPropVector(targethuman, Prop_Send, "m_vecOrigin", pos);
dist_target = get_power_distance(present, pos);
}
if (IsValidClient(target_enemy))
{
GetEntPropVector(target_enemy, Prop_Send, "m_vecOrigin", pos);
enemy_distance = get_power_distance(present, pos);
}
if ((0 < enemy_distance && targeteam == 2) || dist_target < 0 < enemy_distance)
{
float feet_origin[3], enemy_feet_origin[3];
GetClientAbsOrigin(present, feet_origin);
GetClientAbsOrigin(target_enemy, enemy_feet_origin);
if (feet_origin[2] + 100 > enemy_feet_origin[2])
face_call(target_enemy);
}
else if (0 < dist_target)
face_call(targethuman);
trace_hulling_bot();
char message[generic_length * 7];
if (IsValidClient(targethuman))
Format(message, sizeof(message), "dist_target: %f targethuman: %N enemy_distance: %f targeteam: %i", dist_target, targethuman, enemy_distance, targeteam);
else
Format(message, sizeof(message), "dist_target: %f targethuman: none enemy_distance: %f targeteam: %i", dist_target, enemy_distance, targeteam);
if (IsValidClient(target_enemy))
Format(message, sizeof(message), "%s target_enemy: %N", message, target_enemy);
else
Format(message, sizeof(message), "%s target_enemy: none", message);
send_socket_msg(message, strlen(message));
}
}
return Plugin_Continue;
}
//https://developer.valvesoftware.com/wiki/Dimensions
public void trace_hulling_bot()
{
char message[generic_length * 3];
float feet_origin[3], mins[3], maxs[3];
float step_cap = 18.0;
float crouch_min = 48.0;
float stand_min = 63.0;
float feet_origin[3], mins[3], maxs[3], eye_position[3];
int BOUNDINGBOX_INFLATION_OFFSET = 3;
GetClientEyePosition(present, eye_position);
GetClientAbsOrigin(present, feet_origin);
GetClientMins(present, mins);
GetClientMaxs(present, maxs);
@ -322,41 +380,72 @@ public void trace_hulling_bot()
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf);
if (TR_DidHit())
{
GetClientAbsOrigin(present, feet_origin);
//check 0.0 to 48.0 units starting from feet
feet_origin[2] -= BOUNDINGBOX_INFLATION_OFFSET;
mins[2] = 0.0;
maxs[2] = 48.0;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf);
maxs[2] = crouch_min;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
if (!(TR_DidHit()))
{
//can crouch
Format(message, sizeof(message), "hull info:crouch");
send_socket_msg(message, strlen(message));
send_socket_msg(message, strlen(message));
return;
}
//something blocks floor crouch
eye_position[2] += 5.0;
TR_TraceHullFilter(eye_position, eye_position, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
if (!(TR_DidHit()))
{
//should not block jump level
Format(message, sizeof(message), "hull info:jump");
send_socket_msg(message, strlen(message));
return;
}
else
{
mins[2] = 75.0;
maxs[2] = 100.0;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf);
if (!(TR_DidHit()))
//still potentially crouch hole in wall or one side jumpable
mins[2] = step_cap;
float iterator = step_cap;
while (iterator < stand_min)
{
mins[2] = 0.0;
maxs[2] = 75.0;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf);
if (TR_DidHit())
{
Format(message, sizeof(message), "hull info:jump");
send_socket_msg(message, strlen(message));
}
}
else
{
//hit wall
float move_angles[3];
GetClientEyeAngles(present, move_angles);
move_angles[0] = 0.0;
move_angles[1] += 15;
move_angles[2] = 0.0;
TeleportEntity(present, NULL_VECTOR, move_angles, NULL_VECTOR);
maxs[2] = iterator;
iterator += step_cap;
for (int jj = 0; jj < 2; jj++)
for (int ij = 0; ij < 2; ij++)
{
if (jj == 0)
mins[ij] += BOUNDINGBOX_INFLATION_OFFSET;
else
maxs[ij] -= BOUNDINGBOX_INFLATION_OFFSET;
TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
if (!(TR_DidHit()))
{
Format(message, sizeof(message), "hull info:jump");
send_socket_msg(message, strlen(message));
return;
}
TR_TraceHullFilter(eye_position, eye_position, mins, maxs, MASK_ALL, TraceRayDontHitSelf);
if (!(TR_DidHit()))
{
Format(message, sizeof(message), "hull info:jump");
send_socket_msg(message, strlen(message));
return;
}
if (jj == 0)
mins[ij] -= BOUNDINGBOX_INFLATION_OFFSET;
else
maxs[ij] += BOUNDINGBOX_INFLATION_OFFSET;
}
}
//currently detects when two walls meet and create a corner
float move_angles[3];
GetClientEyeAngles(present, move_angles);
move_angles[0] = 0.0;
move_angles[1] += 35.0;
move_angles[2] = 0.0;
TeleportEntity(present, NULL_VECTOR, move_angles, NULL_VECTOR);
return;
}
}
}
@ -456,32 +545,39 @@ public int GetClosestClient_option1(int targeteam)
for (int i = 1; i <= MaxClients; i++)
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
{
if (!IsAbleToSee(present, i))
continue;
if (is_client_stuck_or_afk(i))
{
if (i != targethuman)
continue;
target_human_afk_counter++;
if (target_human_afk_counter > 5)
{
target_human_afk_counter = 0;
continue;
}
}
else if (i == targethuman)
target_human_afk_counter = 0;
float pos[3];
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(present, pos);
if (admins[i] || vips[i] || i == targethuman || i == target_enemy)
dist_target /= 5;
if (nearestdistance < 0 || dist_target < nearestdistance)
{
nearest = i;
nearestdistance = dist_target;
}
}
if (!IsAbleToSee(present, i))
continue;
if (is_client_stuck_or_afk(i) && GetClientTeam(i) == GetClientTeam(present))
{
if (i != targethuman)
continue;
target_human_afk_counter++;
if (target_human_afk_counter > 5)
{
target_human_afk_counter = 0;
continue;
}
}
else if (i == targethuman)
target_human_afk_counter = 0;
float pos[3];
GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos);
float dist_target = get_power_distance(present, pos);
if (GetClientTeam(present) == 3 && IsValidClient(target_enemy) && targeteam == 3)
{
float enemey_cap = 1500.0;
float enemy_dist = get_power_distance(target_enemy, pos);
if (enemy_dist < enemey_cap)
dist_target += enemey_cap;
}
if (admins[i] || vips[i] || i == targethuman || i == target_enemy)
dist_target /= 5;
if (nearestdistance < 0 || dist_target < nearestdistance)
{
nearest = i;
nearestdistance = dist_target;
}
}
return nearest;
}
@ -742,4 +838,4 @@ public bool IsRectangleVisible(const float start[3], const float end[3], const f
if (IsPointVisible(start, vRectangle[i]))
return true;
return false;
}
}