Дело было вечером, делать было нечего...
При написании очередного плагина потребовались функции для работы с балансом игрока. Чтобы каждый раз не искать их, вынес в инклюд.
Делюсь:
При написании очередного плагина потребовались функции для работы с балансом игрока. Чтобы каждый раз не искать их, вынес в инклюд.
Делюсь:
/*
* File: money.inc
* Description: Account management function for player (Counter-Strike: Source only)
* Author(s): duxa
*/
#if defined _money_included
#endinput
#endif
#define _money_included
new g_iAccount = -1;
/*
* Get the amount of the player's account.
*
* @param client Client index
* @return Amount of the player's account
*/
stock GetMoney(client)
{
g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
if (g_iAccount == -1) return -1;
return GetEntData(client, g_iAccount, 4);
}
/*
* Set the amount of the player's account.
*
* @param client Client index
* @param amount Amount of the player's account
* @noreturn
*/
stock SetMoney(client, amount)
{
g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
if (g_iAccount == -1) return;
if (amount > 16000) amount = 16000;
if (amount < 0) amount = 0;
SetEntData(client, g_iAccount, amount, 4, true);
}
/*
* Reset the amount of the player's account.
*
* @param client Client index
* @noreturn
*/
stock ResetMoney(client)
{
g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
if (g_iAccount == -1) return;
SetEntData(client, g_iAccount, 0, 4, true);
}
/*
* Add the amount of the player's account.
*
* @param client Client index
* @param amount Amount that add to the player's account
* @noreturn
*/
stock GiveMoney(client, amount)
{
g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
if (g_iAccount == -1) return;
new Money;
new Get = GetMoney(client);
if(Get == -1) return;
if (amount > 16000) amount = 16000;
if (amount < 0) amount = 0;
Money = Get + amount;
if(Money > 16000) Money = 16000;
SetEntData(client, g_iAccount, Money, 4, true);
}
/*
* Take the amount of the player's account.
*
* @param client Client index
* @param amount Amount that take to the player's account
* @noreturn
*/
stock TakeMoney(client, amount)
{
g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
if (g_iAccount == -1) return;
new Money;
new Get = GetMoney(client);
if(Get == -1) return;
if (amount < 0) amount = 0;
Money = Get - amount;
if(Money < 0) Money = 0;
SetEntData(client, g_iAccount, Money, 4, true);
}