From 54d911dd3281b078df4c07877121497b9a679e90 Mon Sep 17 00:00:00 2001 From: jenzur Date: Sun, 4 Oct 2020 00:53:36 +0200 Subject: [PATCH 1/5] added priority less afk restrictions --- AutismBotIngame/scripting/autism_bot_info.sp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index 18505777..e378f9a0 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -448,6 +448,7 @@ stock bool is_client_stuck_or_afk(int client) return client_own_distance < min_distance_cap; } +int target_human_afk_counter = 0; public int GetClosestClient_option1(int targeteam) { float nearestdistance = -1.0; @@ -458,7 +459,18 @@ public int GetClosestClient_option1(int targeteam) if (!IsAbleToSee(present, i)) continue; if (is_client_stuck_or_afk(i)) - continue; + { + if (i != targethuman) + continue; + target_human_afk_counter++; + if (target_human_afk_counter > 5) + { + target_human_afk_counter = 0; + continue; + } + } + else + target_human_afk_counter = 0; float pos[3]; GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); float dist_target = get_power_distance(present, pos); From c5cb235a720970ca4dc5163f23b1f2c72e06437f Mon Sep 17 00:00:00 2001 From: jenzur Date: Sun, 4 Oct 2020 14:31:19 +0200 Subject: [PATCH 2/5] minor fix --- AutismBotIngame/scripting/autism_bot_info.sp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index e378f9a0..44422cc5 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -469,7 +469,7 @@ public int GetClosestClient_option1(int targeteam) continue; } } - else + else if (i == targethuman) target_human_afk_counter = 0; float pos[3]; GetEntPropVector(i, Prop_Send, "m_vecOrigin", pos); From 8b5c0029610611aeb7e4df485306ef4c321a04e6 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 13 Oct 2020 18:51:56 +0200 Subject: [PATCH 3/5] the include started throwing depcrecated messages, so gotta add on git, maybe all methods need to be updated --- AutismBotIngame/scripting/include/socket.inc | 488 +++++++++++++++++++ 1 file changed, 488 insertions(+) create mode 100644 AutismBotIngame/scripting/include/socket.inc diff --git a/AutismBotIngame/scripting/include/socket.inc b/AutismBotIngame/scripting/include/socket.inc new file mode 100644 index 00000000..2bcc3fa1 --- /dev/null +++ b/AutismBotIngame/scripting/include/socket.inc @@ -0,0 +1,488 @@ +// socket extension include file + +#if defined _socket_included + #endinput +#endif +#define _socket_included +#include + +enum SocketType { + SOCKET_TCP = 1, + SOCKET_UDP, + SOCKET_RAW +} + +#define EMPTY_HOST 1 +#define NO_HOST 2 +#define CONNECT_ERROR 3 +#define SEND_ERROR 4 +#define BIND_ERROR 5 +#define RECV_ERROR 6 +#define LISTEN_ERROR 7 + + +/*************************************************************************************************/ +/******************************************** options ********************************************/ +/*************************************************************************************************/ + + +/** + * Options available for SocketSetOption() + * + * @note modifying these options is not required for normal operation, you can skip the whole + * section in most cases. + */ +enum SocketOption { +/** + * If this option is set the socket extension will try to concatenate SocketReceive callbacks. + * + * This will possibly lower the amount of callbacks passed to SourceMod plugins and improve the + * performance. The socket extension will preserve the packet order. + * + * @note this doesn't prevent multiple callbacks, it only reduces them for high load. + * @note this will not truncate packets below 4096 bytes, setting it lower will be ignored + * @note set this option if you expect lots of data in a short timeframe + * @note don't forget to set your buffer sizes at least to the value passed to this function, but + * always at least to 4096 + * + * @param cell_t 0(=default) to disable or max. chunk size including \0 terminator in bytes + * @return bool true on success + */ + ConcatenateCallbacks = 1, +/** + * If this option is set the socket extension will enforce a mutex lock in the GameFrame() hook. + * + * This will ensure that callbacks will be processed every gameframe as fast as possible with the + * drawback of potentially creating lag. It's not recommended to set this option for most cases. + * If this option is not set the gameframe will be skipped if quietly obtaining a lock fails. + * + * @note combine this with CallbacksPerFrame for best performance + * @note this option will affect all sockets from all plugins, use it with caution! + * + * @param bool whether to force locking or not + * @return bool true on success + */ + ForceFrameLock, +/** + * This will specify the maximum amount of callbacks processed in every gameframe. + * + * The default value for this option is 1, setting it higher will possibly increase networking + * performance but may cause lag if it's set too high. + * The amount of callbacks actually being processed is limited by not being able to quietly obtain + * a lock (see ForceFrameLock) and the amount of callbacks in the queue. + * + * @note this option will affect all sockets from all plugins, use it with caution! + * + * @param cell_t maximum amount of callbacks per gameframe + * @return bool true on success + */ + CallbacksPerFrame, +/** + * If this option is set the socket will be allowed to send broadcast messages in case the protocol + * supports it. This is a wrapper for setting SO_BROADCAST. + * + * @param bool whether to allow broadcasting or not + * @return bool true on success + */ + SocketBroadcast, +/** + * If this option is set SocketBind() will allow reusing local adresses in case the protocol + * supports it. This is a wrapper for setting SO_REUSEADDR. + * + * @param bool whether to allow broadcasting or not + * @return bool true on success + */ + SocketReuseAddr, +/** + * If this option is set the socket will try to keep the connection alive by periodically sending + * messages if the protocol supports it. This is a wrapper for setting SO_KEEPALIVE. + * + * @param bool whether to allow broadcasting or not + * @return bool true on success + */ + SocketKeepAlive, +/** + * This option specifies how long a socket will wait if it's being closed and its send buffer is + * still filled. This is a wrapper for setting SO_LINGER. + * + * @param cell_t 0 (=default) to disable or time in s + * @return bool true on success + */ + SocketLinger, +/** + * If this option is set out-of-band data will be inlined into the normal receive stream. This is a + * wrapper for setting SO_OOBINLINE. + * + * @param bool whether to inline out-of-band data or not + * @return bool true on success + */ + SocketOOBInline, +/** + * This option specifies how large the send buffer will be. This is a wrapper for setting + * SO_SNDBUF. + * + * @param cell_t size in bytes + * @return bool true on success + */ + SocketSendBuffer, +/** + * This option specifies how large the receive buffer will be. This is a wrapper for setting + * SO_RCVBUF. + * + * @param cell_t size in bytes + * @return bool true on success + */ + SocketReceiveBuffer, +/** + * If this option is set outgoing messages will ignore the default routing facilities if the + * protocol implementation supports it. The remote site should be directly connected to the sender. + * This is a wrapper for setting SO_DONTROUTE. + * + * @param bool whether to skip default routing or not + * @return bool true on success + */ + SocketDontRoute, +/** + * This option specifies the minimum amount of data to receive before processing it. This is a + * wrapper for setting SO_RCVLOWAT. + * + * @note this can probably block the extension, use it with caution! + * + * @param cell_t size in bytes + * @return bool true on success + */ + SocketReceiveLowWatermark, +/** + * This option specifies how long a socket will try to receive data before it times out and + * processes the data. This is a wrapper for setting SO_RCVTIMEO. + * + * @param cell_t 0 (=default) to disable or time in ms + * @return bool true on success + */ + SocketReceiveTimeout, +/** + * This option specifies the minimum amount of data required in the send buffer before starting to + * send it. This is a wrapper for setting SO_SNDLOWAT. + * + * @note this can probably block the extension, use it with caution! + * + * @param cell_t size in bytes + * @return bool true on success + */ + SocketSendLowWatermark, +/** + * This option specifies how long a socket will try to send data before it times out and + * retries it later. This is a wrapper for setting SO_SNDTIMEO. + * + * @param cell_t 0 (=default) to disable or time in ms + * @return bool true on success + */ + SocketSendTimeout, +/** + * If this option is set the socket extension will display debugging messages in the server console/logs. + * + * @param bool whether to enable debugging or not + * @return bool true on success + */ + DebugMode +} + + +/*************************************************************************************************/ +/******************************************* callbacks *******************************************/ +/*************************************************************************************************/ + + +/** + * triggered if a normal sockets finished connecting and is ready to be used + * + * @param socket The socket handle pointing to the calling socket + * @param arg The argument set by SocketSetArg() + * @noreturn + */ +typeset SocketConnectCB +{ + function void(Handle socket, any arg); +}; + +/** + * triggered if a listening socket received an incoming connection and is ready to be used + * + * @note The child-socket won't work until receive-, disconnect-, and errorcallback for it are set. + * + * @param Handle socket The socket handle pointing to the calling listen-socket + * @param Handle newSocket The socket handle to the newly spawned child socket + * @param String remoteIP The remote IP + * @param any arg The argument set by SocketSetArg() for the listen-socket + * @noreturn + */ +typeset SocketIncomingCB +{ + function void(Handle socket, Handle newSocket, const char remoteIP[], char remotePort, any arg); +}; + +/** + * triggered if a socket receives data + * + * @note This is binary safe if you always use dataSize for operations on receiveData[] + * @note packets may be split up into multiple chunks -> multiple calls to the receive callback + * @note if not set otherwise by SocketSetOption(..., ConcatenateCallbacks, ...) receiveData will + * never be longer than 4096 characters including \0 terminator + * + * @param Handle socket The socket handle pointing to the calling socket + * @param String receiveData The data which arrived, 0-terminated at receiveData[dataSize] + * @param cell_t dataSize The length of the arrived data excluding the 0-termination + * @param any arg The argument set by SocketSetArg() for the socket + * @noreturn + */ +typeset SocketReceiveCB +{ + function void(Handle socket, const char receiveData[], const int dataSize, any arg); +}; + +/** + * called after a socket sent all items in its send queue successfully + * + * @param Handle socket The socket handle pointing to the calling socket + * @param any arg The argument set by SocketSetArg() for the socket + * @noreturn + */ +typeset SocketSendqueueEmptyCB +{ + function void(Handle socket, any arg); +}; + +/** + * called if a socket has been properly disconnected by the remote side + * + * @note You should call CloseHandle(socket) or reuse the socket before this function ends + * + * @param Handle socket The socket handle pointing to the calling socket + * @param any arg The argument set by SocketSetArg() for the socket + * @noreturn + */ +typeset SocketDisconnectCB +{ + function void(Handle socket, any arg); +}; + +/** + * called if an unrecoverable error occured, close the socket without an additional call to a disconnect callback + * + * @note You should call CloseHandle(socket) or reuse the socket before this function ends + * + * @param Handle socket The socket handle pointing to the calling socket + * @param cell_t errorType The error type, see defines above + * @param cell_t errorNum The errno, see errno.h for details + * @param any arg The argument set by SocketSetArg() for the socket + * @noreturn + */ +typeset SocketErrorCB +{ + function void(Handle socket, const int errorType, const int errorNum, any arg); +}; + + +/*************************************************************************************************/ +/******************************************** natives ********************************************/ +/*************************************************************************************************/ + + +/** + * Returns whether a socket is connected or not. + * + * @param socket Socket handle to check + * @return bool The connection status + */ +native bool:SocketIsConnected(Handle:socket); + + +/** + * Creates a new socket. + * + * @note this function may be relatively expensive, reuse sockets if possible + * + * @param SocketType protocol The protocol to use, SOCKET_TCP is default + * @param SocketErrorCB efunc The error callback + * @return Handle The socket handle. Returns INVALID_HANDLE on failure + */ +native Handle SocketCreate(SocketType protocol=SOCKET_TCP, SocketErrorCB efunc); + +/** + * Binds the socket to a local address + * + * @param Handle socket The handle of the socket to be used. + * @param String hostname The hostname (or IP) to bind the socket to. + * @param cell_t port The port to bind the socket to. + * @return bool true on success + */ +native bool:SocketBind(Handle:socket, const String:hostname[], port); + +/** + * Connects a socket + * + * @note this native is threaded, it may be still running after it executed, use the connect callback + * @note invokes the SocketError callback with errorType = CONNECT_ERROR or EMPTY_HOST if it fails + * @note invokes the SocketConnect callback if it succeeds + * + * @param Handle socket The handle of the socket to be used. + * @param SocketConnectCB cfunc The connect callback + * @param SocketReceiveCB rfunc The receive callback + * @param SocketDisconnectCB dfunc The disconnect callback + * @param String hostname The hostname (or IP) to connect to. + * @param cell_t port The port to connect to. + * @noreturn + */ +native SocketConnect(Handle:socket, SocketConnectCB:cfunc, SocketReceiveCB:rfunc, SocketDisconnectCB:dfunc, const String:hostname[], port); + +/** + * Disconnects a socket + * + * @note this will not close the handle, the socket will be reset to a state similar to after SocketCreate() + * @note this won't trigger any disconnect/error callbacks + * + * @noreturn + */ +native bool:SocketDisconnect(Handle:socket); + +/** + * Makes a socket listen for incoming connections + * + * @param Handle socket The handle of the socket to be used. + * @param SocketIncomingCB ifunc The callback for incoming connections + * @return bool true on success + */ +native bool:SocketListen(Handle:socket, SocketIncomingCB:ifunc); + +/** + * Sends data through the socket. + * + * @note specify size for binary safe operation + * @note if size is not specified the \0 terminator will not be included + * @note This native is threaded, it may be still running after it executed (not atomic). + * @note Use the SendqueueEmpty callback to determine when all data has been successfully sent. + * @note The socket extension will ensure that the data will be send in the correct order and split + * the data if required. + * + * @param Handle socket The handle of the socket to be used. + * @param String data The data to send. + * @noreturn + */ +native SocketSend(Handle:socket, const String:data[], size=-1); + +/** + * Sends UDP data through the socket to a specific destination. + * + * @note specify size for binary safe operation + * @note if size is not specified the \0 terminator will not be included + * @note This native is threaded, it may be still running after it executed (not atomic). + * @note Use the SendqueueEmpty callback to determine when all data has been successfully sent. + * @note The socket extension will ensure that the data will be send in the correct order and split + * the data if required. + * + * @param Handle socket The handle of the socket to be used. + * @param String data The data to send. + * @param String hostname The hostname (or IP) to send to. + * @param cell_t port The port to send to. + * @noreturn + */ +native SocketSendTo(Handle:socket, const String:data[], size=-1, const String:hostname[], port); + +/** + * Set a socket option. + * + * @param Handle socket The handle of the socket to be used. May be INVALID_HANDLE if not essential. + * @param SocketOption option The option to modify (see enum SocketOption for details). + * @param cellt_ value The value to set the option to. + * @return cell_t 1 on success. + */ +native SocketSetOption(Handle:socket, SocketOption:option, value); + + +/** + * Defines the callback function for when the socket receives data + * + * @note this is only useful and required for child-sockets spawned by listen-sockets + * (otherwise you already set it in SocketConnect()) + * + * @param Handle socket The handle of the socket to be used. + * @param SocketReceiveCB rfunc The receive callback + * @noreturn + */ +native SocketSetReceiveCallback(Handle:socket, SocketReceiveCB:rfunc); + +/** + * Defines the callback function for when the socket sent all items in its send queue + * + * @note this must be called AFTER sending (queueing) the data + * @note if no send-data is queued this will fire the callback itself + * @note the callback is guaranteed to fire + * + * @param Handle socket The handle of the socket to be used. + * @param SocketDisconnectCB dfunc The disconnect callback + * @noreturn + */ +native SocketSetSendqueueEmptyCallback(Handle:socket, SocketSendqueueEmptyCB:sfunc); + +/** + * Defines the callback function for when the socket was properly disconnected by the remote side + * + * @note this is only useful and required for child-sockets spawned by listen-sockets + * (otherwise you already set it in SocketConnect()) + * + * @param Handle socket The handle of the socket to be used. + * @param SocketDisconnectCB dfunc The disconnect callback + * @noreturn + */ +native SocketSetDisconnectCallback(Handle:socket, SocketDisconnectCB:dfunc); + +/** + * Defines the callback function for when the socket triggered an error + * + * @note this is only useful and required for child-sockets spawned by listen-sockets + * (otherwise you already set it in SocketCreate()) + * + * @param Handle socket The handle of the socket to be used. + * @param SocketErrorCB efunc The error callback + * @noreturn + */ +native SocketSetErrorCallback(Handle:socket, SocketErrorCB:efunc); + + +/** + * Sets the argument being passed to callbacks + * + * @param Handle socket The handle of the socket to be used. + * @param any arg The argument to set + * @noreturn + */ +native SocketSetArg(Handle:socket, any:arg); + +/** + * Retrieve the local system's hostname as the command "hostname" does. + * + * @param dest Destination string buffer to copy to. + * @param destLen Destination buffer length (includes null terminator). + * + * @return 1 on success + */ +native SocketGetHostName(String:dest[], destLen); + +/** + * _________________Do not edit below this line!_______________________ + */ +public Extension:__ext_smsock = +{ + name = "Socket", + file = "socket.ext", +#if defined AUTOLOAD_EXTENSIONS + autoload = 1, +#else + autoload = 0, +#endif +#if defined REQUIRE_EXTENSIONS + required = 1, +#else + required = 0, +#endif +}; From 20c19c925f527bd23acb20e75f24d0fffbb23bb2 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 18 Oct 2020 22:54:22 +0200 Subject: [PATCH 4/5] major update to detecting objects around bot but probably not done --- AutismBotIngame/scripting/autism_bot_info.sp | 346 ++++++++++++------- 1 file changed, 221 insertions(+), 125 deletions(-) diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index 44422cc5..e41b62e2 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -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; -} \ No newline at end of file +} From 6e665609ec827ba4084f0d017317022d4cc062c5 Mon Sep 17 00:00:00 2001 From: Christian Date: Sat, 24 Oct 2020 23:07:38 +0200 Subject: [PATCH 5/5] removed bot targeting humans when zm as requested by admin team --- AutismBotIngame/scripting/autism_bot_info.sp | 30 +++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/AutismBotIngame/scripting/autism_bot_info.sp b/AutismBotIngame/scripting/autism_bot_info.sp index e41b62e2..5d56605a 100644 --- a/AutismBotIngame/scripting/autism_bot_info.sp +++ b/AutismBotIngame/scripting/autism_bot_info.sp @@ -217,7 +217,7 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float if (client == present) { int flags = GetEntityFlags(client); - 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) && (GetEntityMoveType(present) != MOVETYPE_LADDER)) { float Vel[3], feet_origin[3], ground_pos[3], downwards[3]; //TODO @@ -229,7 +229,7 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float downwards[0] = 90.0; downwards[1] = 0.0; downwards[2] = 0.0; - TR_TraceRayFilter(feet_origin, downwards, MASK_PLAYERSOLID, RayType_Infinite, TraceRayDontHitSelf, present); + TR_TraceRayFilter(feet_origin, downwards, MASK_ALL, RayType_Infinite, TraceRayDontHitSelf, present); if (TR_DidHit()) { TR_GetEndPosition(ground_pos); @@ -240,7 +240,7 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float 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); + TR_TraceRayFilter(feet_origin, angles_eye, MASK_ALL, RayType_Infinite, TraceRayDontHitSelf, present); if (TR_DidHit()) { TR_GetEndPosition(ground_pos); @@ -254,6 +254,7 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float GetClientAbsOrigin(present, feet_origin_pre); GetClientAbsOrigin(targethuman, human_feet_origin); //target human is below, get down to them + //TODO maybe? if (feet_origin_pre[2] - 200 > human_feet_origin[2]) { buttons_old = buttons; @@ -261,13 +262,12 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float 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); + float velocity[3]; + GetEntPropVector(present, Prop_Data, "m_vecVelocity", velocity); + velocity[2] += 30.0; + NegateVector(velocity); + for (int y = 0; y < 10; y++) + TeleportEntity(present, NULL_VECTOR, NULL_VECTOR, velocity); } } } @@ -315,7 +315,7 @@ public Action recursive_pressing(Handle timer, any data) reset_target_human_tp_coord(); return Plugin_Continue; } - target_enemy = GetClosestClient_option1(targeteam == 2 ? 3 : 2); + //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; @@ -325,11 +325,13 @@ public Action recursive_pressing(Handle timer, any data) 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]; @@ -377,7 +379,7 @@ public void trace_hulling_bot() } //acts as full body check feet_origin[2] += BOUNDINGBOX_INFLATION_OFFSET; - TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_SOLID, TraceRayDontHitSelf); + TR_TraceHullFilter(feet_origin, feet_origin, mins, maxs, MASK_ALL, TraceRayDontHitSelf); if (TR_DidHit()) { //check 0.0 to 48.0 units starting from feet @@ -464,7 +466,7 @@ public void check_bot_surfing() 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); + TR_TraceHullFilter(vPos, vEndPos, vMins, vMaxs, MASK_ALL, TraceRayDontHitSelf, present); if (TR_DidHit()) { //< 0.7 = surf ramp @@ -724,7 +726,7 @@ public bool Filter_NoPlayers(int entity, int mask) public bool IsPointVisible(const float start[3], const float end[3]) { - TR_TraceRayFilter(start, end, MASK_SOLID, RayType_EndPoint, Filter_NoPlayers); + TR_TraceRayFilter(start, end, MASK_ALL, RayType_EndPoint, Filter_NoPlayers); return TR_GetFraction() == 1.0; }