SA-MP Forums Archive
Vehicle System problem - 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: Vehicle System problem (/showthread.php?tid=566265)



Vehicle System problem - RenSoprano - 04.03.2015

Hi guys,

I have some problems with my vehicle system it isn't unloading the vehicles I debugged it but I still can't find the problem I will give you the code so you can try to search it too. Thanks

PHP код:
stock SaveVehicle(vehid)
{
    new 
uFile[35], string[128];
    
format(uFile35VEHICLE_PATHvehid);
    new 
INI:playerFile INI_Open(uFile);
    
INI_WriteInt(playerFile"Model"VehicleInfo[vehid][vModel]);
    
INI_WriteInt(playerFile"Color1"VehicleInfo[vehid][vColor1]);
    
INI_WriteInt(playerFile"Color2"VehicleInfo[vehid][vColor2]);
    
INI_WriteInt(playerFile"Paintjob"VehicleInfo[vehid][vPaintjob]);
    
INI_WriteFloat(playerFile"PosX"VehicleInfo[vehid][vPosX]);
    
INI_WriteFloat(playerFile"PosY"VehicleInfo[vehid][vPosY]);
    
INI_WriteFloat(playerFile"PosZ"VehicleInfo[vehid][vPosZ]);
    
INI_WriteFloat(playerFile"PosA"VehicleInfo[vehid][vPosA]);
    
INI_WriteFloat(playerFile"SavePosX"VehicleInfo[vehid][vSavePosX]);
    
INI_WriteFloat(playerFile"SavePosY"VehicleInfo[vehid][vSavePosY]);
    
INI_WriteFloat(playerFile"SavePosZ"VehicleInfo[vehid][vSavePosZ]);
    
INI_WriteFloat(playerFile"SavePosA"VehicleInfo[vehid][vSavePosA]);
    
INI_WriteInt(playerFile"ID"VehicleInfo[vehid][vID]);
    
INI_WriteInt(playerFile"Price"VehicleInfo[vehid][vPrice]);
    
INI_WriteInt(playerFile"Buyable"VehicleInfo[vehid][vBuyable]);
    
INI_WriteInt(playerFile"Temp"VehicleInfo[vehid][vTemp]);
    
INI_WriteString(playerFile"Owner"VehicleInfo[vehid][vOwner]);
    for(new 
016i++)
    {
        
format(stringsizeof(string), "Mods%d"i);
        
INI_WriteInt(playerFilestringVehicleInfo[vehid][vMods][i]);
    }
    
INI_Close(playerFile);
    return 
1;
}
stock UnloadPlayerVehicles(playerid)
{
    for(new 
0MAX_DYNAMIC_CARSi++)
    {
        if(
VehicleInfo[i][vID] != INVALID_VEHICLE_ID)
        {
            print(
"Unloaded part 1");
            if(
strcmp(VehicleInfo[i][vOwner], PlayerName(playerid)) == 0)
            {
                print(
"strcmp correct");
                  
SaveVehicle(VehicleInfo[i][vID]);
                print(
"SaveVehicle");
                
DestroyVehicle(VehicleInfo[i][vID]);
                print(
"DestroyVehicle");
                
VehicleInfo[i][vID] = INVALID_VEHICLE_ID;
                print(
"vID = Invalid ID");
            }
            
printf("UnloadPlayerVehicles: playerid = %d, vID = %d, Owner = %s"playeridVehicleInfo[i][vID], VehicleInfo[i][vOwner]);
        }
    }

DEBUG Resultats
Код:
[21:12:07] FeRRum[Scripter] [ID:0]: /createveh 0 522 0 0
[21:12:07] AdmCmd: FeRRum[Scripter] направи кола на FeRRum[Scripter]. Модел: 522
[21:12:16] Unloaded part 1
[21:12:16] strcmp correct
[21:12:16] [part] FeRRum[Scripter] has left the server (0:1)



Re: Vehicle System problem - MikE1990 - 04.03.2015

Maybe problem is in SaveVehicle ??


Re: Vehicle System problem - Misiur - 04.03.2015

Do you have crashdetect enabled? If no, enable it, I'm quite certain some crash happens within SaveVehicle.

1. You don't need "stock" prefix if you're not writing a library.
2. Check if INI_Open returns valid handle with
pawn Код:
if (file != INI_NO_FILE)
3. You don't need separate file for vehicle mods, as you can just use another tag within same file.


Re: Vehicle System problem - MikE1990 - 04.03.2015

Debug SaveVehicle and if code somewhere stop show it.


Re: Vehicle System problem - RenSoprano - 04.03.2015

Here are crashdetect logs

Код:
[21:44:38] Unloaded part 1
[21:44:38] strcmp correct
[21:44:38] [debug] Run time error 4: "Array index out of bounds"
[21:44:38] [debug]  Accessing element at index 46 past array upper bound 0
[21:44:38] [debug] AMX backtrace:
[21:44:38] [debug] #0 00042574 in ?? (46) from drift.amx
[21:44:38] [debug] #1 00043f70 in ?? (0) from drift.amx
[21:44:38] [debug] #2 0002e280 in public Itter_OnPlayerDisconnect (0, 1) from drift.amx
[21:44:38] [debug] #3 native CallLocalFunction () from samp-server.exe
[21:44:38] [debug] #4 0001cb34 in ?? (0, 1) from drift.amx
[21:44:38] [debug] #5 0000bca0 in public Streamer_OnPlayerDisconnect (0, 1) from drift.amx
[21:44:38] [debug] #6 00006258 in public SSCANF_OnPlayerDisconnect (0, 1) from drift.amx
[21:44:38] [debug] #7 native CallLocalFunction () from samp-server.exe
[21:44:38] [debug] #8 00000684 in public OnPlayerDisconnect (0, 1) from drift.amx
[21:44:38] [part] FeRRum[Scripter] has left the server (0:1)
PHP код:
public OnPlayerDisconnect(playeridreason)
{
    new 
sz_String[128];
    
    switch(
reason)
    {
        case 
0format(sz_Stringsizeof(sz_String), "%s[ID:%d] {FF0000}загуби връзка. {ffffff}(Crash)",PlayerName(playerid),playerid);
        case 
1format(sz_Stringsizeof(sz_String), "%s[ID:%d] {FF0000}излезе от сървъра. {ffffff}(Leave)",PlayerName(playerid),playerid);
        case 
2format(sz_Stringsizeof(sz_String), "%s[ID:%d] {FF0000}беше кикнат от сървъра. {ffffff}(Kick)",PlayerName(playerid),playerid);
    }
    
SendClientMessageToAll(-1sz_String);
    
    
InDM[playerid] = 0;
    
NoGoto[playerid] = 0;
    
NoPM[playerid] = 0;
    
LastPM[playerid] = -1;
    
GodMode[playerid] = 0;
    
NameTag[playerid] = 0;
    if(
CreatedRamp[playerid] == trueDestroyObject(Ramp[playerid]), CreatedRamp[playerid] = false;
    
CreatedRamp[playerid] = false;
    
RampEnabled[playerid] = 0;
    
Pers[playerid] = 0;
    
IsAFK[playerid] = 0;
    
PlayerPos[playerid][pPosX] = 0.0;
    
PlayerPos[playerid][pPosY] = 0.0;
    
PlayerPos[playerid][pPosZ] = 0.0;
    
PlayerPos[playerid][pPosA] = 0.0;
    
PlayerPos[playerid][pInterior] = 0;
    
PlayerPos[playerid][pVW] = 0;
    
PlayerPos[playerid][pSaved] = 0;
    
KillTimer(JailTimer[playerid]);
    
UnloadPlayerVehicles(playerid);
    
TextDrawHideForPlayer(playerid,ServerTextDrawOne);
    
TextDrawHideForPlayer(playerid,ServerTextDrawTwo);
    
TextDrawHideForPlayer(playerid,ServerTextDrawThree);
      
TextDrawHideForPlayer(playerid,ServerTextDrawFour[playerid]);
      
TextDrawHideForPlayer(playerid,ServerTextDrawFive[playerid]);
      
TextDrawHideForPlayer(playerid,ServerTextDrawSix[playerid]);
       
TextDrawSetString(ServerTextDrawFour[playerid]," ");
       
TextDrawSetString(ServerTextDrawFive[playerid]," ");
       
TextDrawSetString(ServerTextDrawSix[playerid]," ");
       
      
TextDrawHideForPlayer(playerid,LevelTXD[playerid]);
      
TextDrawHideForPlayer(playerid,ExpTXD[playerid]);
       
    
DriftMoney[playerid] = 0;
    
DriftScore[playerid] = 0;
    
DriftPoints[playerid] = 1;
    
PlayerPositionX[playerid] = 0.0;
    
PlayerPositionY[playerid] = 0.0;
    
PlayerPositionZ[playerid] = 0.0;
    
KillTimer(PlayerTimerOne[playerid]);
    
    if(
PlayerInfo[playerid][pMuted] >= 1)
    {
        new 
string[128];
        
format(stringsizeof(string), "AdmWarn: %s напусна сървъра с оставащо време от това, че беше заглушен %d минути."PlayerName(playerid), PlayerInfo[playerid][pMuted]);
        for (new 
0MAX_PLAYERSi++)
        {
            if (
IsPlayerConnected(i))
            {
                
AdminMessage(COLOR_ADMCMDstring);
            }
        }
    }
    
    
HideSpawnTextdraws(playerid);
    
HideAFKTextdraws(playerid);
    
    
SavePlayer(playerid);
    return 
1;