SA-MP Forums Archive
Help Loading Objects - 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 Loading Objects (/showthread.php?tid=661289)



Help Loading Objects - theralio - 29.11.2018

Hey when i read from a file i get this printed in my console:


19295 7538.399900 -2031.000000 332.500000 0.000000 0.000000 0.000000
Objectid X Y Z ROT:X ROT:Y ROT:Z


i need help to read this step by step

i use filemanager


Re: Help Loading Objects - NaS - 29.11.2018

I'd suggest using sscanf. It's really easy to read line by line with that.

I assume you have the reading part done already, so you have the current line in an array inside a loop or so.

With sscanf you can extract the values by their format and load them into variables:

PHP код:
new modelFloat:xFloat:yFloat:zFloat:rxFloat:ryFloat:rz;
if(
sscanf(text"iffffff"modelxyzrxryrz))
{
    
// Invalid line
}
else
{
    
// Line was parsed, you can now use model, x, y, z, rx, ry, rz to create the object

The "iffffff" part in the sscanf function tells it to read one integer (i) and 6 float values (f), followed by the variables to write the values to.
"text" would be the array with the current line you want to parse.


Re: Help Loading Objects - theralio - 29.11.2018

But i read it like this from the file

Код:
19295 7538.399900 -2031.000000 332.500000 0.000000 0.000000 0.000000
How can i read it without the spaces like

Код:
CreateDynamicObject(19295,7538.399900, -2031.000000, 332.500000, 0.000000, 0.000000 ,0.000000);



Re: Help Loading Objects - NaS - 29.11.2018

Quote:
Originally Posted by theralio
Посмотреть сообщение
But i read it like this from the file

Код:
19295 7538.399900 -2031.000000 332.500000 0.000000 0.000000 0.000000
How can i read it without the spaces like

Код:
CreateDynamicObject(19295,7538.399900, -2031.000000, 332.500000, 0.000000, 0.000000 ,0.000000);
Oh I see.

You can do it with sscanf too:

PHP код:
sscanf(text"p<,();>'CreateDynamicObject'iffffff"modelxyzrxryrz); 
p<,();> will ignore the signs , ( ) ; (so all these signs are accepted as delimiters).

The 'CreateDynamicObject' part will require it to be part of the line (at the start).


Re: Help Loading Objects - theralio - 29.11.2018

ok thx it works