Load vehicles
#1

I have a problem with loading vehicles
This is my code:
pawn Код:
forward LoadVehicles();
public LoadVehicles()
{
    print("=========================");
    print("Load Vehicles ...");
    LoadStaticVehiclesFromFile("ServerVehicles.ini");
    new INI:ini, count;
    for(new i; i < MAX_VEHICLES; i++)
    {
        format(vFile(i), 14, "Cars/%d.ini", i);
        if(!fexist(vFile(i)))
        {
            if(!IsValidVehicle(i)) continue;
            Vehicles[i][vModel] = GetVehicleModel(i);
            GetVehiclePos(i, Vehicles[i][vPos][0], Vehicles[i][vPos][1], Vehicles[i][vPos][2]);
            GetVehicleZAngle(i, Vehicles[i][vPos][3]);
            Vehicles[i][vColor][0] = random(255);
            Vehicles[i][vColor][1] = random(255);
            Vehicles[i][vPrice] = GetVehiclePrice(GetVehicleModel(i));
            Vehicles[i][vType] = VEHICLE_TYPE_PUBLIC;
            Vehicles[i][vHaveOwners] = false;
            Vehicles[i][vOwners] = EOS;
            strcpy(Vehicles[i][vName], GetVehicleName(GetVehicleModel(i)), 32);
            Vehicles[i][vPayTax] = 0;
            Vehicles[i][vSale] = 0;
            Vehicles[i][vTrade] = 0;
            ini = INI_Open(vFile(i));
            INI_SetTag(ini, "VehicleData");
            INI_WriteInt(ini, "Model", Vehicles[i][vModel]);
            INI_WriteFloat(ini, "X", Vehicles[i][vPos][0]);
            INI_WriteFloat(ini, "Y", Vehicles[i][vPos][1]);
            INI_WriteFloat(ini, "Z", Vehicles[i][vPos][2]);
            INI_WriteFloat(ini, "A", Vehicles[i][vPos][3]);
            INI_WriteInt(ini, "Color1", Vehicles[i][vColor][0]);
            INI_WriteInt(ini, "Color2", Vehicles[i][vColor][1]);
            INI_WriteInt(ini, "Price", Vehicles[i][vPrice]);
            INI_WriteInt(ini, "Type", Vehicles[i][vType]);
            INI_WriteBool(ini, "HaveOwners", Vehicles[i][vHaveOwners]);
            INI_WriteString(ini, "Owners", Vehicles[i][vOwners]);
            INI_WriteString(ini, "Name", Vehicles[i][vName]);
            INI_WriteInt(ini, "PayTax", Vehicles[i][vPayTax]);
            INI_WriteInt(ini, "Sale", Vehicles[i][vSale]);
            INI_WriteInt(ini, "3DColor", Vehicles[i][v3DColor]);
            INI_WriteString(ini, "3DText", Vehicles[i][v3DText]);
            INI_WriteBool(ini, "HaveNitro", Vehicles[i][vHaveNitro]);
            INI_WriteBool(ini, "HaveAutoNitro", Vehicles[i][vHaveAutoNitro]);
            INI_WriteBool(ini, "HaveHyd", Vehicles[i][vHaveHyd]);
            INI_WriteBool(ini, "HaveDisco", Vehicles[i][vHaveDisco]);
            INI_WriteBool(ini, "DiscoActive", Vehicles[i][vDiscoActive]);
            INI_WriteInt(ini, "Wheels", Vehicles[i][vWheels]);
            INI_Close(ini);
            Vehicles[i][vCreated] = true;
        }
        else INI_ParseFile(vFile(i), "load_vehicle_data_%s", .bExtra = true, .extra = i);
        if(!IsValidVehicle(i)) continue;
        CarText(i);
        count++;
    }
    new vcount = AddStaticVehicle(411, 0.0, 0.0, 0.0, 0.0, -1, -1);
    DestroyVehicle(vcount);
    printf("%s Files Loaded | %s Vehicles loaded", GetNum(count), GetNum(vcount - 1));
    return print("=========================");
}

forward load_vehicle_data_VehicleData(i, name[], value[]);
public load_vehicle_data_VehicleData(i, name[], value[])
{
        INI_Int("Model", Vehicles[i][vModel]);
    INI_Float("X", Vehicles[i][vPos][0]);
    INI_Float("Y", Vehicles[i][vPos][1]);
    INI_Float("Z", Vehicles[i][vPos][2]);
    INI_Float("A", Vehicles[i][vPos][3]);
    INI_Int("Color1", Vehicles[i][vColor][0]);
    INI_Int("Color2", Vehicles[i][vColor][1]);
    INI_Int("Price", Vehicles[i][vPrice]);
    INI_Int("Type", Vehicles[i][vType]);
    INI_Bool("HaveOwners", Vehicles[i][vHaveOwners]);
    INI_String("Owners", Vehicles[i][vOwners], MAX_PLAYER_NAME + 1);
    INI_String("Name", Vehicles[i][vName], 32);
    INI_Int("PayTax", Vehicles[i][vPayTax]);
    INI_Int("Sale", Vehicles[i][vSale]);
    INI_Int("3DColor", Vehicles[i][v3DColor]);
    INI_String("3DText", Vehicles[i][v3DText], 64);
    INI_Bool("HaveNitro", Vehicles[i][vHaveNitro]);
    INI_Bool("HaveAutoNitro", Vehicles[i][vHaveAutoNitro]);
    INI_Bool("HaveHyd", Vehicles[i][vHaveHyd]);
    INI_Bool("HaveDisco", Vehicles[i][vHaveDisco]);
    INI_Bool("DiscoActive", Vehicles[i][vDiscoActive]);
    INI_Int("Wheels", Vehicles[i][vWheels]);
    Vehicles[i][vCreated] = true;
    return 1;
}
The problem is that the text does not appear above the car ...
CarText:
pawn Код:
forward CarText(i);
public CarText(i)
{
    DestroyDynamic3DTextLabel(Vehicles[i][v3DLabel]);
    if(!fexist(vFile(i))) return 1;
    switch(Vehicles[i][vType])
    {
        case VEHICLE_TYPE_PUBLIC:
        {
            if(strlen(Vehicles[i][v3DText]) != 0) Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel(Vehicles[i][v3DText], Vehicles[i][v3DColor], 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
            else Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel("шлб цйбешй", Red, 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
        }
        case VEHICLE_TYPE_ADMIN:
        {
            if(strlen(Vehicles[i][v3DText]) != 0) Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel(Vehicles[i][v3DText], Vehicles[i][v3DColor], 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
            else Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel("шлб агойрйн", Yellow, 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
        }
        case VEHICLE_TYPE_HQ:
        {
            if(strlen(Vehicles[i][v3DText]) != 0) Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel(Vehicles[i][v3DText], Vehicles[i][v3DColor], 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
            else Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel("шлб офчгд", Red, 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
        }
        case VEHICLE_TYPE_REGULAR:
        {
            if(strlen(Vehicles[i][v3DText]) != 0) Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel(Vehicles[i][v3DText], Vehicles[i][v3DColor], 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
            else
            {
                new string[128];
                if(Vehicles[i][vHaveOwners])
                {
                    if(Vehicles[i][vSale]) format(string, sizeof string, ""purple"%s :бтмйн", Vehicles[i][vOwners]);
                    else format(string, sizeof string, "%s :бтмйн", Vehicles[i][vOwners]);
                }
                else format(string, sizeof string, ""green"фрей мшлйщд\n$%s :озйш", GetNum(Vehicles[i][vPrice]));
                Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel(string, Orange, 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
            }
        }
        case VEHICLE_TYPE_SPECIAL:
        {
            if(strlen(Vehicles[i][v3DText]) != 0) Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel(Vehicles[i][v3DText], Vehicles[i][v3DColor], 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
            else
            {
                new string[128];
                if(Vehicles[i][vHaveOwners])
                {
                    if(Vehicles[i][vSale]) format(string, sizeof string, "шлб ойезг\n"purple"%s :бтмйн", Vehicles[i][vOwners]);
                    else format(string, sizeof string, "шлб ойезг\n"orange"%s :бтмйн", Vehicles[i][vOwners]);
                }
                else format(string, sizeof string, "шлб ойезг\n"green"фрей мшлйщд\n$%s :озйш", GetNum(Vehicles[i][vPrice]));
                Vehicles[i][v3DLabel] = CreateDynamic3DTextLabel(string, Aqua, 0.0, 0.0, 1.2, 25.0, INVALID_PLAYER_ID, i);
            }
        }
    }
    return 1;
}
When I do "printf("%d", Vehicles[i][vType]);" in public load_vehicle_data_VehicleData
It does not print anything ...
And I do not see any problem with the code ...
Reply
#2

Does it save correctly and did you define VEHICLE_TYPE_PUBLIC, etc..?
Reply
#3

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
Does it save correctly and did you define VEHICLE_TYPE_PUBLIC, etc..?
About saving ..
I think there the problem

SA-MP dedicated server stop working...
Then I just do close and now I also checked the information is not saved
And what is "run time error 6: "Invalid instruction""?
pawn Код:
public OnGameModeExit()
{
    new file[14];
    for(new i; i < MAX_VEHICLES; i++) if(IsValidVehicle(i) && Vehicles[i][vCreated])
    {
        format(file, sizeof file, "Cars/%d.ini", i);
        new INI:ini = INI_Open(file);
        INI_SetTag(ini, "VehicleData");
        INI_WriteInt(ini, "Model", Vehicles[i][vModel]);
        INI_WriteFloat(ini, "X", Vehicles[i][vPos][0]);
        INI_WriteFloat(ini, "Y", Vehicles[i][vPos][1]);
        INI_WriteFloat(ini, "Z", Vehicles[i][vPos][2]);
        INI_WriteFloat(ini, "A", Vehicles[i][vPos][3]);
        INI_WriteInt(ini, "Color1", Vehicles[i][vColor][0]);
        INI_WriteInt(ini, "Color2", Vehicles[i][vColor][1]);
        INI_WriteInt(ini, "Price", Vehicles[i][vPrice]);
        INI_WriteInt(ini, "Type", Vehicles[i][vType]);
        INI_WriteBool(ini, "HaveOwners", Vehicles[i][vHaveOwners]);
        INI_WriteString(ini, "Owners", Vehicles[i][vOwners]);
        INI_WriteString(ini, "Name", Vehicles[i][vName]);
        INI_WriteInt(ini, "PayTax", Vehicles[i][vPayTax]);
        INI_WriteInt(ini, "Sale", Vehicles[i][vSale]);
        INI_WriteInt(ini, "3DColor", Vehicles[i][v3DColor]);
        INI_WriteString(ini, "3DText", Vehicles[i][v3DText]);
        INI_WriteBool(ini, "HaveNitro", Vehicles[i][vHaveNitro]);
        INI_WriteBool(ini, "HaveAutoNitro", Vehicles[i][vHaveAutoNitro]);
        INI_WriteBool(ini, "HaveHyd", Vehicles[i][vHaveHyd]);
        INI_WriteBool(ini, "HaveDisco", Vehicles[i][vHaveDisco]);
        INI_WriteBool(ini, "DiscoActive", Vehicles[i][vDiscoActive]);
        INI_WriteInt(ini, "Wheels", Vehicles[i][vWheels]);
        INI_Close(ini);
    }
    mysql_close();
    return 1;
}
Reply
#4

Is this the code from PerfectDM.pwn?
Reply
#5

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
Is this the code from PerfectDM.pwn?
yes...
the full code:
pawn Код:
public OnGameModeExit()
{
    new string[452];
    for(new i, size = sizeof Teleports; i < size; i++)
    {
        mysql_format(SQL, string, sizeof string, "INSERT INTO `teleports` (`PID`, `Closed`) VALUES(%d, %d) ON DUPLICATE KEY UPDATE `Closed` = %d", i, Teleports[i][tClosed], Teleports[i][tClosed]);
        mysql_query(SQL, string);
    }
    for(new i, size = sizeof Weapons; i < size; i++)
    {
        mysql_format(SQL, string, sizeof string, "INSERT INTO `weapons` (`WID`, `PID`, `Ammo`, `Price`, `Level`, `Special`, `ForSale`, `OuterList`, `MaxAmmo`) VALUES(%d, %d, %d, %d, %d, %d, %d, %d, %d) ON DUPLICATE KEY", Weapons[i][WeaponID], i, Weapons[i][WeaponAmmo], Weapons[i][WeaponPrice], Weapons[i][WeaponLevel], Weapons[i][SpecialWeapon], Weapons[i][WeaponForSale], Weapons[i][OuterList], Weapons[i][WeaponMaxAmmo]);
        mysql_format(SQL, string, sizeof string, "%e UPDATE `WID` = %d, `Ammo` = %d, `Price` = %d, `Level` = %d, `Special` = %d, `ForSale` = %d, `OuterList` = %d, `MaxAmmo` = %d", string, Weapons[i][WeaponID], Weapons[i][WeaponAmmo], Weapons[i][WeaponPrice], Weapons[i][WeaponLevel], Weapons[i][SpecialWeapon], Weapons[i][WeaponForSale], Weapons[i][OuterList], Weapons[i][WeaponMaxAmmo]);
        mysql_query(SQL, string);
    }
    new file[14];
    for(new i; i < MAX_VEHICLES; i++) if(IsValidVehicle(i) && Vehicles[i][vCreated])
    {
        format(file, sizeof file, "Cars/%d.ini", i);
        new INI:ini = INI_Open(file);
        INI_SetTag(ini, "VehicleData");
        INI_WriteInt(ini, "Model", Vehicles[i][vModel]);
        INI_WriteFloat(ini, "X", Vehicles[i][vPos][0]);
        INI_WriteFloat(ini, "Y", Vehicles[i][vPos][1]);
        INI_WriteFloat(ini, "Z", Vehicles[i][vPos][2]);
        INI_WriteFloat(ini, "A", Vehicles[i][vPos][3]);
        INI_WriteInt(ini, "Color1", Vehicles[i][vColor][0]);
        INI_WriteInt(ini, "Color2", Vehicles[i][vColor][1]);
        INI_WriteInt(ini, "Price", Vehicles[i][vPrice]);
        INI_WriteInt(ini, "Type", Vehicles[i][vType]);
        INI_WriteBool(ini, "HaveOwners", Vehicles[i][vHaveOwners]);
        INI_WriteString(ini, "Owners", Vehicles[i][vOwners]);
        INI_WriteString(ini, "Name", Vehicles[i][vName]);
        INI_WriteInt(ini, "PayTax", Vehicles[i][vPayTax]);
        INI_WriteInt(ini, "Sale", Vehicles[i][vSale]);
        INI_WriteInt(ini, "3DColor", Vehicles[i][v3DColor]);
        INI_WriteString(ini, "3DText", Vehicles[i][v3DText]);
        INI_WriteBool(ini, "HaveNitro", Vehicles[i][vHaveNitro]);
        INI_WriteBool(ini, "HaveAutoNitro", Vehicles[i][vHaveAutoNitro]);
        INI_WriteBool(ini, "HaveHyd", Vehicles[i][vHaveHyd]);
        INI_WriteBool(ini, "HaveDisco", Vehicles[i][vHaveDisco]);
        INI_WriteBool(ini, "DiscoActive", Vehicles[i][vDiscoActive]);
        INI_WriteInt(ini, "Wheels", Vehicles[i][vWheels]);
        INI_Close(ini);
    }
    mysql_close();
    return 1;
}
Reply
#6

Myql is causing the crash them. I'm not familiar with mysql, I'm using y_ini. Someone will help you, just wait.
Reply
#7

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
Myql is causing the crash them. I'm not familiar with mysql, I'm using y_ini. Someone will help you, just wait.
ok
thanks for trying to help
Reply
#8

Help please... :\
Reply
#9

Try closing the MySQL database ( mysql_close(); ) before saving the vehicles.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)