enum e_Sector
{
i_SectorId,
Float:f_X,
Float:f_Y,
Float:f_Z
};
new Sector[e_Sector];
#include <a_samp>
enum e_Sector
{
i_SectorId,
Float:f_X,
Float:f_Y,
Float:f_Z
};
GetSectorCount(a_File[])
{
new File:l_file;
new Sector[e_Sector];
new l_count;
l_file = fopen(a_File, io_read);
l_count = 0;
if(l_file != File:0)
{
l_count = flength(l_file) / (sizeof(Sector) * 4/*sizeof(cell)*/);
fclose(l_file);
}
return l_count;
}
CreateSector(a_File[], a_SectorId, Float:a_X, Float:a_Y, Float:a_Z)
{
new File:l_file;
new Sector[e_Sector];
l_file = fopen(a_File, io_append);
if(l_file != File:0)
{
Sector[i_SectorId] = a_SectorId;
Sector[f_X] = a_X;
Sector[f_Y] = a_Y;
Sector[f_Z] = a_Z;
fblockwrite(l_file, Sector, sizeof(Sector));
fclose(l_file);
}
}
GetSector(a_File[], a_SectorId, &Float:a_X, &Float:a_Y, &Float:a_Z)
{
new File:l_file;
new Sector[e_Sector];
new i;
l_file = fopen(a_File, io_read);
if(l_file != File:0)
{
i = GetSectorCount(a_File);
while(i > 0)
{
fblockread(l_file, Sector, sizeof(Sector));
if(Sector[i_SectorId] == a_SectorId)
{
a_X = Sector[f_X];
a_Y = Sector[f_Y];
a_Z = Sector[f_Z];
i = 0;
}
i --;
}
fblockwrite(l_file, Sector, sizeof(Sector));
fclose(l_file);
}
}
public OnFilterScriptInit()
{
new Float:l_X, Float:l_Y, Float:l_Z;
new l_count;
CreateSector("s_001.sec", 0, 10.0, 0.0, 0.0);
CreateSector("s_001.sec", 1, 10.0, 10.0, 0.0);
CreateSector("s_001.sec", 2, 10.0, 10.0, 10.0);
CreateSector("s_001.sec", 3, 10.0, 10.0, 15.0);
l_count = GetSectorCount("s_001.sec");
printf("Sector count %d", l_count);
l_count --;
while(l_count >= 0)
{
GetSector("s_001.sec", l_count, l_X, l_Y, l_Z);
printf("ID %d X : %f Y : %f Z : %f", l_count, l_X, l_Y, l_Z);
l_count--;
}
}
[/spoiler]GetSectorCount(a_File[])
{
new File:l_file;
new Sector[e_Sector];
new l_count;
l_file = fopen(a_File, io_read);
l_count = 0;
Sector[i_SectorId] = 0;
if(l_file != File:0)
{
l_count = flength(l_file) / (sizeof(Sector) * 4/*sizeof(cell)*/);
fclose(l_file);
}
return l_count;
}
Sector count 4
ID 3 X : 10.000000 Y : 10.000000 Z : 15.000000
ID 2 X : 10.000000 Y : 10.000000 Z : 10.000000
ID 1 X : 10.000000 Y : 10.000000 Z : 0.000000
ID 0 X : 10.000000 Y : 0.000000 Z : 0.000000
Filterscript 'sector.amx' loaded.