Пользователь
- Сообщения
- 47
- Реакции
- 1
Hello, this is the best forum i could find so far with english allowed and active people helping here.
I did a plugin which gives zp_ammo_packs from database and deletes after use of code.
My problem is that it crashes the server when redeeming the code... Anyone could help?
I did a plugin which gives zp_ammo_packs from database and deletes after use of code.
My problem is that it crashes the server when redeeming the code... Anyone could help?
C++:
#include < amxmodx >
#include < hamsandwich >
#include < sqlx >
#include < zombieplague >
new Handle:g_SqlTuple;
new Handle:g_SqlConnection;
new g_iIndexPromoCode
new g_iMoney
new g_szPromoCode[PLATFORM_MAX_PATH]
new const table_name[] = "bank_activate"
new Float:g_lastCodeUseTime;
public plugin_init()
{
register_plugin("Redeem Plugin", "1.0", "LVNDR");
register_clcmd("bank_activate", "RedeemCodeCommand");
g_SqlTuple = SQL_MakeDbTuple("127.0.0.1","root","123","login",1);
if(g_SqlTuple != Empty_Handle)
{
new ErrorCode,Error[32];
g_SqlConnection = SQL_Connect(g_SqlTuple,ErrorCode,Error,charsmax(Error));
if(g_SqlConnection == Empty_Handle)
{
set_fail_state("[%i] %s",ErrorCode,Error);
}
}
}
public RedeemCodeCommand(id)
{
if (get_gametime() - g_lastCodeUseTime < 6)
{
client_print(id, print_console, "Wait a bit before using this command...");
return PLUGIN_HANDLED
}
if(read_argc()<2)
{
client_print(id, print_console, "Usage: bank_activate <code>");
}
else
{
g_lastCodeUseTime = get_gametime()
new szPromoCode[PLATFORM_MAX_PATH]
read_args(szPromoCode, charsmax(szPromoCode))
remove_quotes(szPromoCode)
trim(szPromoCode)
new szQuery[MAX_FMT_LENGTH]
formatex(szQuery, charsmax(szQuery), "SELECT * FROM `%s` WHERE `activation_code` = '%s'", table_name, szPromoCode)
SQL_ThreadQuery(g_SqlTuple, "ActivePromoCode_QueryHandler", szQuery)
}
return PLUGIN_HANDLED;
}
public ActivePromoCode_QueryHandler(iFailState, Handle:Query, szError[], iErrNum, data[], size, Float:flQueryTime)
{
if(iFailState != TQUERY_SUCCESS)
{
log_amx("MySQL Error: %d (%s)", iErrNum, szError)
return
}
new id = data[0]
g_iMoney = 0
SQL_Execute(Query)
if(SQL_NumResults(Query) > 0)
{
g_iMoney = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "num_ammo_packs"))
SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "activation_code"), g_szPromoCode, charsmax(g_szPromoCode))
g_iIndexPromoCode = SQL_ReadResult(Query, SQL_FieldNameToNum(Query, "id"))
set_task(0.5, "func_SuccessfullyActivatingPromocode", id)
}
else {
client_print(id, print_console, "This code is not valid!"); }
SQL_FreeHandle(Query)
}
public func_SuccessfullyActivatingPromocode(id)
{
new szQuery[MAX_FMT_LENGTH]
new iData[2]
iData[0] = id
zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + g_iMoney)
client_print(id, print_console, "You successfully claimed the code and received your coins!")
formatex(szQuery, charsmax(szQuery), "DELETE FROM `%s` WHERE `id` = '%d';", table_name, g_iIndexPromoCode)
SQL_ThreadQuery(g_SqlTuple, "QueryHandler", szQuery, iData, charsmax(iData))
}
public QueryHandler(iFailState, Handle:Query, szError[], iErrNum, data[], size, Float:flQueryTime)
{
if(iFailState != TQUERY_SUCCESS)
{
log_amx("MySQL Error: %d (%s)", iErrNum, szError)
return
}
}
public plugin_end()
{
if (g_SqlConnection) SQL_FreeHandle(g_SqlConnection)
return;
}