AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Need help for one plugin (https://forums.alliedmods.net/showthread.php?t=329872)

nG_getwreck 01-11-2021 06:10

Need help for one plugin
 
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:
https://i.imgur.com/baCvz3h.png

After executing:
https://i.imgur.com/aZFUWCG.png

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); 


Natsheh 01-11-2021 07:21

Re: Need help for one plugin
 
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;




All times are GMT -4. The time now is 10:29.

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