SA-MP Forums Archive
Strange thing - 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: Strange thing (/showthread.php?tid=283318)



[HELP] My vehicle system - Universal - 14.09.2011

Hello people, Im messing with my fucked up vehicle system again... Problem is that: the same car gets laoded twice! This is my stock function which loads the player vehicle. It should load a vehicle from the specified slot.

pawn Код:
stock SpawnPlayerVehicle( playerid, slot )
{
    if( gPlayerData[ playerid ][ pVehSQLID ][ slot ] != -1 )
    {
        format( gSQL, sizeof( gSQL ), "SELECT * FROM `vehicles` WHERE `id` = '%d'", gPlayerData[ playerid ][ pVehSQLID ][ slot ] );

        mysql_query( gSQL );
        mysql_store_result( );

        if( mysql_num_rows( ) )
        {
            while( mysql_retrieve_row( ) )
            {
                new
                    buffer[ 12 ],
                    model,
                    Float: angle;

                mysql_get_field( "model", buffer );
                model = strval( buffer );

                mysql_get_field( "angle", buffer );
                angle = floatstr( buffer );

                new vehid = CreateVehicle( model, 0.0, 0.0, 0.0, angle, 0, 0, -1 );

                gVehData[ vehid ][ vModel ] = model;
                gVehData[ vehid ][ vPos_A ] = angle;
                gVehData[ vehid ][ vSQLID ] = gPlayerData[ playerid ][ pVehSQLID ][ slot ];
                gVehData[ vehid ][ vSlot ] = slot;

                mysql_get_field( "x", buffer );
                gVehData[ vehid ][ vPos_X ] = floatstr( buffer );

                mysql_get_field( "y", buffer );
                gVehData[ vehid ][ vPos_Y ] = floatstr( buffer );

                mysql_get_field( "z", buffer );
                gVehData[ vehid ][ vPos_Z ] = floatstr( buffer );

                mysql_get_field( "color1", buffer );
                gVehData[ vehid ][ vColor1 ] = strval( buffer );

                mysql_get_field( "color2", buffer );
                gVehData[ vehid ][ vColor2 ] = strval( buffer );

                mysql_get_field( "locked", buffer );
                gVehData[ vehid ][ vLocked ] = strval( buffer );

                mysql_get_field( "enginetype", buffer );
                gVehData[ vehid ][ vEngineType ] = strval( buffer );

                mysql_get_field( "fuel", buffer );
                gVehData[ vehid ][ vFuel ] = strval( buffer );

                mysql_get_field( "owner", buffer );
                gVehData[ vehid ][ vOwner ] = strval( buffer );

                mysql_get_field( "plate", buffer );
                format( gVehData[ vehid ][ vPlate ], 12, "%s", buffer );

                SetVehiclePos( vehid,   gVehData[ vehid ][ vPos_X ],    gVehData[ vehid ][ vPos_Y ],    gVehData[ vehid ][ vPos_Z ] );
                ChangeVehicleColor( vehid,  gVehData[ vehid ][ vColor1 ],   gVehData[ vehid ][ vColor2 ] );

                UpdateVehicleParams( vehid );

                gOwnableVehicles++;

                gVehData[ vehid ][ vLoaded ] = true;

                printf( "  [LOG] Vehicle: SQLID:%d, slot:%d which owner is %s spawned.", gVehData[ vehid ][ vSQLID ], gVehData[ vehid ][ vSlot ], gPlayerData[ GetPlayerIdFromSQLID( gVehData[ vehid ][ vOwner ] ) ][ pFull ] );
            }
        }
        mysql_free_result( );
    }
}
This function is called like this:
pawn Код:
// Spawn player vehicles
        for(  new i = 1; i <= MAX_VEHICLE_SLOTS; i++ )
        {
            SpawnPlayerVehicle( playerid, i );
        }
The MAX_VEHICLE_SLOTS is 3. In my database there are two vehicles with the same owner, so it should load them both, but it loads them both and then does that again. Look at the debug:

Код:
[17:49:40]   [LOG] Vehicle: SQLID:1, slot:1 which owner is Paul_Finneti spawned.
[17:49:40]   [LOG] Vehicle: SQLID:3, slot:2 which owner is Paul_Finneti spawned.
[17:49:40]   [LOG] Vehicle: SQLID:1, slot:1 which owner is Paul_Finneti spawned.
[17:49:40]   [LOG] Vehicle: SQLID:3, slot:2 which owner is Paul_Finneti spawned.
And here is the debug code from the command which assigns vehicles to player:
Код:
[17:49:39] --SQLID:1 | slot:1
[17:49:39] --SQLID:3 | slot:2
So as you can see, there are only two cars, which are assigned perfectly, but it loads the cars TWICE... What the?
Any ideas guys?

Thanks in advice