[NEW PROBLEM] sscanf with PVars? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [NEW PROBLEM] sscanf with PVars? (
/showthread.php?tid=148075)
[NEW PROBLEM] sscanf with PVars? -
cAMo - 15.05.2010
mysql_fetch_row_format(line, "|");
sscanf(line, "p|dssddsddffffddddddddddddddddd",
PlayerInfo[playerid][name],
PlayerInfo[playerid][password],
PlayerInfo[playerid][age],
etc, etc, etc......);
mysql_free_result();
Q: How would I set this up so that these variables go into PVar's?
I assume that I cannot swap SetPVarInt(playerid, "name") with PlayerInfo[playerid][name]... right?
Re: sscanf with PVars? -
juice.j - 15.05.2010
You need to store it in a temporary variable first and then call the SetPVar... function.
Re: sscanf with PVars? -
Killa_ - 15.05.2010
You can use
SetPVarString(playerid, varname[], string_value[]);
Re: sscanf with PVars? -
cAMo - 15.05.2010
How would you write something like that?
Re: sscanf with PVars? -
juice.j - 15.05.2010
Well either you create as many variables as you need (which will be a very bad solution regarding the amount you'd need) or you grab your result string and split it step-by-step while writing each splitted part in only one temporary variable.
Re: sscanf with PVars? -
cAMo - 15.05.2010
Can you please show me an example with my code from the first post?
Re: sscanf with PVars? -
juice.j - 15.05.2010
Sorry no time to make a custom build function right now, but one idea:
Rebuild the strtok function to split the string using "|" as its delimiter. You got it somewhere in your script.
Re: sscanf with PVars? -
Sergei - 15.05.2010
You could search around G-sTyLeZzZ's topic a bit, I have written this example at least 10 times already.
pawn Код:
if(mysql_retrieve_row())
{
mysql_get_field("name",line); SetPVarString(playerid,"Name",line);
mysql_get_field("age",line); SetPVarInt(playerid,"Age,strval(line));
//other shit
}
And why are you extracting 'password' field? Just compare passwords when using SELECT command like:
Код:
SELECT * FROM `players` WHERE playername='somename' AND password='somepassword'
PS: Ask in plugin's topic if you need any additional help.
Re: sscanf with PVars? -
cAMo - 15.05.2010
What MYSQL plugin are you working with using mysql_get_field?
I am using
http://forum.sa-mp.com/index.php?topic=79352.0 in my script. Would you recommend something else, as I don't see mysql_get_field as a function for this plugin
Re: sscanf with PVars? -
juice.j - 15.05.2010
Does it still crash the server when doing this on a windows machine Serg?