Help loading and fomatting name..
#1

Well, here are the functions im using:

pawn Код:
stock LoadVehicles()
{
    new Argumento[8][100];
    new str[256];
    new ModelID, Float:X, Float:Y, Float:Z, Float:A, Color1, Color2, VehicleID;
    new File: ArquivoVeiculo = fopen(PVEH_FILE_NAME, io_read);
    if (ArquivoVeiculo)
    {
        for(new id; id<MAX_VEHICLES; id++)
        {
            fread(ArquivoVeiculo, str);
            split(str, Argumento, ',');

            ModelID     =       strval   (Argumento[0]);
            X           =       floatstr (Argumento[1]);
            Y           =       floatstr (Argumento[2]);
            Z           =       floatstr (Argumento[3]);
            A           =       floatstr (Argumento[4]);
            Color1      =       strval   (Argumento[5]);
            Color2      =       strval   (Argumento[6]);
            VehicleID   =       AddStaticVehicle(ModelID, X, Y, Z, A, Color1, Color2);
            format(VEHICLE_OWNER[VehicleID][VEHOWNER],20,Argumento[7]);
        }
        fclose(ArquivoVeiculo);
    }
    return 1;
}
^ that function works good, no problems.

Now here is the function giving problems:

pawn Код:
stock AddVehiclesFromFile(FileName[])
{
    if(!fexist(FileName)) return 0;

    new File:VehicleFile, vModel, Float:VX, Float:VY, Float:VZ, Float:VA, vTotal, Line[128], vOwner, C1, C2;

    VehicleFile = fopen(FileName, io_read);
    while(fread(VehicleFile, Line))
    {
        unformat(Line, "iffffiis[50]", vModel, VX, VY, VZ, VA, C1, C2, vOwner);
        AddStaticVehicleEx(vModel, VX, VY, VZ, VA, -1, -1, (30*60));
        format(VEHICLE_OWNER[vTotal][VEHOWNER], 30, pName(vOwner));
        vTotal++;
    }
    fclose(VehicleFile);
    return vTotal;
}
No compiling errors whatsoever, but on the first function, it will check a line from a file, and check if the name is correct as the line, but not sure how it must be on my function(bottom one).

just in case, here is the line reading from:
pawn Код:
402 -2277.204101 1007.403686 11.075104 173.957427 13 56 test
Oh, the bottom function DOES load the vehicles, but won't format the name.
Reply
#2

Give this a try:

pawn Код:
stock AddVehiclesFromFile(FileName[])
{
    if(!fexist(FileName)) return 0;

    new File:VehicleFile, vModel, Float:VX, Float:VY, Float:VZ, Float:VA, vTotal, Line[128], vOwner[MAX_PLAYER_NAME+6], C1, C2;

    VehicleFile = fopen(FileName, io_read);
    while(fread(VehicleFile, Line))
    {
        unformat(Line, "iffffiis[30]", vModel, VX, VY, VZ, VA, C1, C2, vOwner);
        AddStaticVehicleEx(vModel, VX, VY, VZ, VA, -1, -1, (30*60));
        format(VEHICLE_OWNER[vTotal][VEHOWNER], 30, vOwner);
        vTotal++;
    }
    fclose(VehicleFile);
    return vTotal;
}
Reply
#3

BUMP!!
Ok, here is the code fixed a little bit:

pawn Код:
stock AddPVehiclesFromFile(FileName[])
{
    if(!fexist(FileName)) return 0;

    new File:VehicleFile, vModel, Float:VX, Float:VY, Float:VZ, Float:VA, vTotal, Line[128], vOwner[MAX_PLAYER_NAME+6], C1, C2, vID;

    VehicleFile = fopen(FileName, io_read);
    while(fread(VehicleFile, Line))
    {
        if(Line[0] == '/' || isnull(Line)) continue;
        unformat(Line, "iffffiis[24]", vModel, VX, VY, VZ, VA, C1, C2, vOwner[24]);
        vID = AddStaticVehicleEx(vModel, VX, VY, VZ, VA, -1, -1, (30*60));
        format(VEHICLE_OWNER[vID][VEHOWNER], MAX_PLAYER_NAME, vOwner[24]);
        vTotal++;
    }
    fclose(VehicleFile);
    return vTotal;
}
Ok, the vehicles now load and formats the name, but somehow its formatting it wrong :S

, here is the function i use to check if the names match:

pawn Код:
stock VehicleOwner(playerid, VehicleID)
{
    if(strlen(VEHICLE_OWNER[VehicleID][VEHOWNER]) == 0)
    {
        return -1;    
    }
    if(!StringCompare(VEHICLE_OWNER[VehicleID][VEHOWNER],pName(playerid)))
    {
        return 0;
    }
    return 1;    
}
and i use this to test it:
pawn Код:
stock StringCompare(String1[], String2[])
{
    if(strlen(String1) == 0 || strlen(String2) == 0)
    {
        return false;
    }
    if(strcmp(String1 ,String2, true ) == 0 )
    {
        printf("\"%s\" is the same as \"%s\"", String1, String2);
        return true;
    }
    else
    {
        printf("\"%s\" is different from \"%s\"", String1, String2);
        return false;
    }
}
The output of the above function is :
pawn Код:
[16:12:05] `U214

` is different from `U214`
[16:12:05] `U214

` is different from `U214`
So the problem is when it creates the function, its not getting the correct name
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)