05.11.2013, 19:27
Hello, I am trying to learn how to work with MySQL in sa-mp
And I have a question, I'm using a gamemode. base godfather
I managed the part to make the registration, enter the data in the table. Update the data in the table when the player leaves.
More I can not do that load the data from player when they login.
Try:
My heartfelt thanks. Who can help me.
Thank you!
And I have a question, I'm using a gamemode. base godfather
I managed the part to make the registration, enter the data in the table. Update the data in the table when the player leaves.
More I can not do that load the data from player when they login.
Try:
pawn Код:
public OnPlayerLogin(playerid,password[])
{
TextDrawShowForPlayer(playerid, forum[playerid]);
TextDrawShowForPlayer(playerid, BPN[playerid]);
TextDrawShowForPlayer(playerid, TextDrawdeData[playerid]);
TextDrawShowForPlayer(playerid, TextDrawdeHora[playerid]);
DisablePlayerCheckpoint(playerid);
new Row, Field;
cache_get_data(Row, Field, Connect);
if(Row)
{
//correct password
new Str[1081], Nome[21];
GetPlayerName(playerid, Nome, 21);
format(Str, 109, "SELECT `Level`, `AdminLevel`, `Helper`, `DonateRank`, `PontosVIP`, `Voto`, `Familia`, `LFamilia`, `Caixinha`,");
format(Str, 232, "%s `UpgradePoints`, `ConnectedTime`, `Registered`, `Sex`, `Respect`, `Dinamit`, `Money`, `Bank`, `Barras`, `Crimes`, `Kills`,", Str);
format(Str, 349, "%s `Deaths`, `Phonebook`, `LottoNr`, `Fishes`, `BiggestFish`, `Emprego`, `Paycheck`, `HeadValue`, `Jailed`, `JailTime`,", Str);
format(Str, 468, "%s `Materiais`, `Maconha`, `Cocaina`, `Crack`, `Lider`, `Member`, `Rank`, `Char`, `ContractTime`, `DetSkill`, `SexSkill`,", Str);
format(Str, 590, "%s `BoxSkill`, `LawSkill`, `MechSkill`, `NewsSkill`, `DrogasSkill`, `CookSkill`, `FishSkill`, `pSHealth`, `Team`, `PhoneNr`,", Str);
format(Str, 706, "%s `House`, `Bizz`, `Spawn`, `SafeMaconha`, `SafeCocaina`, `SafeCrack`, `NivelProcurado`, `Galao`, `Madeira`, `Pizza`,", Str);
format(Str, 824, "%s `SafeMateriais`, `Pos_x`, `Pos_y`, `Pos_z`, `CarLic`, `FlyLic`, `BoatLic`, `FishLic`, `GunLic`, `PayDay`, `CDPlayer`,", Str);
format(Str, 940, "%s `Wins`, `Loses`, `AlcoholPerk`, `DrugPerk`, `MiserPerk`, `PainPerk`, `TraderPerk`, `Tutorial`, `Avisos`, `Married`,", Str);
format(Str, 1081, "%s `MarriedTo`, `Luta`, `Dorgado`, `Dorgado2`, `Doenca`, `Creditos`, `LU` FROM `contas` WHERE `Nome` = '%s' LIMIT 0,1", Str, Nome);
mysql_function_query(Connect, Str, true, "OnPlayerLooad", "i", playerid);
}
else
{
//incorrect pass
SendClientMessage(playerid, COLOR_YELLOW, "Senha errada! - Se errar a senha 5 vezes terб o IP Banido!");
new loginstring[256];
new loginname[64];
GetPlayerName(playerid,loginname,sizeof(loginname));
format(loginstring,sizeof(loginstring),"{33CCFF}******************************************\n\n{f2fafa}Bem vindo(a), {12e03b}%s\n\n{f2fafa}Digite sua senha para entrar no servidor!!!\n\n{33CCFF}******************************************",loginname);
ShowPlayerDialog(playerid, 1, DIALOG_STYLE_PASSWORD,"Brasil Vision Street v1.3B",loginstring,"Logar","Sair");
gPlayerLogTries[playerid] += 1;
if(gPlayerLogTries[playerid] == 5)
{
new stri[64], tmp[20], tmp3[20], ip[16];
GetPlayerIp(playerid, ip, sizeof ip);
format(stri, sizeof(stri), "IPsBanidos/%s.ini",ip);
getdate(Ano, Mes, Dia);
format(tmp, 20, "%d/%d/%d", Dia, Mes, Ano);
gettime(Hora, Minuto, Segundo);
format(tmp3, 20, "%d:%d:%d", Hora, Minuto, Segundo);
format(stri, sizeof(stri), "IPsBanidos/%s.ini",ip);
dini_Create(stri);
dini_Set(stri,"Motivo","Errou a senha 5 vezes");
dini_Set(stri,"Admin","Automбtico");
dini_Set(stri,"Data",tmp);
dini_Set(stri,"Hora",tmp3);
dini_Set(stri,"Nick",PlayerName(playerid));
Kick(playerid);
}
return 0;
}
TempoLogin = SetTimerEx("LoginAgora", 10000, 0, "i", playerid);
return 1;
}
pawn Код:
forward OnPlayerLooad(playerid);
public OnPlayerLooad(playerid)
{
new rows, fields,temp[25];
if(rows)
{
cache_get_data(rows, fields);
cache_get_row(0, 0, temp, Connect), PlayerInfo[playerid][pLevel] = strval(temp);
cache_get_row(0, 1, temp, Connect), PlayerInfo[playerid][pAdmin] = strval(temp);
cache_get_row(0, 2, temp, Connect), PlayerInfo[playerid][pHelper] = strval(temp);
cache_get_row(0, 3, temp, Connect), PlayerInfo[playerid][pVIP] = strval(temp);
cache_get_row(0, 4, temp, Connect), PlayerInfo[playerid][pPontosVIP] = strval(temp);
cache_get_row(0, 5, temp, Connect), PlayerInfo[playerid][pVoto] = strval(temp);
cache_get_row(0, 6, temp, Connect), PlayerInfo[playerid][pFamilia] = strval(temp);
cache_get_row(0, 7, temp, Connect), PlayerInfo[playerid][pLFamilia] = strval(temp);
cache_get_row(0, 8, temp, Connect), PlayerInfo[playerid][pCaixinha] = strval(temp);
cache_get_row(0, 9, temp, Connect), PlayerInfo[playerid][gPupgrade] = strval(temp);
cache_get_row(0, 10, temp, Connect), PlayerInfo[playerid][pConnectTime] = strval(temp);
cache_get_row(0, 11, temp, Connect), PlayerInfo[playerid][pReg] = strval(temp);
cache_get_row(0, 12, temp, Connect), PlayerInfo[playerid][pSex] = strval(temp);
cache_get_row(0, 13, temp, Connect), PlayerInfo[playerid][pExp] = strval(temp);
cache_get_row(0, 14, temp, Connect), PlayerInfo[playerid][pDina] = strval(temp);
cache_get_row(0, 15, temp, Connect), PlayerInfo[playerid][pCash] = strval(temp);
cache_get_row(0, 16, temp, Connect), PlayerInfo[playerid][pConta] = strval(temp);
cache_get_row(0, 17, temp, Connect), PlayerInfo[playerid][pBarras] = strval(temp);
cache_get_row(0, 18, temp, Connect), PlayerInfo[playerid][pCrimes] = strval(temp);
cache_get_row(0, 19, temp, Connect), PlayerInfo[playerid][pKills] = strval(temp);
cache_get_row(0, 20, temp, Connect), PlayerInfo[playerid][pDeaths] = strval(temp);
cache_get_row(0, 21, temp, Connect), PlayerInfo[playerid][pPhoneBook] = strval(temp);
cache_get_row(0, 22, temp, Connect), PlayerInfo[playerid][pLottoNr] = strval(temp);
cache_get_row(0, 23, temp, Connect), PlayerInfo[playerid][pFishes] = strval(temp);
cache_get_row(0, 24, temp, Connect), PlayerInfo[playerid][pBiggestFish] = strval(temp);
cache_get_row(0, 25, temp, Connect), PlayerInfo[playerid][pEmprego] = strval(temp);
cache_get_row(0, 26, temp, Connect), PlayerInfo[playerid][pSalario] = strval(temp);
cache_get_row(0, 27, temp, Connect), PlayerInfo[playerid][pHeadValue] = strval(temp);
cache_get_row(0, 28, temp, Connect), PlayerInfo[playerid][pJailed] = strval(temp);
cache_get_row(0, 29, temp, Connect), PlayerInfo[playerid][pJailTime] = strval(temp);
cache_get_row(0, 30, temp, Connect), PlayerInfo[playerid][pMats] = strval(temp);
cache_get_row(0, 31, temp, Connect), PlayerInfo[playerid][pDrogas] = strval(temp);
cache_get_row(0, 32, temp, Connect), PlayerInfo[playerid][pDrogas2] = strval(temp);
cache_get_row(0, 33, temp, Connect), PlayerInfo[playerid][pDrogas3] = strval(temp);
cache_get_row(0, 34, temp, Connect), PlayerInfo[playerid][pLider] = strval(temp);
cache_get_row(0, 35, temp, Connect), PlayerInfo[playerid][pMembro] = strval(temp);
cache_get_row(0, 36, temp, Connect), PlayerInfo[playerid][pCargo] = strval(temp);
cache_get_row(0, 37, temp, Connect), PlayerInfo[playerid][pSkin] = strval(temp);
cache_get_row(0, 38, temp, Connect), PlayerInfo[playerid][pContractTime] = strval(temp);
cache_get_row(0, 39, temp, Connect), PlayerInfo[playerid][pDetSkill] = strval(temp);
cache_get_row(0, 40, temp, Connect), PlayerInfo[playerid][pSexSkill] = strval(temp);
cache_get_row(0, 41, temp, Connect), PlayerInfo[playerid][pBoxSkill] = strval(temp);
cache_get_row(0, 42, temp, Connect), PlayerInfo[playerid][pLawSkill] = strval(temp);
cache_get_row(0, 43, temp, Connect), PlayerInfo[playerid][pMechSkill] = strval(temp);
cache_get_row(0, 44, temp, Connect), PlayerInfo[playerid][pNewsSkill] = strval(temp);
cache_get_row(0, 45, temp, Connect), PlayerInfo[playerid][pDrogasSkill] = strval(temp);
cache_get_row(0, 46, temp, Connect), PlayerInfo[playerid][pCookSkill] = strval(temp);
cache_get_row(0, 47, temp, Connect), PlayerInfo[playerid][pFishSkill] = strval(temp);
cache_get_row(0, 48, temp, Connect), PlayerInfo[playerid][pSHealth] = strval(temp);
cache_get_row(0, 49, temp, Connect), PlayerInfo[playerid][pTeam] = strval(temp);
cache_get_row(0, 50, temp, Connect), PlayerInfo[playerid][pPnumber] = strval(temp);
cache_get_row(0, 51, temp, Connect), PlayerInfo[playerid][pPHousekey] = strval(temp);
cache_get_row(0, 52, temp, Connect), PlayerInfo[playerid][pPbiskey] = strval(temp);
cache_get_row(0, 53, temp, Connect), PlayerInfo[playerid][pSpawn] = strval(temp);
cache_get_row(0, 54, temp, Connect), PlayerInfo[playerid][pSafeDrogas] = strval(temp);
cache_get_row(0, 55, temp, Connect), PlayerInfo[playerid][pSafeDrogas2] = strval(temp);
cache_get_row(0, 56, temp, Connect), PlayerInfo[playerid][pSafeDrogas3] = strval(temp);
cache_get_row(0, 57, temp, Connect), WantedPoints[playerid] = strval(temp);
cache_get_row(0, 58, temp, Connect), Galao[playerid] = strval(temp);
cache_get_row(0, 59, temp, Connect), Madeira[playerid] = strval(temp);
cache_get_row(0, 60, temp, Connect), Pizza = strval(temp);
cache_get_row(0, 61, temp, Connect), PlayerInfo[playerid][psMats] = strval(temp);
cache_get_row(0, 62, temp, Connect), PlayerInfo[playerid][pPos_x] = strval(temp);
cache_get_row(0, 63, temp, Connect), PlayerInfo[playerid][pPos_y] = strval(temp);
cache_get_row(0, 64, temp, Connect), PlayerInfo[playerid][pPos_z] = strval(temp);
cache_get_row(0, 65, temp, Connect), PlayerInfo[playerid][pCarLic] = strval(temp);
cache_get_row(0, 66, temp, Connect), PlayerInfo[playerid][pFlyLic] = strval(temp);
cache_get_row(0, 67, temp, Connect), PlayerInfo[playerid][pBoatLic] = strval(temp);
cache_get_row(0, 68, temp, Connect), PlayerInfo[playerid][pFishLic] = strval(temp);
cache_get_row(0, 69, temp, Connect), PlayerInfo[playerid][pGunLic] = strval(temp);
cache_get_row(0, 70, temp, Connect), PlayerInfo[playerid][pPayDay] = strval(temp);
cache_get_row(0, 71, temp, Connect), PlayerInfo[playerid][pCDPlayer] = strval(temp);
cache_get_row(0, 72, temp, Connect), PlayerInfo[playerid][pWins] = strval(temp);
cache_get_row(0, 73, temp, Connect), PlayerInfo[playerid][pLoses] = strval(temp);
cache_get_row(0, 74, temp, Connect), PlayerInfo[playerid][pAlcoholPerk] = strval(temp);
cache_get_row(0, 75, temp, Connect), PlayerInfo[playerid][pDrugPerk] = strval(temp);
cache_get_row(0, 76, temp, Connect), PlayerInfo[playerid][pMiserPerk] = strval(temp);
cache_get_row(0, 77, temp, Connect), PlayerInfo[playerid][pPainPerk] = strval(temp);
cache_get_row(0, 78, temp, Connect), PlayerInfo[playerid][pTraderPerk] = strval(temp);
cache_get_row(0, 79, temp, Connect), printf("Tutorial %i", strval(temp));/*PlayerInfo[playerid][pTut] = strval(temp);*/
cache_get_row(0, 80, temp, Connect), PlayerInfo[playerid][pWarns] = strval(temp);
cache_get_row(0, 81, temp, Connect), PlayerInfo[playerid][pMarried] = strval(temp);
cache_get_row(0, 82, temp, Connect), PlayerInfo[playerid][pMarriedTo] = strval(temp);
cache_get_row(0, 83, temp, Connect), PlayerInfo[playerid][pLuta] = strval(temp);
cache_get_row(0, 84, temp, Connect), PlayerInfo[playerid][pDorgado] = strval(temp);
cache_get_row(0, 85, temp, Connect), PlayerInfo[playerid][pDorgado2] = strval(temp);
cache_get_row(0, 86, temp, Connect), PlayerInfo[playerid][pDoenca] = strval(temp);
cache_get_row(0, 87, temp, Connect), PlayerInfo[playerid][pCreditos] = strval(temp);
cache_get_row(0, 88, temp, Connect), printf("LU %i", strval(temp));/*PlayerInfo[playerid][pLastLogin] = strval(temp);*/
}
return 1;
}
Thank you!