mirror of
https://github.com/alliedmodders/amxmodx.git
synced 2024-12-24 13:55:36 +03:00
Cstrike: Implement CS_OnBuyAttempt forward.
This commit is contained in:
parent
0728fee706
commit
6c4cb27d3e
@ -42,6 +42,7 @@ void CtrlDetours_BuyCommands(bool set);
|
||||
|
||||
int g_CSCliCmdFwd = -1;
|
||||
int g_CSBuyCmdFwd = -1;
|
||||
int g_CSBuyAttemptCmdFwd = -1;
|
||||
|
||||
int *g_UseBotArgs = 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.
|
||||
if (command && *command)
|
||||
{
|
||||
// Just for safety.
|
||||
command = UTIL_StringToLower((char *)command);
|
||||
|
||||
int itemId = 0;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -139,4 +139,15 @@ bool UTIL_CheckForPublic(const char *publicname)
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
char *UTIL_StringToLower(char *str)
|
||||
{
|
||||
char *p;
|
||||
for (p = str; *p != '\0'; ++p)
|
||||
{
|
||||
*p = tolower(*p);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
@ -37,6 +37,7 @@ bool UTIL_IsPlayer(AMX* amx, edict_t* pPlayer);
|
||||
void UTIL_TextMsg_Generic(edict_t* pPlayer, const char* message);
|
||||
void *UTIL_FindAddressFromEntry(const char *entry, bool isHidden = false, const char *library = "mod");
|
||||
bool UTIL_CheckForPublic(const char *publicname);
|
||||
char *UTIL_StringToLower(char *str);
|
||||
|
||||
#define GETINFOKEYBUFFER (*g_engfuncs.pfnGetInfoKeyBuffer)
|
||||
#define SETCLIENTKEYVALUE (*g_engfuncs.pfnSetClientKeyValue)
|
||||
|
@ -37,6 +37,7 @@ extern AMX_NATIVE_INFO cstrikeNatives[];
|
||||
|
||||
extern int g_CSCliCmdFwd;
|
||||
extern int g_CSBuyCmdFwd;
|
||||
extern int g_CSBuyAttemptCmdFwd;
|
||||
|
||||
void InitializeHacks();
|
||||
void ShutdownHacks();
|
||||
@ -64,9 +65,10 @@ void OnPluginsLoaded()
|
||||
{
|
||||
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_CSBuyAttemptCmdFwd = MF_RegisterForward("CS_OnBuyAttempt", ET_STOP, FP_CELL, FP_CELL, FP_DONE);
|
||||
|
||||
ToggleDetour_ClientCommands(UTIL_CheckForPublic("CS_InternalCommand"));
|
||||
ToggleDetour_BuyCommands(UTIL_CheckForPublic("CS_OnBuy"));
|
||||
ToggleDetour_BuyCommands(UTIL_CheckForPublic("CS_OnBuy") || UTIL_CheckForPublic("CS_OnBuyAttempt"));
|
||||
}
|
||||
|
||||
void OnAmxxDetach()
|
||||
|
@ -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_SCOUT CSW_SCOUT
|
||||
@ -397,9 +397,22 @@ forward CS_InternalCommand(id, const cmd[]);
|
||||
|
||||
/**
|
||||
* 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_OnBuy(index, item);
|
||||
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 item Item index, see CSI_* constants.
|
||||
*/
|
||||
forward CS_OnBuy(index, item);
|
Loading…
Reference in New Issue
Block a user