Object editor - only saving last 7 objects :/ -
HondaCBR - 13.04.2012
Basically I want objects to save to file, and then load from file, but for some reason it only saves last 7 objects.
pawn Код:
if(strcmp(cmd, "/obiekt", true) == 0)
{
tmp = strtok (cmdtext,idx);
if (!strlen(tmp))
{
SendClientMessage(playerid, COLOR_RED, "USAGE: /obiekt [ID]");
return 1;
}
new CreateFile09[35];
format(CreateFile09,sizeof(CreateFile09),"/Ustawienia/settings.ini");
new Float:pX,Float:pY,Float:pZ;
GetPlayerPos(playerid, pX,pY,pZ);
for(new h = dini_Int(CreateFile09,"Obiektow"); h < sizeof(ObiektInfo); h++)
{
ObiektInfo[h][ModelID] = strval(tmp);
ObiektInfo[h][oX] = pX;
ObiektInfo[h][oY] = pY;
ObiektInfo[h][oZ] = pZ;
ObiektInfo[h][orX] = 0;
ObiektInfo[h][orY] = 0;
ObiektInfo[h][orZ] = 0;
SelectedOneP[playerid] = dini_Int(CreateFile09,"Obiektow");
ObiektCreator2[h] = CreateObject(strval(tmp),pX+1,pY+1,pZ,0,0,0);
EditObject(playerid, ObiektCreator2[h]);
}
return 1;
}
pawn Код:
public LoadObiekty()
{
new arrCoords[29][64];
new strFromFile2[256];
new File: file = fopen("/Ustawienia/obiekty.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(ObiektInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
ObiektInfo[idx][ModelID] = strval(arrCoords[0]);
ObiektInfo[idx][oX] = floatstr(arrCoords[1]);
ObiektInfo[idx][oY] = floatstr(arrCoords[2]);
ObiektInfo[idx][oZ] = floatstr(arrCoords[3]);
ObiektInfo[idx][orX] = floatstr(arrCoords[4]);
ObiektInfo[idx][orY] = floatstr(arrCoords[5]);
ObiektInfo[idx][orZ] = floatstr(arrCoords[6]);
if(ObiektInfo[idx][oX] == 0 && ObiektInfo[idx][oY] == 0 && ObiektInfo[idx][oZ] == 0) { }
else
{
ObiektCreator2[idx] = CreateObject(ObiektInfo[idx][ModelID],ObiektInfo[idx][oX],ObiektInfo[idx][oY],ObiektInfo[idx][oZ],ObiektInfo[idx][orX],ObiektInfo[idx][orY],ObiektInfo[idx][orZ]);
}
printf("Obiekt o ID:%d zostal zaladowany",ObiektInfo[idx][ModelID]);
idx++;
}
printf("Zaladowano:%d obiektow",idx);
fclose(file);
}
return 1;
}
public SaveObiekty()
{
new idx;
new File: file2;
while (idx < sizeof(ObiektInfo))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%f,%d\n",
ObiektInfo[idx][ModelID],
ObiektInfo[idx][oX],
ObiektInfo[idx][oY],
ObiektInfo[idx][oZ],
ObiektInfo[idx][orX],
ObiektInfo[idx][orY],
ObiektInfo[idx][orZ]);
if(idx == 0)
{
file2 = fopen("/Ustawienia/obiekty.cfg", io_write);
}
else
{
file2 = fopen("/Ustawienia/obiekty.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
if(!IsValidObject(objectid)) return;
MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
if(response == 0) //esc
{
new CreateFile09[35];
format(CreateFile09,sizeof(CreateFile09),"/Ustawienia/settings.ini");
for(new h = SelectedOneP[playerid]; h < sizeof(ObiektInfo); h++)
{
// new h = SelectedOneP[playerid];
ObiektInfo[h][oX] = 0;
ObiektInfo[h][oY] = 0;
ObiektInfo[h][oZ] = 0;
ObiektInfo[h][orX] = 0;
ObiektInfo[h][orY] = 0;
ObiektInfo[h][orZ] = 0;
CancelEdit(playerid);
DestroyObject(ObiektCreator2[h]);
SaveObiekty();
}
}
if(response == 1)//save
{
new CreateFile09[35];
format(CreateFile09,sizeof(CreateFile09),"/Ustawienia/settings.ini");
for(new h = SelectedOneP[playerid]; h < sizeof(ObiektInfo); h++)
{
// new h = SelectedOneP[playerid];
ObiektInfo[h][oX] = fX;
ObiektInfo[h][oY] = fY;
ObiektInfo[h][oZ] = fZ;
ObiektInfo[h][orX] = fRotX;
ObiektInfo[h][orY] = fRotY;
ObiektInfo[h][orZ] = fRotZ;
SaveObiekty();
}
}
}
Re: Object editor - only saving last 7 objects :/ -
WardenCS - 13.04.2012
show us ObiektInfo define
Re: Object editor - only saving last 7 objects :/ -
HondaCBR - 13.04.2012
pawn Код:
enum ObInfo
{
ModelID,
Float:oX,
Float:oY,
Float:oZ,
Float:orX,
Float:orY,
Float:orZ,
};
new ObiektInfo[7][ObInfo];
Re: Object editor - only saving last 7 objects :/ -
WardenCS - 13.04.2012
new ObiektInfo[7][ObInfo];
change the 7 to max objects...
Re: Object editor - only saving last 7 objects :/ -
ReneG - 13.04.2012
The dude above me is correct. It only loads 7 because that is how big the array is. So just change it to MAX_OBJECTS.
Re: Object editor - only saving last 7 objects :/ -
HondaCBR - 13.04.2012
Yep done but now when I save one object it creates like 34kb file with about 500 objects:
take a look where I'm at now:
pawn Код:
enum ObInfo
{
ModelID,
Float:oX,
Float:oY,
Float:oZ,
Float:orX,
Float:orY,
Float:orZ,
};
new ObiektInfo[MAX_OBJECTS][ObInfo];
new ObiektCreator2[MAX_OBJECTS];
new SelectedOneP[MAX_PLAYERS];
public LoadObiekty()
{
new arrCoords[29][64];
new strFromFile2[256];
new File: file = fopen("/Ustawienia/obiekty.cfg", io_read);
if (file)
{
new idx;
while (idx < sizeof(ObiektInfo))
{
fread(file, strFromFile2);
split(strFromFile2, arrCoords, ',');
ObiektInfo[idx][ModelID] = strval(arrCoords[0]);
ObiektInfo[idx][oX] = floatstr(arrCoords[1]);
ObiektInfo[idx][oY] = floatstr(arrCoords[2]);
ObiektInfo[idx][oZ] = floatstr(arrCoords[3]);
ObiektInfo[idx][orX] = floatstr(arrCoords[4]);
ObiektInfo[idx][orY] = floatstr(arrCoords[5]);
ObiektInfo[idx][orZ] = floatstr(arrCoords[6]);
if(ObiektInfo[idx][oX] == 0 && ObiektInfo[idx][oY] == 0 && ObiektInfo[idx][oZ] == 0) { }
else
{
ObiektCreator2[idx] = CreateObject(ObiektInfo[idx][ModelID],ObiektInfo[idx][oX],ObiektInfo[idx][oY],ObiektInfo[idx][oZ],ObiektInfo[idx][orX],ObiektInfo[idx][orY],ObiektInfo[idx][orZ]);
}
printf("Obiekt o ID:%d zostal zaladowany",ObiektInfo[idx][ModelID]);
idx++;
}
printf("Zaladowano:%d obiektow",idx);
fclose(file);
}
return 1;
}
public SaveObiekty()
{
new idx;
new File: file2;
while (idx < sizeof(ObiektInfo))
{
new coordsstring[256];
format(coordsstring, sizeof(coordsstring), "%d,%f,%f,%f,%f,%f,%d\n",
ObiektInfo[idx][ModelID],
ObiektInfo[idx][oX],
ObiektInfo[idx][oY],
ObiektInfo[idx][oZ],
ObiektInfo[idx][orX],
ObiektInfo[idx][orY],
ObiektInfo[idx][orZ]);
if(idx == 0)
{
file2 = fopen("/Ustawienia/obiekty.cfg", io_write);
}
else
{
file2 = fopen("/Ustawienia/obiekty.cfg", io_append);
}
fwrite(file2, coordsstring);
idx++;
fclose(file2);
}
return 1;
}
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
{
if(!IsValidObject(objectid)) return;
MoveObject(objectid, fX, fY, fZ, 10.0, fRotX, fRotY, fRotZ);
if(response == 0) //esc
{
new CreateFile09[35];
format(CreateFile09,sizeof(CreateFile09),"/Ustawienia/settings.ini");
for(new h = SelectedOneP[playerid]; h < sizeof(ObiektInfo); h++)
{
// new h = SelectedOneP[playerid];
ObiektInfo[h][oX] = 0;
ObiektInfo[h][oY] = 0;
ObiektInfo[h][oZ] = 0;
ObiektInfo[h][orX] = 0;
ObiektInfo[h][orY] = 0;
ObiektInfo[h][orZ] = 0;
CancelEdit(playerid);
DestroyObject(ObiektCreator2[h]);
SaveObiekty();
}
}
if(response == 1)//save
{
new CreateFile09[35];
format(CreateFile09,sizeof(CreateFile09),"/Ustawienia/settings.ini");
for(new h = SelectedOneP[playerid]; h < sizeof(ObiektInfo); h++)
{
// new h = SelectedOneP[playerid];
ObiektInfo[h][oX] = fX;
ObiektInfo[h][oY] = fY;
ObiektInfo[h][oZ] = fZ;
ObiektInfo[h][orX] = fRotX;
ObiektInfo[h][orY] = fRotY;
ObiektInfo[h][orZ] = fRotZ;
SaveObiekty();
}
}
}
if(strcmp(cmd, "/obiekt", true) == 0)
{
tmp = strtok (cmdtext,idx);
if (!strlen(tmp))
{
SendClientMessage(playerid, COLOR_RED, "USAGE: /obiekt [1 - 1]");
return 1;
}
new CreateFile09[35];
format(CreateFile09,sizeof(CreateFile09),"/Ustawienia/settings.ini");
new Float:pX,Float:pY,Float:pZ;
GetPlayerPos(playerid, pX,pY,pZ);
new h = 0;
ObiektInfo[h][ModelID] = strval(tmp);
ObiektInfo[h][oX] = pX;
ObiektInfo[h][oY] = pY;
ObiektInfo[h][oZ] = pZ;
ObiektInfo[h][orX] = 0;
ObiektInfo[h][orY] = 0;
ObiektInfo[h][orZ] = 0;
SelectedOneP[playerid] = h;
ObiektCreator2[h] = CreateObject(strval(tmp),pX+1,pY+1,pZ,0,0,0);
EditObject(playerid, ObiektCreator2[h]);
h ++;
return 1;
}
Re: Object editor - only saving last 7 objects :/ -
ReneG - 13.04.2012
This is a map editor. People need to be able to have that many objects. It's your code though, so just change the second array value to whatever you want the max objects allowed to be.
Re: Object editor - only saving last 7 objects :/ -
HondaCBR - 14.04.2012
No, thats not what I meant. Basically I create one object ID:19450, I click save, and that object is in the file 500 times(19450,1,2,3,4,5,6) and the other 500 times its 0,0,0,0,0,0,0.
It should just create one line in the file, look at my code again, see if you can spot any mistakes.
Thx.