PDA

View Full Version : How to translate this sscanf function to avoid the plugin?


iSanchez
16/04/2017, 03:56 AM
Hello, I am using this include: http://forum.sa-mp.com/showthread.php?t=329813

But it uses sscanf2, I didn't like it because I already have too many plugins and I don't use it for my gamemode.

The code I want to "translate" is:

while(fread(camFile, line, 128))
{
if (idx == MAX_CAMNODE)
{
print("ERROR: Camera node limit reached");
break;
}
if (!sscanf(line, "p<,>ffffffD(-1)D(-1)D(-1)", // Too much for one line
camData[id][idx][cam_cPosX], camData[id][idx][cam_cPosY], camData[id][idx][cam_cPosZ],
camData[id][idx][cam_lPosX], camData[id][idx][cam_lPosY], camData[id][idx][cam_lPosZ],
tmpData[TMP_LOAD][0], tmpData[TMP_LOAD][1], tmpData[TMP_LOAD][2] ))
{
for(new c;c<TMP_DATA_COUNT;c++) // c = cell reference
{
if (tmpData[TMP_LOAD][c] == -1) tmpData[TMP_LOAD][c] = tmpData[TMP_KEEP][c]; // If it an optional param has -1 set it's detault value
else tmpData[TMP_KEEP][c] = tmpData[TMP_LOAD][c]; // Otherwise set the default value to the value just read
// This method means that you can define timings for a set of coordinates
// simply by defining the top one as what you want and leaving the rest blank
// These settings will be default until the next line is found with optional params
}
camData[id][idx][cam_moveTime] = tmpData[TMP_LOAD][0]; // Set the values to the global array cell of this camera
camData[id][idx][cam_waitTime] = tmpData[TMP_LOAD][1];
camData[id][idx][cam_moveType] = tmpData[TMP_LOAD][2];
}
idx++;
}


More specific:

if (!sscanf(line, "p<,>ffffffD(-1)D(-1)D(-1)", // Too much for one line
camData[id][idx][cam_cPosX], camData[id][idx][cam_cPosY], camData[id][idx][cam_cPosZ],
camData[id][idx][cam_lPosX], camData[id][idx][cam_lPosY], camData[id][idx][cam_lPosZ],
tmpData[TMP_LOAD][0], tmpData[TMP_LOAD][1], tmpData[TMP_LOAD][2] ))


I want to remove that sscanf function but I don't understand what "p<,>ffffffD(-1)D(-1)D(-1)" means.

Is it possible to translate or I must use the plugin just for this include?

Thank you

Logic_
16/04/2017, 04:03 AM
Oh boy, you're doing something which no one would EVER advice you... You should use sscanf because it's the best (C++, speed and reliability) and better than strtok.

p<,>ffffffD(-1)D(-1)D(-1) means PHP]f,f,f,f,f,f,d,d,d[/PHP]
f is float and d is for integer.

You can enter the float value (and the integer value) with the 'comma' (,) separator between them.
1.0,1.0,1.0,1.0,1.0,1.0,0,0,0

but here, it loads the value from the file which are seperated by the comma.

Vince
16/04/2017, 08:48 AM
But it uses sscanf2, I didn't like it because I already have too many plugins and I don't use it for my gamemode.


Yet people will happily use the Whirlpool plugin which is also just one function and which is probably only used two times in the entire gamemode. This is really not an argument.

iSanchez
18/04/2017, 06:08 PM
Oh boy, you're doing something which no one would EVER advice you... You should use sscanf because it's the best (C++, speed and reliability) and better than strtok.

p<,>ffffffD(-1)D(-1)D(-1) means PHP]f,f,f,f,f,f,d,d,d[/PHP]
f is float and d is for integer.

You can enter the float value (and the integer value) with the 'comma' (,) separator between them.
1.0,1.0,1.0,1.0,1.0,1.0,0,0,0

but here, it loads the value from the file which are seperated by the comma.

I'm not using strtok anywhere too, I'm using the Pawn.CMD plugin by urShadow.

Thank you for the explanation ^-^ about what the sscanf string means.