Can someone help me 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: Can someone help me with sscanf? (
/showthread.php?tid=456423)
Can someone help me with sscanf? -
Magic_Time - 05.08.2013
Hi,
Sorry for my ignorance at sscanf.
I'm trying to make a converter from MTA code to samp but it doesn't work..
PHP код:
forward Convert(file[]);
public Convert(file[])
{
if (!fexist(file)) return printf("File %s was not found. Please make sure you have placed it on your ScriptFiles folder.", file);
new File:openfile = fopen(file);
new string[4000], string2[4000], playerid, objcount;
while(fread(openfile, string))
{
for(new idk = 0; idk < sizeof(rObj); idk++)
{
if(!sscanf(string, "'model='d'posX='f'posY='f'posZ='f'rX='f'rY='f'rZ='f",rObj[idk][modelid_],rObj[idk][x_],rObj[idk][y_],rObj[idk][z_],rObj[idk][rX], rObj[idk][rY], rObj[idk][rZ]))
{
objcount++;
new File:newfile = fopen("Objects.pwn",io_write);
fwrite(newfile, "public OnGameModeInit()\n{\n");
format(string,sizeof(string)," CreateObject(%d, %f, %f, %f, %f, %f, %f);\n",rObj[idk][modelid_], rObj[idk][x_], rObj[idk][y_], rObj[idk][z_], rObj[idk][rX], rObj[idk][rY], rObj[idk][rZ]);
strcat(string2,string);
printf("%s", string);
fwrite(newfile,string2);
fwrite(newfile, " return 1;\n}");
fclose(newfile);
}
}
}
fclose(openfile);
printf("%d objects were converted from '%s' to Converted.pwn (Saved in Scriptfiles folder)",objcount, file);
return objcount;
}
Re: Can someone help me with sscanf? -
Jefff - 05.08.2013
Show example .map file
Re: Can someone help me with sscanf? -
Magic_Time - 05.08.2013
Код:
<object id="object (ClubGate01_LAx) (1)" interior="0" collisions="true" alpha="255" doublesided="false" model="3749" scale="1" dimension="0" name="delux object" posX="1545.30005" posY="-1627.69995" posZ="18.2" rotX="0" rotY="0" rotZ="270"></object>
<object id="object (fenceshit2) (1)" interior="0" collisions="true" alpha="255" doublesided="false" model="984" scale="1" dimension="0" name="delux object (1)" posX="1556" posY="-1617.80005" posZ="13.2" rotX="0" rotY="0" rotZ="270"></object>
<object id="object (fenceshit2) (2)" interior="0" collisions="true" alpha="255" doublesided="false" model="984" scale="1" dimension="0" name="delux object (2)" posX="1568.80005" posY="-1617.80005" posZ="13.2" rotX="0" rotY="0" rotZ="270"></object>
<object id="object (fenceshit2) (3)" interior="0" collisions="true" alpha="255" doublesided="false" model="984" scale="1" dimension="0" name="delux object (3)" posX="1568.80005" posY="-1622.80005" posZ="13.2" rotX="0" rotY="0" rotZ="270"></object>
<object id="object (fenceshit2) (4)" interior="0" collisions="true" alpha="255" doublesided="false" model="984" scale="1" dimension="0" name="delux object (4)" posX="1556" posY="-1622.80005" posZ="13.2" rotX="0" rotY="0" rotZ="270"></object>
<object id="object (fenceshit3) (1)" interior="0" collisions="true" alpha="255" doublesided="false" model="983" scale="1" dimension="0" name="delux object (5)" posX="1541" posY="-1605.90002" posZ="13.1" rotX="0" rotY="0" rotZ="0"></object>
<object id="object (fenceshit3) (2)" interior="0" collisions="true" alpha="255" doublesided="false" model="983" scale="1" dimension="0" name="delux object (6)" posX="1546" posY="-1605.90002" posZ="13.1" rotX="0" rotY="0" rotZ="0"></object>
<object id="object (fenceshit3) (3)" interior="0" collisions="true" alpha="255" doublesided="false" model="983" scale="1" dimension="0" name="delux object (7)" posX="1550.5" posY="-1605.89941" posZ="13.1" rotX="0" rotY="0" rotZ="0"></object>
<object id="object (fenceshit3) (4)" interior="0" collisions="true" alpha="255" doublesided="false" model="983" scale="1" dimension="0" name="delux object (8)" posX="1555.09998" posY="-1605.90002" posZ="13.1" rotX="0" rotY="0" rotZ="0"></object>
<object id="object (fenceshit3) (5)" interior="0" collisions="true" alpha="255" doublesided="false" model="983" scale="1" dimension="0" name="delux object (9)" posX="1559.69995" posY="-1605.90002" posZ="13.1" rotX="0" rotY="0" rotZ="0"></object>
Re: Can someone help me with sscanf? -
Jefff - 06.08.2013
pawn Код:
forward Convert(const file[]);
public Convert(const file[])
{
new File:openfile = fopen(file,io_read);
if(!openfile) return printf("File %s was not found. Please make sure you have placed it on your ScriptFiles folder.", file);
new File:newfile = fopen("Objects.pwn",io_write);
fwrite(newfile, "public OnGameModeInit()\r\n{\r\n");
new string[350], idx;
while(fread(openfile, string))
{
if(idk >= sizeof(rObj)) break;
if(!sscanf(string, "'model=\"'p<\">d'posX=\"'p<\">f'posY=\"'p<\">f'posZ=\"'p<\">f'rotX=\"'p<\">f'rotY=\"'p<\">f'rotZ=\"'p<\">f",rObj[idx][modelid_],rObj[idx][x_],rObj[idx][y_],rObj[idx][z_],rObj[idx][rX], rObj[idx][rY], rObj[idx][rZ]))
{
format(string,sizeof(string),"\tCreateObject(%d, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f);\r\n",rObj[idx][modelid_],rObj[idx][x_],rObj[idx][y_],rObj[idx][z_],rObj[idx][rX], rObj[idx][rY], rObj[idx][rZ]);
fwrite(newfile,string);
idx++;
}
}
fwrite(newfile, "\treturn 1;\r\n}");
fclose(openfile);
fclose(newfile);
printf("%d objects were converted from '%s' to Converted.pwn (Saved in Scriptfiles folder)",idx, file);
return idx;
}
Re: Can someone help me with sscanf? -
ThePhenix - 06.08.2013
It works...