Raised This Month: $183 Target: $400
 45% 

Solved Need help for one plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
nG_getwreck
Senior Member
Join Date: Oct 2020
Location: Philippines from South K
Old 01-11-2021 , 07:10   Need help for one plugin
Reply With Quote #1

Hello, I need help about a plugin. I want something like this.

If the /redeem is called, it will show another message named "Code" and you have to type the code on it.

Before executing:


After executing:


PHP Code:
/*================================================================================
    
    -------------------------------
    -*- [ZE] REDEEM AP -*-
    -------------------------------
    
    This plugin is part of Zombie Escape Mod and is distributed under the
    terms of the GNU General Public License. Check ZE_ReadME.txt for details.
    
================================================================================*/

#include <amxmodx>
#include <zombieplague>
#include <sqlx>

/* ====================================================================================== */

new const __Plugin[][] = { "[ZE] Redeem AP" ZP_VERSION_STRING"Kiki" };

new const 
DB_HOST[] = "localhost";
new const 
DB_USER[] = "root";
new const 
DB_PASS[] = "";
new const 
DB_NAME[] = "Codes";
new const 
DB_TABLE[] = "data";

new 
Handle:gTuple;

/* ====================================================================================== */

public plugin_init() 
{
    
register_plugin__Plugin0x0000 ], __Plugin0x0001 ], __Plugin0x0002 ] );
    
    
register_clcmd"/redeem""clcmdCode" );
    
    
    
RegisterSQL();
}

public 
clcmdCodeindex )
{
    new 
szBuffer[128], szQuery[256], iData[2]; iData[0] = indexiData[1] = 1;
    
read_argsszBuffer127 )
    
remove_quotesszBuffer );

    
formatexszQuery 255 "SELECT * FROM %s WHERE Code=^"%s^""DB_TABLEszBuffer );
    
SQL_ThreadQuery(gTuple"DataHandler"szQueryiData);
    
    return 
PLUGIN_HANDLED;
}

stock Print(index, const input[], any:...)
{
    static 
szMsg[191], msgSayTextlen;
    
    if (!
msgSayTextmsgSayText get_user_msgid("SayText");
    
    
len formatex(szMsgcharsmax(szMsg), "!g[ AMXX CODES ] !y");
    
vformat(szMsg[len], 190 leninput3);

    
replace_all(szMsg190"!g""^4");
    
replace_all(szMsg190"!y""^1");
    
replace_all(szMsg190"!t""^3");

    
message_begin(index MSG_ONE_UNRELIABLE MSG_BROADCASTmsgSayText, .player index);
    
write_byte(index index 33);
    
write_string(szMsg);
    
message_end();



/* ====================================================================================== */


public DataHandler(failstateHandle:Queryerror[ ], error2data[ ], datasizeFloat:time
{    
    switch(
failstate
    {        
        case 
TQUERY_CONNECT_FAILED
        {            
            
log_to_file("SQL_LOG.txt""[ AMXX CODE ] Error en la conexion al MySQL [%i]: %s"error2error);
            return;            
        }        
        case 
TQUERY_QUERY_FAILED:
            
log_to_file("SQL_LOG.txt""[ AMXX CODE ] Error en la consulta al MySQL [%i]: %s"error2error );
    }

    new 
index data[0];

    if( !
is_user_connected(index)) return;

    if( 
data[1] == )
    {
        if(
SQL_NumResults(Query)) 
        {
            if(  
SQL_ReadResultQuery ) == )
            {
                Print( 
index "Al parecer el codigo ya fue usado" );
                return;
            }
            
            new 
apsszBuffer[256], Code[32];
            
aps SQL_ReadResult(Query1);
            
SQL_ReadResultQuery0Code31 );
            
            
zp_set_user_ammo_packsindex zp_get_user_ammo_packs(index) + aps );
            Print( 
index "Recibes !g%d ammopacks !ypor activar un codigo"aps );
            
            
formatexszBuffer255"UPDATE %s SET Used=1 WHERE Code=^"%s^""DB_TABLECode );
            
SQL_ThreadQuerygTuple"DataHandler"szBuffer );
        }
        else
            Print( 
index "El codigo que ingresaste es incorrecto" );
    }
}



RegisterSQL()
{
    
gTuple SQL_MakeDbTupleDB_HOSTDB_USER,DB_PASSDB_NAME );

    if(!
gTuple)
    {
        
log_to_file("SQL_LOG.txt""[ BANS ] No se pudo conectar con la base de datos.");
        return 
pause("a");
    }

    new 
szQuery[512], len 0;

    
len += formatex(szQuery[len], charsmax(szQuery)-len
    
"CREATE TABLE IF NOT EXISTS %s \
    ( Code varchar(32) NOT NULL PRIMARY KEY, \
    Aps int(4) NOT NULL,\
    Used int(2) NOT NULL DEFAULT '0' ); "
DB_TABLE);

    
SQL_ThreadQuery(gTuple"DataHandler"szQuery);
    return 
PLUGIN_CONTINUE;
}

public 
plugin_end() SQL_FreeHandle(gTuple); 
__________________
My Steam:


Last edited by nG_getwreck; 01-12-2021 at 14:12.
nG_getwreck is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 01-11-2021 , 08:21   Re: Need help for one plugin
Reply With Quote #2

PHP Code:

public plugin_init()
{
   
register_clcmd("say /redeem""clcmd_redeemcode_entering");
   
register_clcmd("REDEEM_CODE""clcmdCode");
}

public 
clcmd_redeemcode_entering(id)
{
   
client_cmd(id"messagemode REDEEM_CODE");
}

public 
clcmdCodeindex )
{
    new 
szBuffer[128], szQuery[256], iData[2]; iData[0] = indexiData[1] = 1;
    
read_argsszBuffer127 )
    
remove_quotesszBuffer );

    
formatexszQuery 255 "SELECT * FROM %s WHERE Code=^"%s^""DB_TABLEszBuffer );
    
SQL_ThreadQuery(gTuple"DataHandler"szQueryiData);
    
    return 
PLUGIN_HANDLED;

__________________
@Jailbreak Main Mod v2.6 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Reply


Thread Tools
Display Modes

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 07:45.


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