From bbbe0cda78afb4fa4512947e424479f3c93599ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Bergstr=C3=B6m?= Date: Mon, 22 Mar 2004 08:57:23 +0000 Subject: [PATCH] Added cs_get_weapon_ammo/cs_set_weapon_ammo --- dlls/cstrike/cstrike.cpp | 53 ++++++++++++++++++++++++++++++++++++++++ dlls/cstrike/cstrike.h | 5 ++-- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/dlls/cstrike/cstrike.cpp b/dlls/cstrike/cstrike.cpp index 379b7b2f..1b90f8f9 100755 --- a/dlls/cstrike/cstrike.cpp +++ b/dlls/cstrike/cstrike.cpp @@ -1185,6 +1185,57 @@ static cell AMX_NATIVE_CALL cs_set_hostage_follow(AMX *amx, cell *params) // cs_ return 1; } +static cell AMX_NATIVE_CALL cs_get_weapon_ammo(AMX *amx, cell *params) // cs_get_weapon_ammo(index); = 1 param +{ + // Get amount of ammo in weapon's clip + // params[1] = weapon index + + // Valid entity should be within range + if (params[1] < 1 || params[1] > gpGlobals->maxEntities) + { + AMX_RAISEERROR(amx, AMX_ERR_NATIVE); + return 0; + } + + // Make into edict pointer + edict_t *pWeapon = INDEXENT(params[1]); + + // Check entity validity + if (FNullEnt(pWeapon)) { + AMX_RAISEERROR(amx, AMX_ERR_NATIVE); + return 0; + } + + return *(int *)pWeapon->pvPrivateData + OFFSET_CLIPAMMO; +} + +static cell AMX_NATIVE_CALL cs_set_weapon_ammo(AMX *amx, cell *params) // cs_set_weapon_ammo(index, newammo); = 2 params +{ + // Set amount of ammo in weapon's clip + // params[1] = weapon index + // params[2] = newammo + + // Valid entity should be within range + if (params[1] < 1 || params[1] > gpGlobals->maxEntities) + { + AMX_RAISEERROR(amx, AMX_ERR_NATIVE); + return 0; + } + + // Make into edict pointer + edict_t *pWeapon = INDEXENT(params[1]); + + // Check entity validity + if (FNullEnt(pWeapon)) { + AMX_RAISEERROR(amx, AMX_ERR_NATIVE); + return 0; + } + + *((int *)pWeapon->pvPrivateData + OFFSET_CLIPAMMO) = params[2]; + + return 1; +} + AMX_NATIVE_INFO cstrike_Exports[] = { {"cs_set_user_money", cs_set_user_money}, {"cs_get_user_money", cs_get_user_money}, @@ -1213,6 +1264,8 @@ AMX_NATIVE_INFO cstrike_Exports[] = { {"cs_get_user_model", cs_get_user_model}, {"cs_set_user_model", cs_set_user_model}, {"cs_reset_user_model", cs_reset_user_model}, + {"cs_set_weapon_ammo", cs_set_weapon_ammo}, + {"cs_get_weapon_ammo", cs_get_weapon_ammo}, //------------------- <-- max 19 characters! {NULL, NULL} }; diff --git a/dlls/cstrike/cstrike.h b/dlls/cstrike/cstrike.h index dd14f164..2cfd84e5 100755 --- a/dlls/cstrike/cstrike.h +++ b/dlls/cstrike/cstrike.h @@ -1,4 +1,4 @@ -#define __cswonbuild__ // comment when compiling for STEAM +//#define __cswonbuild__ // comment when compiling for STEAM #define CS_WON_BUILD /* AMX Mod X @@ -113,9 +113,9 @@ pfnmodule_engine_g* g_engModuleFunc; #define OFFSET_CSDEATHS 448 + EXTRAOFFSET // differs -1 from STEAM // "weapon_*" entities #define OFFSET_WEAPONTYPE 43 + EXTRAOFFSET // same as STEAM + //#define OFFSET_CLIPAMMO 51 + EXTRAOFFSET // not tested under WON!!!!!!!!!!!!!!!!!! #define OFFSET_SILENCER_FIREMODE 70 + EXTRAOFFSET // differs -4 from STEAM // "hostage_entity" entities - #define OFFSET_HOSTAGEFOLLOW 86 + EXTRAOFFSET // NOT YET CHECKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! find out before build #define OFFSET_HOSTAGEFOLLOW 86 + EXTRAOFFSET // same as STEAM #define OFFSET_HOSTAGEID 487 + EXTRAOFFSET // same as STEAM #else // from here STEAM build looks for offsets @@ -145,6 +145,7 @@ pfnmodule_engine_g* g_engModuleFunc; #define OFFSET_CSDEATHS 449 + EXTRAOFFSET // "weapon_*" entities #define OFFSET_WEAPONTYPE 43 + EXTRAOFFSET + #define OFFSET_CLIPAMMO 51 + EXTRAOFFSET #define OFFSET_SILENCER_FIREMODE 74 + EXTRAOFFSET // "hostage_entity" entities #define OFFSET_HOSTAGEFOLLOW 86 + EXTRAOFFSET