help with sscanf - 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: help with sscanf (
/showthread.php?tid=412310)
help with sscanf -
BlackRaven - 01.02.2013
I'm trying to load the information from the database to the enumeration vehicleinfo with sscanf but it doesnt print the Licenses etc. What I am doing wrong? Thank's in advance.
pawn Код:
stock LoadVehicleID(vehicleid, playerid)
{
new query[1021];
format(query, sizeof(query), " SELECT * FROM vehicles WHERE id= %d", vehicleid);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows())
if(mysql_fetch_row(query))
{
sscanf(query, "p<|>e<iiiiffffs[25]s[25]iiiii>", vehicleinfo[vehicleid]);
vkey[playerid] = CreateVehicle(vehicleinfo[vehicleid][Model],vehicleinfo[vehicleid][x],vehicleinfo[vehicleid][y],vehicleinfo[vehicleid][z],vehicleinfo[vehicleid][a],vehicleinfo[vehicleid][Color1],vehicleinfo[vehicleid][Color2], 60*10000);
printf("result: %d",vkey[playerid]);
printf("lock = %d pawked = %d spawned %d destroyed %d liceneses %d",
vehicleinfo[vehicleid][Lock],
vehicleinfo[vehicleid][Parked],
vehicleinfo[vehicleid][Spawned],
vehicleinfo[vehicleid][Destroyed],
vehicleinfo[vehicleid][Licenses]);
}
}
Re: help with sscanf -
BlackRaven - 01.02.2013
Quote:
[18:09:20] lock = 0 pawked = 0 spawned 1 destroyed 1 liceneses 0
|
here is the print.
Re: help with sscanf -
BlackRaven - 02.02.2013
Quote:
[08:36:10] query: 12|411|0|0|340.81253|-1345.224609|14.234893|118.757064|infernus|Mark|1|1 |0|2|3
[08:36:10] lock = 0 pawked = 0 spawned 1 destroyed 1 liceneses 0
|
Thats the query and the print of the variables also im gonna show the enumeration:
pawn Код:
enum vInfo()
{
id,
Model,
Color1,
Color2,
Float:x,
Float:y,
Float:z,
Float:a,
Name[MAX_PLAYER_NAME],
Owner[MAX_PLAYER_NAME],
Lock,
Parked,
Spawned,
Destroyed,
Licenses,
}
new vehicleinfo[MAX_VEHICLES][vInfo];
Re: help with sscanf -
BlackRaven - 02.02.2013
Is the sscanf plugin buged?
Re: help with sscanf -
BlackRaven - 02.02.2013
Someone can help me with this?
Re: help with sscanf -
Misiur - 02.02.2013
pawn Код:
if(mysql_num_rows())
if(mysql_fetch_row(query))
{
This doesn't look good
Is for example the Name field correctly fetched?
Re: help with sscanf -
BlackRaven - 02.02.2013
The problem is with the plugin because the print of the query is showing everything alright.
Re: help with sscanf -
Misiur - 02.02.2013
Ok, now this is just weird - MAX_PLAYER_NAME is 24, yup? So s[25] should suffice, yup? BUT current code causes runtime error for me - why? No idea - probably stack corruption or something. So I changed it to 26 - no dice, owner wasn't loaded. So I tried 24, and guess what:
Now - it works, but I have no idea what will happen if the name will be 24 characters long (so in fact 24 + \0 NUL).
Re: help with sscanf -
BlackRaven - 02.02.2013
Thanks Misiur it worked, the problem was with the strings!