Playerdata doesn't load correcly -
lulo356 - 17.01.2016
PHP код:
LoadPlayerData(playerid)
{
clearPlayerChat(playerid);
new Data[2048],Field[258],idx;
mysql_queryF("SELECT * FROM `Accounts` WHERE `Username` = '%s' LIMIT 1", GetName(playerid));
mysql_store_result();
if(mysql_num_rows() == 1){
mysql_fetch_rowEx(Data);
print(Data);
Field = strtuk( Data, idx, '|' );
for(new s = 0; s < 121; s++)
{
switch(s)
{
case 0: Player[playerid][UserID] = strval(Field);
case 2: strmid(Player[playerid][Password],Field,0,strlen(Field),129);
case 3: strmid(Player[playerid][LastIP],Field,0,strlen(Field),26);
case 4: Player[playerid][Adminlevel] = strval(Field);
case 5: Player[playerid][Money] = strval(Field);
case 6: Player[playerid][RegTime] = strval(Field);
case 7: Player[playerid][LastOn] = strval(Field);
case 8: Player[playerid][Level] = strval(Field);
case 9: Player[playerid][Gender] = strval(Field);
case 10: Player[playerid][Age] = strval(Field);
case 11: Player[playerid][Health] = floatstr(Field);
case 12: Player[playerid][Armour] = floatstr(Field);
case 13: Player[playerid][Skin] = strval(Field);
case 14: strmid(Player[playerid][Country],Field,0,strlen(Field),255);
case 15: Player[playerid][Test] = strval(Field);
case 16: Player[playerid][Faction] = strval(Field);
case 17: Player[playerid][FactionRank] = strval(Field);
case 18: strmid(Player[playerid][FactionRankName],Field,0,strlen(Field),255);
case 19: strmid(Player[playerid][Suspect], Field, 0, strlen(Field), 255);
case 20: Player[playerid][Arrest] = strval(Field);
case 21: Player[playerid][PrisonSelect] = strval(Field);
case 22: Player[playerid][PrisonTime] = strval(Field);
case 23: Player[playerid][AdminPrisonCount] = strval(Field);
case 24: Player[playerid][SecondsLoggedIn] = strval(Field);
case 25: Player[playerid][PlayingHours] = strval(Field);
case 26: Player[playerid][AdminCode] = strval(Field);
case 27: Player[playerid][PhoneN] = strval(Field);
case 28: Player[playerid][PhoneCredit] = strval(Field);
case 29: Player[playerid][PhoneBook] = strval(Field);
case 30: Player[playerid][House] = strval(Field);
case 31: Player[playerid][Hotel] = strval(Field);
case 32: Player[playerid][Hospitalized] = strval(Field);
case 33: Player[playerid][OnDuty] = strval(Field);
case 34: Player[playerid][DutyClothes] = strval(Field);
case 35: Player[playerid][LastSkin] = strval(Field);
case 36: Player[playerid][LastX] = floatstr(Field);
case 37: Player[playerid][LastY] = floatstr(Field);
case 38: Player[playerid][LastZ] = floatstr(Field);
case 39: Player[playerid][LastA] = floatstr(Field);
case 40: Player[playerid][LastInt] = strval(Field);
case 41: Player[playerid][LastWorld] = strval(Field);
case 42: Player[playerid][InFactionHQ] = strval(Field);
case 43: Player[playerid][InHouse] = strval(Field);
case 44: Player[playerid][Helper] = strval(Field);
case 45: Player[playerid][Moderator] = strval(Field);
case 46: strmid(Player[playerid][BankPincode],Field,0,strlen(Field),5);
case 47: Player[playerid][BankNumber] = strval(Field);
case 48: Player[playerid][BankMoney] = strval(Field);
case 49: Player[playerid][ExperiencePoints] = strval(Field);
case 50: Player[playerid][ExperiencePointsNeeded] = strval(Field);
case 51: Player[playerid][Coins] = strval(Field);
case 52: Player[playerid][WalkieTalkie] = strval(Field);
case 53: Player[playerid][WalkieFrequency] = strval(Field);
case 54: Player[playerid][HasMask] = strval(Field);
case 55: Player[playerid][Banned] = strval(Field);
case 56: Player[playerid][Bans] = strval(Field);
case 57: Player[playerid][Kicks] = strval(Field);
case 58: Player[playerid][WeaponSlot0] = strval(Field);
case 59: Player[playerid][WeaponSlot1] = strval(Field);
case 60: Player[playerid][WeaponSlot2] = strval(Field);
case 61: Player[playerid][WeaponSlot3] = strval(Field);
case 62: Player[playerid][WeaponSlot4] = strval(Field);
case 63: Player[playerid][WeaponSlot5] = strval(Field);
case 64: Player[playerid][WeaponSlot6] = strval(Field);
case 65: Player[playerid][WeaponSlot7] = strval(Field);
case 66: Player[playerid][WeaponSlot8] = strval(Field);
case 67: Player[playerid][WeaponSlot9] = strval(Field);
case 68: Player[playerid][WeaponSlot10] = strval(Field);
case 69: Player[playerid][WeaponSlot11] = strval(Field);
case 70: Player[playerid][WeaponSlot0Ammo] = strval(Field);
case 71: Player[playerid][WeaponSlot1Ammo] = strval(Field);
case 72: Player[playerid][WeaponSlot2Ammo] = strval(Field);
case 73: Player[playerid][WeaponSlot3Ammo] = strval(Field);
case 74: Player[playerid][WeaponSlot4Ammo] = strval(Field);
case 75: Player[playerid][WeaponSlot5Ammo] = strval(Field);
case 76: Player[playerid][WeaponSlot6Ammo] = strval(Field);
case 77: Player[playerid][WeaponSlot7Ammo] = strval(Field);
case 78: Player[playerid][WeaponSlot8Ammo] = strval(Field);
case 79: Player[playerid][WeaponSlot9Ammo] = strval(Field);
case 80: Player[playerid][WeaponSlot10Ammo] = strval(Field);
case 81: Player[playerid][WeaponSlot11Ammo] = strval(Field);
case 82: Player[playerid][DutyWeaponSlot0] = strval(Field);
case 83: Player[playerid][DutyWeaponSlot1] = strval(Field);
case 84: Player[playerid][DutyWeaponSlot2] = strval(Field);
case 85: Player[playerid][DutyWeaponSlot3] = strval(Field);
case 86: Player[playerid][DutyWeaponSlot4] = strval(Field);
case 87: Player[playerid][DutyWeaponSlot5] = strval(Field);
case 88: Player[playerid][DutyWeaponSlot6] = strval(Field);
case 89: Player[playerid][DutyWeaponSlot7] = strval(Field);
case 90: Player[playerid][DutyWeaponSlot8] = strval(Field);
case 91: Player[playerid][DutyWeaponSlot9] = strval(Field);
case 92: Player[playerid][DutyWeaponSlot10] = strval(Field);
case 93: Player[playerid][DutyWeaponSlot11] = strval(Field);
case 94: Player[playerid][DutyWeaponSlot0Ammo] = strval(Field);
case 95: Player[playerid][DutyWeaponSlot1Ammo] = strval(Field);
case 96: Player[playerid][DutyWeaponSlot2Ammo] = strval(Field);
case 97: Player[playerid][DutyWeaponSlot3Ammo] = strval(Field);
case 98: Player[playerid][DutyWeaponSlot4Ammo] = strval(Field);
case 99: Player[playerid][DutyWeaponSlot5Ammo] = strval(Field);
case 100: Player[playerid][DutyWeaponSlot6Ammo] = strval(Field);
case 101: Player[playerid][DutyWeaponSlot7Ammo] = strval(Field);
case 102: Player[playerid][DutyWeaponSlot8Ammo] = strval(Field);
case 103: Player[playerid][DutyWeaponSlot9Ammo] = strval(Field);
case 104: Player[playerid][DutyWeaponSlot10Ammo] = strval(Field);
case 105: Player[playerid][DutyWeaponSlot11Ammo] = strval(Field);
case 106: Player[playerid][AntiCheatExemption] = strval(Field);
case 107: strmid(Player[playerid][Email],Field,0,strlen(Field),128);
case 108: Player[playerid][Warns] = strval(Field);
case 109: Player[playerid][Badge] = strval(Field);
case 110: strmid(Player[playerid][SecretWord],Field,0,strlen(Field),128);
case 111: Player[playerid][DisconnectReason] = strval(Field);
case 112: Player[playerid][Business] = strval(Field);
case 113: Player[playerid][FightStyle] = strval(Field);
case 114: Player[playerid][SpawnedPersonalCar] = strval(Field);
case 115: Player[playerid][DRIVINGLC] = strval(Field);
case 116: Player[playerid][FIREARMSLC] = strval(Field);
case 117: Player[playerid][BOATLC] = strval(Field);
case 118: Player[playerid][BIKELC] = strval(Field);
}
Field = strtuk( Data, idx, '|' );
}
clearPlayerChat(playerid);
SPD(playerid, DIALOG_AUTHENTICATION);
TextDrawHideForPlayer(playerid, Text:LoadingTD);
//printf("%s",Player[playerid][SecretWord]);
//printf("%s",Player[playerid][LastIP]);
//printf("%s",PlayerConnectedIP[playerid]);
}else if(mysql_num_rows() == 0){
clearPlayerChat(playerid);
new playernamesplit[3][MAX_PLAYER_NAME], Name[MAX_PLAYER_NAME];
GetPlayerName(playerid, Name, sizeof(Name));
split2(Name, playernamesplit, '_');
if (!strlen(playernamesplit[0]) || !strlen(playernamesplit[1]))
{
KickWithMessage(playerid, COLOR_WHITE, "Unfortunately, your name is not in the proper format! Please use the format of "#COL_EMB_LIGHTBLUE"\"Firstname_Lastname\""#COL_EMB_WHITE".");
}
else
{
SPD(playerid, DIALOG_REGISTER);
TextDrawHideForPlayer(playerid, Text:LoadingTD);
}
}
mysql_free_result();
}
PHP код:
`UserID` int(11) NOT NULL,
`Username` varchar(255) DEFAULT NULL,
`Password` varchar(129) DEFAULT NULL,
`LastIP` varchar(16) NOT NULL DEFAULT '-1',
`Adminlevel` int(4) NOT NULL,
`Money` int(10) NOT NULL,
`RegTime` int(20) NOT NULL,
`LastOn` int(20) NOT NULL,
`Level` int(4) NOT NULL,
`Gender` int(11) NOT NULL,
`Age` int(3) NOT NULL,
`Health` float NOT NULL,
`Armour` float NOT NULL,
`Skin` int(3) NOT NULL,
`Country` varchar(255) NOT NULL,
`Test` int(11) NOT NULL DEFAULT '0',
`Faction` int(11) NOT NULL,
`FactionRank` int(11) NOT NULL,
`FactionRankName` varchar(255) NOT NULL,
`Suspect` varchar(255) NOT NULL,
`Arrest` int(11) NOT NULL,
`PrisonSelect` int(6) NOT NULL DEFAULT '0',
`PrisonTime` int(6) NOT NULL DEFAULT '0',
`AdminPrisonCount` int(11) NOT NULL DEFAULT '0',
`SecondsLoggedIn` int(11) NOT NULL,
`PlayingHours` int(11) NOT NULL,
`AdminCode` int(255) NOT NULL,
`PhoneN` int(6) NOT NULL,
`PhoneCredit` int(11) NOT NULL,
`PhoneBook` int(11) NOT NULL DEFAULT '0',
`House` int(11) NOT NULL DEFAULT '0',
`Hotel` int(11) NOT NULL DEFAULT '0',
`Hospitalized` int(11) NOT NULL DEFAULT '0',
`OnDuty` int(11) NOT NULL DEFAULT '0',
`DutyClothes` int(11) NOT NULL DEFAULT '0',
`LastSkin` int(11) NOT NULL,
`LastX` float NOT NULL,
`LastY` float NOT NULL,
`LastZ` float NOT NULL,
`LastA` float NOT NULL,
`LastInt` int(11) NOT NULL,
`LastWorld` int(11) NOT NULL,
`InFactionHQ` int(11) NOT NULL,
`InHouse` int(11) NOT NULL,
`Helper` int(11) NOT NULL DEFAULT '0',
`Moderator` int(11) NOT NULL DEFAULT '0',
`BankPincode` varchar(5) DEFAULT '0',
`BankNumber` int(11) NOT NULL DEFAULT '0',
`BankMoney` int(11) NOT NULL DEFAULT '0',
`ExperiencePoints` int(11) NOT NULL,
`ExperiencePointsNeeded` int(11) NOT NULL DEFAULT '8',
`Coins` int(11) NOT NULL DEFAULT '0',
`WalkieTalkie` int(11) NOT NULL DEFAULT '0',
`WalkieFrequency` int(11) NOT NULL DEFAULT '0',
`HasMask` int(11) NOT NULL DEFAULT '0',
`Banned` int(11) NOT NULL DEFAULT '0',
`Bans` int(11) NOT NULL DEFAULT '0',
`Kicks` int(11) DEFAULT '0',
`WeaponSlot0` int(11) NOT NULL DEFAULT '0',
`WeaponSlot1` int(11) NOT NULL DEFAULT '0',
`WeaponSlot2` int(11) NOT NULL DEFAULT '0',
`WeaponSlot3` int(11) NOT NULL DEFAULT '0',
`WeaponSlot4` int(11) NOT NULL DEFAULT '0',
`WeaponSlot5` int(11) NOT NULL DEFAULT '0',
`WeaponSlot6` int(11) NOT NULL DEFAULT '0',
`WeaponSlot7` int(11) NOT NULL DEFAULT '0',
`WeaponSlot8` int(11) NOT NULL DEFAULT '0',
`WeaponSlot9` int(11) NOT NULL DEFAULT '0',
`WeaponSlot10` int(11) NOT NULL DEFAULT '0',
`WeaponSlot11` int(11) NOT NULL DEFAULT '0',
`WeaponSlot0Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot1Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot2Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot3Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot4Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot5Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot6Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot7Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot8Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot9Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot10Ammo` int(11) NOT NULL DEFAULT '0',
`WeaponSlot11Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot0` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot1` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot2` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot3` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot4` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot5` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot6` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot7` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot8` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot9` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot10` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot11` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot0Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot1Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot2Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot3Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot4Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot5Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot6Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot7Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot8Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot9Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot10Ammo` int(11) NOT NULL DEFAULT '0',
`DutyWeaponSlot11Ammo` int(11) NOT NULL DEFAULT '0',
`AntiCheatExemption` int(11) NOT NULL DEFAULT '0',
`Email` varchar(255) NOT NULL,
`Warns` int(11) NOT NULL DEFAULT '0',
`Badge` int(11) NOT NULL DEFAULT '0',
`SecretWord` varchar(128) NOT NULL,
`DisconnectReason` int(11) NOT NULL,
`Business` int(11) NOT NULL DEFAULT '-1',
`FightStyle` int(11) NOT NULL DEFAULT '0',
`SpawnedPersonalCar` int(11) NOT NULL DEFAULT '-1',
`DRIVINGLC` int(11) NOT NULL DEFAULT '0',
`FIREARMSLC` int(11) NOT NULL DEFAULT '0',
`BOATLC` int(11) NOT NULL DEFAULT '0',
`BIKELC` int(11) NOT NULL DEFAULT '0',
`LastOnDate` varchar(255) NOT NULL,
`Offline` int(11) NOT NULL DEFAULT '1'
) ENGINE=InnoDB AUTO_INCREMENT=29 DEFAULT CHARSET=latin1;
--
-- Dumping data for table `accounts`
--
INSERT INTO `accounts` (`UserID`, `Username`, `Password`, `LastIP`, `Adminlevel`, `Money`, `RegTime`, `LastOn`, `Level`, `Gender`, `Age`, `Health`, `Armour`, `Skin`, `Country`, `Test`, `Faction`, `FactionRank`, `FactionRankName`, `Suspect`, `Arrest`, `PrisonSelect`, `PrisonTime`, `AdminPrisonCount`, `SecondsLoggedIn`, `PlayingHours`, `AdminCode`, `PhoneN`, `PhoneCredit`, `PhoneBook`, `House`, `Hotel`, `Hospitalized`, `OnDuty`, `DutyClothes`, `LastSkin`, `LastX`, `LastY`, `LastZ`, `LastA`, `LastInt`, `LastWorld`, `InFactionHQ`, `InHouse`, `Helper`, `Moderator`, `BankPincode`, `BankNumber`, `BankMoney`, `ExperiencePoints`, `ExperiencePointsNeeded`, `Coins`, `WalkieTalkie`, `WalkieFrequency`, `HasMask`, `Banned`, `Bans`, `Kicks`, `WeaponSlot0`, `WeaponSlot1`, `WeaponSlot2`, `WeaponSlot3`, `WeaponSlot4`, `WeaponSlot5`, `WeaponSlot6`, `WeaponSlot7`, `WeaponSlot8`, `WeaponSlot9`, `WeaponSlot10`, `WeaponSlot11`, `WeaponSlot0Ammo`, `WeaponSlot1Ammo`, `WeaponSlot2Ammo`, `WeaponSlot3Ammo`, `WeaponSlot4Ammo`, `WeaponSlot5Ammo`, `WeaponSlot6Ammo`, `WeaponSlot7Ammo`, `WeaponSlot8Ammo`, `WeaponSlot9Ammo`, `WeaponSlot10Ammo`, `WeaponSlot11Ammo`, `DutyWeaponSlot0`, `DutyWeaponSlot1`, `DutyWeaponSlot2`, `DutyWeaponSlot3`, `DutyWeaponSlot4`, `DutyWeaponSlot5`, `DutyWeaponSlot6`, `DutyWeaponSlot7`, `DutyWeaponSlot8`, `DutyWeaponSlot9`, `DutyWeaponSlot10`, `DutyWeaponSlot11`, `DutyWeaponSlot0Ammo`, `DutyWeaponSlot1Ammo`, `DutyWeaponSlot2Ammo`, `DutyWeaponSlot3Ammo`, `DutyWeaponSlot4Ammo`, `DutyWeaponSlot5Ammo`, `DutyWeaponSlot6Ammo`, `DutyWeaponSlot7Ammo`, `DutyWeaponSlot8Ammo`, `DutyWeaponSlot9Ammo`, `DutyWeaponSlot10Ammo`, `DutyWeaponSlot11Ammo`, `AntiCheatExemption`, `Email`, `Warns`, `Badge`, `SecretWord`, `DisconnectReason`, `Business`, `FightStyle`, `SpawnedPersonalCar`, `DRIVINGSLC`, `FIREARMSLC`, `BOATLC`, `BIKELC`, `LastOnDate`, `Offline`);
Its loading not like it should be, Everthing will be messed up,,
Re: Playerdata doesn't load correcly -
Riddick94 - 17.01.2016
What is that loop and switch() statement doing there with such a huge amount of numbers to check in the loop? Why are you mixing it up, do you know how SQL language works?
What version of MySQL do you use, I guess it's a non-threaded version. Here's how you should actually do it and trying to avoid being a cave-man programmer.
https://sampforum.blast.hk/showthread.php?tid=557276
Re: Playerdata doesn't load correcly -
lulo356 - 18.01.2016
Bump
Re: Playerdata doesn't load correcly -
Pottus - 19.01.2016
@Riddick it isn't his code that is why.
Re: Playerdata doesn't load correcly -
Prokill911 - 19.01.2016
Just a few questions..
1, (Not a question, A statement) Your SQL Syn-taxing is fucking horrendous..
2, Silly question really but worth an ask.. - Are you sure it's sending the correct "Username"
Код:
mysql_queryF("SELECT * FROM `Accounts` WHERE `Username` = '%s' LIMIT 1", GetName(playerid));
Question.
Is your TABLE spelled exactly: "Accounts" or is it "ACCOUNTS" or "accounts" , Some times tables will be spazzy if you don't put the exact name..
-
3, Why the hell are you sending an SQL statement and then responding to that statement in the same function..
Create a seperate function for that SQL to send the information too.
And then you can use the SQL statement in multiple locations and draw the information you need in separate functions, Looking @ that code makes me gag..
I can easily tell you're using multiple statements which do the exact same thing..
I don't have to see it to know it.. (More code = More time compiling = Looks ugly as fuck)
4, Quick observation.
You're putting loop statement in with the default value of 121, < Being max yet you've defined the max rows as 1..
Another observation
You NEVER once call information from the column it's stored in..
You're simply repeating a statement with no variable.. Namely: "Field"
Where does Field get it's data from because you're not telling the script where it's actually coming from
All you've done is throw a ton of enums @ the script with the value of "Field" well "Field has no value and it's not getting any value for that enum.
You're just switching case statements telling it the value = "Field".
That's why your code doesn't work.....
__
Side note:
Here is an EXAMPLE.. Of Clean and working code..
Код:
new SqlQuery[1024];
format(SqlQuery, sizeof(SqlQuery), "SELECT * FROM `Accounts` WHERE `username` = '%s'", Getname(playerid));
mysql_function_query(g_mysql_handle, SqlQuery, true, "LoadAccountInfo", "d",playerid);
Код:
forward LoadAccountInfo(playerid);
public LoadAccountInfo(playerid) {;
new accountname[MAX_PLAYER_NAME+1];
new level, ph;
new rows,fields;
cache_get_data(rows,fields);
if(rows < 1) {
//Do Something if the account isn't found.
return 1;
}
cache_get_row(0, 0, accountname);
PlayerInfo[playerid][AccountName] = accountname;
cache_get_row(0, 1, level);
PlayerInfo[playerid][PlayerLevel] = level;
cache_get_row(0, 2, ph);
PlayerInfo[playerid][PlayingHours] = ph;
return 1;
}
Obviously if we were Lazy we could just set a function Var to do all the work instead of individual names like accountname etc..
We could just create
< and just call that for each row - assign it and then reuse it.