strtok > Sscanf
#1

Hey,,

I have this script:
Код:
mysql_strtok(Field, "|", Data);
while (mysql_strtok(Field, "|", "")==1)
{
How can i replace this with sscanf?

Thanks!
Wouter0100
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=176372

This might help.
Reply
#3

I dont think, can somebody make that little replace pleas
Reply
#4

Okay then, how can i replace this:
pawn Код:
mysql_strtok(Field, "|", Data);
        while (mysql_strtok(Field, "|", "")==1)
        {
            if (rcnt == 3) PlayerInfo[playerid][pLevel] = strval(Field);
            if (rcnt == 4) PlayerInfo[playerid][pAdmin] = strval(Field);
            if (rcnt == 5) PlayerInfo[playerid][pDonateRank] = strval(Field);
            if (rcnt == 6) PlayerInfo[playerid][gPupgrade] = strval(Field);
            if (rcnt == 7) PlayerInfo[playerid][pConnectTime] = strval(Field);
            if (rcnt == 8) PlayerInfo[playerid][pReg] = strval(Field);
            if (rcnt == 9) PlayerInfo[playerid][pSex] = strval(Field);
            if (rcnt == 10) PlayerInfo[playerid][pAge] = strval(Field);
            if (rcnt == 11) PlayerInfo[playerid][pOrigin] = strval(Field);
            if (rcnt == 12) PlayerInfo[playerid][pCK] = strval(Field);
            if (rcnt == 13) PlayerInfo[playerid][pMuted] = strval(Field);
            if (rcnt == 14) PlayerInfo[playerid][pExp] = strval(Field);
            if (rcnt == 15) PlayerInfo[playerid][pCash] = strval(Field);
            if (rcnt == 16) PlayerInfo[playerid][pAccount] = strval(Field);
            if (rcnt == 17) PlayerInfo[playerid][pCrimes] = strval(Field);
            if (rcnt == 18) PlayerInfo[playerid][pKills] = strval(Field);
            if (rcnt == 19) PlayerInfo[playerid][pDeaths] = strval(Field);
            if (rcnt == 20) PlayerInfo[playerid][pArrested] = strval(Field);
            if (rcnt == 21) PlayerInfo[playerid][pWantedDeaths] = strval(Field);
            if (rcnt == 22) PlayerInfo[playerid][pPhoneBook] = strval(Field);
            if (rcnt == 23) PlayerInfo[playerid][pLottoNr] = strval(Field);
            if (rcnt == 24) PlayerInfo[playerid][pFishes] = strval(Field);
            if (rcnt == 25) PlayerInfo[playerid][pBiggestFish] = strval(Field);
            if (rcnt == 26) PlayerInfo[playerid][pJob] = strval(Field);
            if (rcnt == 27) PlayerInfo[playerid][pPayCheck] = strval(Field);
            if (rcnt == 28) PlayerInfo[playerid][pHeadValue] = strval(Field);
            if (rcnt == 29) PlayerInfo[playerid][pJailed] = strval(Field);
            if (rcnt == 30) PlayerInfo[playerid][pJailTime] = strval(Field);
            if (rcnt == 31) PlayerInfo[playerid][pMats] = strval(Field);
            if (rcnt == 32) PlayerInfo[playerid][pDrugs] = strval(Field);
            if (rcnt == 33) PlayerInfo[playerid][pLeader] = strval(Field);
            if (rcnt == 34) PlayerInfo[playerid][pMember] = strval(Field);
            if (rcnt == 35) PlayerInfo[playerid][pFMember] = strval(Field);
            if (rcnt == 36) PlayerInfo[playerid][pRank] = strval(Field);
            if (rcnt == 37) PlayerInfo[playerid][pChar] = strval(Field);
            if (rcnt == 38) PlayerInfo[playerid][pContractTime] = strval(Field);
            if (rcnt == 39) PlayerInfo[playerid][pDetSkill] = strval(Field);
            if (rcnt == 40) PlayerInfo[playerid][pSexSkill] = strval(Field);
            if (rcnt == 41) PlayerInfo[playerid][pBoxSkill] = strval(Field);
            if (rcnt == 42) PlayerInfo[playerid][pLawSkill] = strval(Field);
            if (rcnt == 43) PlayerInfo[playerid][pMechSkill] = strval(Field);
            if (rcnt == 44) PlayerInfo[playerid][pJackSkill] = strval(Field);
            if (rcnt == 45) PlayerInfo[playerid][pCarSkill] = strval(Field);
            if (rcnt == 46) PlayerInfo[playerid][pNewsSkill] = strval(Field);
            if (rcnt == 47) PlayerInfo[playerid][pDrugsSkill] = strval(Field);
            if (rcnt == 48) PlayerInfo[playerid][pCookSkill] = strval(Field);
            if (rcnt == 49) PlayerInfo[playerid][pFishSkill] = strval(Field);
            if (rcnt == 50) PlayerInfo[playerid][pSHealth] = floatstr(Field);
            if (rcnt == 51) PlayerInfo[playerid][pHealth] = floatstr(Field);
            if (rcnt == 52) PlayerInfo[playerid][pInt] = strval(Field);
            if (rcnt == 53) PlayerInfo[playerid][pLocal] = strval(Field);
            if (rcnt == 54) PlayerInfo[playerid][pTeam] = strval(Field);
            if (rcnt == 55) PlayerInfo[playerid][pModel] = strval(Field);
            if (rcnt == 56) PlayerInfo[playerid][pPnumber] = strval(Field);
            if (rcnt == 57) PlayerInfo[playerid][pPhousekey] = strval(Field);
            if (rcnt == 58) PlayerInfo[playerid][pPcarkey] = strval(Field);
            if (rcnt == 59) PlayerInfo[playerid][pPapptkey] = strval(Field);
            if (rcnt == 60) PlayerInfo[playerid][pPbiskey] = strval(Field);
            if (rcnt == 61) PlayerInfo[playerid][pPos_x] = floatstr(Field);
            if (rcnt == 62) PlayerInfo[playerid][pPos_y] = floatstr(Field);
            if (rcnt == 63) PlayerInfo[playerid][pPos_z] = floatstr(Field);
            if (rcnt == 64) PlayerInfo[playerid][pCarLic] = strval(Field);
            if (rcnt == 65) PlayerInfo[playerid][pFlyLic] = strval(Field);
            if (rcnt == 66) PlayerInfo[playerid][pBoatLic] = strval(Field);
            if (rcnt == 67) PlayerInfo[playerid][pFishLic] = strval(Field);
            if (rcnt == 68) PlayerInfo[playerid][pGunLic] = strval(Field);
            if (rcnt == 69) PlayerInfo[playerid][pGun1] = strval(Field);
            if (rcnt == 70) PlayerInfo[playerid][pGun2] = strval(Field);
            if (rcnt == 71) PlayerInfo[playerid][pGun3] = strval(Field);
            if (rcnt == 72) PlayerInfo[playerid][pGun4] = strval(Field);
            if (rcnt == 73) PlayerInfo[playerid][pAmmo1] = strval(Field);
            if (rcnt == 74) PlayerInfo[playerid][pAmmo2] = strval(Field);
            if (rcnt == 75) PlayerInfo[playerid][pAmmo3] = strval(Field);
            if (rcnt == 76) PlayerInfo[playerid][pAmmo4] = strval(Field);
            if (rcnt == 77) PlayerInfo[playerid][pCarTime] = strval(Field);
            if (rcnt == 78) PlayerInfo[playerid][pPayDay] = strval(Field);
            if (rcnt == 79) PlayerInfo[playerid][pPayDayHad] = strval(Field);
            if (rcnt == 80) PlayerInfo[playerid][pCDPlayer] = strval(Field);
            if (rcnt == 81) PlayerInfo[playerid][pWins] = strval(Field);
            if (rcnt == 82) PlayerInfo[playerid][pLoses] = strval(Field);
            if (rcnt == 83) PlayerInfo[playerid][pAlcoholPerk] = strval(Field);
            if (rcnt == 84) PlayerInfo[playerid][pDrugPerk] = strval(Field);
            if (rcnt == 85) PlayerInfo[playerid][pMiserPerk] = strval(Field);
            if (rcnt == 86) PlayerInfo[playerid][pPainPerk] = strval(Field);
            if (rcnt == 87) PlayerInfo[playerid][pTraderPerk] = strval(Field);
            if (rcnt == 88) PlayerInfo[playerid][pTut] = strval(Field);
            if (rcnt == 89) PlayerInfo[playerid][pMissionNr] = strval(Field);
            if (rcnt == 90) PlayerInfo[playerid][pWarns] = strval(Field);
            if (rcnt == 91) PlayerInfo[playerid][pAdjustable] = strval(Field);
            if (rcnt == 92) PlayerInfo[playerid][pFuel] = strval(Field);
            if (rcnt == 93) PlayerInfo[playerid][pMarried] = strval(Field);
            if (rcnt == 94) PlayerInfo[playerid][pMarriedTo] = strmid(PlayerInfo[playerid][pMarriedTo], Field, 0, strlen(Field)-1, 255);
            if (rcnt == 96) PlayerInfo[playerid][pLinked] = strval(Field);
            if (rcnt == 97) PlayerInfo[playerid][pDeagle] = strval(Field);
            if (rcnt == 98) PlayerInfo[playerid][pShotgun] = strval(Field);
            if (rcnt == 99) PlayerInfo[playerid][pRifle] = strval(Field);
            if (rcnt == 100) PlayerInfo[playerid][pSDPistol] = strval(Field);
            if (rcnt == 101) PlayerInfo[playerid][pMP5] = strval(Field);
            if (rcnt == 102) PlayerInfo[playerid][pM4] = strval(Field);
            if (rcnt == 103) PlayerInfo[playerid][pAK47] = strval(Field);
/*
            if (rcnt == 104) PlayerInfo[playerid][pStartIP] = strmid(PlayerInfo[playerid][pStartIP], Field, 0, strlen(Field), 255);
            if (rcnt == 105) PlayerInfo[playerid][pEndIP] = strmid(PlayerInfo[playerid][pEndIP], Field, 0, strlen(Field), 255);
*/

            if (rcnt == 104) format(PlayerInfo[playerid][pStartIP], 16, "%s", Field);
            if (rcnt == 105) format(PlayerInfo[playerid][pEndIP], 16, "%s", Field);
            if (rcnt == 106) PlayerInfo[playerid][pLocker] = strval(Field);
            rcnt++;
        }
to Sscanf?
Reply
#5

Assuming that you're storing all the data from the MySQL player table into a string, and that string is "Data",
the correct sscanf(2) syntax would look like this:
pawn Код:
// your query code
        // storing the result set..
        mysql_store_result();
       
        sscanf(Data, "p<|>dddddddddddddddddddddddddddddddddddddddddddddddfffdddddddddddddddddddddddddddddds[24]dddddddds[16]s[16]d",
        PlayerInfo[playerid][pLevel],
        PlayerInfo[playerid][pAdmin]
        PlayerInfo[playerid][pDonateRank],
        PlayerInfo[playerid][gPupgrade],
        PlayerInfo[playerid][pConnectTime],
        PlayerInfo[playerid][pReg],
        PlayerInfo[playerid][pSex],
        PlayerInfo[playerid][pAge],
        PlayerInfo[playerid][pOrigin],
        PlayerInfo[playerid][pCK],
        PlayerInfo[playerid][pMuted],
        PlayerInfo[playerid][pExp],
        PlayerInfo[playerid][pCash],
        PlayerInfo[playerid][pAccount],
        PlayerInfo[playerid][pCrimes],
        PlayerInfo[playerid][pKills],
        PlayerInfo[playerid][pDeaths],
        PlayerInfo[playerid][pArrested],
        PlayerInfo[playerid][pWantedDeaths],
        PlayerInfo[playerid][pPhoneBook],
        PlayerInfo[playerid][pLottoNr],
        PlayerInfo[playerid][pFishes],
        PlayerInfo[playerid][pBiggestFish],
        PlayerInfo[playerid][pJob],
        PlayerInfo[playerid][pPayCheck],
        PlayerInfo[playerid][pHeadValue],
        PlayerInfo[playerid][pJailed],
        PlayerInfo[playerid][pJailTime],
        PlayerInfo[playerid][pMats],
        PlayerInfo[playerid][pDrugs],
        PlayerInfo[playerid][pLeader],
        PlayerInfo[playerid][pMember],
        PlayerInfo[playerid][pFMember],
        PlayerInfo[playerid][pRank],
        PlayerInfo[playerid][pChar],
        PlayerInfo[playerid][pContractTime],
        PlayerInfo[playerid][pDetSkill],
        PlayerInfo[playerid][pSexSkill],
        PlayerInfo[playerid][pBoxSkill],
        PlayerInfo[playerid][pLawSkill],
        PlayerInfo[playerid][pMechSkill],
        PlayerInfo[playerid][pJackSkill],
        PlayerInfo[playerid][pCarSkill],
        PlayerInfo[playerid][pNewsSkill],
        PlayerInfo[playerid][pDrugsSkill],
        PlayerInfo[playerid][pCookSkill],
        PlayerInfo[playerid][pFishSkill],
        PlayerInfo[playerid][pSHealth],
        PlayerInfo[playerid][pHealth],
        PlayerInfo[playerid][pInt],
        PlayerInfo[playerid][pLocal],
        PlayerInfo[playerid][pTeam],
        PlayerInfo[playerid][pModel],
        PlayerInfo[playerid][pPnumber],
        PlayerInfo[playerid][pPhousekey],
        PlayerInfo[playerid][pPcarkey],
        PlayerInfo[playerid][pPapptkey],
        PlayerInfo[playerid][pPbiskey],
        PlayerInfo[playerid][pPos_x],
        PlayerInfo[playerid][pPos_z],
        PlayerInfo[playerid][pPos_y],
        PlayerInfo[playerid][pCarLic],
        PlayerInfo[playerid][pFlyLic],
        PlayerInfo[playerid][pBoatLic],
        PlayerInfo[playerid][pFishLic],
        PlayerInfo[playerid][pGunLic],
        PlayerInfo[playerid][pGun1],
        PlayerInfo[playerid][pGun2],
        PlayerInfo[playerid][pGun3],
        PlayerInfo[playerid][pGun4],
        PlayerInfo[playerid][pAmmo1],
        PlayerInfo[playerid][pAmmo2],
        PlayerInfo[playerid][pAmmo3],
        PlayerInfo[playerid][pAmmo4],
        PlayerInfo[playerid][pCarTime],
        PlayerInfo[playerid][pPayDay],
        PlayerInfo[playerid][pPayDayHad],
        PlayerInfo[playerid][pCDPlayer],
        PlayerInfo[playerid][pWins],
        PlayerInfo[playerid][pLoses],
        PlayerInfo[playerid][pAlcoholPerk],
        PlayerInfo[playerid][pDrugPerk],
        PlayerInfo[playerid][pMiserPerk],
        PlayerInfo[playerid][pPainPerk],
        PlayerInfo[playerid][pTraderPerk],
        PlayerInfo[playerid][pTut],
        PlayerInfo[playerid][pMissionNr],
        PlayerInfo[playerid][pWarns],
        PlayerInfo[playerid][pAdjustable],
        PlayerInfo[playerid][pFuel],
        PlayerInfo[playerid][pMarried],
        PlayerInfo[playerid][pMarriedTo],
        PlayerInfo[playerid][pLinked],
        PlayerInfo[playerid][pDeagle],
        PlayerInfo[playerid][pShotgun],
        PlayerInfo[playerid][pRifle],
        PlayerInfo[playerid][pSDPistol],
        PlayerInfo[playerid][pMP5],
        PlayerInfo[playerid][pM4],
        PlayerInfo[playerid][pAK47],
        PlayerInfo[playerid][pStartIP],
        PlayerInfo[playerid][pEndIP],
        PlayerInfo[playerid][pLocker]);
Also if you can give me some rep on this since it really took a while to convert all of this to sscanf2!
Edit: Aso, for your reference, if you don't understand what does all that loong code after "sscanf(Data," do, have a look at the original sscanf2 topic !
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)