Cstrike: Implement CS_OnBuyAttempt forward.

This commit is contained in:
Arkshine 2014-07-04 10:33:55 +02:00
parent 0728fee706
commit 6c4cb27d3e
5 changed files with 40 additions and 4 deletions

View File

@ -42,6 +42,7 @@ void CtrlDetours_BuyCommands(bool set);
int g_CSCliCmdFwd = -1; int g_CSCliCmdFwd = -1;
int g_CSBuyCmdFwd = -1; int g_CSBuyCmdFwd = -1;
int g_CSBuyAttemptCmdFwd = -1;
int *g_UseBotArgs = NULL; int *g_UseBotArgs = NULL;
const char **g_BotArgs = NULL; const char **g_BotArgs = NULL;
@ -98,6 +99,9 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma
// to be used in OnBuy* forwards. // to be used in OnBuy* forwards.
if (command && *command) if (command && *command)
{ {
// Just for safety.
command = UTIL_StringToLower((char *)command);
int itemId = 0; int itemId = 0;
// Handling buy via menu. // Handling buy via menu.
@ -166,6 +170,11 @@ DETOUR_DECL_STATIC1(C_ClientCommand, void, edict_t*, pEdict) // void ClientComma
} }
} }
if (g_CurrentItemId && MF_ExecuteForward(g_CSBuyAttemptCmdFwd, static_cast<cell>(ENTINDEX(pEdict)), static_cast<cell>(g_CurrentItemId)) > 0)
{
return;
}
DETOUR_STATIC_CALL(C_ClientCommand)(pEdict); DETOUR_STATIC_CALL(C_ClientCommand)(pEdict);
} }

View File

@ -140,3 +140,14 @@ bool UTIL_CheckForPublic(const char *publicname)
return false; return false;
} }
char *UTIL_StringToLower(char *str)
{
char *p;
for (p = str; *p != '\0'; ++p)
{
*p = tolower(*p);
}
return str;
}

View File

@ -37,6 +37,7 @@ bool UTIL_IsPlayer(AMX* amx, edict_t* pPlayer);
void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message); void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message);
void *UTIL_FindAddressFromEntry(const char *entry, bool isHidden = false, const char *library = "mod"); void *UTIL_FindAddressFromEntry(const char *entry, bool isHidden = false, const char *library = "mod");
bool UTIL_CheckForPublic(const char *publicname); bool UTIL_CheckForPublic(const char *publicname);
char *UTIL_StringToLower(char *str);
#define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer) #define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
#define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue) #define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue)

View File

@ -37,6 +37,7 @@ extern AMX_NATIVE_INFO cstrikeNatives[];
extern int g_CSCliCmdFwd; extern int g_CSCliCmdFwd;
extern int g_CSBuyCmdFwd; extern int g_CSBuyCmdFwd;
extern int g_CSBuyAttemptCmdFwd;
void InitializeHacks(); void InitializeHacks();
void ShutdownHacks(); void ShutdownHacks();
@ -64,9 +65,10 @@ void OnPluginsLoaded()
{ {
g_CSCliCmdFwd = MF_RegisterForward("CS_InternalCommand", ET_STOP, FP_CELL, FP_STRING, FP_DONE); g_CSCliCmdFwd = MF_RegisterForward("CS_InternalCommand", ET_STOP, FP_CELL, FP_STRING, FP_DONE);
g_CSBuyCmdFwd = MF_RegisterForward("CS_OnBuy", ET_STOP, FP_CELL, FP_CELL, FP_DONE); g_CSBuyCmdFwd = MF_RegisterForward("CS_OnBuy", ET_STOP, FP_CELL, FP_CELL, FP_DONE);
g_CSBuyAttemptCmdFwd = MF_RegisterForward("CS_OnBuyAttempt", ET_STOP, FP_CELL, FP_CELL, FP_DONE);
ToggleDetour_ClientCommands(UTIL_CheckForPublic("CS_InternalCommand")); ToggleDetour_ClientCommands(UTIL_CheckForPublic("CS_InternalCommand"));
ToggleDetour_BuyCommands(UTIL_CheckForPublic("CS_OnBuy")); ToggleDetour_BuyCommands(UTIL_CheckForPublic("CS_OnBuy") || UTIL_CheckForPublic("CS_OnBuyAttempt"));
} }
void OnAmxxDetach() void OnAmxxDetach()

View File

@ -357,7 +357,7 @@ forward CS_InternalCommand(id, const cmd[]);
/** /**
* The following constants are used with CS_OnBuy forward. * The following constants are used with CS_OnBuy[Attempt] forwards.
*/ */
#define CSI_P228 CSW_P228 #define CSI_P228 CSW_P228
#define CSI_SCOUT CSW_SCOUT #define CSI_SCOUT CSW_SCOUT
@ -397,7 +397,20 @@ forward CS_InternalCommand(id, const cmd[]);
/** /**
* Called when a player attempts to purchase an item. * Called when a player attempts to purchase an item.
* Return PLUGIN_CONTINUE to allow the purchase or return a higher action to deny. * This is ususally called right away on buy commands issued by a player.
*
* @note Return PLUGIN_CONTINUE to allow the purchase or return a higher action to deny.
*
* @param index Player index.
* @param item Item index, see CSI_* constants.
*/
forward CS_OnBuyAttempt(index, item);
/**
* Called when a player purchases an item.
* This usually called right before a player gets the purchased item.
*
* @note Return PLUGIN_CONTINUE to allow the purchase or return a higher action to deny.
* *
* @param index Player index. * @param index Player index.
* @param item Item index, see CSI_* constants. * @param item Item index, see CSI_* constants.