### Installing Build Dependencies on Debian/Ubuntu Source: https://github.com/rehlds/reapi/blob/master/README.md This code block provides the necessary `apt-get` commands to install essential build tools and libraries on Debian-based Linux systems (like Ubuntu). It includes commands for adding i386 architecture support, installing multi-arch compilers, and essential build utilities. ```bash sudo dpkg --add-architecture i386 sudo apt-get update sudo apt-get install -y gcc-multilib g++-multilib sudo apt-get install -y build-essential sudo apt-get install -y libc6-dev libc6-dev-i386 ``` -------------------------------- ### Selecting C/C++ Compiler on Debian/Ubuntu Source: https://github.com/rehlds/reapi/blob/master/README.md This snippet shows how to install either the GCC or Clang compiler on Debian/Ubuntu systems. Users can choose their preferred compiler by running the corresponding `apt-get install` command. ```bash 1) sudo apt-get install -y gcc g++ 2) sudo apt-get install -y clang ``` -------------------------------- ### Shell Command: Compile with Clang Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Uses CMake with Clang as the C++ compiler and then builds the project using make. Assumes Clang is installed and in the PATH. ```shell CC="clang" CXX="clang++" cmake .. make ``` -------------------------------- ### Shell Command: Compile with Intel C++ Compiler Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Uses CMake with the Intel C++ compiler (icc/icpc) and then builds the project using make. Requires Intel compilers to be installed and configured. ```shell CC="icc" CXX="icpc" cmake .. make ``` -------------------------------- ### rh_emit_sound2 - Advanced Sound Control Source: https://context7.com/rehlds/reapi/llms.txt This function allows for advanced control over sound emission, including specifying recipients, channels, and audio positioning. Examples show playing sounds to a single player, to all players at a location, and with custom pitch. ```APIDOC ## rh_emit_sound2 - Advanced Sound Control ### Description Emits sounds with full control over recipients, channels, and positioning. ### Method N/A (Function call within game engine) ### Endpoint N/A ### Parameters N/A ### Request Example ```pawn // Play to specific player only rh_emit_sound2(id, id, channel, sound, volume, ATTN_NORM, 0, PITCH_NORM); // Play to everyone at position rh_emit_sound2(0, 0, channel, sound, volume, ATTN_NORM, 0, PITCH_NORM, 0, origin); ``` ### Response N/A ``` -------------------------------- ### Manipulate Entity Variables with set_entvar / get_entvar Source: https://context7.com/rehlds/reapi/llms.txt Access and modify entity variables to control physics, rendering, and behavior. Examples include changing velocity, gravity, transparency, color, collision properties, and entity size. Requires the 'reapi' include. ```pawn #include public ModifyEntityPhysics(ent) { // Movement properties new Float:velocity[3]; get_entvar(ent, var_velocity, velocity); velocity[2] += 300.0; // Launch upward set_entvar(ent, var_velocity, velocity); new Float:gravity = get_entvar(ent, var_gravity); set_entvar(ent, var_gravity, 0.5); // Half gravity new Float:friction = get_entvar(ent, var_friction); set_entvar(ent, var_friction, 0.1); // Low friction // Rendering set_entvar(ent, var_rendermode, kRenderTransAlpha); set_entvar(ent, var_renderamt, 128.0); // 50% transparent new Float:color[3] = {255.0, 0.0, 0.0}; set_entvar(ent, var_rendercolor, color); // Red tint // Collision and solidity set_entvar(ent, var_solid, SOLID_BBOX); set_entvar(ent, var_movetype, MOVETYPE_FLY); // Size new Float:mins[3] = {-16.0, -16.0, -16.0}; new Float:maxs[3] = {16.0, 16.0, 16.0}; set_entvar(ent, var_mins, mins); set_entvar(ent, var_maxs, maxs); } // Create custom projectile public CreateProjectile(owner, Float:origin[3], Float:velocity[3]) { new ent = rg_create_entity("info_target"); if (ent <= 0) return 0; // Set basic properties set_entvar(ent, var_classname, "custom_projectile"); set_entvar(ent, var_owner, owner); set_entvar(ent, var_origin, origin); set_entvar(ent, var_velocity, velocity); // Physics set_entvar(ent, var_movetype, MOVETYPE_TOSS); set_entvar(ent, var_solid, SOLID_BBOX); set_entvar(ent, var_gravity, 0.8); // Model and size set_entvar(ent, var_model, "models/w_hegrenade.mdl"); set_entvar(ent, var_modelindex, engfunc(EngFunc_ModelIndex, "models/w_hegrenade.mdl")); new Float:mins[3] = {-2.0, -2.0, -2.0}; new Float:maxs[3] = {2.0, 2.0, 2.0}; set_entvar(ent, var_mins, mins); set_entvar(ent, var_maxs, maxs); // Touch callback SetTouch(ent, "ProjectileTouch"); // Lifetime set_entvar(ent, var_nextthink, get_gametime() + 5.0); SetThink(ent, "ProjectileExplode"); return ent; } public ProjectileTouch(ent, other) { if (!is_valid_ent(ent)) return; new Float:origin[3]; get_entvar(ent, var_origin, origin); new owner = get_entvar(ent, var_owner); rg_dmg_radius(origin, ent, owner, 100.0, 200.0, CLASS_NONE, DMG_BLAST); set_entvar(ent, var_flags, FL_KILLME); } ``` -------------------------------- ### set_entvar / get_entvar - Entity Variable Access Source: https://context7.com/rehlds/reapi/llms.txt These functions provide access to and manipulation of entity variables, controlling aspects like physics, rendering, and behavior. Examples demonstrate modifying an entity's physics properties, creating a custom projectile with specific attributes, and handling touch events. ```APIDOC ## set_entvar / get_entvar - Entity Variable Access ### Description Manipulates entity variables for physics, rendering, and behavior. ### Method N/A (Function calls within game engine) ### Endpoint N/A ### Parameters N/A ### Request Example ```pawn // Modify entity physics new Float:velocity[3]; get_entvar(ent, var_velocity, velocity); velocity[2] += 300.0; // Launch upward set_entvar(ent, var_velocity, velocity); // Create custom projectile new ent = rg_create_entity("info_target"); set_entvar(ent, var_classname, "custom_projectile"); set_entvar(ent, var_origin, origin); ``` ### Response N/A ``` -------------------------------- ### Shell Script: Prepare Build Directory Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Commands to clean and create a new build directory before compiling. This ensures a fresh build environment. ```shell rm -rf build mkdir build && cd build ``` -------------------------------- ### Build Script Options for ReAPI on Linux Source: https://github.com/rehlds/reapi/blob/master/README.md This snippet details the command-line options available for the `build.sh` script on Linux. It allows users to specify the compiler, number of parallel jobs, and define build-time options like debugging mode or static linking. ```bash ./build.sh --compiler=[gcc] --jobs=[N] -D[option]=[ON or OFF] ``` -------------------------------- ### Linux Build Commands with Specific Compilers Source: https://github.com/rehlds/reapi/blob/master/README.md These commands demonstrate how to build the ReAPI project on Linux using different C/C++ compilers. Users can select between Intel C++ Compiler (ICC), LLVM (Clang), or the GNU Compiler Collection (GCC) by passing the appropriate flag to the build script. ```bash ./build.sh --compiler=intel ``` ```bash ./build.sh --compiler=clang ``` ```bash ./build.sh --compiler=gcc ``` -------------------------------- ### Shell Command: Compile with GCC Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Uses CMake with the default GCC compiler (if not otherwise specified) and then builds the project using make. This is the standard build if no specific compiler is set. ```shell cmake .. make ``` -------------------------------- ### CMakeLists.txt: Project Configuration Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Defines the minimum CMake version, project name, build options (DEBUG, USE_STATIC_LIBSTDC), and C++ standard. It also sets initial compiler and linker flags. ```cmake cmake_minimum_required(VERSION 3.1) project(reapi CXX) option(DEBUG "Build with debug information." OFF) option(USE_STATIC_LIBSTDC "Enables static linking libstdc++." OFF) set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Avoid -fPIC option set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") set(COMPILE_FLAGS "-m32 -U_FORTIFY_SOURCE") set(LINK_FLAGS "-m32 -s") set(COMPILE_FLAGS "${COMPILE_FLAGS} -Wall -fno-exceptions -fno-builtin -Wno-unknown-pragmas") # Remove noxref code and data set(COMPILE_FLAGS "${COMPILE_FLAGS} -ffunction-sections -fdata-sections") if (DEBUG) set(COMPILE_FLAGS "${COMPILE_FLAGS} -g3 -O3 -ggdb") else() set(COMPILE_FLAGS "${COMPILE_FLAGS} -g0 -O3 -fno-stack-protector") endif() ``` -------------------------------- ### Include and Compile Definitions (CMake) Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Configures include directories and preprocessor definitions for the 'reapi' target. It includes project-specific directories and defines various macros for different platforms and build settings. ```cmake target_include_directories(reapi PRIVATE ${PROJECT_SRC_DIR} ${PROJECT_CSSDK_DIR} ${PROJECT_METAMOD_DIR} ) target_compile_definitions(reapi PRIVATE _LINUX LINUX NDEBUG _GLIBCXX_USE_CXX11_ABI=0 HAVE_STRONG_TYPEDEF _stricmp=strcasecmp _strnicmp=strncasecmp _vsnprintf=vsnprintf _snprintf=snprintf ) ``` -------------------------------- ### Project Source and Include Directories (CMake) Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Defines lists of source and include directories for the project. These lists are used to organize project files and specify paths for header files during compilation. ```cmake set(PROJECT_SRC_DIR "${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/src" "${PROJECT_SOURCE_DIR}/common" "${PROJECT_SOURCE_DIR}/src/mods" "${PROJECT_SOURCE_DIR}/src/natives" "${PROJECT_SOURCE_DIR}/include" "${PROJECT_SOURCE_DIR}/version" ) set(PROJECT_CSSDK_DIR "${PROJECT_SOURCE_DIR}/include/cssdk/common" "${PROJECT_SOURCE_DIR}/include/cssdk/dlls" "${PROJECT_SOURCE_DIR}/include/cssdk/engine" "${PROJECT_SOURCE_DIR}/include/cssdk/game_shared" "${PROJECT_SOURCE_DIR}/include/cssdk/pm_shared" "${PROJECT_SOURCE_DIR}/include/cssdk/public" ) set(PROJECT_METAMOD_DIR "${PROJECT_SOURCE_DIR}/include/metamod" ) ``` -------------------------------- ### Emit Sounds with rh_emit_sound2 Source: https://context7.com/rehlds/reapi/llms.txt Controls sound emission with parameters for target, channel, volume, attenuation, pitch, and origin. Supports playing sounds to specific players, all players at a location, or with custom pitch. Requires the 'reapi' include. ```pawn #include public PlayCustomSound(id, const sound[], Float:volume = 1.0, channel = CHAN_AUTO) { if (!is_user_connected(id)) return; new Float:origin[3]; get_entvar(id, var_origin, origin); // Play to specific player only rh_emit_sound2(id, id, channel, sound, volume, ATTN_NORM, 0, PITCH_NORM); // Play to everyone at position rh_emit_sound2(0, 0, channel, sound, volume, ATTN_NORM, 0, PITCH_NORM, 0, origin); // Play with custom pitch rh_emit_sound2(id, 0, channel, sound, volume, ATTN_NORM, 0, 120); // Higher pitch } // Proximity-based audio system public HandleProximityVoice() { new players[MAX_PLAYERS], pnum; get_players(players, pnum, "ac"); for (new i = 0; i < pnum; i++) { new speaker = players[i]; new Float:speakerOrigin[3]; get_entvar(speaker, var_origin, speakerOrigin); for (new j = 0; j < pnum; j++) { if (i == j) continue; new listener = players[j]; new Float:listenerOrigin[3]; get_entvar(listener, var_origin, listenerOrigin); new Float:distance = vector_distance(speakerOrigin, listenerOrigin); // Set voice proximity if (distance < 512.0) { rg_set_can_hear_player(listener, speaker, true); } else { rg_set_can_hear_player(listener, speaker, false); } } } } // Directional sound with distance falloff public PlayDirectionalSound(Float:origin[3], const sound[], Float:maxDistance) { new players[MAX_PLAYERS], pnum; get_players(players, pnum, "c"); for (new i = 0; i < pnum; i++) { new id = players[i]; new Float:playerOrigin[3]; get_entvar(id, var_origin, playerOrigin); new Float:distance = vector_distance(origin, playerOrigin); if (distance < maxDistance) { new Float:volume = 1.0 - (distance / maxDistance); rh_emit_sound2(0, id, CHAN_AUTO, sound, volume, ATTN_NONE, 0, PITCH_NORM, 0, origin); } } } ``` -------------------------------- ### CMakeLists.txt: Intel C++ Compiler Flags Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Configures specific compilation and linking flags when the Intel C++ compiler (icpc) is detected via the CXX environment variable. Includes options for precise floating-point modeling and static linking. ```cmake if ("$ENV{CXX}" MATCHES "icpc") # # -fp-model=precise # ICC uses -fp-model fast=1 by default for more aggressive optimizations on floating-point calculations # https://software.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/floating-point-options/fp-model-fp.html#fp-model-fp_GUID-99936BBA-1508-4E9F-AC09-FA98613CE2F5 # set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -fp-model=precise\ -Qoption,cpp,--treat_func_as_string_literal_cpp\ -inline-forceinline\ -no-ansi-alias") set(LINK_FLAGS "${LINK_FLAGS} \ -static-intel\ -no-intel-extensions") if (NOT DEBUG) set(COMPILE_FLAGS "${COMPILE_FLAGS} -ipo") set(LINK_FLAGS "${LINK_FLAGS} -ipo") endif() else() # Produce code optimized for the most common IA32/AMD64/EM64T processors. # As new processors are deployed in the marketplace, the behavior of this option will change. set(COMPILE_FLAGS "${COMPILE_FLAGS} \ -mtune=generic -msse3\ -fno-sized-deallocation -Wno-strict-aliasing") endif() ``` -------------------------------- ### Linking Libraries and Flags (CMake) Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Specifies libraries to link against and sets linker flags. It links the 'dl' library and conditionally adds static C++ runtime libraries if 'USE_STATIC_LIBSTDC' is enabled. It also sets runtime path and library search paths. ```cmake target_sources(reapi PRIVATE ${REAPI_SRCS} ${COMMON_SRCS} ${PUBLIC_SRCS} ) target_link_libraries(reapi PRIVATE dl ) if (USE_STATIC_LIBSTDC) target_compile_definitions(reapi PRIVATE BUILD_STATIC_LIBSTDC) set(LINK_FLAGS "${LINK_FLAGS} -static-libgcc -static-libstdc++") endif() set(LINK_FLAGS "${LINK_FLAGS} \ -Wl,-rpath,'$ORIGIN/.' \ -L${PROJECT_SOURCE_DIR}/lib/linux32") ``` -------------------------------- ### Target Properties Configuration (CMake) Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Sets properties for the 'reapi' target, including the output name, prefix, compile flags, link flags, and position-independent code setting. ```cmake set_target_properties(reapi PROPERTIES OUTPUT_NAME reapi_amxx_i386 PREFIX "" COMPILE_FLAGS ${COMPILE_FLAGS} LINK_FLAGS ${LINK_FLAGS} POSITION_INDEPENDENT_CODE OFF ) ``` -------------------------------- ### Source File Definitions (CMake) Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Defines lists of source files for different components of the reapi project, including main sources, common utilities, and public interfaces. These lists are used when adding sources to the target library. ```cmake set(REAPI_SRCS "src/main.cpp" "src/amx_hook.cpp" "src/amxxmodule.cpp" "src/h_export.cpp" "src/dllapi.cpp" "src/entity_callback_dispatcher.cpp" "src/hook_callback.cpp" "src/hook_list.cpp" "src/hook_manager.cpp" "src/hook_message_manager.cpp" "src/api_config.cpp" "src/member_list.cpp" "src/meta_api.cpp" "src/reapi_utils.cpp" "src/sdk_util.cpp" "src/natives/natives_common.cpp" "src/natives/natives_hookchains.cpp" "src/natives/natives_hookmessage.cpp" "src/natives/natives_members.cpp" "src/natives/natives_misc.cpp" "src/natives/natives_rechecker.cpp" "src/natives/natives_reunion.cpp" "src/natives/natives_vtc.cpp" "src/mods/mod_rechecker_api.cpp" "src/mods/mod_regamedll_api.cpp" "src/mods/mod_rehlds_api.cpp" "src/mods/mod_reunion_api.cpp" "src/mods/mod_vtc_api.cpp" "src/mods/queryfile_handler.cpp" ) set(COMMON_SRCS "common/info.cpp" "common/stdc++compat.cpp" ) set(PUBLIC_SRCS "include/cssdk/public/interface.cpp" ) ``` -------------------------------- ### Give Weapons and Items to Players with rg_give_item Source: https://context7.com/rehlds/reapi/llms.txt Provides weapons and items to players, supporting inventory management options like replacement or appending. Dependencies: reapi.inc. Inputs/Outputs: Player ID and item name as input, returns entity integer or 0. Limitations: Requires correct item names and item type constants. ```pawn #include public GivePlayerLoadout(id) { if (!is_user_alive(id)) return; // Remove existing weapons first rg_remove_all_items(id, false); // Primary weapon - replace existing rg_give_item(id, "weapon_m4a1", GT_REPLACE); rg_set_user_bpammo(id, WEAPON_M4A1, 90); // Secondary weapon new wpnEnt = rg_give_item(id, "weapon_deagle", GT_APPEND); if (wpnEnt > 0) { set_member(wpnEnt, m_Weapon_iClip, 7); rg_set_user_bpammo(id, WEAPON_DEAGLE, 35); } // Equipment rg_give_item(id, "weapon_hegrenade", GT_APPEND); rg_give_item(id, "weapon_flashbang", GT_APPEND); rg_give_item(id, "weapon_flashbang", GT_APPEND); rg_give_item(id, "weapon_smokegrenade", GT_APPEND); // Armor and defuser rg_set_user_armor(id, 100, ARMOR_VESTHELM); if (get_member(id, m_iTeam) == TEAM_CT) { rg_give_defusekit(id); } } // Custom weapon drop system public OnWeaponDrop(id, weaponEnt) { new WeaponIdType:weaponID = get_member(weaponEnt, m_iId); // Prevent dropping knife if (weaponID == WEAPON_KNIFE) { return HC_SUPERCEDE; } // Drop with reduced ammo new clip = get_member(weaponEnt, m_Weapon_iClip); set_member(weaponEnt, m_Weapon_iClip, clip / 2); return HC_CONTINUE; } ``` -------------------------------- ### rg_give_item - Give Weapons and Items Source: https://context7.com/rehlds/reapi/llms.txt Provides players with specified weapons and items, with options to replace existing ones or append to their inventory. ```APIDOC ## rg_give_item - Give Weapons and Items ### Description Provides items to players with inventory management options. ### Method `rg_give_item(id, itemName, giveType) ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **id** (integer) - Required - The player's ID. - **itemName** (string) - Required - The name of the item to give (e.g., "weapon_m4a1"). - **giveType** (GT_*) - Required - The type of give operation (GT_REPLACE, GT_APPEND). ### Request Example ```pawn // Give a player an M4A1, replacing any existing primary weapon rg_give_item(id, "weapon_m4a1", GT_REPLACE); // Give a player a Deagle, adding it to their inventory new wpnEnt = rg_give_item(id, "weapon_deagle", GT_APPEND); ``` ### Response #### Success Response (integer) - **return value** (integer) - The entity index of the given item if GT_APPEND was used and successful, otherwise 0 or a non-positive value. ``` -------------------------------- ### Library Target Definition (CMake) Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Defines the 'reapi' shared library target. It specifies the source files to be compiled into the library and adds a dependency on the 'appversion' target, creating it if it doesn't exist. ```cmake add_library(reapi SHARED ${appversion.sh}) if (NOT TARGET appversion) add_custom_target(appversion DEPENDS COMMAND "${PROJECT_SOURCE_DIR}/version/appversion.sh" "${PROJECT_SOURCE_DIR}/.." "reapi") endif() add_dependencies(reapi appversion) ``` -------------------------------- ### Access Entity Properties with set_member / get_member Source: https://context7.com/rehlds/reapi/llms.txt Provides direct access to internal entity members for fine-grained control over player and entity states. Dependencies: reapi.inc. Inputs/Outputs: Takes entity ID and member name, returns or sets member values. Limitations: Requires understanding of entity structure and member names. ```pawn #include public ModifyPlayerState(id) { // Health and armor manipulation new Float:health = get_entvar(id, var_health); set_entvar(id, var_health, health * 1.5); new armor = get_member(id, m_iKevlar); set_member(id, m_iKevlar, 100); set_member(id, m_bHasHelmet, true); // Money and score new money = get_member(id, m_iAccount); set_member(id, m_iAccount, money + 16000); new frags = get_member(id, m_iNumKills); set_member(id, m_iNumKills, frags + 10); // Speed and gravity new Float:maxSpeed = get_member(id, m_flMaxSpeed); set_member(id, m_flMaxSpeed, maxSpeed * 1.2); set_entvar(id, var_gravity, 0.8); // Weapon state new activeItem = get_member(id, m_pActiveItem); if (activeItem > 0) { new clip = get_member(activeItem, m_Weapon_iClip); new maxClip = rg_get_iteminfo(activeItem, ItemInfo_iMaxClip); set_member(activeItem, m_Weapon_iClip, maxClip); // No recoil set_member(activeItem, m_Weapon_iShotsFired, 0); set_member(activeItem, m_Weapon_flAccuracy, 0.01); } } public CheckPlayerStatus(id) { // Query player state new TeamName:team = get_member(id, m_iTeam); new bool:isVIP = bool:get_member(id, m_bIsVIP); new bool:hasC4 = bool:get_member(id, m_bHasC4); new bool:hasDefuser = bool:get_member(id, m_bHasDefuser); new Float:velocity[3]; get_entvar(id, var_velocity, velocity); new Float:speed = vector_length(velocity); new bool:isOnGround = !!(get_entvar(id, var_flags) & FL_ONGROUND); new bool:isDucking = !!(get_entvar(id, var_flags) & FL_DUCKING); client_print(id, print_chat, "Team: %d | VIP: %d | C4: %d | Speed: %.1f", team, isVIP, hasC4, speed); } ``` -------------------------------- ### Apply Area Damage with rg_dmg_radius Source: https://context7.com/rehlds/reapi/llms.txt Applies damage in a specified radius around an origin point. Supports class filtering and damage falloff based on distance. Can be used for standard explosions or custom damage systems. Requires the 'reapi' include. ```pawn #include public CreateExplosion(Float:origin[3], attacker, Float:damage, Float:radius) { // Standard explosion rg_dmg_radius(origin, 0, attacker, damage, radius, CLASS_NONE, DMG_BLAST); // Create explosion effects message_begin(MSG_PVS, SVC_TEMPENTITY, origin); write_byte(TE_EXPLOSION); engfunc(EngFunc_WriteCoord, origin[0]); engfunc(EngFunc_WriteCoord, origin[1]); engfunc(EngFunc_WriteCoord, origin[2]); write_short(g_sprExplosion); write_byte(30); // scale write_byte(15); // framerate write_byte(TE_EXPLFLAG_NONE); message_end(); } // Custom grenade damage system public OnGrenadeExplode(grenadeEnt) { new Float:origin[3]; get_entvar(grenadeEnt, var_origin, origin); new owner = get_entvar(grenadeEnt, var_owner); new WeaponIdType:grenadeType = GetGrenadeType(grenadeEnt); if (grenadeType == WEAPON_HEGRENADE) { // Custom HE damage - more powerful, larger radius rg_dmg_radius(origin, grenadeEnt, owner, 120.0, 400.0, CLASS_NONE, DMG_BLAST | DMG_EXPLOSION); // Knockback effect new players[MAX_PLAYERS], pnum; get_players(players, pnum, "a"); for (new i = 0; i < pnum; i++) { new id = players[i]; new Float:playerOrigin[3]; get_entvar(id, var_origin, playerOrigin); new Float:distance = vector_distance(origin, playerOrigin); if (distance < 400.0) { new Float:direction[3]; xs_vec_sub(playerOrigin, origin, direction); xs_vec_normalize(direction, direction); new Float:force = (400.0 - distance) * 2.0; xs_vec_mul_scalar(direction, force, direction); new Float:velocity[3]; get_entvar(id, var_velocity, velocity); xs_vec_add(velocity, direction, velocity); set_entvar(id, var_velocity, velocity); } } } } ``` -------------------------------- ### Modify Game Rules and Query Game State (Pawn) Source: https://context7.com/rehlds/reapi/llms.txt These functions demonstrate direct access to CSGameRules members to modify game parameters like round time, bomb timer, scores, and buy times, as well as query the current game state including bomb status, round over status, player counts, and remaining round time. Requires the reapi library. ```pawn #include public ModifyGameRules() { // Round time control new Float:roundTime = get_member_game(m_fRoundStartTime); new Float:timeRemaining = get_member_game(m_fRoundTimeLimit) - (get_gametime() - roundTime); // Extend round time set_member_game(m_fRoundTimeLimit, timeRemaining + 60.0); // Bomb timer new Float:c4Timer = get_member_game(m_fC4Bomb); set_member_game(m_fC4Bomb, 45.0); // 45 second bomb timer // Game phase new bool:freezePeriod = bool:get_member_game(m_bFreezePeriod); if (freezePeriod) { set_member_game(m_bFreezePeriod, false); set_member_game(m_fRoundStartTimeReal, get_gametime()); } // Team scores new ctScore = get_member_game(m_iNumCTWins); new tScore = get_member_game(m_iNumTerroristWins); // Reset scores set_member_game(m_iNumCTWins, 0); set_member_game(m_iNumTerroristWins, 0); set_member_game(m_iNumConsecutiveCTLoses, 0); set_member_game(m_iNumConsecutiveTerroristLoses, 0); // Force buy time new bool:canBuy = bool:get_member_game(m_bCanBuy); set_member_game(m_bCanBuy, true); // VIP settings set_member_game(m_iMapHasVIPSafetyZone, 1); } public QueryGameState() { new bool:bombPlanted = rg_is_bomb_planted(); new bool:bombDefused = bool:get_member_game(m_bBombDefused); new bool:roundOver = bool:get_member_game(m_bRoundTerminating); new aliveCT, aliveT, deadCT, deadT; rg_initialize_player_counts(aliveT, aliveCT, deadT, deadCT); new Float:roundTimeLeft; new Float:roundStart = get_member_game(m_fRoundStartTime); new Float:roundLimit = get_member_game(m_fRoundTimeLimit); roundTimeLeft = roundLimit - (get_gametime() - roundStart); server_print("Bomb: %d | Defused: %d | Round Over: %d", bombPlanted, bombDefused, roundOver); server_print("Alive - CT: %d T: %d | Dead - CT: %d T: %d | Time: %.1f", aliveCT, aliveT, deadCT, deadT, roundTimeLeft); } ``` -------------------------------- ### Accumulate and Apply Damage with rg_multidmg_* Source: https://context7.com/rehlds/reapi/llms.txt Manages damage application across multiple entities efficiently. It allows clearing, adding, and applying accumulated damage. Useful for effects like shotgun blasts or area-of-effect attacks that hit multiple targets. Requires the 'reapi' include. ```pawn #include public ApplyMultiTargetDamage(attacker, Float:damage, damageBits) { // Clear any existing damage rg_multidmg_clear(); new Float:attackerOrigin[3]; get_entvar(attacker, var_origin, attackerOrigin); // Find all enemies in radius new players[MAX_PLAYERS], pnum; get_players(players, pnum, "a"); new TeamName:attackerTeam = get_member(attacker, m_iTeam); for (new i = 0; i < pnum; i++) { new victim = players[i]; if (victim == attacker) continue; new TeamName:victimTeam = get_member(victim, m_iTeam); if (victimTeam == attackerTeam) continue; new Float:victimOrigin[3]; get_entvar(victim, var_origin, victimOrigin); new Float:distance = vector_distance(attackerOrigin, victimOrigin); if (distance < 300.0) { // Add damage to accumulator new Float:actualDamage = damage * (1.0 - (distance / 300.0)); rg_multidmg_add(attacker, victim, actualDamage, damageBits); } } // Apply all accumulated damage at once rg_multidmg_apply(attacker, attacker); } // Shotgun-style multi-pellet damage public FireShotgunPellets(attacker, pelletCount, Float:damagePerPellet) { new Float:vecSrc[3], Float:vecAngles[3]; get_entvar(attacker, var_origin, vecSrc); get_entvar(attacker, var_v_angle, vecAngles); rg_multidmg_clear(); for (new i = 0; i < pelletCount; i++) { // Random spread for each pellet new Float:vecSpread[3]; vecSpread[0] = random_float(-0.08, 0.08); vecSpread[1] = random_float(-0.08, 0.08); vecSpread[2] = 0.0; // Trace each pellet new Float:vecDir[3], Float:vecEnd[3]; engfunc(EngFunc_MakeVectors, vecAngles); global_get(glb_v_forward, vecDir); xs_vec_add(vecDir, vecSpread, vecDir); xs_vec_normalize(vecDir, vecDir); xs_vec_mul_scalar(vecDir, 3000.0, vecEnd); xs_vec_add(vecSrc, vecEnd, vecEnd); new tr = create_tr2(); engfunc(EngFunc_TraceLine, vecSrc, vecEnd, DONT_IGNORE_MONSTERS, attacker, tr); new hitEnt = get_tr2(tr, TR_pHit); if (is_user_connected(hitEnt)) { rg_multidmg_add(attacker, hitEnt, damagePerPellet, DMG_BULLET); } free_tr2(tr); } rg_multidmg_apply(attacker, attacker); } ``` -------------------------------- ### set_member_game / get_member_game - Game Rules Access Source: https://context7.com/rehlds/reapi/llms.txt This section describes functions for accessing and modifying game rules and global game state directly through CSGameRules members. ```APIDOC ## set_member_game / get_member_game - Game Rules Access ### Description Provides direct access to CSGameRules members for global game state control. These functions allow reading and modifying various aspects of the game's rules and current state, such as round time, scores, and buy permissions. ### Method N/A (These are function calls within a script, not HTTP endpoints) ### Endpoint N/A ### Parameters N/A (Function parameters are defined in the Pawn code) ### Request Example ```pawn // Example: Extending round time new Float:roundTime = get_member_game(m_fRoundTimeLimit); set_member_game(m_fRoundTimeLimit, roundTime + 60.0); // Example: Checking if the buy period is active new bool:canBuy = bool:get_member_game(m_bCanBuy); ``` ### Response N/A (Functions modify game state or return game state values directly) #### Success Response (N/A) N/A #### Response Example N/A ``` -------------------------------- ### RegisterHookChain - Hook Game Functions Source: https://context7.com/rehlds/reapi/llms.txt Intercepts engine and game DLL functions to modify behavior. Returns a hook handle for enable/disable control. ```APIDOC ## POST /rehlds/reapi/RegisterHookChain ### Description Intercepts engine and game DLL functions to modify behavior. Returns a hook handle for enable/disable control. ### Method POST ### Endpoint /rehlds/reapi/RegisterHookChain ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **hookName** (string) - Required - The name of the hook to register. - **callbackName** (string) - Required - The name of the callback function to execute. - **isPostHook** (boolean) - Required - Whether to execute the hook after the original function (true) or before (false). ### Request Example ```json { "hookName": "RG_CBasePlayer_Spawn", "callbackName": "OnPlayerSpawn_Post", "isPostHook": true } ``` ### Response #### Success Response (200) - **hookHandle** (integer) - A unique identifier for the registered hook chain. #### Response Example ```json { "hookHandle": 12345 } ``` ``` -------------------------------- ### Simulate Combat Bullets with rg_fire_bullets3 Source: https://context7.com/rehlds/reapi/llms.txt Enables advanced bullet simulation, including full penetration and spread calculations. This function is crucial for implementing custom weapon behaviors and damage models. It requires the 'reapi' module and provides parameters for bullet type, damage, penetration, and spread. ```pawn #include public FireCustomBullets(attacker, victim) { if (!is_user_alive(attacker) || !is_user_alive(victim)) return; new Float:vecSrc[3], Float:vecEnd[3]; get_entvar(attacker, var_origin, vecSrc); get_entvar(victim, var_origin, vecEnd); // Calculate shooting direction new Float:vecDir[3]; xs_vec_sub(vecEnd, vecSrc, vecDir); xs_vec_normalize(vecDir, vecDir); // Fire with high accuracy, medium penetration new Float:vecSpread = 0.01; // Low spread rg_fire_bullets3( attacker, // inflictor attacker, // attacker vecSrc, // source position vecDir, // shooting direction vecSpread, // spread 8192.0, // distance 2, // penetration power BULLET_PLAYER_556MM, // bullet type 35, // damage 0.98, // range modifier false, // not pistol get_member(attacker, m_iWeaponVolume) // shared random seed ); } // Custom weapon with modified bullets public OnWeaponPrimaryAttack(weaponEnt) { new id = get_member(weaponEnt, m_pPlayer); new WeaponIdType:weaponID = get_member(weaponEnt, m_iId); if (weaponID == WEAPON_M4A1) { // Custom M4A1 behavior - explosive bullets new Float:vecSrc[3], Float:vecAngles[3], Float:vecDir[3]; get_entvar(id, var_origin, vecSrc); get_entvar(id, var_v_angle, vecAngles); engfunc(EngFunc_MakeVectors, vecAngles); global_get(glb_v_forward, vecDir); // Fire original bullet rg_fire_bullets3(id, id, vecSrc, vecDir, 0.02, 4096.0, 2, BULLET_PLAYER_556MM, 33, 0.98, false, 0); // Create explosion effect on hit new Float:vecEnd[3]; xs_vec_mul_scalar(vecDir, 4096.0, vecEnd); xs_vec_add(vecSrc, vecEnd, vecEnd); // Trace line to get hit position new tr = create_tr2(); engfunc(EngFunc_TraceLine, vecSrc, vecEnd, DONT_IGNORE_MONSTERS, id, tr); new Float:vecHit[3]; get_tr2(tr, TR_vecEndPos, vecHit); // Explosion damage rg_dmg_radius(vecHit, weaponEnt, id, 50.0, 150.0, CLASS_NONE, DMG_EXPLOSION); free_tr2(tr); } } ``` -------------------------------- ### Manage Player Teams with rg_set_user_team Source: https://context7.com/rehlds/reapi/llms.txt Provides functions to change a player's team dynamically without requiring them to die. It supports automatic model updates and can be used for team balancing or custom team assignments with specific models. Dependencies include the 'reapi' module. ```pawn #include public BalanceTeams() { new players[MAX_PLAYERS], pnum; get_players(players, pnum, "h"); // Get alive players new ctCount, tCount; for (new i = 0; i < pnum; i++) { new id = players[i]; new TeamName:team = get_member(id, m_iTeam); if (team == TEAM_CT) ctCount++; else if (team == TEAM_TERRORIST) tCount++; } // Balance if difference > 2 while (abs(ctCount - tCount) > 2) { new TeamName:fromTeam = (ctCount > tCount) ? TEAM_CT : TEAM_TERRORIST; new TeamName:toTeam = (ctCount > tCount) ? TEAM_TERRORIST : TEAM_CT; // Find random player to switch for (new i = 0; i < pnum; i++) { new id = players[i]; if (get_member(id, m_iTeam) == fromTeam) { rg_set_user_team(id, toTeam, MODEL_AUTO, true, true); client_print(id, print_center, "You were switched for team balance"); if (fromTeam == TEAM_CT) { ctCount--; tCount++; } else { tCount--; ctCount++; } break; } } } } // Custom team switcher with model selection public SwitchTeamWithModel(id, TeamName:newTeam) { new TeamName:oldTeam = get_member(id, m_iTeam); if (oldTeam == newTeam) return; // Switch team without killing rg_set_user_team(id, newTeam, MODEL_UNASSIGNED, false, false); // Set custom model new const szCTModels[][] = {"gign", "gsg9", "sas", "urban"}; new const szTModels[][] = {"arctic", "guerilla", "leet", "terror"}; if (newTeam == TEAM_CT) { rg_set_user_model(id, szCTModels[random(sizeof(szCTModels))], true); } else if (newTeam == TEAM_TERRORIST) { rg_set_user_model(id, szTModels[random(sizeof(szTModels))], true); } // Reset player state rg_remove_all_items(id); rg_give_default_items(id); } ``` -------------------------------- ### set_member / get_member - Access Entity Properties Source: https://context7.com/rehlds/reapi/llms.txt Provides direct access to internal entity members (player properties) for fine-grained control over player attributes and states. ```APIDOC ## set_member / get_member - Access Entity Properties ### Description Direct access to internal entity members for fine-grained control. ### Method `set_member(entity, member_index, value)` `get_member(entity, member_index)` ### Endpoint N/A (Function Calls) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **entity** (integer) - Required - The entity index (usually a player ID). - **member_index** (m_* or similar constant) - Required - The index or identifier for the member property (e.g., `m_iTeam`, `m_flMaxSpeed`). - **value** (*type*) - Required (for `set_member`) - The new value to set for the member. ### Request Example ```pawn // Get and modify player's armor new armor = get_member(id, m_iKevlar); set_member(id, m_iKevlar, 100); // Get and modify player's max speed new Float:maxSpeed = get_member(id, m_flMaxSpeed); set_member(id, m_flMaxSpeed, maxSpeed * 1.2); ``` ### Response #### Success Response (Variable Type) - **return value** (type depends on member) - The current value of the member property. ``` -------------------------------- ### Conditional Compilation Flags (CMake) Source: https://github.com/rehlds/reapi/blob/master/reapi/CMakeLists.txt Sets compile flags based on the GCC version and build type. If GCC version is 8.3 or greater, it adds '-fcf-protection=none'. If not in debug mode, it adds linker flags for section garbage collection and version scripting. ```cmake if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) set(COMPILE_FLAGS "${COMPILE_FLAGS} -fcf-protection=none") endif() if (NOT DEBUG) set(LINK_FLAGS "${LINK_FLAGS} \ -Wl,-gc-sections -Wl,--version-script=\"${PROJECT_SOURCE_DIR}/../version_script.lds\"") endif() ```