SA-MP Forums Archive
[Help] File Functions - 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] File Functions (/showthread.php?tid=547602)



[Help] File Functions - Haides - 23.11.2014

So, im doing Vehicle Register/License plate system for my gamemode.
I made it that when you enter the text for your plate it will save in the file vehplates.cfg

Код:
if(!fexist("vehplates.cfg")) fcreate("vehplates.cfg");
new File: file = fopen("vehplates.cfg", io_append), stringplate[128];
format(stringplate, sizeof(stringplate), "%d|{FF0000}%s", VehicleId, inputtext);
fwrite(file, stringplate);
fclose(file);
and that works. Now I'm at the point where I have to load the file OnVehicleSpawn
Can someone help me out, please?


Re: [Help] File Functions - Haides - 24.11.2014

Ok... so I made it like this
pawn Код:
public OnVehicleSpawn(vehicleid)
{
    new vpinfo[2][19];
    new vpstring[256];
    new File:file = fopen("vehplates.cfg", io_read);
    if(file)
    {
        fread(file, vpstring);
        split(vpstring, vpinfo, '|');
        vehicleid = strval(vpinfo[0]);
        format(vplate, 64, "%s", vpinfo[1]);
        SetVehicleNumberPlate(vehicleid, vplate);
    }
    return 1;
}
And that only worked for one car (the first in the file)
So I made it like this

pawn Код:
#define MAX_VPLATES 256 //top of the script

public OnVehicleSpawn(vehicleid)
{
    new vpinfo[2][19];
    new vpstring[256];
    new File:file = fopen("vehplates.cfg", io_read);
    if(file)
    {
        new vpx = 1;
        while(vpx < MAX_VPLATES)
        {
            fread(file, vpstring);
            split(vpstring, vpinfo, '|');
            vehicleid = strval(vpinfo[0]);
            format(vplate, 64, "%s", vpinfo[1]);
            SetVehicleNumberPlate(vehicleid, vplate);
        }
        vpx++;
    }
    return 1;
}
Now the server does not load. Can you tell me why?

It stays like this:


But it should be like this: