Raised This Month: $51 Target: $400
 12% 

Get string from database


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
HowToRuski
Senior Member
Join Date: Feb 2019
Location: Hungary
Old 05-01-2023 , 09:37   Get string from database
Reply With Quote #1

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(idcmd[])
{
    if(!
strcmp(cmd"zp_ammo_active"true))
    {
        new 
authcode[33];
        
get_user_authcode(idauthcodesizeof(authcode));
        
        new 
db SQLX_GetDatabase();
        if(!
db)
        {
            
client_print(idprint_console"Could not connect to database.");
            return 
PLUGIN_HANDLED;
        }
        
        new 
query[256];
        
format(querysizeof(query), "SELECT num_ammo_packs FROM zp_ammo_active WHERE activation_code = '%s'"authcode);
        
SQLX_Query(dbquery"i""ZP_Ammo_active_Callback"id);
        
        return 
PLUGIN_HANDLED;
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
ZP_Ammo_active_Callback(idresult[], num_rows)
{
    if(
num_rows 1)
    {
        
client_print(idprint_console"Invalid activation code.");
        return;
    }
    
    new 
num_ammo_packs get_pcvar_num("zp_ammo_active_num_ammo_packs");
    
client_print(idprint_console"You have received %d ammo packs."num_ammo_packs);
    
zp_set_user_ammo_packs(idzp_get_user_ammo_packs(id) + num_ammo_packs);
    
    new 
db SQLX_GetDatabase();
    if(!
db)
    {
        
client_print(idprint_console"Could not connect to database.");
        return;
    }
    
    new 
query[256];
    
format(querysizeof(query), "DELETE FROM zp_ammo_active WHERE activation_code = '%s'"result);
    
SQLX_Query(dbquery);


Last edited by HowToRuski; 05-01-2023 at 14:16.
HowToRuski is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-01-2023 , 14:13   Re: Get string from database
Reply With Quote #2

and where is the problem?
lexzor is offline
mlibre
Veteran Member
Join Date: Nov 2015
Location: return PLUGIN_CONTINUE
Old 05-01-2023 , 14:57   Re: Get string from database
Reply With Quote #3

Quote:
Originally Posted by mlibre View Post
enable debugging

Code:
plugin.amxx debug
look "amxmodx\logs" if it details any error
__________________
mlibre is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:11.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode