Hello, basically i have a database where it has strings which needs to be activated in game by a command, and the corresponding string has a reward next to it, so what im trying to do is giving a player ammo packs if he enters a command like zp_ammo_active ERJ340RET39SDF and he gets rewarded with ammo packs what was meant for this key in database.
I have this script here and it throws me a lot of errors
PHP Code:
#include < amxmodx >
#include < amxmisc >
#include < fakemeta >
#include < engine >
#include < hamsandwich >
#include < sqlx >
#include < zombieplague >
#define DB_HOST "localhost"
#define DB_USER "root"
#define DB_PASS "123"
#define DB_NAME "login"
public plugin_precache()
{
register_plugin("ZP Ammo Bank", "1.0", "LVNDR");
register_cvar("zp_bank_activate_time", "30");
register_clcmd( "activateammo", "zp_ammo_active")
}
public zp_ammo_active(id, cmd[])
{
if(!strcmp(cmd, "zp_ammo_active", true))
{
new authcode[33];
get_user_authcode(id, authcode, sizeof(authcode));
new db = SQLX_GetDatabase();
if(!db)
{
client_print(id, print_console, "Could not connect to database.");
return PLUGIN_HANDLED;
}
new query[256];
format(query, sizeof(query), "SELECT num_ammo_packs FROM zp_ammo_active WHERE activation_code = '%s'", authcode);
SQLX_Query(db, query, "i", "ZP_Ammo_active_Callback", id);
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public ZP_Ammo_active_Callback(id, result[], num_rows)
{
if(num_rows < 1)
{
client_print(id, print_console, "Invalid activation code.");
return;
}
new num_ammo_packs = get_pcvar_num("zp_ammo_active_num_ammo_packs");
client_print(id, print_console, "You have received %d ammo packs.", num_ammo_packs);
zp_set_user_ammo_packs(id, zp_get_user_ammo_packs(id) + num_ammo_packs);
new db = SQLX_GetDatabase();
if(!db)
{
client_print(id, print_console, "Could not connect to database.");
return;
}
new query[256];
format(query, sizeof(query), "DELETE FROM zp_ammo_active WHERE activation_code = '%s'", result);
SQLX_Query(db, query);
}