[NEW PROBLEM] sscanf with PVars?
#1

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?
Reply
#2

You need to store it in a temporary variable first and then call the SetPVar... function.
Reply
#3

You can use SetPVarString(playerid, varname[], string_value[]);
Reply
#4

How would you write something like that?
Reply
#5

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.
Reply
#6

Can you please show me an example with my code from the first post?
Reply
#7

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.
Reply
#8

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.
Reply
#9

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
Reply
#10

Does it still crash the server when doing this on a windows machine Serg?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)