SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 30/11/2009, 11:22 PM   #1
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default [HELP] Loading player variables - MySQL

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...

Code:
//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
.....
Code:
//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?
tom_jonez is offline  
Old 30/11/2009, 11:46 PM   #2
yezizhu
Gangsta
 
yezizhu's Avatar
 
Join Date: Nov 2007
Location: Shenzhen,China
Posts: 640
Reputation: 2
Default Re: Loading player variables

pawn Code:
printf("loadStaut:%s",Players[playerid][loggedin]?"loaded":"unload");
yezizhu is offline  
Old 30/11/2009, 11:56 PM   #3
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Re: Loading player variables

can you explain that code a bit more please?
tom_jonez is offline  
Old 01/12/2009, 12:05 AM   #4
thegoliathmaster
Little Clucker
 
thegoliathmaster's Avatar
 
Join Date: Aug 2008
Posts: 20
Reputation: 0
Default Re: Loading player variables

hi,

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

the result is equivalent to:

Code:
if(Players[playerid][loggedin])
{
  print("loadsaut:loaded");
}
else
{
  print("loadsaut:unload");
}
++Sim++
thegoliathmaster is offline  
Old 01/12/2009, 01:14 AM   #5
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Re: [HELP] Loading player variables - MySQL

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.
tom_jonez is offline  
Old 01/12/2009, 02:27 AM   #6
yezizhu
Gangsta
 
yezizhu's Avatar
 
Join Date: Nov 2007
Location: Shenzhen,China
Posts: 640
Reputation: 2
Default Re: [HELP] Loading player variables - MySQL

That you mean?
pawn Code:
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 Code:
print("\1");
print("\0");
//null
And you should do
pawn Code:
printf("%d",Players[playerid][loggedin]);
yezizhu is offline  
Old 01/12/2009, 07:31 PM   #7
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Re: [HELP] Loading player variables - MySQL

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:
Code:
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
Code:
...
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?
tom_jonez is offline  
Old 02/12/2009, 12:05 AM   #8
yezizhu
Gangsta
 
yezizhu's Avatar
 
Join Date: Nov 2007
Location: Shenzhen,China
Posts: 640
Reputation: 2
Default Re: [HELP] Loading player variables - MySQL

Not anything can be stored as "s" string, something they must stored as integer, float, etc.
Here's my untested code.
pawn Code:
if(sizeof(Players[][pInfo:fval])<2){
  Players[playerid][pInfo:fval] = strval(field);
}else{
  format(Players[playerid][pInfo:fval],sizeof(Players[][pInfo:fval]),"%s",filed);
}
yezizhu is offline  
Old 02/12/2009, 12:25 AM   #9
tom_jonez
Huge Clucker
 
Join Date: Dec 2007
Posts: 219
Reputation: 0
Default Re: [HELP] Loading player variables - MySQL

Code:
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
tom_jonez is offline  
Old 02/12/2009, 01:18 AM   #10
yezizhu
Gangsta
 
yezizhu's Avatar
 
Join Date: Nov 2007
Location: Shenzhen,China
Posts: 640
Reputation: 2
Default Re: [HELP] Loading player variables - MySQL

Try Players[playerid][pInfo:fval]
?
yezizhu is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading problem (mysql) oliverrud Help Archive 10 08/07/2010 10:52 AM
[SOLVED] Storing variables from MySQL Faraday Help Archive 5 08/01/2010 02:31 PM
Loading pickups from MySQL [WS]Hyper Help Archive 0 29/11/2009 09:39 AM
MySQL House loading GTA967 Help Archive 0 13/11/2009 10:43 PM


All times are GMT. The time now is 12:35 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.