[HELP] Loading player variables - MySQL
#1

Hey guys, im making an "auto unload variable" script to unload variables from an sql database and load them into an array for the player variables. Im having trouble tho...

Код:
//login command
.... 
		LoadPlayerVariables(playerid,query); // goes fine, prints all values how they should be
		if(Players[playerid][loggedin] == 0)
		{
		  print(Players[playerid][loggedin]); // Printed as null
.....
Код:
//Loading player variables
public LoadPlayerVariables(playerid,query[])
{
	new fval = 0;
	new field[256],update[256],date[256],day,month,year,line[1024];
	samp_mysql_query(query);
	samp_mysql_store_result();
	samp_mysql_fetch_row(line);
	print(line); // to view the sql result... appears normal
	samp_mysql_strtok(field, "|", line);
	format(Players[playerid][pInfo:fval],256,"%s",field); // loads "R4nk3d" into Players[playerid][pInfo:fval]
 	printf("%s is now stored as %s for player id (%i).",field,Players[playerid][pInfo:fval],playerid);
	fval ++;
	while(samp_mysql_strtok(field, "|", "")==1)
	{
	  //Players[playerid][pInfo:fval] =
		format(Players[playerid][pInfo:fval],256,"%s",field);
	  printf("%s is now stored as %s for player id (%i).",field,Players[playerid][pInfo:fval],playerid);
	  fval ++;
	}
.....
}
So why is it when i call Players[playerid][loggedin] it says null even though it loads it?
Reply
#2

pawn Код:
printf("loadStaut:%s",Players[playerid][loggedin]?"loaded":"unload");
Reply
#3

can you explain that code a bit more please?
Reply
#4

hi,

this is a basic if test written another way....

the result is equivalent to:

Код:
if(Players[playerid][loggedin])
{
  print("loadsaut:loaded");
}
else
{
  print("loadsaut:unload");
}
++Sim++
Reply
#5

gotcha, well i got more in depth to figuring it out.

btw, loggedin == 0, means theyre banned, and 1 means theyre logged in now. it unloads it and instead of it being null/0 it now says 1.
Players[playerid][loggedin] is returned as 0/null.
But Players[playerid][pInfo:6] is returned as 1.

So how do i automatically unload the variables into the enum without putting every name in? i thought i was doing that with pInfo:0, pInfo:1, but apparently not. Thats a whole other variable.
Reply
#6

That you mean?
pawn Код:
enum _Players{
  e1,
  e2,
  e3,
  e4,
  e5,
  loggedin,
  .
  .
  .
};
new
  Players[MAX_PLAYERS][_Players];
Whatever, loggedin is either 0 or 1, use print(Players[playerid][loggedin]); is alyways outputting null.
Because the code is same as
pawn Код:
print("\1");
print("\0");
//null
And you should do
pawn Код:
printf("%d",Players[playerid][loggedin]);
Reply
#7

Alright, now it prints as 0. Thank you for clearing that small bit up for me and explaining it.

let me give some more code:

heres the player info enum:
Код:
enum pInfo
{
	username[28],
	password[32],
	email[50],
	hideemail,
	datejoined[28],
	id,
	loggedin,
	score,
	money,
	bankstate,
	adminlevel,
	regular,
	armyaccess,
	robrank,
	lastseen[10],
	dlicense,
	plicense,
	dinstructor,
	pinstructor,
	bannedby[28],
	bantime[20],
	banreason[128]
};
new Players[MAX_PLAYERS][pInfo];
this conforms to the mysql table structure, every thing w/o a set value/length is an integer in the mysql table. ex: loggedin

and here is the loading part of the Loadplayerinfo command
Код:
...
samp_mysql_strtok(field, "|", line);
	format(Players[playerid][pInfo:fval],256,"%s",field);
 	printf("%s is now stored as %s for player id (%i).",field,Players[playerid][pInfo:fval],playerid);
	fval ++;
	while(samp_mysql_strtok(field, "|", "")==1)
	{
	  //Players[playerid][pInfo:fval] =
		format(Players[playerid][pInfo:fval],256,"%s",field);
	  printf("%s is now stored as %s for player id (%i).",field,Players[playerid][pInfo:fval],playerid);
	  fval ++;
	}
...
Now i just came up with an idea, make a new array that list the table fields, and for each field, select the value of it (after mysql_fetch_row) and then say format(Players[playerid][field],256,"%s",fieldvalue); would that work?
Reply
#8

Not anything can be stored as "s" string, something they must stored as integer, float, etc.
Here's my untested code.
pawn Код:
if(sizeof(Players[][pInfo:fval])<2){
  Players[playerid][pInfo:fval] = strval(field);
}else{
  format(Players[playerid][pInfo:fval],sizeof(Players[][pInfo:fval]),"%s",filed);
}
Reply
#9

Код:
if(sizeof(Players[][pInfo:fval])<2){
is returning errors:

Quote:

C:\Inetpub\wwwroot\lvrcr\gameserver\gamemodes\debu g.pwn(1869) : error 001: expected token: "]", but found "-label-"
C:\Inetpub\wwwroot\lvrcr\gameserver\gamemodes\debu g.pwn(1869) : warning 221: label name "pInfo" shadows tag name
C:\Inetpub\wwwroot\lvrcr\gameserver\gamemodes\debu g.pwn(1869) : warning 215: expression has no effect
C:\Inetpub\wwwroot\lvrcr\gameserver\gamemodes\debu g.pwn(1869) : error 001: expected token: ";", but found "]"
C:\Inetpub\wwwroot\lvrcr\gameserver\gamemodes\debu g.pwn(1869) : error 029: invalid expression, assumed zero
C:\Inetpub\wwwroot\lvrcr\gameserver\gamemodes\debu g.pwn(1869) : fatal error 107: too many error messages on one line

Reply
#10

Try Players[playerid][pInfo:fval]
?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)