09.02.2015, 14:14
Hola, simplemente compile un sistema de registro por MySQL para empezar el GM, al momento de colocarlo al servidor e iniciarlo, me arroja este error:
Acб les dejo todo el cуdigo sacado de un tutorial (Compila perfecto, sin un warning o error):
Код:
---------- Loaded log file: "server_log.txt". ---------- SA-MP Dedicated Server ---------------------- v0.3z, ©2005-2014 SA-MP Team plugins = "" (string) Server Plugins -------------- Loaded 0 plugins. Started server on port: 7777, with maxplayers: 50 lanmode is OFF. Filterscripts --------------- Loading filterscript 'gl_actions.amx'... Loading filterscript 'gl_realtime.amx'... Loading filterscript 'gl_property.amx'... ----------------------------------- Grand Larceny Property Filterscript ----------------------------------- Loading filterscript 'gl_mapicon.amx'... Loading filterscript 'ls_mall.amx'... Loading filterscript 'ls_elevator.amx'... Loading filterscript 'attachments.amx'... Loading filterscript 'skinchanger.amx'... --Admin Player Skin Changer Loaded Loading filterscript 'vspawner.amx'... --Admin Vehicle Spawner Loaded Loaded 9 filterscripts. Reading File: blank Reading File: properties/houses.txt Reading File: properties/businesses.txt Reading File: properties/banks.txt Reading File: properties/police.txt Script[gamemodes/GMSG.amx]: Run time error 19: "File or function is not found" Number of vehicle models: 0
PHP код:
#include <a_samp>
#include <a_mysql>
//#define FILTERSCRIPT
// DIALOGOS
#define D_LOGIN 1 // Dialogo de inicio de sesion
#define D_REGISTER 2 // Dialogo de registro.
// THREADS
#define THREAD_CHECK_ACCOUNT 1 // Redefinimos dicho macro con el numero 1 para ser mas facil recordar su "ID".
#define THREAD_CHECK_PASS 2 // etc
#define THREAD_LOAD_DATA 3 // .. etc
// MYSQL DATA
#define MySQL_Host "127.0.0.1" // Servidor al que nos conectaremos, 127.0.0.1 o localhost si esta configurado en el mismo servidor
#define MySQL_Usuario "root" // Usuario, en mi caso el root.
#define MySQL_BD "ServidorMySQL" // Base de datos, cual creamos y nombramos, su nombre.
#define MySQL_Pass "" // Password del usuario, en mi caso root no tiene Password..
// MACROS
/*#define PlayerLogged(%0) (PlayerInfo[playerid][pLogged])*/
enum E_INFO
{ // Enumerador de variables.
pID, // ID que tiene en la base de datos
pLogged, // Variable que almacena el estado de SESION De un jugador
pInterior, // Interior ..
pVirtualworld, // etc..
pSkin,
Float:pPos[4] // etc.. Posicion, que seria un array de 4, X, Y, Z, A.
};
new PlayerInfo[MAX_PLAYERS][E_INFO], // Definicion de las variables del enumerador.
gTunel, // Aqui almacenaremos el ID que tomara nuestra conexion.
bool:pRegisterLast[MAX_PLAYERS]; // Usada para comprobar si se acaba de registrar asi no usar dos funciones distintas.
#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
print("\n--------------------------------------");
print(" Blank Filterscript by your name here");
print("--------------------------------------\n");
return 1;
}
public OnFilterScriptExit()
{
return 1;
}
#else
main()
{
print("\n----------------------------------");
print(" Blank Gamemode by your name here");
print("----------------------------------\n");
}
#endif
public OnGameModeInit()
{
gTunel = mysql_connect(MySQL_Host, MySQL_Usuario, MySQL_BD, MySQL_Pass);
if(mysql_errno(gTunel) != 0){ // En caso de usar MySQL R7 usen mysql_ping
return print("La conexion a la base de datos fallo!");
}
else{
print("La conexion a la base de datos se realizo!");
}
return 1;
/*// Don't use these lines if it's a filterscript
SetGameModeText("Blank Script");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
return 1;*/
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerRequestClass(playerid, classid)
{
if(IsPlayerNPC(playerid))
{ // Retorna si es un NPC, si van a usar NPC provoquen su spawn
// TogglePlayerControllable(playerid, false);
return 1; // Retorna uno, valga la redundancia lo que retorne a excepcion de que quieran hacer algo especial.
}
if(PlayerInfo[playerid][pLogged])
{ // Condicion para aplicar una funcion si el jugador llega a esta callback y ya esta logueado.
SpawnPlayer(playerid); // Si ya esta logueado y llega aqui lo hacemo spawnear.
}
else
{ // Pero si no lo esta ..
TogglePlayerSpectating(playerid, true); // Le ponemos en modo espectador para evitar los botones de la callback ..
CheckAccount(playerid); // Llamamos a CheckAccount a que nos muestre el dialogo y aplique cambios para inicio de sesion ..
}
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
return 1;
}
public OnPlayerConnect(playerid)
{
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
SaveAccount(playerid);
return 1;
}
public OnPlayerSpawn(playerid)
{
if(!PlayerInfo[playerid][pLogged])
return 0;
SetPlayerPos(playerid, PlayerInfo[playerid][pPos][0], PlayerInfo[playerid][pPos][1], PlayerInfo[playerid][pPos][2]);
SetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPos][3]);
SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVirtualworld]);
SetPlayerInterior(playerid, PlayerInfo[playerid][pInterior]);
SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnVehicleSpawn(vehicleid)
{
return 1;
}
public OnVehicleDeath(vehicleid, killerid)
{
return 1;
}
public OnPlayerText(playerid, text[])
{
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/mycommand", cmdtext, true, 10) == 0)
{
// Do something here
return 1;
}
return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
return 1;
}
public OnPlayerEnterCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveCheckpoint(playerid)
{
return 1;
}
public OnPlayerEnterRaceCheckpoint(playerid)
{
return 1;
}
public OnPlayerLeaveRaceCheckpoint(playerid)
{
return 1;
}
public OnRconCommand(cmd[])
{
return 1;
}
public OnPlayerRequestSpawn(playerid)
{
return 1;
}
public OnObjectMoved(objectid)
{
return 1;
}
public OnPlayerObjectMoved(playerid, objectid)
{
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
return 1;
}
public OnVehicleMod(playerid, vehicleid, componentid)
{
return 1;
}
public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
return 1;
}
public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
return 1;
}
public OnPlayerSelectedMenuRow(playerid, row)
{
return 1;
}
public OnPlayerExitedMenu(playerid)
{
return 1;
}
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
return 1;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
return 1;
}
public OnRconLoginAttempt(ip[], password[], success)
{
return 1;
}
public OnPlayerUpdate(playerid)
{
return 1;
}
public OnPlayerStreamIn(playerid, forplayerid)
{
return 1;
}
public OnPlayerStreamOut(playerid, forplayerid)
{
return 1;
}
public OnVehicleStreamIn(vehicleid, forplayerid)
{
return 1;
}
public OnVehicleStreamOut(vehicleid, forplayerid)
{
return 1;
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case D_LOGIN:
{
if (!response){ // Si selecciona 'Salir'
return Kick(playerid); // .. Lo expulsa del servidor,
}
else{
if(!IsPlayerConnected(playerid) || PlayerInfo[playerid][pLogged]) // Nos devuelve si el jugador no es una ID valida o ya esta logeado no hara nada.
return 0; // Retornamos 0
if(inputtext[0] == '\0')
return Kick(playerid); // Si no envia nada a la caja del dialogo de LOGIN lo expulsa del servidor.
new query[160];
format(query, sizeof(query), "SELECT `id` FROM `users` WHERE `name` = '%s' AND `pass` = '%s'", _getNameEx(playerid), inputtext);
mysql_function_query(gTunel, query, true, "QueryCheckAccount", "dd", playerid, THREAD_CHECK_PASS);
}
}
case D_REGISTER:
{
if (!response){
return Kick(playerid);
}
else{
if(inputtext[0] == '\0')
return Kick(playerid);
pRegisterLast[playerid] = true; // Variable que determina que se acaba de registrar
CreatePlayerAccount(playerid, _getNameEx(playerid), inputtext); // creamos su cuenta
SendToLogin(playerid); // Lo forzamos a logear
}
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
/**********************************************************/
/**********************************************************/
CreatePlayerAccount(playerid, username[], password[])
{
if(playerid == INVALID_PLAYER_ID)
return 0;
new query[129+120];
format(query, sizeof(query), "INSERT INTO `users` (`name`, `pass`) VALUES('%s', '%s')", username, password);
mysql_function_query(gTunel, query, false, "CrearCuenta", "d", playerid);
return 1;
}
forward CrearCuenta(playerid); public CrearCuenta(playerid)
{
PlayerInfo[playerid][pID] = cache_insert_id(gTunel);
return 1;
}
stock CheckAccount(playerid)
{
if(!IsPlayerConnected(playerid))
return 0;
SetSpawnInfo( playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, -1, -1, -1, -1, -1, -1);
TogglePlayerControllable(playerid, false); // Congelamos al jugador
SendToLogin(playerid); // Hacemos que se muestre lo demas ..
return 1;
}
SendToLogin(playerid)
{
if(playerid == INVALID_PLAYER_ID)
return 0;
new query[120]; // Definimos el array para almacenar lo del format, a deduccion pienso que es lo que usaremos.
format(query, sizeof(query), "SELECT id, name FROM `users` WHERE `name` = '%s' LIMIT 1", _getNameEx(playerid));
/* Situamos a query la consulta formateada con el nombre del jugador ..
-> SELECT - SELECCIONAMOS
-> id, name - SELECCIONAMOS LA FILA id y name ..
-> FROM - DE
-> SELECCIONAMOS FILA id y name DE LA TABLA users
-> WHERE - WHERE
-> SELECCIONAMOS FILA id y name DE LA TABLA users QUE CUMPLAN CON LA CONDICION name LIMITANDO A 1 RESULTADO.
------------------------------------------------------------------------------------------------------------------------ */
mysql_function_query(gTunel, query, true, "QueryCheckAccount", "dd", playerid, THREAD_CHECK_ACCOUNT); /* Ejecutamos ..
La consulta.
-> El primer argumento hara ejecutar la consulta a la conexion que tengamos almacenada en gTunel
-> El segundo ... agrega la consulta que ejecutaremos, la que esta mas arriba explicada.
-> El ter ... habilitamos el cache ..
-> El c .. Hacemos que nos envie los datos a dicha callback.
-> El q .. Situamos los argumentos del formato, en este caso d por que seria para "playerid" */
return 1;
}
stock _getNameEx(playerid)
{
new name[MAX_PLAYER_NAME + 1];
GetPlayerName(playerid, name, sizeof(name));
return name;
}
stock ShowPlayerDialogEx(playerid, dialogid, style, caption[], info[], button1[], button2[], {Float,_}:...)
{
static
string[1024],
start,
end;
if (numargs() > 7)
{
#emit ADDR.pri button2
#emit STOR.pri start
for (end = start + (numargs() << 2) - 28; end > start; end -= 4)
{
#emit LREF.pri end
#emit PUSH.pri
}
#emit PUSH.S info
#emit PUSH.C 1024
#emit PUSH.C string
#emit LOAD.S.pri 8
#emit CONST.alt 16
#emit SUB
#emit PUSH.pri
#emit SYSREQ.C format
#emit LCTRL 5
#emit SCTRL 4
ShowPlayerDialog(playerid, dialogid, style, caption, string, button1, button2);
}
else
{
ShowPlayerDialog(playerid, dialogid, style, caption, info, button1, button2);
}
return 1;
}
cache_get_field_int(row, const field_name[])
{
new str[12];
cache_get_field_content(row, field_name, str, gTunel);
return strval(str);
}
stock Float:cache_get_field_float(row, const field_name[])
{
new str[16];
cache_get_field_content(row, field_name, str, gTunel);
return floatstr(str);
}
stock SaveAccount(playerid)
{
if (!PlayerInfo[playerid][pLogged])
return 0;
new query[2400];
if (GetPlayerState(playerid) != PLAYER_STATE_SPECTATING)
{
PlayerInfo[playerid][pInterior] = GetPlayerInterior(playerid);
PlayerInfo[playerid][pVirtualworld] = GetPlayerVirtualWorld(playerid);
PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
GetPlayerPos(playerid,PlayerInfo[playerid][pPos][0],PlayerInfo[playerid][pPos][1],PlayerInfo[playerid][pPos][2]);
GetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPos][3]);
}
format(query, sizeof(query), "UPDATE `users` SET `interior` = '%d', `vw` = '%d', `skin` = '%d'",
PlayerInfo[playerid][pInterior],
PlayerInfo[playerid][pVirtualworld],
PlayerInfo[playerid][pSkin]
);
format(query, sizeof(query), "%s, `x` = '%.4f', `y` = '%.4f', `z` = '%.4f', `a` = '%.4f' WHERE `id` = '%d'",
query,
PlayerInfo[playerid][pPos][0],
PlayerInfo[playerid][pPos][1],
PlayerInfo[playerid][pPos][2],
PlayerInfo[playerid][pPos][3],
PlayerInfo[playerid][pID]
);
mysql_function_query(gTunel, query, false, "EnviarConsulta", "");
return 1;
}
stock SpawnPlayerEx(playerid)
{
if(!IsPlayerConnected(playerid))
return 0;
TogglePlayerSpectating(playerid, false); // Quitamos el modo espectador, que lo hara spawnear.
if(pRegisterLast[playerid] == true)
{
pRegisterLast[playerid] = false;
SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
SetPlayerSkin(playerid, 274);
SetPlayerVirtualWorld(playerid, 0);
SetPlayerInterior(playerid, 0);
}
return 1;
}
forward QueryCheckAccount(playerid, option); public QueryCheckAccount(playerid, option){
new rows, fields;
if(playerid == INVALID_PLAYER_ID)
return 0;
switch(option)
{
case THREAD_CHECK_ACCOUNT:
{
cache_get_data(rows, fields, gTunel);
if(rows)
{
SendClientMessage(playerid, -1, "Ingresa tu Password para identificarte");
PlayerInfo[playerid][pID] = cache_get_field_int(0, "id"); // Situamos al index del array el ID que tiene en la base de datos.
ShowPlayerDialogEx(playerid, D_LOGIN, DIALOG_STYLE_PASSWORD, "Inicio", "Ingresa tu pass para identificarte ->", "Aceptar", "Salir");
}
else
{
ShowPlayerDialogEx(playerid, D_REGISTER, DIALOG_STYLE_PASSWORD, "Registro", "Ingresa tu pass para registrarte ->", "Aceptar", "Salir");
}
return 1;
}
case THREAD_CHECK_PASS:
{
cache_get_data(rows, fields, gTunel);
if (!rows) // Password incorrecta!
{
Kick(playerid); // Lo expulsa del servidor.
}
else // Password correcta!
{
// Cargamos sus datos.
new query[160];
format(query, sizeof(query), "SELECT * FROM `users` WHERE `name` = '%s'", _getNameEx(playerid));
mysql_function_query(gTunel, query, true, "QueryCheckAccount", "dd", playerid, THREAD_LOAD_DATA);
}
return 1;
}
case THREAD_LOAD_DATA:
{
cache_get_data(rows, fields, gTunel);
if (!rows)
{
return 0;
}
else
{
PlayerInfo[playerid][pLogged] = true;
PlayerInfo[playerid][pInterior] = cache_get_field_int(0, "interior");
PlayerInfo[playerid][pVirtualworld] = cache_get_field_int(0, "vw");
PlayerInfo[playerid][pSkin] = cache_get_field_int(0, "skin");
PlayerInfo[playerid][pPos][0] = cache_get_field_float(0, "x");
PlayerInfo[playerid][pPos][1] = cache_get_field_float(0, "y");
PlayerInfo[playerid][pPos][2] = cache_get_field_float(0, "z");
PlayerInfo[playerid][pPos][3] = cache_get_field_float(0, "a");
SendClientMessage(playerid, -1, "Bienvenido al servidor!");
SpawnPlayerEx(playerid);
}
}
}
return 0;
}