From d0b5886d7d93f938b9b25a9cce2ff4100a89e7f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johnny=20Bergstr=C3=B6m?= Date: Sun, 7 Aug 2005 20:43:29 +0000 Subject: [PATCH] Added cs_get_armoury_type and cs_set_armoury_type --- dlls/cstrike/cstrike.cpp | 103 +++++++++++++++++++++++++++++++++++ dlls/cstrike/cstrike.h | 27 +++++++++ plugins/include/amxconst.inc | 34 ++++++------ plugins/include/cstrike.inc | 16 +++++- 4 files changed, 162 insertions(+), 18 deletions(-) diff --git a/dlls/cstrike/cstrike.cpp b/dlls/cstrike/cstrike.cpp index 9b212f6c..862fe848 100755 --- a/dlls/cstrike/cstrike.cpp +++ b/dlls/cstrike/cstrike.cpp @@ -1232,6 +1232,107 @@ static cell AMX_NATIVE_CALL cs_user_spawn(AMX *amx, cell *params) return 1; } +static cell AMX_NATIVE_CALL cs_get_armoury_type(AMX *amx, cell *params) +{ + // Return CSW_* constants of specified armoury_entity. + // params[1] = entity + + // Valid entity should be within range. + CHECK_NONPLAYER(params[1]); + + // Make into edict pointer. + edict_t *pArmoury = INDEXENT(params[1]); + + // Make sure this is an armoury_entity. + if (strcmp(STRING(pArmoury->v.classname), "armoury_entity")) { + // Error out here. + MF_LogError(amx, AMX_ERR_NATIVE, "Not an armoury_entity! (%d)", params[1]); + return 0; + } + + int weapontype = *((int *)pArmoury->pvPrivateData + OFFSET_ARMOURY_TYPE); + + // We do a switch instead of a mapped array because this way we can nicely catch unexpected values, and we don't get array out of bounds thingies. + int weapontype_out; + switch (weapontype) { + case CSA_MP5NAVY: weapontype_out = CSW_MP5NAVY; break; + case CSA_TMP: weapontype_out = CSW_TMP; break; + case CSA_P90: weapontype_out = CSW_P90; break; + case CSA_MAC10: weapontype_out = CSW_MAC10; break; + case CSA_AK47: weapontype_out = CSW_AK47; break; + case CSA_SG552: weapontype_out = CSW_SG552; break; + case CSA_M4A1: weapontype_out = CSW_M4A1; break; + case CSA_AUG: weapontype_out = CSW_AUG; break; + case CSA_SCOUT: weapontype_out = CSW_SCOUT; break; + case CSA_G3SG1: weapontype_out = CSW_G3SG1; break; + case CSA_AWP: weapontype_out = CSW_AWP; break; + case CSA_M3: weapontype_out = CSW_M3; break; + case CSA_XM1014: weapontype_out = CSW_XM1014; break; + case CSA_M249: weapontype_out = CSW_M249; break; + case CSA_FLASHBANG: weapontype_out = CSW_FLASHBANG; break; + case CSA_HEGRENADE: weapontype_out = CSW_HEGRENADE; break; + case CSA_VEST: weapontype_out = CSW_VEST; break; + case CSA_VESTHELM: weapontype_out = CSW_VESTHELM; break; + case CSA_SMOKEGRENADE: weapontype_out = CSW_SMOKEGRENADE; break; + default: + MF_LogError(amx, AMX_ERR_NATIVE, "Unexpected weapon type of %d!", params[1]); + return 0; + } + + return weapontype_out; +} + +static cell AMX_NATIVE_CALL cs_set_armoury_type(AMX *amx, cell *params) +{ + // Set CSW->CSA mapped weapon type to entity. + // params[1] = entity + // params[2] = CSW_* constant + + // Valid entity should be within range. + CHECK_NONPLAYER(params[1]); + + // Make into edict pointer. + edict_t *pArmoury = INDEXENT(params[1]); + + // Make sure this is an armoury_entity. + if (strcmp(STRING(pArmoury->v.classname), "armoury_entity")) { + // Error out here. + MF_LogError(amx, AMX_ERR_NATIVE, "Not an armoury_entity! (%d)", params[1]); + return 0; + } + + // We do a switch instead of a mapped array because this way we can nicely catch unexpected values, and we don't get array out of bounds thingies. + int weapontype; + switch (params[2]) { + case CSW_MP5NAVY: weapontype = CSA_MP5NAVY; break; + case CSW_TMP: weapontype = CSA_TMP; break; + case CSW_P90: weapontype = CSA_P90; break; + case CSW_MAC10: weapontype = CSA_MAC10; break; + case CSW_AK47: weapontype = CSA_AK47; break; + case CSW_SG552: weapontype = CSA_SG552; break; + case CSW_M4A1: weapontype = CSA_M4A1; break; + case CSW_AUG: weapontype = CSA_AUG; break; + case CSW_SCOUT: weapontype = CSA_SCOUT; break; + case CSW_G3SG1: weapontype = CSA_G3SG1; break; + case CSW_AWP: weapontype = CSA_AWP; break; + case CSW_M3: weapontype = CSA_M3; break; + case CSW_XM1014: weapontype = CSA_XM1014; break; + case CSW_M249: weapontype = CSA_M249; break; + case CSW_FLASHBANG: weapontype = CSA_FLASHBANG; break; + case CSW_HEGRENADE: weapontype = CSA_HEGRENADE; break; + case CSW_VEST: weapontype = CSA_VEST; break; + case CSW_VESTHELM: weapontype = CSA_VESTHELM; break; + case CSW_SMOKEGRENADE: weapontype = CSA_SMOKEGRENADE; break; + default: + MF_LogError(amx, AMX_ERR_NATIVE, "Unsupported weapon type! (%d)", params[2]); + return 0; + } + + *((int *)pArmoury->pvPrivateData + OFFSET_ARMOURY_TYPE) = weapontype; + + return 1; +} + AMX_NATIVE_INFO cstrike_Exports[] = { {"cs_set_user_money", cs_set_user_money}, {"cs_get_user_money", cs_get_user_money}, @@ -1274,6 +1375,8 @@ AMX_NATIVE_INFO cstrike_Exports[] = { {"cs_set_user_armor", cs_set_user_armor}, {"cs_get_user_shield", cs_get_user_shield}, {"cs_user_spawn", cs_user_spawn}, + {"cs_get_armoury_type", cs_get_armoury_type}, + {"cs_set_armoury_type", cs_set_armoury_type}, //------------------- <-- max 19 characters! {NULL, NULL} }; diff --git a/dlls/cstrike/cstrike.h b/dlls/cstrike/cstrike.h index f11830a0..af70a3ca 100755 --- a/dlls/cstrike/cstrike.h +++ b/dlls/cstrike/cstrike.h @@ -102,6 +102,8 @@ // "hostage_entity" entities #define OFFSET_HOSTAGEFOLLOW 86 + EXTRAOFFSET #define OFFSET_HOSTAGEID 487 + EXTRAOFFSET + // "armoury_entity" + #define OFFSET_ARMOURY_TYPE 34 + EXTRAOFFSET #else // Amd64 offsets here #define OFFSET_ARMORTYPE 137 + EXTRAOFFSET @@ -141,6 +143,8 @@ // "hostage_entity" entities #define OFFSET_HOSTAGEFOLLOW 51 + EXTRAOFFSET // +21, long=51, int=107! (must use the long* offset because pointers on amd64 are stored the size of longs, 8 bytes, instead of the usual int 4 bytes.) #define OFFSET_HOSTAGEID 516 + EXTRAOFFSET // +29 + // "armoury_entity" + #define OFFSET_WEAPONTYPE ??? + EXTRAOFFSET // To do... #endif // Ids of weapons in CS @@ -174,6 +178,29 @@ #define CSW_AK47 28 //#define CSW_KNIFE 29 #define CSW_P90 30 +#define CSW_VEST 31 // Brand new invention! +#define CSW_VESTHELM 32 // Brand new invention! + +// These are used with armoury_entity:s. +#define CSA_MP5NAVY 0 +#define CSA_TMP 1 +#define CSA_P90 2 +#define CSA_MAC10 3 +#define CSA_AK47 4 +#define CSA_SG552 5 +#define CSA_M4A1 6 +#define CSA_AUG 7 +#define CSA_SCOUT 8 +#define CSA_G3SG1 9 +#define CSA_AWP 10 +#define CSA_M3 11 +#define CSA_XM1014 12 +#define CSA_M249 13 +#define CSA_FLASHBANG 14 +#define CSA_HEGRENADE 15 +#define CSA_VEST 16 +#define CSA_VESTHELM 17 +#define CSA_SMOKEGRENADE 18 #define M4A1_SILENCED (1<<2) #define M4A1_ATTACHSILENCEANIM 6 diff --git a/plugins/include/amxconst.inc b/plugins/include/amxconst.inc index 80f34126..15e99270 100755 --- a/plugins/include/amxconst.inc +++ b/plugins/include/amxconst.inc @@ -115,6 +115,8 @@ stock const AMXX_VERSION_STR[]="1.50" #define CSW_AK47 28 #define CSW_KNIFE 29 #define CSW_P90 30 +#define CSW_VEST 31 +#define CSW_VESTHELM 32 #define HIW_BERETTA 1 #define HIW_SPAS12 2 @@ -201,7 +203,7 @@ enum { } /* Render for set_user_rendering() */ -enum { +enum { kRenderNormal = 0, /* src */ kRenderTransColor, /* c*a+dest*(1-a) */ kRenderTransTexture, /* src*a+dest*(1-a) */ @@ -211,20 +213,20 @@ enum { } /* Fx for set_user_rendering() */ -enum { - kRenderFxNone = 0, - kRenderFxPulseSlow, - kRenderFxPulseFast, - kRenderFxPulseSlowWide, - kRenderFxPulseFastWide, - kRenderFxFadeSlow, - kRenderFxFadeFast, - kRenderFxSolidSlow, - kRenderFxSolidFast, - kRenderFxStrobeSlow, - kRenderFxStrobeFast, - kRenderFxStrobeFaster, - kRenderFxFlickerSlow, +enum { + kRenderFxNone = 0, + kRenderFxPulseSlow, + kRenderFxPulseFast, + kRenderFxPulseSlowWide, + kRenderFxPulseFastWide, + kRenderFxFadeSlow, + kRenderFxFadeFast, + kRenderFxSolidSlow, + kRenderFxSolidFast, + kRenderFxStrobeSlow, + kRenderFxStrobeFast, + kRenderFxStrobeFaster, + kRenderFxFlickerSlow, kRenderFxFlickerFast, kRenderFxNoDissipation, kRenderFxDistort, /* Distort/scale/translate flicker */ @@ -263,7 +265,7 @@ enum { #define AMX_FLAG_BROWSE 0x4000 /* busy browsing */ #define AMX_FLAG_RELOC 0x8000 /* jump/call addresses relocated */ -#define INVALID_PLUGIN_ID -1 +#define INVALID_PLUGIN_ID -1 #define MENU_EXIT -3 #define MENU_BACK -2 diff --git a/plugins/include/cstrike.inc b/plugins/include/cstrike.inc index aa54c053..3397604c 100755 --- a/plugins/include/cstrike.inc +++ b/plugins/include/cstrike.inc @@ -235,5 +235,17 @@ native cs_get_no_knives(); */ native cs_set_no_knives(noknives = 0); -//Spawns a Counter-Strike player -native cs_user_spawn(player); \ No newline at end of file +/* Spawns a Counter-Strike player + */ +native cs_user_spawn(player); + +/* Get what weapon type (CSW_*) an armoury_entity is. + */ +native cs_get_armoury_type(index); + +/* Set an armoury_entity to be of specified type. You will have to set the appropriate model. + * The second argument, type, should be a CSW_* constant. Not all weapons are supported by Counter-strike. + * Supported weapons/items: CSW_MP5NAVY, CSW_TMP, CSW_P90, CSW_MAC10, CSW_AK47, CSW_SG552, CSW_M4A1, CSW_AUG, CSW_SCOUT + * CSW_G3SG1, CSW_AWP, CSW_M3, CSW_XM1014, CSW_M249, CSW_FLASHBANG, CSW_HEGRENADE, CSW_VEST, CSW_VESTHELM, CSW_SMOKEGRENADE + */ +native cs_set_armoury_type(index, type); \ No newline at end of file