Addding vehicle component crashing player when connecting o_O
#1

Hi, I have function that creates vehicle from database. Today I tried to add components saving.

Thats my function:
pawn Код:
public CreateVehicleFromSQL(uid)
{
    LoadCarTemp(uid);
    new pointer = CreateVehicle(TempCar[carModel], TempCar[carLocX], TempCar[carLocY], TempCar[carLocZ], TempCar[carAngle], TempCar[carColor1], TempCar[carColor2], -1);
    TempToVeh(pointer);
    for(new tune = 0; tune < 16; tune++)
    {
        if(Cars[pointer][carTuning][tune] != 0)
        {
            AddVehicleComponent(pointer, Cars[pointer][carTuning][tune]);
        }
    }
    return pointer;
}
It is working without:
pawn Код:
for(new tune = 0; tune < 16; tune++)
    {
        if(Cars[pointer][carTuning][tune] != 0)
        {
            AddVehicleComponent(pointer, Cars[pointer][carTuning][tune]);
        }
    }
But when I add this it crashes player when connecting. Why?

Thanks in advance,
Kacper
Reply
#2

maybe because the component models are beginning from 1000 to 1193, you have from 0 to 16 this can crash it...

Try this

Код:
public CreateVehicleFromSQL(uid)
{
LoadCarTemp(uid);
new pointer = CreateVehicle(TempCar[carModel], TempCar[carLocX], TempCar[carLocY], TempCar[carLocZ], TempCar[carAngle], TempCar[carColor1], TempCar[carColor2], -1);
TempToVeh(pointer);
for(new tune = 0; tune < 16; tune++)
{
if(Cars[pointer][carTuning][tune] != 0)
{
AddVehicleComponent(pointer, 1000+Cars[pointer][carTuning][tune]);
}
}
return pointer;
}
Reply
#3

Quote:
Originally Posted by robotboy655
maybe because the component models are beginning from 1000 to 1193, you have from 0 to 16 this can crash it...

Try this

Код:
public CreateVehicleFromSQL(uid)
{
LoadCarTemp(uid);
new pointer = CreateVehicle(TempCar[carModel], TempCar[carLocX], TempCar[carLocY], TempCar[carLocZ], TempCar[carAngle], TempCar[carColor1], TempCar[carColor2], -1);
TempToVeh(pointer);
for(new tune = 0; tune < 16; tune++)
{
if(Cars[pointer][carTuning][tune] != 0)
{
AddVehicleComponent(pointer, 1000+Cars[pointer][carTuning][tune]);
}
}
return pointer;
}
You don't get it.

Value of items in array Cars[vehicleid][carTuning] is ID of component, so my code should by ok.
Reply
#4

Old bug maybe, if adding components in OnGameModeInit will crash people when they join. Add a run once timer to OnGameModeInit to upgrade the vehicles.
Reply
#5

Tried to move to OnVehicleSpawn, but also crashes the game when player connects.
Reply
#6

Quote:
Originally Posted by kacperoo
Tried to move to OnVehicleSpawn, but also crashes the game when player connects.
Did you spawn any cars in OnGameModeInit?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)