SA-MP Forums Archive
sscanf won't work as I want it to - 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: sscanf won't work as I want it to (/showthread.php?tid=274559)



sscanf won't work as I want it to - Kyle_Olsen - 06.08.2011

Well, I'm using this code to try to access information from my database to spawn vehicles:

pawn Код:
InitVehicles(){
   for (new i = 0; i < MAX_VEHICLES; i++)
   {
     new Query[200];
     format(Query, sizeof(Query), "SELECT * FROM `vehicles` WHERE `id` = '%d'", i);
     mysql_query(Query);
     mysql_store_result();
     if(mysql_num_rows() != 0){
         new line[1500];
         if(mysql_fetch_row(line))
         {
            sscanf(line, "p|ddddffffsdfdddddd", Vehicle[i][vID], Vehicle[i][Model], Vehicle[i][Color1], Vehicle[i][Color2], Vehicle[i][X], Vehicle[i][Y],
            Vehicle[i][Z], Vehicle[i][ZAngle], Vehicle[i][Owner], Vehicle[i][OwnerType], Vehicle[i][Health], Vehicle[i][Panels],
            Vehicle[i][Doors], Vehicle[i][Lights], Vehicle[i][Tires], Vehicle[i][Siren], Vehicle[i][vFaction]); //Splits the line with sscanf
            Vehicle[i][GameID] = AddStaticVehicleEx(Vehicle[i][Model], Vehicle[i][X], Vehicle[i][Y], Vehicle[i][Z], Vehicle[i][ZAngle], Vehicle[i][Color1], Vehicle[i][Color2], 3600);
            Vehicle[i][SirenOn] = 0;
            if(Vehicle[i][OwnerType] > 0)
            {
            new engine, lights, alarm, doors, bonnet, boot, objective;
            GetVehicleParamsEx(Vehicle[i][GameID], engine, lights, alarm, doors, bonnet, boot, objective);
            SetVehicleParamsEx(Vehicle[i][GameID], engine, lights, alarm, 1, bonnet, boot, objective);
            }
            printf("InitVehicles: Vehicle %d was spawned from the database. Ownertype: %d, Faction: %d", i, Vehicle[i][OwnerType], Vehicle[i][vFaction]);
         }
     }
     mysql_free_result();
   }
   return 1;
}
On one vehicle, is the stats like this:
ID: 2
MODEL: 596
Color 1: 1
Color 2: 1
X: 1558.734619
Y: -1711.563110
Z: 5.611854
ZAngle: 0.445877
Owner: 0
Ownertype: 2
Health: 1000.0000
Panels: 0
Doors: 0
Lights: 0
Tires: 0
Siren: 1
Faction: 1

But, it returns different values on some. What I have figured this far (wrong values marked with red):
ID: 2
MODEL: 596
Color 1: 1
Color 2: 1
X: 1558.734619
Y: -1711.563110
Z: 5.611854
ZAngle: 0.445877
Owner: 0
Ownertype: 0
Health: 1000.0000
Panels: 0
Doors: 0
Lights: 0
Tires: 0
Siren: 0
Faction: 0


Does anyone know what I may do with this problem?



EDIT:
Adding the enum stuff:
pawn Код:
enum VehicleStatistics{
vID,
Model,
Color1,
Color2,
Float:X,
Float:Y,
Float:Z,
Float:ZAngle,
Owner[24],
OwnerType,
GameID,
Float:Health,
Panels,
Doors,
Lights,
Tires,
Siren,
SirenOn,
Siren1,
Siren2,
Siren3,
vFaction,
};
new Vehicle[MAX_VEHICLES][VehicleStatistics];



Re: sscanf won't work as I want it to - Ash. - 06.08.2011

If you're running the latest SAMP Server Version (R5) then you will need to update your sscanf version also. I'm not sure what the incompatibility is, but when I upgraded the TruckingWorld server, I had to upgrade sscanf and hadn't realised, I had the SOME of the problems you described above.


Re: sscanf won't work as I want it to - Kyle_Olsen - 06.08.2011

I've actually reinstalled the old version of sscanf because sscanf 2.0 gave me too much errors (didn't send full messages, etc).


Re: sscanf won't work as I want it to - Ash. - 06.08.2011

The include? That's even further back! What server version are you running?


Re: sscanf won't work as I want it to - Kyle_Olsen - 06.08.2011

I'm running 0.3c R5

EDIT:
I just tried sscanf2 again, it still worked as bad as before.
It cuts off some text, EG when I use my /o command, and writes for example
Quote:

/o Hi there, how are you all doing today? Nice weather huh?

it should return in the client messages:
Quote:

(( Kyle_Olsen: Hi there, how are you all doing today? Nice weather huh? ))

But what it returns is:
Quote:

(( Kyle_Olsen: Hi there, how are you all ))

And also, it gives me a lot of sscanf warnings in my server console


Re: sscanf won't work as I want it to - Stylock - 06.08.2011

Have you tried using enum specifiers? It was added in sscanf 2.0.
pawn Код:
sscanf(line, "e<ddddffffs[24]dfdddddd>", Vehicle[i])



Re: sscanf won't work as I want it to - Kyle_Olsen - 06.08.2011

Well, as sscanf 2.0 isn't working good with me as I described above, I haven't tried that, no...

I'd like to hear if you've got any other solutions, perhaps..?

EDIT:
I fixed the problem, turned out one of the database rows were empty.
Thanks for your help anyway.