Added goggles, get_user_deaths, and some fixing...

This commit is contained in:
Johnny Bergström 2004-02-27 13:36:02 +00:00
parent ca0fdd7fdc
commit 79912dea1b
2 changed files with 163 additions and 61 deletions

View File

@ -35,7 +35,7 @@
// Utils first // Utils first
bool isplayer(AMX* amx, edict_t* pPlayer) { bool UTIL_IsPlayer(AMX* amx, edict_t* pPlayer) {
bool player = false; bool player = false;
// Check entity validity // Check entity validity
if (FNullEnt(pPlayer)) { if (FNullEnt(pPlayer)) {
@ -48,6 +48,22 @@ bool isplayer(AMX* amx, edict_t* pPlayer) {
return player; return player;
} }
void UTIL_TextMsg_Generic(edict_t* pPlayer, char* message)
{
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pPlayer);
WRITE_BYTE(HUD_PRINTCENTER); // 1 = console, 2 = console, 3 = chat, 4 = center
WRITE_STRING(message);
MESSAGE_END();
/*
The byte above seems to use these:
#define HUD_PRINTNOTIFY 1
#define HUD_PRINTCONSOLE 2
#define HUD_PRINTTALK 3
#define HUD_PRINTCENTER 4
However both 1 and 2 seems to go to console with Steam CS.
*/
}
// Then natives // Then natives
static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params) // cs_set_user_money(index, money, flash = 1); = 3 arguments static cell AMX_NATIVE_CALL cs_set_user_money(AMX *amx, cell *params) // cs_set_user_money(index, money, flash = 1); = 3 arguments
@ -110,6 +126,30 @@ static cell AMX_NATIVE_CALL cs_get_user_money(AMX *amx, cell *params) // cs_get_
return (int)*((int *)pPlayer->pvPrivateData + OFFSET_CSMONEY); return (int)*((int *)pPlayer->pvPrivateData + OFFSET_CSMONEY);
} }
static cell AMX_NATIVE_CALL cs_get_user_deaths(AMX *amx, cell *params) // cs_get_user_deaths(index); = 1 param
{
// Gets user deaths in cs.
// params[1] = user
// Check index
if (params[1] < 1 || params[1] > gpGlobals->maxClients)
{
AMX_RAISEERROR(amx, AMX_ERR_NATIVE);
return 0;
}
// Fetch player pointer
edict_t *pPlayer = INDEXENT(params[1]);
// Check entity validity
if (FNullEnt(pPlayer)) {
AMX_RAISEERROR(amx, AMX_ERR_NATIVE);
return 0;
}
return *((int *)pPlayer->pvPrivateData + OFFSET_CSDEATHS);
}
static cell AMX_NATIVE_CALL cs_set_user_deaths(AMX *amx, cell *params) // cs_set_user_deaths(index, newdeaths); = 2 arguments static cell AMX_NATIVE_CALL cs_set_user_deaths(AMX *amx, cell *params) // cs_set_user_deaths(index, newdeaths); = 2 arguments
{ {
// Sets user deaths in cs. // Sets user deaths in cs.
@ -315,24 +355,16 @@ static cell AMX_NATIVE_CALL cs_set_weapon_burstmode(AMX *amx, cell *params) // c
*firemode = GLOCK_BURSTMODE; *firemode = GLOCK_BURSTMODE;
// Is this weapon's owner a player? If so send this message... // Is this weapon's owner a player? If so send this message...
if (isplayer(amx, pWeapon->v.owner)) { if (UTIL_IsPlayer(amx, pWeapon->v.owner))
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pWeapon->v.owner); UTIL_TextMsg_Generic(pWeapon->v.owner, "#Switch_To_BurstFire");
WRITE_BYTE(4); // dunno really what this 4 is for :-)
WRITE_STRING("#Switch_To_BurstFire");
MESSAGE_END();
}
} }
} }
else if (previousMode != GLOCK_SEMIAUTOMATIC) { else if (previousMode != GLOCK_SEMIAUTOMATIC) {
*firemode = GLOCK_SEMIAUTOMATIC; *firemode = GLOCK_SEMIAUTOMATIC;
// Is this weapon's owner a player? If so send this message... // Is this weapon's owner a player? If so send this message...
if (isplayer(amx, pWeapon->v.owner)) { if (UTIL_IsPlayer(amx, pWeapon->v.owner))
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pWeapon->v.owner); UTIL_TextMsg_Generic(pWeapon->v.owner, "#Switch_To_SemiAuto");
WRITE_BYTE(4); // dunno really what this 4 is for :-)
WRITE_STRING("#Switch_To_SemiAuto");
MESSAGE_END();
}
} }
break; break;
case CSW_FAMAS: case CSW_FAMAS:
@ -341,24 +373,16 @@ static cell AMX_NATIVE_CALL cs_set_weapon_burstmode(AMX *amx, cell *params) // c
*firemode = FAMAS_BURSTMODE; *firemode = FAMAS_BURSTMODE;
// Is this weapon's owner a player? If so send this message... // Is this weapon's owner a player? If so send this message...
if (isplayer(amx, pWeapon->v.owner)) { if (UTIL_IsPlayer(amx, pWeapon->v.owner))
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pWeapon->v.owner); UTIL_TextMsg_Generic(pWeapon->v.owner, "#Switch_To_BurstFire");
WRITE_BYTE(4); // dunno really what this 4 is for :-)
WRITE_STRING("#Switch_To_BurstFire");
MESSAGE_END();
}
} }
} }
else if (previousMode != FAMAS_AUTOMATIC) { else if (previousMode != FAMAS_AUTOMATIC) {
*firemode = FAMAS_AUTOMATIC; *firemode = FAMAS_AUTOMATIC;
// Is this weapon's owner a player? If so send this message... // Is this weapon's owner a player? If so send this message...
if (isplayer(amx, pWeapon->v.owner)) { if (UTIL_IsPlayer(amx, pWeapon->v.owner))
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "TextMsg", NULL), NULL, pWeapon->v.owner); UTIL_TextMsg_Generic(pWeapon->v.owner, "#Switch_To_FullAuto");
WRITE_BYTE(4); // dunno really what this 4 is for :-)
WRITE_STRING("#Switch_To_FullAuto");
MESSAGE_END();
}
} }
break; break;
default: default:
@ -534,7 +558,7 @@ static cell AMX_NATIVE_CALL cs_get_user_plant(AMX *amx, cell *params) // cs_get_
return 0; return 0;
} }
if ((int)*((int *)pPlayer->pvPrivateData + OFFSET_DEFUSE_PLANT) == CAN_PLANT_BOMB) if ((int)*((int *)pPlayer->pvPrivateData + OFFSET_DEFUSE_PLANT) & CAN_PLANT_BOMB)
return 1; return 1;
return 0; return 0;
@ -566,7 +590,7 @@ static cell AMX_NATIVE_CALL cs_set_user_plant(AMX *amx, cell *params) // cs_set_
int* plantskill = ((int *)pPlayer->pvPrivateData + OFFSET_DEFUSE_PLANT); int* plantskill = ((int *)pPlayer->pvPrivateData + OFFSET_DEFUSE_PLANT);
if (params[2]) { if (params[2]) {
*plantskill = CAN_PLANT_BOMB; *plantskill |= CAN_PLANT_BOMB;
if (params[3]) { if (params[3]) {
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer); MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer);
WRITE_BYTE(1); // show WRITE_BYTE(1); // show
@ -578,7 +602,7 @@ static cell AMX_NATIVE_CALL cs_set_user_plant(AMX *amx, cell *params) // cs_set_
} }
} }
else { else {
*plantskill = NO_DEFUSE_OR_PLANTSKILL; *plantskill &= ~CAN_PLANT_BOMB;
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer); MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer);
WRITE_BYTE(0); // hide WRITE_BYTE(0); // hide
WRITE_STRING("c4"); WRITE_STRING("c4");
@ -619,7 +643,7 @@ static cell AMX_NATIVE_CALL cs_get_user_defusekit(AMX *amx, cell *params) // cs_
return 0; return 0;
} }
if ((int)*((int *)pPlayer->pvPrivateData + OFFSET_DEFUSE_PLANT) == HAS_DEFUSE_KIT) if ((int)*((int *)pPlayer->pvPrivateData + OFFSET_DEFUSE_PLANT) & HAS_DEFUSE_KIT)
return 1; return 1;
return 0; return 0;
@ -669,9 +693,9 @@ static cell AMX_NATIVE_CALL cs_set_user_defusekit(AMX *amx, cell *params) // cs_
else else
icon = "defuser"; icon = "defuser";
*defusekit = HAS_DEFUSE_KIT; *defusekit |= HAS_DEFUSE_KIT;
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer); MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer);
WRITE_BYTE(params[7] == 1 ? 2 : 1); // show WRITE_BYTE(params[7] == 1 ? 2 : 1); // show (if params[7] == 1, then this should flash, so we should set two here, else just 1 to show normally)
WRITE_STRING(icon); WRITE_STRING(icon);
WRITE_BYTE(colour[0]); WRITE_BYTE(colour[0]);
WRITE_BYTE(colour[1]); WRITE_BYTE(colour[1]);
@ -679,7 +703,7 @@ static cell AMX_NATIVE_CALL cs_set_user_defusekit(AMX *amx, cell *params) // cs_
MESSAGE_END(); MESSAGE_END();
} }
else { else {
*defusekit = NO_DEFUSE_OR_PLANTSKILL; *defusekit &= ~HAS_DEFUSE_KIT;
MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer); MESSAGE_BEGIN(MSG_ONE, GET_USER_MSG_ID(PLID, "StatusIcon", NULL), NULL, pPlayer);
WRITE_BYTE(0); // hide WRITE_BYTE(0); // hide
WRITE_STRING("defuser"); WRITE_STRING("defuser");
@ -888,10 +912,77 @@ static cell AMX_NATIVE_CALL cs_set_user_backpackammo(AMX *amx, cell *params) //
return 1; return 1;
} }
static cell AMX_NATIVE_CALL cs_get_user_nvgoggles(AMX *amx, cell *params) // cs_get_user_nvgoggles(index); = 1 param
{
// Does user have night vision goggles?
// params[1] = user index
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients)
{
AMX_RAISEERROR(amx, AMX_ERR_NATIVE);
return 0;
}
// Make into edict pointer
edict_t *pPlayer = INDEXENT(params[1]);
// Check entity validity
if (FNullEnt(pPlayer)) {
AMX_RAISEERROR(amx, AMX_ERR_NATIVE);
return 0;
}
if ((int)*((int *)pPlayer->pvPrivateData + OFFSET_NVGOGGLES) & HAS_NVGOGGLES)
return 1;
return 0;
}
static cell AMX_NATIVE_CALL cs_set_user_nvgoggles(AMX *amx, cell *params) // cs_set_user_nvgoggles(index, nvgoggles = 1); = 2 params
{
// Give/take nvgoggles..
// params[1] = user index
// params[2] = 1 = give, 0 = remove
// Valid entity should be within range
if (params[1] < 1 || params[1] > gpGlobals->maxClients)
{
AMX_RAISEERROR(amx, AMX_ERR_NATIVE);
return 0;
}
// Make into edict pointer
edict_t *pPlayer = INDEXENT(params[1]);
// Check entity validity
if (FNullEnt(pPlayer)) {
AMX_RAISEERROR(amx, AMX_ERR_NATIVE);
return 0;
}
int* defusekit = ((int *)pPlayer->pvPrivateData + OFFSET_NVGOGGLES);
if (params[2]) {
if (*defusekit & HAS_NVGOGGLES)
UTIL_TextMsg_Generic(pPlayer, "#Already_Have_One");
else
*defusekit |= HAS_NVGOGGLES;
}
else
*defusekit &= ~HAS_NVGOGGLES;
/*L 02/27/2004 - 09:16:43: [JGHG Trace] {MessageBegin type=TextMsg(77), dest=MSG_ONE(1), classname=player netname=JGHG
L 02/27/2004 - 09:16:43: [JGHG Trace] WriteByte byte=4
L 02/27/2004 - 09:16:43: [JGHG Trace] WriteString string=#Already_Have_One
L 02/27/2004 - 09:16:43: [JGHG Trace] MessageEnd}*/
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},
{"cs_get_user_deaths", cs_get_user_deaths},
{"cs_set_user_deaths", cs_set_user_deaths}, {"cs_set_user_deaths", cs_set_user_deaths},
{"cs_get_hostage_id", cs_get_hostage_id}, {"cs_get_hostage_id", cs_get_hostage_id},
{"cs_get_weapon_silenced", cs_get_weapon_silenced}, {"cs_get_weapon_silenced", cs_get_weapon_silenced},
@ -909,6 +1000,8 @@ AMX_NATIVE_INFO cstrike_Exports[] = {
{"cs_set_user_defusekit", cs_set_user_defusekit}, {"cs_set_user_defusekit", cs_set_user_defusekit},
{"cs_get_user_backpackammo", cs_get_user_backpackammo}, {"cs_get_user_backpackammo", cs_get_user_backpackammo},
{"cs_set_user_backpackammo", cs_set_user_backpackammo}, {"cs_set_user_backpackammo", cs_set_user_backpackammo},
{"cs_get_user_nvgoggles", cs_get_user_nvgoggles},
{"cs_set_user_nvgoggles", cs_set_user_nvgoggles},
{NULL, NULL} {NULL, NULL}
}; };

View File

@ -65,38 +65,43 @@ pfnmodule_engine_g* g_engModuleFunc;
#define LOGTAG "AMXCS" #define LOGTAG "AMXCS"
#define DATE __DATE__ #define DATE __DATE__
// cstrike-specific defines below
#if defined __linux__ #if defined __linux__
#define OFFSET_WEAPONTYPE 43 + 5 #define LINUXOFFSET 5
#define OFFSET_SILENCER_FIREMODE 74 + 5 // "player" entities
#define OFFSET_TEAM 114 + 5 #define OFFSET_TEAM 114 + LINUXOFFSET
#define OFFSET_CSMONEY 115 + 5 #define OFFSET_CSMONEY 115 + LINUXOFFSET
#define OFFSET_DEFUSE_PLANT 193 + 5 #define OFFSET_NVGOGGLES 129 + LINUXOFFSET
#define OFFSET_VIP 215 + 5 #define OFFSET_DEFUSE_PLANT 193 + LINUXOFFSET
#define OFFSET_BUYZONE 241 + 5 #define OFFSET_VIP 215 + LINUXOFFSET
#define OFFSET_BUYZONE 241 + LINUXOFFSET
#define OFFSET_AWM_AMMO 382 + 5 #define OFFSET_AWM_AMMO 382 + LINUXOFFSET
#define OFFSET_SCOUT_AMMO 383 + 5 #define OFFSET_SCOUT_AMMO 383 + LINUXOFFSET
#define OFFSET_PARA_AMMO 384 + 5 #define OFFSET_PARA_AMMO 384 + LINUXOFFSET
#define OFFSET_FAMAS_AMMO 385 + 5 #define OFFSET_FAMAS_AMMO 385 + LINUXOFFSET
#define OFFSET_M3_AMMO 386 + 5 #define OFFSET_M3_AMMO 386 + LINUXOFFSET
#define OFFSET_USP_AMMO 387 + 5 #define OFFSET_USP_AMMO 387 + LINUXOFFSET
#define OFFSET_FIVESEVEN_AMMO 388 + 5 #define OFFSET_FIVESEVEN_AMMO 388 + LINUXOFFSET
#define OFFSET_DEAGLE_AMMO 389 + 5 #define OFFSET_DEAGLE_AMMO 389 + LINUXOFFSET
#define OFFSET_P228_AMMO 390 + 5 #define OFFSET_P228_AMMO 390 + LINUXOFFSET
#define OFFSET_GLOCK_AMMO 391 + 5 #define OFFSET_GLOCK_AMMO 391 + LINUXOFFSET
#define OFFSET_FLASH_AMMO 392 + 5 #define OFFSET_FLASH_AMMO 392 + LINUXOFFSET
#define OFFSET_HE_AMMO 393 + 5 #define OFFSET_HE_AMMO 393 + LINUXOFFSET
#define OFFSET_SMOKE_AMMO 394 + 5 #define OFFSET_SMOKE_AMMO 394 + LINUXOFFSET
#define OFFSET_C4_AMMO 395 + 5 #define OFFSET_C4_AMMO 395 + LINUXOFFSET
#define OFFSET_CSDEATHS 449 + LINUXOFFSET
// "weapon_*" entities
#define OFFSET_WEAPONTYPE 43 + LINUXOFFSET
#define OFFSET_SILENCER_FIREMODE 74 + LINUXOFFSET
// "hostage_entity" entities
#define OFFSET_HOSTAGEID 487 + LINUXOFFSET
#define OFFSET_CSDEATHS 449 + 5
#define OFFSET_HOSTAGEID 487 + 5
#else #else
#define OFFSET_WEAPONTYPE 43 // "player" entities
#define OFFSET_SILENCER_FIREMODE 74
#define OFFSET_TEAM 114 #define OFFSET_TEAM 114
#define OFFSET_CSMONEY 115 #define OFFSET_CSMONEY 115
#define OFFSET_NVGOGGLES 129
#define OFFSET_DEFUSE_PLANT 193 #define OFFSET_DEFUSE_PLANT 193
#define OFFSET_VIP 215 #define OFFSET_VIP 215
#define OFFSET_BUYZONE 241 #define OFFSET_BUYZONE 241
@ -117,6 +122,10 @@ pfnmodule_engine_g* g_engModuleFunc;
#define OFFSET_C4_AMMO 395 #define OFFSET_C4_AMMO 395
#define OFFSET_CSDEATHS 449 #define OFFSET_CSDEATHS 449
// "weapon_*" entities
#define OFFSET_WEAPONTYPE 43
#define OFFSET_SILENCER_FIREMODE 74
// "hostage_entity" entities
#define OFFSET_HOSTAGEID 487 #define OFFSET_HOSTAGEID 487
#endif // defined __linux__ #endif // defined __linux__
@ -188,14 +197,14 @@ pfnmodule_engine_g* g_engModuleFunc;
#define TEAM_CT 2 #define TEAM_CT 2
#define TEAM_SPECTATOR 3 #define TEAM_SPECTATOR 3
#define NO_DEFUSE_OR_PLANTSKILL 0 #define CAN_PLANT_BOMB (1<<8) // 256
#define CAN_PLANT_BOMB 256 #define HAS_DEFUSE_KIT (1<<16) // 65536
#define HAS_DEFUSE_KIT 65536
#define DEFUSER_COLOUR_R 0 #define DEFUSER_COLOUR_R 0
#define DEFUSER_COLOUR_G 160 #define DEFUSER_COLOUR_G 160
#define DEFUSER_COLOUR_B 0 #define DEFUSER_COLOUR_B 0
#define HAS_NVGOGGLES (1<<0)
// cstrike-specific defines above // cstrike-specific defines above
// Globals below // Globals below