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( __Plugin[ 0x0000 ], __Plugin[ 0x0001 ], __Plugin[ 0x0002 ] );
register_clcmd( "/redeem", "clcmdCode" );
RegisterSQL();
}
public clcmdCode( index )
{
new szBuffer[128], szQuery[256], iData[2]; iData[0] = index; iData[1] = 1;
read_args( szBuffer, 127 )
remove_quotes( szBuffer );
formatex( szQuery , 255 , "SELECT * FROM %s WHERE Code=^"%s^"", DB_TABLE, szBuffer );
SQL_ThreadQuery(gTuple, "DataHandler", szQuery, iData, 2 );
return PLUGIN_HANDLED;
}
stock Print(index, const input[], any:...)
{
static szMsg[191], msgSayText, len;
if (!msgSayText) msgSayText = get_user_msgid("SayText");
len = formatex(szMsg, charsmax(szMsg), "!g[ AMXX CODES ] !y");
vformat(szMsg[len], 190 - len, input, 3);
replace_all(szMsg, 190, "!g", "^4");
replace_all(szMsg, 190, "!y", "^1");
replace_all(szMsg, 190, "!t", "^3");
message_begin(index ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgSayText, .player = index);
write_byte(index ? index : 33);
write_string(szMsg);
message_end();
}
/* ====================================================================================== */
public DataHandler(failstate, Handle:Query, error[ ], error2, data[ ], datasize, Float:time)
{
switch(failstate)
{
case TQUERY_CONNECT_FAILED:
{
log_to_file("SQL_LOG.txt", "[ AMXX CODE ] Error en la conexion al MySQL [%i]: %s", error2, error);
return;
}
case TQUERY_QUERY_FAILED:
log_to_file("SQL_LOG.txt", "[ AMXX CODE ] Error en la consulta al MySQL [%i]: %s", error2, error );
}
new index = data[0];
if( !is_user_connected(index)) return;
if( data[1] == 1 )
{
if(SQL_NumResults(Query))
{
if( SQL_ReadResult( Query , 2 ) == 1 )
{
Print( index , "Al parecer el codigo ya fue usado" );
return;
}
new aps, szBuffer[256], Code[32];
aps = SQL_ReadResult(Query, 1);
SQL_ReadResult( Query, 0, Code, 31 );
zp_set_user_ammo_packs( index , zp_get_user_ammo_packs(index) + aps );
Print( index , "Recibes !g%d ammopacks !ypor activar un codigo", aps );
formatex( szBuffer, 255, "UPDATE %s SET Used=1 WHERE Code=^"%s^"", DB_TABLE, Code );
SQL_ThreadQuery( gTuple, "DataHandler", szBuffer );
}
else
Print( index , "El codigo que ingresaste es incorrecto" );
}
}
RegisterSQL()
{
gTuple = SQL_MakeDbTuple( DB_HOST, DB_USER,DB_PASS, DB_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);
|