SA-MP Forums Archive
Sscanf & MySQL help :D - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Sscanf & MySQL help :D (/showthread.php?tid=280294)



Sscanf & MySQL help :D - wouter0100 - 31.08.2011

Hey,

I'am bussy with a new gamemode, you see in my sign ;p.
Okay,

In the topic of Sscanf say a space is dont return.
This is my output of a query:
[Databaseid]|[name]|[pass sha1]|[skin]|[adminlevel]|[viprank]|[vipexperdate]|[ip]|[money]|[level]|[kill]|[death]
Works good!
Now, i'am set in in Player Array's with:
pawn Код:
sscanf(savingstring,"p<|>   iiis iii",
        Playerdata[playerid][Skin],
        Playerdata[playerid][Adminlevel],
        Playerdata[playerid][Vip],
        Playerdata[playerid][Vipexp],
        money,
        Playerdata[playerid][Level],
        Playerdata[playerid][Kill],
        Playerdata[playerid][Death]);
So, the first 3 (Databaseid, name, pass) dont need.
and the IP dont need. (Spaces.)

When i'am going Ingame, my skin is 11 (My database id)
How can i fix this?
The spaces dont work.
Thanks!


Re: Sscanf & MySQL help :D - [MWR]Blood - 31.08.2011

If you don't need something, just don't put its variable... don't leave spaces.


Re: Sscanf & MySQL help :D - wouter0100 - 31.08.2011

I dont need to put the 'Pass, Databaseid, Name, IP' in a variable, then the topic of 'Sscanf' say, you need to do a space?


Re: Sscanf & MySQL help :D - [MWR]Blood - 31.08.2011

Sure you do, why wouldn't you need to store them in a variable?


Re: Sscanf & MySQL help :D - Sinner - 31.08.2011

Do it like this:

PHP код:
new unused[5];
sscanf(savingstring,"p<|>iiiiiisiiiii",
        
unused[0],
        
unused[1],
        
unused[3],
        
Playerdata[playerid][Skin],
        
Playerdata[playerid][Adminlevel],
        
Playerdata[playerid][Vip],
        
Playerdata[playerid][Vipexp],
        
unused[4],
        
money,
        
Playerdata[playerid][Level],
        
Playerdata[playerid][Kill],
        
Playerdata[playerid][Death]); 



Re: Sscanf & MySQL help :D - mprofitt - 31.08.2011

pawn Код:
sscanf(savingstring,"p<|>e<{iii}iiis[STRLEN]{i}iiii>", Playerdata[playerid]);

Use the quiet {} specifiers ...
The s specifier needs an EXACT string length of the enum variable.


Re: Sscanf & MySQL help :D - wouter0100 - 31.08.2011

The string is this:
0000-00-00 00:00:00
so:
19?


Re: Sscanf & MySQL help :D - wouter0100 - 31.08.2011

Okay,
pawn Код:
MySQL_Login(playerid)
{
    new query[250], pname[24], savingstring[250], money;
    GetPlayerName(playerid, pname, 24);
    format(query, sizeof(query), "SELECT * FROM users WHERE name='%s' LIMIT 1", pname);
    mysql_query(query);
    mysql_store_result();
    if(mysql_fetch_row_format(savingstring))
    {
        sscanf(savingstring,"p<|>e<{iii}iiis[19]{i}iiii>",
        Playerdata[playerid][Skin],
        Playerdata[playerid][Adminlevel],
        Playerdata[playerid][Vip],
        Playerdata[playerid][Vipexp],
        money,
        Playerdata[playerid][Level],
        Playerdata[playerid][Kill],
        Playerdata[playerid][Death]);
    }
    mysql_free_result();
    format(string, sizeof(string), "Welcome back %s!", pname);
    SendClientMessage(playerid, COLOR_YELLOW2, string);
    ResetPlayerMoney(playerid);
    GivePlayerMoney(playerid, money);
    SetPlayerScore(playerid, Playerdata[playerid][Level]);
    if(Playerdata[playerid][Adminlevel] > 0)
    {
        format(string, sizeof(string), "You are a staff member, rank: %i", Playerdata[playerid][Adminlevel]);
        SendClientMessage(playerid, COLOR_YELLOW2, string);
    }
    SetSpawnInfo(playerid, Playerdata[playerid][Skin], 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
    SpawnPlayer(playerid);
    return 1;
}
Whole login script.
Database structuur:
Quote:

CREATE TABLE IF NOT EXISTS `users` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(225) NOT NULL,
`password` text NOT NULL,
`skin` int(250) NOT NULL DEFAULT '101',
`adminlevel` int(4) NOT NULL DEFAULT '0',
`vip` int(3) NOT NULL DEFAULT '0',
`vipexp` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`ip` varchar(20) NOT NULL,
`money` int(225) NOT NULL DEFAULT '0',
`level` int(10) NOT NULL DEFAULT '1',
`kill` int(10) NOT NULL DEFAULT '1',
`death` int(10) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=13 ;



Re: Sscanf & MySQL help :D - mprofitt - 31.08.2011

Quote:
Originally Posted by wouter0100
Посмотреть сообщение
The string is this:
0000-00-00 00:00:00
so:
19?
pawn Код:
enum DATA
{
     ...
     ...
     Vipexp[STRLEN]
     ...
     ...
};
new PlayerData[MAX_PLAYERS][DATA];
whatever STRLEN is ...


Re: Sscanf & MySQL help :D - [MWR]Blood - 31.08.2011

Quote:
Originally Posted by Sinner
Посмотреть сообщение
Do it like this:

PHP код:
new unused[5];
sscanf(savingstring,"p<|>iiiiiisiiiii",
        
unused[0],
        
unused[1],
        
unused[3],
        
Playerdata[playerid][Skin],
        
Playerdata[playerid][Adminlevel],
        
Playerdata[playerid][Vip],
        
Playerdata[playerid][Vipexp],
        
unused[4],
        
money,
        
Playerdata[playerid][Level],
        
Playerdata[playerid][Kill],
        
Playerdata[playerid][Death]); 
Did you try what he suggested?