### Synchronous HTTP Client Example Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md Demonstrates how to perform a synchronous HTTP GET request and process the response. ```APIDOC ## Synchronous HTTP Client Example This example shows a complete synchronous GET request to fetch content from a URL. ```angelscript int request_id = g_EngineFuncs.CreateHTTPRequest("http://www.baidu.com/", false, // synchronous request ASCURL_METHOD_GET, 1000, // connect timeout in ms 5000 // transfer timeout in ms ); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Cache-control: no-cache"); g_EngineFuncs.SendHTTPRequest(request_id); int response_code = 0; string response_header; string response_body; // Loop to get the response. In synchronous mode, GetHTTPResponse might need to be called multiple times // until the response code is >= 200, indicating completion or an error. while(g_EngineFuncs.GetHTTPResponse(request_id, response_code, response_header, response_body)) { // If response_code is 100 (Continue), the request is still processing. if(response_code >= 200) break; // Exit loop once a final status code is received } // Process the response_code, response_header, and response_body here... g_EngineFuncs.DestroyHTTPRequest(request_id); ``` ``` -------------------------------- ### Synchronous HTTP Client Example Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md Demonstrates a synchronous HTTP GET request, showing the sequence of creating, configuring, sending, and retrieving a response. The code blocks until the response is fully received or a timeout occurs. ```angelscript int request_id = g_EngineFuncs.CreateHTTPRequest("http://www.baidu.com/", false, ASCURL_METHOD_GET, 1000,//connect timeout in ms 5000 //transfer timeout in ms ); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Cache-control: no-cache"); g_EngineFuncs.SendHTTPRequest(request_id); int response_code = 0; string response_header; string response_body; while(g_EngineFuncs.GetHTTPResponse(request_id, response_code, response_header, response_body)) { //if response_code == 100, keeps looping if(response_code >= 200) break; } g_EngineFuncs.DestroyHTTPRequest(request_id); ``` -------------------------------- ### Install Angelscript Header File Source: https://github.com/hzqst/metamod-fallguys/blob/main/thirdparty/angelscript-sdk/angelscript/projects/cmake/CMakeLists.txt Installs the main Angelscript header file to the 'include' directory as part of the 'Devel' component. ```cmake install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/../../include/angelscript.h DESTINATION include COMPONENT Devel ) ``` -------------------------------- ### Install Package Configuration Files Source: https://github.com/hzqst/metamod-fallguys/blob/main/thirdparty/angelscript-sdk/angelscript/projects/cmake/CMakeLists.txt Installs the `AngelscriptTargets.cmake` and `AngelscriptConfig.cmake` files into a specific location (`lib/cmake/Angelscript`) for CMake package discovery, also installing the version file. ```cmake set(ConfigPackageLocation lib/cmake/Angelscript) install(EXPORT AngelscriptTargets FILE AngelscriptTargets.cmake NAMESPACE Angelscript:: DESTINATION ${ConfigPackageLocation} ) install( FILES cmake/AngelscriptConfig.cmake "${CMAKE_CURRENT_BINARY_DIR}/Angelscript/AngelscriptConfigVersion.cmake" DESTINATION ${ConfigPackageLocation} COMPONENT Devel ) ``` -------------------------------- ### Global Include Directories Setup Source: https://github.com/hzqst/metamod-fallguys/blob/main/CMakeLists.txt Specifies the global include directories for the project, pointing to common SDK headers required for compilation. ```cmake # 全局包含目录 include_directories( ${CMAKE_SOURCE_DIR}/hlsdk/common ${CMAKE_SOURCE_DIR}/hlsdk/dlls ${CMAKE_SOURCE_DIR}/hlsdk/pm_shared ${CMAKE_SOURCE_DIR}/hlsdk/engine ${CMAKE_SOURCE_DIR}/metamod ) ``` -------------------------------- ### CMake Project Setup and C++ Standard Configuration Source: https://github.com/hzqst/metamod-fallguys/blob/main/CMakeLists.txt Initializes the CMake project, sets the C++ standard to C++17, and enforces its usage. It also defines a build option for 64-bit compilation. ```cmake cmake_minimum_required(VERSION 3.15) project(metamod-fallguys) # 设置 C++ 标准 set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) option(METAMOD_64BIT "Compile as 64bit" OFF) if(METAMOD_64BIT) add_definitions(-DMETAMOD_64BIT) endif() ``` -------------------------------- ### Asynchronous HTTP Request and Response Handling in Metamod Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md This code snippet illustrates how to initiate an asynchronous HTTP GET request using Metamod's engine functions. It shows setting timeouts, appending headers, defining a callback for response processing, and displaying the response code, headers, and body. The request is then sent, and upon successful completion, the HTTP request is destroyed. Dependencies include Metamod's engine functions and game functions for alert messages. ```cpp int request_id = g_EngineFuncs.CreateHTTPRequest("http://www.baidu.com/", true, ASCURL_METHOD_GET, 1000,//connect timeout in ms 5000 //transfer timeout in ms ); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Cache-control: no-cache"); g_EngineFuncs.SetHTTPRequestCallback(request_id, function(int reqid){ int response_code = 0; string response_header; string response_body; g_EngineFuncs.GetHTTPResponse(reqid, response_code, response_header, response_body); if(response_code >= 200) { g_Game.AlertMessage(at_aiconsole, "%1", response_header ); g_Game.AlertMessage(at_aiconsole, "%1", response_body ); g_EngineFuncs.DestroyHTTPRequest(reqid); } }); g_EngineFuncs.SendHTTPRequest(request_id); ``` -------------------------------- ### Install Target for Angelscript Library Source: https://github.com/hzqst/metamod-fallguys/blob/main/thirdparty/angelscript-sdk/angelscript/projects/cmake/CMakeLists.txt Installs the Angelscript target, defining destinations for runtime, library, archive, and include files. Also exports targets for package configuration. ```cmake install(TARGETS ${ANGELSCRIPT_LIBRARY_NAME} EXPORT AngelscriptTargets RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib INCLUDES DESTINATION include ) ``` -------------------------------- ### Get Sound File Information with AngelScript Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_FALLGUYS.md This AngelScript snippet demonstrates how to retrieve detailed information about a sound file, including its type, format, channel count, bit depth, and length in milliseconds. It utilizes the `GetSoundInfo` function from a `SoundEngine` object and displays the retrieved data using `AlertMessage`. This is useful for debugging and verifying audio asset properties. ```angelscript //bool GetSoundInfo(const string& in szSoundName, SoundEngine_SoundInfo & out SoundInfo) SoundEngine_SoundInfo info; if(g_SoundEngine.GetSoundInfo("weapons/357_shot1.wav", info)) { g_Game.AlertMessage( at_console, "Sound %1, type=%2, format=%3, channels=%4, bits=%5, length=%6\n", "weapons/357_shot1.wav", info.type, info.format, info.channels, info.bits, info.length); //The units of info.length is Milliseconds } ``` -------------------------------- ### Define HTTP Request Method Constants Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md Defines integer constants for various HTTP request methods (GET, POST, PUT) to be used with the ascurl plugin. These constants improve code readability. ```angelscript const int ASCURL_METHOD_GET = 0; const int ASCURL_METHOD_POST = 1; const int ASCURL_METHOD_PUT = 2; ``` -------------------------------- ### Enable Super Pusher for Brush Entities (AngelScript) Source: https://context7.com/hzqst/metamod-fallguys/llms.txt This code snippet demonstrates how to enable the 'Super Pusher' functionality for brush entities. When enabled, these entities can forcefully push players backward even if they are blocked by other players. The example includes a basic brush entity setup and its touch callback. ```angelscript class MovingPlatform : ScriptBaseEntity { void Spawn() { // Standard brush entity setup Precache(); pev.solid = SOLID_BSP; pev.movetype = MOVETYPE_PUSH; g_EntityFuncs.SetModel(self, pev.model); g_EntityFuncs.SetSize(pev, pev.mins, pev.maxs); g_EntityFuncs.SetOrigin(self, pev.origin); // Enable Super Pusher: pushes through blocking players g_EntityFuncs.SetEntitySuperPusher(self.edict(), true); } // Touch callback fires when Super Pusher impacts a player/monster void Touch(CBaseEntity@ pOther) { if(pOther.IsPlayer()) { CBasePlayer@ pPlayer = cast(pOther); // Player was pushed - apply additional effects g_PlayerFuncs.ScreenFade(pPlayer, Vector(255, 100, 0), 0.5, 0.1, 50, FFADE_IN); } } } ``` -------------------------------- ### Get Sound Info Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_FALLGUYS.md Retrieves detailed information about a specified sound file. This includes its type, format, channel count, bit depth, and duration in milliseconds. ```APIDOC ## GET /sound/info ### Description Retrieves detailed information about a specified sound file. ### Method GET ### Endpoint /sound/info ### Parameters #### Query Parameters - **szSoundName** (string) - Required - The name or path of the sound file to retrieve information for. ### Request Example ```json { "szSoundName": "weapons/357_shot1.wav" } ``` ### Response #### Success Response (200) - **type** (FMOD_SOUND_TYPE) - The type of the sound file (e.g., WAV, MP3). - **format** (FMOD_SOUND_FORMAT) - The native format of the audio data (e.g., PCM16, PCMFLOAT). - **channels** (integer) - The number of audio channels (e.g., mono, stereo). - **bits** (integer) - The bit depth of the audio data. - **length** (integer) - The length of the sound in milliseconds. #### Response Example ```json { "type": "FMOD_SOUND_TYPE_WAV", "format": "FMOD_SOUND_FORMAT_PCM16", "channels": 2, "bits": 16, "length": 1500 } ``` ``` -------------------------------- ### Asext Plugin: Handle Custom Hooks in AngelScript Source: https://context7.com/hzqst/metamod-fallguys/llms.txt Registers a handler function for a custom hook defined in C++ using the Asext plugin. The `OnPlayerCustomEvent` function will be called when the `PlayerCustomEvent` hook is triggered. The hook registration is typically done during map initialization or plugin setup. ```angelscript // Register and handle the custom hook from AngelScript HookReturnCode OnPlayerCustomEvent(CBasePlayer@ pPlayer, int eventType, float value) { g_Game.AlertMessage(at_console, "Player %1 triggered event %2 with value %3\n", pPlayer.pev.netname, eventType, value); return HOOK_CONTINUE; } void MapInit() { g_Hooks.RegisterHook(Hooks::Player::PlayerCustomEvent, @OnPlayerCustomEvent); } ``` -------------------------------- ### Send QueryCvar Request to Client Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASQCVAR.md Initiates a querycvar request to a client using NetworkMessages. While this can be done without metamod, receiving the response requires its integration. The example sends a request for 'default_fov' with a specific request ID. ```angelscript //NetworkMessages::NetworkMessageType(58) means "svc_sendcvarvalue2" NetworkMessage m( MSG_ONE, NetworkMessages::NetworkMessageType(58), pPlayer.edict() ); m.WriteLong(114514);//RequestId m.WriteString("default_fov"); m.End(); ``` -------------------------------- ### C++ Synchronous AliyunOSS File Upload Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md Demonstrates synchronous file upload to Aliyun OSS. It reads a local file into a BLOB, generates an authentication signature using HMAC-SHA1, and constructs an HTTP PUT request with all necessary headers. The upload is performed synchronously, and the code includes a loop to check for the HTTP response. Dependencies include Aliyun OSS SDK functions, file system access, and HTTP request handling. ```C++ string szSoundCacheFile = "maps/soundcache/"+g_Engine.mapname+".txt"; size_t nFileSize = 0; File@ pFile = g_FileSystem.OpenFile(szSoundCacheFile, OpenFile::READ); if (pFile !is null && pFile.IsOpen()) { nFileSize = pFile.GetSize(); BLOB @pBlob = pFile.ReadBlob(); string AccessKeyId = "************"; string AccessKeySecret = "************************"; string Host = "****bucket****.oss-cn-shanghai.aliyuncs.com"; string CanonicalizedResource = "/****bucket****/"+szSoundCacheFile; string szFileMD5 = ""; string szFileType = "text/plain"; string GMTDate = UnixTimeToGMT(UnixTimestamp()); string CanonicalizedOSSHeaders = ""; string Signature; string SignatureBase64; g_EngineFuncs.hmac_sha1(AccessKeySecret, "PUT" + "\n" + szFileMD5 + "\n" + szFileType + "\n" + GMTDate + "\n" + CanonicalizedOSSHeaders + CanonicalizedResource, Signature); g_EngineFuncs.base64_encode(Signature, SignatureBase64); string Authorization = "OSS " + AccessKeyId + ":" + SignatureBase64; int request_id = g_EngineFuncs.CreateHTTPRequest("http://"+Host+"/"+szSoundCacheFile, false,//false=sync, true=async ASCURL_METHOD_PUT, 1000,//connect timeout in ms 5000 //transfer timeout in ms ); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Host: " + Host); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Cache-control: no-cache"); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Content-Type: " + szFileType); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Content-Length: " + nFileSize); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Date: " + GMTDate); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Authorization: " + Authorization); g_EngineFuncs.SetHTTPRequestUploadBlob(request_id, pBlob); g_EngineFuncs.SendHTTPRequest(request_id); int response_code = 0; string response_header; string response_body; while(g_EngineFuncs.GetHTTPResponse(request_id, response_code, response_header, response_body)) { if(response_code >= 200) ``` -------------------------------- ### HTTP Request Lifecycle Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md Covers the creation, configuration, sending, and destruction of HTTP requests. ```APIDOC ## HTTP Request Lifecycle ### Create HTTP Request Creates a new HTTP request. - **Method**: `POST` (Implicitly, as it returns an ID to be configured) - **Endpoint**: Not applicable (Function call) #### Function Signature `int g_EngineFuncs.CreateHTTPRequest(const string& in url, bool async, int method, int conn_timeout_ms, int timeout_ms)` #### Parameters - **url** (string) - Required - The URL to make the request to. - **async** (bool) - Required - `true` for asynchronous, `false` for synchronous. - **method** (int) - Required - The HTTP method (e.g., `ASCURL_METHOD_GET`, `ASCURL_METHOD_POST`). - **conn_timeout_ms** (int) - Required - Connection timeout in milliseconds. - **timeout_ms** (int) - Required - Transfer timeout in milliseconds. #### Request Example ```angelscript int request_id = g_EngineFuncs.CreateHTTPRequest("http://curl.se", true, // false=sync, true=async ASCURL_METHOD_PUT, 1000, // connect timeout in ms 5000 // transfer timeout in ms ); ``` ### Send HTTP Request Sends the configured HTTP request. - **Method**: `POST` (Implicitly, as it sends the request) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.SendHTTPRequest(int request_id)` #### Parameters - **request_id** (int) - Required - The ID of the request to send. #### Request Example ```angelscript g_EngineFuncs.SendHTTPRequest(request_id); ``` ### Destroy HTTP Request Frees resources associated with an HTTP request. - **Method**: `POST` (Implicitly, as it destroys the request) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.DestroyHTTPRequest(int request_id)` #### Parameters - **request_id** (int) - Required - The ID of the request to destroy. #### Request Example ```angelscript g_EngineFuncs.DestroyHTTPRequest(request_id); ``` ``` -------------------------------- ### Request Configuration Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md APIs for setting request details such as post fields, headers, and upload data. ```APIDOC ## Request Configuration ### Set HTTP Request Post Field Sets the post fields for an HTTP request, typically used for POST requests. The `post_fields` string must be URL-encoded. - **Method**: `POST` (Implicitly, as it configures the request) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.SetHTTPRequestPostField(int request_id, const string& in post_fields)` #### Parameters - **request_id** (int) - Required - The ID of the request to configure. - **post_fields** (string) - Required - URL-encoded string of key-value pairs for the post body. #### Request Example ```angelscript g_EngineFuncs.SetHTTPRequestPostField(request_id, "xyz=114514"); ``` ### Set HTTP Request Post Field (Extended) Sets the post fields with an explicit size, useful when `post_fields.length()` might be inaccurate. - **Method**: `POST` (Implicitly, as it configures the request) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.SetHTTPRequestPostFieldEx(int request_id, const string& in post_fields, int sizeof_post_fields)` #### Parameters - **request_id** (int) - Required - The ID of the request to configure. - **post_fields** (string) - Required - URL-encoded string of key-value pairs for the post body. - **sizeof_post_fields** (int) - Required - The exact size of the `post_fields` string. #### Request Example ```angelscript g_EngineFuncs.SetHTTPRequestPostFieldEx(request_id, "xyz=114514", 10); // Assuming size is 10 ``` ### Append HTTP Request Header Appends a custom header to the HTTP request. - **Method**: `POST` (Implicitly, as it configures the request) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.AppendHTTPRequestHeader(int request_id, const string& in header)` #### Parameters - **request_id** (int) - Required - The ID of the request to configure. - **header** (string) - Required - The header string (e.g., "Content-Type: application/json"). #### Request Example ```angelscript g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Cache-control: no-cache"); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Content-Type: text/plain"); ``` ### Append Form String to HTTP Request Appends a form field with a string value, typically used for `multipart/form-data` POST requests. - **Method**: `POST` (Implicitly, as it configures the request) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool AppendHTTPRequestFormString(int request_id, const string& in form, const string& in content)` #### Parameters - **request_id** (int) - Required - The ID of the request to configure. - **form** (string) - Required - The name of the form field. - **content** (string) - Required - The string content for the form field. #### Request Example ```angelscript g_EngineFuncs.AppendHTTPRequestFormString(request_id, "filename", "test.jpg"); ``` ### Append Form Blob to HTTP Request Appends a form field with binary data (BLOB), typically used for file uploads in `multipart/form-data` POST requests. - **Method**: `POST` (Implicitly, as it configures the request) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool AppendHTTPRequestFormBlob(int request_id, const string& in form, const BLOB& in blob)` #### Parameters - **request_id** (int) - Required - The ID of the request to configure. - **form** (string) - Required - The name of the form field. - **blob** (BLOB) - Required - The binary data for the form field. #### Request Example ```angelscript // Assuming pBlob is a valid BLOB object g_EngineFuncs.AppendHTTPRequestFormBlob(request_id, "filedata", pBlob); ``` ### Set HTTP Request Upload Blob Sets the entire request body as a binary blob, typically used for PUT requests. - **Method**: `POST` (Implicitly, as it configures the request) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool SetHTTPRequestUploadBlob(int request_id, const BLOB& in blob)` #### Parameters - **request_id** (int) - Required - The ID of the request to configure. - **blob** (BLOB) - Required - The binary data to upload. #### Request Example ```angelscript // Assuming pBlob is a valid BLOB object g_EngineFuncs.SetHTTPRequestUploadBlob(request_id, pBlob); ``` ``` -------------------------------- ### Ascurl Plugin: Asynchronous HTTP GET Request in AngelScript Source: https://context7.com/hzqst/metamod-fallguys/llms.txt Performs a non-blocking HTTP GET request using the Ascurl plugin. It includes options for setting timeouts, custom headers, and a callback function to handle the response asynchronously. The request must be explicitly sent after configuration. ```angelscript // HTTP method constants const int ASCURL_METHOD_GET = 0; const int ASCURL_METHOD_POST = 1; const int ASCURL_METHOD_PUT = 2; void FetchWebData() { // Create async HTTP GET request int request_id = g_EngineFuncs.CreateHTTPRequest( "https://api.example.com/data", true, // async = true ASCURL_METHOD_GET, 1000, // connect timeout (ms) 5000 // transfer timeout (ms) ); // Add custom headers g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Cache-Control: no-cache"); g_EngineFuncs.AppendHTTPRequestHeader(request_id, "Accept: application/json"); // Set callback for response handling g_EngineFuncs.SetHTTPRequestCallback(request_id, function(int reqid) { int response_code = 0; string response_header; string response_body; g_EngineFuncs.GetHTTPResponse(reqid, response_code, response_header, response_body); if(response_code >= 200 && response_code < 300) { // Success - parse response_body JSON here g_Game.AlertMessage(at_console, "HTTP Success: %1\n", response_body); } else { g_Game.AlertMessage(at_error, "HTTP Error %1\n", response_code); } // Clean up request g_EngineFuncs.DestroyHTTPRequest(reqid); }); // Send the request g_EngineFuncs.SendHTTPRequest(request_id); } ``` -------------------------------- ### Response Handling Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md APIs for setting callbacks to handle asynchronous responses and retrieving response details. ```APIDOC ## Response Handling ### Set Asynchronous Callback for HTTP Request Registers a callback function to be executed when an asynchronous HTTP request completes. - **Method**: `POST` (Implicitly, as it configures the request) - **Endpoint**: Not applicable (Function call) #### Function Signature `void HTTPResponseCallback(int request_id)` `bool g_EngineFuncs.SetHTTPRequestCallback(int request_id, HTTPResponseCallback @callback)` #### Parameters - **request_id** (int) - Required - The ID of the request to set the callback for. - **callback** (HTTPResponseCallback) - Required - A reference to the callback function. #### Callback Function Signature `function(int reqid)` #### Request Example (Setting Callback) ```angelscript g_EngineFuncs.SetHTTPRequestCallback(request_id, function(int reqid){ int response_code = 0; string response_header; string response_body; g_EngineFuncs.GetHTTPResponse(reqid, response_code, response_header, response_body); if(response_code >= 200) { g_Game.AlertMessage(at_aiconsole, "%1", response_header ); // Example action g_EngineFuncs.DestroyHTTPRequest(reqid); } }); ``` ### Get HTTP Response Retrieves the response code, header, and body of a completed HTTP request. - **Method**: `POST` (Implicitly, as it retrieves response data) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.GetHTTPResponse(int request_id, int& out out_response, string& out out_header, string& out out_body)` #### Parameters - **request_id** (int) - Required - The ID of the request whose response to get. - **out_response** (int& out) - Output - The HTTP response code. - **out_header** (string& out) - Output - The response headers. - **out_body** (string& out) - Output - The response body. #### Request Example ```angelscript int response_code = 0; string response_header; string response_body; g_EngineFuncs.GetHTTPResponse(reqid, response_code, response_header, response_body); ``` ``` -------------------------------- ### Get View Entity Utility Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_FALLGUYS.md Retrieves the player's current view entity, which could be an entity like a trigger_camera. ```APIDOC ## Get Player's View Entity ### Description This function retrieves the player's current view entity. This is useful for scenarios where the player's camera might be controlled by another entity, such as a `trigger_camera`. ### Method Function Call ### Endpoint N/A (Function) ### Parameters - **pClient** (edict_t@) - The player's client entity. ### Request Example ```angelscript // Function signature (commented out in provided example): // edict_t@ GetViewEntity(edict_t@ pClient) edict_t@viewent = g_EngineFuncs.GetViewEntity(pPlayer.edict()); ``` ### Response #### Success Response - **viewent** (edict_t@) - The entity dictionary of the player's current view entity. Returns null if no specific view entity is set. #### Response Example ```json { "viewent": "" } ``` ``` -------------------------------- ### Call Registered AngelScript Function Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASEXT.md An example of calling a C++ function that has been registered with the AngelScript engine. If the registration was successful, this call will return the value 114514. ```angelscript int test = g_EngineFuncs.TestFunc(); ``` -------------------------------- ### ascrl Constants and Macros Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md Defines constants for HTTP methods and a macro for checking ascrl availability. ```APIDOC ## Constants and Macros ### Macro `METAMOD_PLUGIN_ASCURL`: Use this macro to identify the accessibility of `ascurl.dll`. ```angelscript #if METAMOD_PLUGIN_ASCURL // Code that uses ascrl #endif ``` ### Constants Constants for specifying HTTP methods: - `ASCURL_METHOD_GET = 0` - `ASCURL_METHOD_POST = 1` - `ASCURL_METHOD_PUT = 2` ```angelscript const int ASCURL_METHOD_GET = 0; const int ASCURL_METHOD_POST = 1; const int ASCURL_METHOD_PUT = 2; ``` ``` -------------------------------- ### Utility Functions Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md Provides utility functions for hashing and encoding. ```APIDOC ## Utility Functions ### HMAC SHA1 Calculates the HMAC-SHA1 hash of a message. - **Method**: `POST` (Implicitly, as it performs a calculation) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.hmac_sha1(const string& in password, const string& in message, string& out outhash)` #### Parameters - **password** (string) - Required - The secret key for HMAC. - **message** (string) - Required - The message to hash. - **outhash** (string& out) - Output - The resulting HMAC-SHA1 hash (binary string). ### HMAC MD5 Calculates the HMAC-MD5 hash of a message. - **Method**: `POST` (Implicitly, as it performs a calculation) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.hmac_md5(const string& in password, const string& in message, string& out outhash)` #### Parameters - **password** (string) - Required - The secret key for HMAC. - **message** (string) - Required - The message to hash. - **outhash** (string& out) - Output - The resulting HMAC-MD5 hash (binary string). ### MD5 Calculates the MD5 hash of a data string. - **Method**: `POST` (Implicitly, as it performs a calculation) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.md5(const string& in data, string& out outhash)` #### Parameters - **data** (string) - Required - The input data to hash. - **outhash** (string& out) - Output - The resulting MD5 hash (binary string). ### Base64 Encode Encodes a string using Base64. - **Method**: `POST` (Implicitly, as it performs encoding) - **Endpoint**: Not applicable (Function call) #### Function Signature `bool g_EngineFuncs.base64_encode(const string& in hash, string& out outstr)` #### Parameters - **hash** (string) - Required - The string to encode. - **outstr** (string& out) - Output - The Base64 encoded string (human-readable). #### Request Example (Utilities) ```angelscript // Example for hmac_sha1 string hashedPassword; g_EngineFuncs.hmac_sha1("mysecretkey", "userpassword", hashedPassword); // Example for base64_encode string encodedData; g_EngineFuncs.base64_encode("some data to encode", encodedData); ``` ``` -------------------------------- ### C++ Utility Functions for Date and Time Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md Provides helper functions for calculating the day of the week and converting Unix timestamps to a human-readable GMT string. These are essential for generating correct timestamps and date formats required by Aliyun OSS. Dependencies include standard C++ time functions. ```C++ int get_weekday(int day, int month, int year) { int a, y, m, R; a = ( 14 - month ) / 12; y = year - a; m = month + 12 * a - 2; R = 7000 + ( day + y + y / 4 - y / 100 + y / 400 + (31 * m) / 12 ); return R % 7; } string UnixTimeToGMT(time_t t) { const int MILLISECONDS_IN_SECOND = 1000; const int MILLISECONDS_IN_MINUTE = 60000; const int MILLISECONDS_IN_HALF_HOUR = 1800000; const int MILLISECONDS_IN_HOUR = 3600000; const int MILLISECONDS_IN_DAY = 86400000; const int SECONDS_IN_MINUTE = 60; const int SECONDS_IN_HALF_HOUR = 1800; const int SECONDS_IN_HOUR = 3600; const int SECONDS_IN_DAY = 86400; const int SECONDS_IN_YEAR = 31536000; const int SECONDS_IN_LEAP_YEAR = 31622400; const int AVERAGE_SECONDS_IN_YEAR = 31557600; const int SECONDS_IN_4_YEAR = 126230400; const int MINUTES_IN_HOUR = 60; const int MINUTES_IN_DAY = 1440; const int MINUTES_IN_WEEK = 10080; const int MINUTES_IN_MONTH = 40320; const int HOURS_IN_DAY = 24; const int MONTHS_IN_YEAR = 12; const int DAYS_IN_WEEK = 7; const int DAYS_IN_LEAP_YEAR = 366; const int DAYS_IN_YEAR = 365; const int DAYS_IN_4_YEAR = 1461; const int FIRST_YEAR_UNIX = 1970; const int MAX_DAY_MONTH = 31; const int OADATE_UNIX_EPOCH = 25569; const int _TBIAS_DAYS = 25567; const int _TBIAS_YEAR = 1900; time_t _secs = t; int _mon, _year; int _days; int i; _days = _TBIAS_DAYS; _days += _secs / SECONDS_IN_DAY; _secs = _secs % SECONDS_IN_DAY; int hour = _secs / SECONDS_IN_HOUR; _secs %= SECONDS_IN_HOUR; int minute = _secs / SECONDS_IN_MINUTE; int second = _secs % SECONDS_IN_MINUTE; int month = 0; int day = 0; array lmos = {0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335}; array mos = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; _year = _days / DAYS_IN_YEAR; int mos_i; mos_i = ( ((_year & 3) != 0) || (_year == 0) ) ? mos[0] : lmos[0]; i = ((_year - 1) / 4) + mos_i + DAYS_IN_YEAR*_year; while (_days < i){ -_year; mos_i = ( ((_year & 3) != 0) || (_year == 0) ) ? mos[0] : lmos[0]; i = ((_year - 1) / 4) + mos_i + DAYS_IN_YEAR*_year; } _days -= i; int year = _year + _TBIAS_YEAR; if( ((_year & 3) != 0) || (_year == 0) ) { // mos for(_mon = MONTHS_IN_YEAR; _days < mos[--_mon];); month = _mon + 1; day = _days - mos[_mon] + 1; } else { for(_mon = MONTHS_IN_YEAR; _days < lmos[--_mon];); month = _mon + 1; day = _days - lmos[_mon] + 1; } //0~11 int week = get_weekday(day, month, year); array weeknames = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; array monthnames = { "", "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; string fullhour = (hour < 10) ? ("0"+hour) : hour; string fullmin = (minute < 10) ? ("0"+minute) : minute; string fullsec = (second < 10) ? ("0"+second) : second; return weeknames[week] + ", " + day + " " + monthnames[month] + " " + year + " " + fullhour + ":" + fullmin + ":" + fullsec + " GMT"; } ``` -------------------------------- ### Call AngelScript Hook from C++ Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASEXT.md Illustrates how to call a registered AngelScript hook from C++ code. The ASEXT_CallHook macro is used, passing the hook pointer and necessary arguments. The result is ignored in this example. ```cpp //Add to where you would like to call AngelScript hooks void NewPlayerPostThink_Post(edict_t *pEntity) { if(ASEXT_CallHook)//The second arg must be zero, the third, 4th, 5th, 6th... args are the real args pass to AngelScript VM. (*ASEXT_CallHook)(g_PlayerPostThinkPostHook, 0, pEntity->pvPrivateData); SET_META_RESULT(MRES_IGNORED); } ``` -------------------------------- ### Asqcvar Plugin: Query Client Console Variables with Per-Request Callbacks Source: https://context7.com/hzqst/metamod-fallguys/llms.txt Provides a method to handle client console variable queries using request-specific callbacks instead of global hooks. This allows for more targeted handling of responses based on a unique request ID. It is useful for validating specific client settings. ```angelscript void ValidatePlayerSettings(CBasePlayer@ pPlayer) { // Set callback for specific request ID int requestId = 99999; g_EngineFuncs.SetQueryCvar2Callback(requestId, function(CBasePlayer@ pPlayer, int reqId, string cvarName, string value) { // This callback only fires for requestId 99999 g_Game.AlertMessage(at_console, "Callback fired: %1 = %2 for %3\n", cvarName, value, pPlayer.pev.netname); // Validate cl_lw (client-side weapon prediction) if(cvarName == "cl_lw" && value != "1") { g_PlayerFuncs.SayText(pPlayer, "Please enable client-side weapon prediction (cl_lw 1)"); } }); // Send the query NetworkMessage m(MSG_ONE, NetworkMessages::NetworkMessageType(58), pPlayer.edict()); m.WriteLong(requestId); m.WriteString("cl_lw"); m.End(); } ``` -------------------------------- ### Get Player's View Entity in AngelScript Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_FALLGUYS.md This AngelScript snippet retrieves the player's associated view entity, such as a trigger_camera. It utilizes the g_EngineFuncs.GetViewEntity function, passing the player's edict_t. The returned entity can be used for various purposes related to camera or view control. ```angelscript //edict_t@ GetViewEntity(edict_t@ pClient) edict_t@viewent = g_EngineFuncs.GetViewEntity(pPlayer.edict()); ``` -------------------------------- ### Load and Import ASExt DLL in Meta_Attach Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASEXT.md Demonstrates how to load the 'asext' DLL (or .so on non-Windows systems) within the Meta_Attach function and import its API. It includes error handling if the DLL cannot be loaded. ```cpp // Add the following code in meta_api.cpp->Meta_Attach void *asextHandle = NULL; #ifdef _WIN32 LOAD_PLUGIN(PLID, "addons/metamod/dlls/asext.dll", PLUG_LOADTIME::PT_ANYTIME, &asextHandle); #else LOAD_PLUGIN(PLID, "addons/metamod/dlls/asext.so", PLUG_LOADTIME::PT_ANYTIME, &asextHandle); #endif if (!asextHandle) { LOG_ERROR(PLID, "asext dll handle not found!"); return FALSE; } IMPORT_ASEXT_API(asext); ``` -------------------------------- ### Asqcvar Plugin: Query Client Console Variables with Global Hooks Source: https://context7.com/hzqst/metamod-fallguys/llms.txt Allows querying client-side console variable values by registering a global hook for all cvar query responses. This enables validation and customization of player settings. It uses network messages to send queries and a hook to receive responses. ```angelscript const int CVAR_QUERY_REQUEST_ID = 12345; void MapInit() { // Register global hook for all cvar query responses g_Hooks.RegisterHook(Hooks::Player::QueryCvar2, @PlayerQueryCvar2); } void CheckPlayerFOV(CBasePlayer@ pPlayer) { // Send query to client for specific cvar // NetworkMessages::NetworkMessageType(58) = svc_sendcvarvalue2 NetworkMessage m(MSG_ONE, NetworkMessages::NetworkMessageType(58), pPlayer.edict()); m.WriteLong(CVAR_QUERY_REQUEST_ID); // Request ID for tracking m.WriteString("default_fov"); // CVar name to query m.End(); } // Global hook receives all cvar query responses HookReturnCode PlayerQueryCvar2(CBasePlayer@ pPlayer, int requestId, const string& in cvarName, const string& in value) { if(requestId == CVAR_QUERY_REQUEST_ID && cvarName == "default_fov") { float fov = atof(value); if(fov > 120 || fov < 75) { g_PlayerFuncs.ClientPrint(pPlayer, HUD_PRINTTALK, "Warning: Your FOV (" + value + ") is outside normal range\n"); } g_Game.AlertMessage(at_console, "%1's FOV is %2\n", pPlayer.pev.netname, value); } return HOOK_CONTINUE; } ``` -------------------------------- ### Utility Functions for Hashing and Encoding Source: https://github.com/hzqst/metamod-fallguys/blob/main/README_ASCURL.md Provides utility functions for cryptographic hashing (HMAC-SHA1, HMAC-MD5, MD5) and Base64 encoding. These are useful for security-sensitive operations or data serialization. ```angelscript //bool g_EngineFuncs.hmac_sha1(const string& in password, const string& in message, string& out outhash)//outhash is non-readable binary string //bool g_EngineFuncs.hmac_md5(const string& in password, const string& in message, string& out outhash)//outhash is non-readable binary string //bool g_EngineFuncs.md5(const string& in data, string& out outhash)//outhash is non-readable binary string //bool g_EngineFuncs.base64_encode(const string& in hash, string& out outstr)//outstr is human-readable string ``` -------------------------------- ### Implement Entity Level of Detail System (AngelScript) Source: https://context7.com/hzqst/metamod-fallguys/llms.txt This section details how to implement a Level of Detail (LOD) system for entities to optimize performance. It covers precaching different models for various LOD levels and setting up model/scale-based LOD with interpolation based on distance. An alternative approach using body-based LOD and custom pev fields is also presented. ```angelscript // LOD flag constants const int LOD_BODY = 1; const int LOD_MODELINDEX = 2; const int LOD_SCALE = 4; const int LOD_SCALE_INTERP = 8; // Interpolate scale between LOD levels void SetupEntityLOD(CBaseEntity@ pEntity) { // Precache different LOD models int modelLOD0 = g_Game.PrecacheModel("models/arrow_hq.mdl"); int modelLOD1 = g_Game.PrecacheModel("models/arrow_med.mdl"); int modelLOD2 = g_Game.PrecacheModel("models/arrow_low.mdl"); int modelLOD3 = g_Game.PrecacheModel("models/arrow_verylow.mdl"); // Setup model and scale LOD with interpolation // Distances: 0-300, 300-700, 700-1000, 1000+ units // Scale interpolates smoothly between 0.15 and 0.75 in LOD1 range g_EntityFuncs.SetEntityLevelOfDetail(pEntity.edict(), LOD_MODELINDEX | LOD_SCALE_INTERP, modelLOD0, 0.15, // LOD 0: 0-300 units modelLOD1, 0.15, 300, // LOD 1: 300-700 units (scale interpolates) modelLOD2, 0.75, 700, // LOD 2: 700-1000 units modelLOD3, 0.75, 1000 // LOD 3: 1000+ units ); } // Alternative: Body-based LOD using pev custom fields void SetupBodyLOD(CBaseEntity@ pEntity) { // Use entity's pev fields to store LOD configuration pEntity.pev.iuser1 = 1; // Body value for LOD 1 pEntity.pev.iuser2 = 2; // Body value for LOD 2 pEntity.pev.iuser3 = 3; // Body value for LOD 3 pEntity.pev.fuser1 = 500; // Distance threshold 1 pEntity.pev.fuser2 = 1000; // Distance threshold 2 pEntity.pev.fuser3 = 2000; // Distance threshold 3 g_EntityFuncs.SetEntityLevelOfDetail(pEntity.edict(), LOD_BODY, 0, 0.0, // LOD 0: body=0, distance 0-fuser1 pEntity.pev.iuser1, 0, pEntity.pev.fuser1, pEntity.pev.iuser2, 0, pEntity.pev.fuser2, pEntity.pev.iuser3, 0, pEntity.pev.fuser3 ); } ```