pawn Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
#include <a_samp>
#include <a_mysql>
new pRegistrado[MAX_PLAYERS];
new pDinheiro[MAX_PLAYERS];
new pLogado[MAX_PLAYERS];
new Logged[MAX_PLAYERS];
#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()
{
// 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)
{
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)
{
pDinheiro[playerid] = 0x0; //Reseta a variavel pDinheiro.
new query[200], pname[24]; //Cria-se nossas variaveis para serem usadas.
GetPlayerName(playerid, pname, 24); //Recebe o nome do jogador
format(query, sizeof(query), "SELECT IP FROM `pinfo` WHERE user = '%s' LIMIT 1", pname); //Formata a QUERY para serem usadas %s, %i, %d, (basico do basico do pawn.)
mysql_query(query); //Essa é a função da query
mysql_store_result(); //Armazena os resultados
new rows = mysql_num_rows(); //Iremos getar quantas rows a query retornou.
if(!rows)
{
//Se a rows for 0, nГЈo encontrou nada
//EntГЈo iremos pedir o registro do jogador no banco de dados.
ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Registrar","VocГЄ nГЈo ta registrado, registra aew campeГЈo!","Registrar","Cancelar");
}
if(rows) //SENГƒO
{
//Rows = 1 , existe na database
//AUTO LOGIN
new IP[2][16]; //Uma para o IP do banco de dados e uma para o IP do jogador!
mysql_fetch_field_row(IP[0],"IP");
GetPlayerIp(playerid, IP[1], 16);
if(strlen(IP[0]) != 0 && !strcmp(IP[0], IP[1], true)) //Checa se os ips sГЈo iguais
{
MySQL_Login(playerid);
}
else if(!strlen(IP[0]) || strcmp(IP[0], IP[1], true))
{
ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Logar","Tu ta registrado manolo loga eww!","Logar","Cancelar");
pRegistrado[playerid] = 1; //Sets the registered variable to 1 (Shows that the player is registered).
}
}
mysql_free_result();
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
if(pLogado[playerid] == 1)
{
new score = GetPlayerScore(playerid); //Armazena o score em uma variavel
new grana = GetPlayerMoney(playerid); //armazena o $$ em uma ' '
new query[200], pname[24]; //Cria as variaveis necessarias..
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "UPDATE pinfo SET score=%d, dinheiro=%d WHERE user='%s'", score, grana, pname);
mysql_query(query);
//NГƒO NECESSITA-SE DE UM FREE_RESULT EM UMA QUERY DE UPDATE
}
return 1;
}
public OnPlayerSpawn(playerid)
{
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)
{
if(!Logged[playerid]) //Caso nГЈo esteje logado e tente spawnar....
{
if(!pRegistrado[playerid]) //Caso nГЈo esteje registrado
{
ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Registrar","Registra antes de jogar manolo!","Registrar","Cancelar"); //Mostra nosso dialog
return 0; //Retorna a falso, para q elee nao spawne..
}
if(pRegistrado[playerid] == 1) //.....
{
ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Logar","Loga ante sde jogar man...!","Logar","Cancelar");
return 0; // ' '
}
}
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[])
{
if(dialogid == 15000)
{
if(response) // Clicou no botГЈo de registrar
{
if(!strlen(inputtext) || strlen(inputtext) > 100) {//Senha nula ou maior que 100 caractГ©res
return SendClientMessage(playerid, 0xFF0000, "You must insert a password between 1-100 characters!"), ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Registrar","Use uma senha de 1-100 caractГ©res!","Registrar","Cancelar");
}
else
{
new escpass[100];
mysql_real_escape_string(inputtext, escpass);
MySQL_Register(playerid, escpass);
}
//Registra o player na função MYSQL_Register
}
if(!response)
{
return SendClientMessage(playerid, 0xFF0000, "You must register before logging in!"),
ShowPlayerDialog(playerid, 15000, DIALOG_STYLE_INPUT, "Registrar","Insira uma senha manolo","Registrar","Cancelar");
}
}
if(dialogid == 15500)
{
if(!response)
{
return SendClientMessage(playerid, 0xFF0000, "You must login before you spawn!"),
ShowPlayerDialog(playerid, 15500, DIALOG_STYLE_INPUT, "Login","VocГЄ em que logar antes de jogar cara!!","Logar","Cancelar");
}
if(response) //Clicou em Login
{
new query[200], pname[24], escapepass[100];
GetPlayerName(playerid, pname, 24);
mysql_real_escape_string(inputtext, escapepass);
format(query, sizeof(query), "SELECT `user` FROM pinfo WHERE user = '%s' AND password = SHA1('%s')", pname, escapepass);
mysql_query(query);
mysql_store_result();
new numrows = mysql_num_rows();
if(!numrows)
{
SendClientMessage(playerid, 0xFF0000, "Senha errada noob!");
}
if(numrows == 1) MySQL_Login(playerid);
mysql_free_result();
}
}
return 1;
}
public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
return 1;
}
stock MySQL_Register(playerid, passwordstring[])
{
new query[200], pname[24], IP[16];
GetPlayerName(playerid, pname, 24);
GetPlayerIp(playerid, IP, 16);
format(query, sizeof(query), "INSERT INTO pinfo (user, password, score, dinheiro, IP) VALUES('%s', SHA1('%s'), 0, 0, '%s')", pname, passwordstring, IP);
mysql_query(query);
SendClientMessage(playerid, -1, "Registrado e Logado.");
pLogado[playerid] = 1; //Logado
return 1;
}
stock MySQL_Login(playerid)
{
new query[300], pname[24], savingstring[20];
GetPlayerName(playerid, pname, 24);
format(query, sizeof(query), "SELECT * FROM pinfo WHERE user = '%s'", pname);
//Selecionamos apenas a variavel que Г© importante.
mysql_query(query);
mysql_store_result();//ARMAZENA O QUERY PARA USARMOS DEPOIS, POIS USAMOS SELECT PARA SELECIONAR, OU SEJA, TEMOS QUE ARMAZENAR O QUE SELECIONAMOS EM ALGUMA COISA NÉ.
while(mysql_fetch_row_format(query,"|"))
{
//WHILE EM APENAS UMA UNICA QUERY!
//Especialmente quando temos varias variaveis
//Pode-se usar sscanf tmb.
mysql_fetch_field_row(savingstring, "score"); SetPlayerScore(playerid, strval(savingstring));
mysql_fetch_field_row(savingstring, "dinheiro"); GivePlayerMoney(playerid, strval(savingstring));
}
mysql_free_result();
SendClientMessage(playerid, -1, "Logou!");
pLogado[playerid] = 1;
return 1;
}