SA-MP Forums Archive
How to translate this sscanf function to avoid the plugin? - 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: How to translate this sscanf function to avoid the plugin? (/showthread.php?tid=632555)



How to translate this sscanf function to avoid the plugin? - iSanchez - 16.04.2017

Hello, I am using this include: https://sampforum.blast.hk/showthread.php?tid=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:
PHP код:
    while(fread(camFileline128))
    {
        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] == -1tmpData[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:

PHP код:
        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


Re: How to translate this sscanf function to avoid the plugin? - Logic_ - 16.04.2017

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.

PHP код:
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.
PHP код:
1.0,1.0,1.0,1.0,1.0,1.0,0,0,
but here, it loads the value from the file which are seperated by the comma.


Re: How to translate this sscanf function to avoid the plugin? - Vince - 16.04.2017

Quote:
Originally Posted by iSanchez
Посмотреть сообщение
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.


Re: How to translate this sscanf function to avoid the plugin? - iSanchez - 18.04.2017

Quote:
Originally Posted by Logic_
Посмотреть сообщение
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.

PHP код:
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.
PHP код:
1.0,1.0,1.0,1.0,1.0,1.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.