Added cs_get_armoury_type and cs_set_armoury_type

This commit is contained in:
Johnny Bergström 2005-08-07 20:43:29 +00:00
parent aa75a143fc
commit d0b5886d7d
4 changed files with 162 additions and 18 deletions

View File

@ -1232,6 +1232,107 @@ static cell AMX_NATIVE_CALL cs_user_spawn(AMX *amx, cell *params)
return 1; 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[] = { AMX_NATIVE_INFO cstrike_Exports[] = {
{"cs_set_user_money", cs_set_user_money}, {"cs_set_user_money", cs_set_user_money},
{"cs_get_user_money", cs_get_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_set_user_armor", cs_set_user_armor},
{"cs_get_user_shield", cs_get_user_shield}, {"cs_get_user_shield", cs_get_user_shield},
{"cs_user_spawn", cs_user_spawn}, {"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! //------------------- <-- max 19 characters!
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -102,6 +102,8 @@
// "hostage_entity" entities // "hostage_entity" entities
#define OFFSET_HOSTAGEFOLLOW 86 + EXTRAOFFSET #define OFFSET_HOSTAGEFOLLOW 86 + EXTRAOFFSET
#define OFFSET_HOSTAGEID 487 + EXTRAOFFSET #define OFFSET_HOSTAGEID 487 + EXTRAOFFSET
// "armoury_entity"
#define OFFSET_ARMOURY_TYPE 34 + EXTRAOFFSET
#else #else
// Amd64 offsets here // Amd64 offsets here
#define OFFSET_ARMORTYPE 137 + EXTRAOFFSET #define OFFSET_ARMORTYPE 137 + EXTRAOFFSET
@ -141,6 +143,8 @@
// "hostage_entity" entities // "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_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 #define OFFSET_HOSTAGEID 516 + EXTRAOFFSET // +29
// "armoury_entity"
#define OFFSET_WEAPONTYPE ??? + EXTRAOFFSET // To do...
#endif #endif
// Ids of weapons in CS // Ids of weapons in CS
@ -174,6 +178,29 @@
#define CSW_AK47 28 #define CSW_AK47 28
//#define CSW_KNIFE 29 //#define CSW_KNIFE 29
#define CSW_P90 30 #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_SILENCED (1<<2)
#define M4A1_ATTACHSILENCEANIM 6 #define M4A1_ATTACHSILENCEANIM 6

View File

@ -115,6 +115,8 @@ stock const AMXX_VERSION_STR[]="1.50"
#define CSW_AK47 28 #define CSW_AK47 28
#define CSW_KNIFE 29 #define CSW_KNIFE 29
#define CSW_P90 30 #define CSW_P90 30
#define CSW_VEST 31
#define CSW_VESTHELM 32
#define HIW_BERETTA 1 #define HIW_BERETTA 1
#define HIW_SPAS12 2 #define HIW_SPAS12 2

View File

@ -235,5 +235,17 @@ native cs_get_no_knives();
*/ */
native cs_set_no_knives(noknives = 0); native cs_set_no_knives(noknives = 0);
//Spawns a Counter-Strike player /* Spawns a Counter-Strike player
*/
native cs_user_spawn(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);