moved tracehull and setting angles out of timer and into onruncmd forward. this prevents having to use teleportentity

This commit is contained in:
jenz 2023-10-28 00:30:53 +02:00
parent c68107be34
commit a049ed7f9a

View File

@ -122,11 +122,115 @@ public MRESReturn OnGetRunCmdPre(int entity, Handle hReturn)
return MRES_Ignored;
}
public void get_new_angles(int client, int target, float angles[3])
{
float TargetPos[3];
float ClientPos[3];
float Result[3];
GetClientEyePosition(target, TargetPos);
GetClientEyePosition(client, ClientPos);
MakeVectorFromPoints(ClientPos, TargetPos, Result);
GetVectorAngles(Result, Result);
angles[0] = Result[0];
angles[1] = Result[1];
angles[2] = Result[2];
}
public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3], float angles[3], int& weapon, int& subtype, int& cmdnum, int& tickcount, int& seed, int mouse[2])
{
//we use info we just got from OnPlayerRunCmdPre to determine if to jump
if (!IsValidClient(client) || !IsPlayerAlive(client) || !is_bot_player[client]) return Plugin_Continue;
//2023 october: the new place to set angles for the client instead of using face_call, through this is teleporting avoided which can trigger trigger_multiples
if (!bot_follow_tp[client])
{
int targeteam = 0;
if (GetClientTeam(client) != 3)
{
//2 = autismo is zm and should follow enemies sometimes
targeteam = 2;
}
else
{
//3 = autismo is human and should follow closest moving ct
targeteam = 3;
}
bool found_enemy = false;
for (int clienti = 1; clienti <= MaxClients; clienti++)
{
if (!IsValidClient(clienti)) continue;
if (GetClientTeam(clienti) == 2 && IsPlayerAlive(clienti))
{
found_enemy = true;
}
}
float pos[3];
float dist_target = -1.0;
if (IsValidClient(target_friend[client]))
{
GetEntPropVector(target_friend[client], Prop_Send, "m_vecOrigin", pos);
dist_target = get_power_distance(client, pos);
}
float max_range_dist = 65.0;
//here we put into consideration if the human is leaving or standing around. If the bots already catched up to the human they can have a larger distance between the player and themselves so they dont constantly follow him. If the player is leaving the bots needs to follow him much closer.
if (targeteam == 3 && human_too_close[client])
{
max_range_dist = 200.0;
}
float enemy_distance = -1.0;
if (IsValidClient(target_enemy[client]))
{
GetEntPropVector(target_enemy[client], Prop_Send, "m_vecOrigin", pos);
enemy_distance = get_power_distance(client, pos);
}
if (GetEntityMoveType(client) == MOVETYPE_LADDER || (IsValidClient(target_friend[client]) && GetEntityMoveType(target_friend[client]) == MOVETYPE_LADDER))
{
if (IsValidClient(target_friend[client]))
{
get_new_angles(client, target_friend[client], angles);
}
}
//if bot is ct: is close enough to friend, can stop following friend and focus on shooting zombies
else if (targeteam == 3 && 0 < dist_target < max_range_dist && IsValidClient(target_enemy[client]))
{
get_new_angles(client, target_enemy[client], angles);
}
//if bot is ct: if bot is not close enough to friend follow him, //dist_target being larger than max_range_dist means a friend was found to follow
//we also check if zm already spawned, if not then stay close to friend
else if ((targeteam == 3 && dist_target > max_range_dist) || !found_enemy)
{
get_new_angles(client, target_friend[client], angles);
}
//if bot is zm follow enemy sometimes
else if (targeteam == 2 && 0 < enemy_distance < max_range_dist * 5 && IsValidClient(target_enemy[client]))
{
get_new_angles(client, target_enemy[client], angles);
}
//if bot is zm just follow the closest friend zm, but not constantly when too close because people start bitching then
else if (targeteam == 2 && dist_target > max_range_dist / 2)
{
get_new_angles(client, target_friend[client], angles);
}
//if bot is zm and no close enemies and no friends far away enough to follow then check if friend is close, if its the case then do nothing
else if (targeteam == 2 && 0 < dist_target < max_range_dist / 2)
{
get_new_angles(client, target_friend[client], angles);
}
//if bot is zm and there are no friends close or far away but there is also no enemy close check if there is an enemy far away
else if (targeteam == 2 && IsValidClient(target_enemy[client]))
{
get_new_angles(client, target_enemy[client], angles);
}
if (GetEntProp(client, Prop_Data, "m_nWaterLevel") == 0 && GetEntityMoveType(client) != MOVETYPE_LADDER)
trace_hulling_bot(client);
}
if ((GetEntityMoveType(client) & MOVETYPE_LADDER))
{
has_to_jump_bots[client] = 2;
@ -152,7 +256,6 @@ public Action OnPlayerRunCmd(int client, int& buttons, int& impulse, float vel[3
//this check accomedates checking for if the bot actually was teleported by the map because then he should not teleport back again to coords_run_cmd
//the famous voodoo incidents that people have seen.
float distance_bot_current_position_last_position = get_power_distance(client, coords_run_cmd[client]);
//PrintToChatAll("distance_bot_current_position_last_position: %f %N", distance_bot_current_position_last_position, client);
if (distance_bot_current_position_last_position > 500.0)
{
@ -570,17 +673,12 @@ public Action recursive_pressing(Handle timer, any data)
//if the bot or its target is on the ladder just use forward to reach the ladder
else if (GetEntityMoveType(client) == MOVETYPE_LADDER || (IsValidClient(target_friend[client]) && GetEntityMoveType(target_friend[client]) == MOVETYPE_LADDER))
{
if (IsValidClient(target_friend[client]))
{
face_call(target_friend[client], client);
}
state = 8;
}
//if bot is ct: is close enough to friend, can stop following friend and focus on shooting zombies
else if (targeteam == 3 && 0 < dist_target < max_range_dist && IsValidClient(target_enemy[client]))
{
human_too_close[client] = true;
face_call(target_enemy[client], client);
state = 0;
}
//if bot is ct: if bot is not close enough to friend follow him, //dist_target being larger than max_range_dist means a friend was found to follow
@ -588,7 +686,6 @@ public Action recursive_pressing(Handle timer, any data)
else if ((targeteam == 3 && dist_target > max_range_dist) || !found_enemy)
{
human_too_close[client] = false;
face_call(target_friend[client], client);
state = 1;
}
//if bot is ct and close enough to friend then just do nothing in case of there being no enemy to shoot at.
@ -600,25 +697,21 @@ public Action recursive_pressing(Handle timer, any data)
//if bot is zm follow enemy sometimes
else if (targeteam == 2 && 0 < enemy_distance < max_range_dist * 5 && IsValidClient(target_enemy[client]))
{
face_call(target_enemy[client], client);
state = 3;
}
//if bot is zm just follow the closest friend zm, but not constantly when too close because people start bitching then
else if (targeteam == 2 && dist_target > max_range_dist / 2)
{
face_call(target_friend[client], client);
state = 4;
}
//if bot is zm and no close enemies and no friends far away enough to follow then check if friend is close, if its the case then do nothing
else if (targeteam == 2 && 0 < dist_target < max_range_dist / 2)
{
face_call(target_friend[client], client);
state = 5;
}
//if bot is zm and there are no friends close or far away but there is also no enemy close check if there is an enemy far away
else if (targeteam == 2 && IsValidClient(target_enemy[client]))
{
face_call(target_enemy[client], client);
state = 6;
}
//else nothing to do as zm
@ -626,8 +719,6 @@ public Action recursive_pressing(Handle timer, any data)
{
state = 7;
}
if (GetEntProp(client, Prop_Data, "m_nWaterLevel") == 0 && GetEntityMoveType(client) != MOVETYPE_LADDER)
trace_hulling_bot(client);
char message[generic_length * 7];
Format(message, sizeof(message), "dist_target: %f enemy_distance: %f targeteam: %i state: %i", dist_target, enemy_distance, targeteam, state);
if (specific_bot_player[client] == 1)
@ -861,27 +952,6 @@ public bool TraceRayDontHitSelf(int entity, int mask, any data)
return entity != data && !(0 < entity <= MaxClients);
}
public void face_call(int client, int selfclient)
{
for (int j = 0; j < 5; j++)
faceclient(client, selfclient);
}
public void faceclient(int target_human, int client)
{
if (IsValidClient(client) && IsValidClient(target_human))
{
float TargetPos[3];
float ClientPos[3];
float Result[3];
GetClientEyePosition(target_human, TargetPos);
GetClientEyePosition(client, ClientPos);
MakeVectorFromPoints(ClientPos, TargetPos, Result);
GetVectorAngles(Result, Result);
TeleportEntity(client, NULL_VECTOR, Result, NULL_VECTOR);
}
}
stock bool IsValidClient(int client)
{
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))