Player vehicle spawn
#1

Hi, i'am using a system that when you doing /myvehicles you got a list of your vehicles and when you click one of your vehicles it will be spawned, but me i want to make all players vehicles spawn when he connect to the server, please help , this is the code of the dialog when you choose your vehicles

PHP код:
        case DIALOG_VEHICLEMANAGE:
        {
            new
                
szOutput[128];
            if(
response) {
                if(
VehicleInfo[playerid][listitem][Spawned] == 0) { // Stored
                    
if(VehicleInfo[playerid][listitem][Disabled] != 0) {
                        switch(
VehicleInfo[playerid][listitem][Disabled])
                        {
                            case 
1szOutput "This vehicle is currently impounded by the LSPD.";
                            case 
2szOutput "This vehicle is currently repossessed by the GOV.";
                            case 
3szOutput "This vehicle is currently disabled by an Admin.";
                        }
                        
SendPlayerMessage(playeridszOutput);
                        return 
1;
                    }
                    
VehicleInfo[playerid][listitem][Spawned] = 1;
                    
VehicleInfo[playerid][listitem][VehicleID] = CreateVehicle(VehicleInfo[playerid][listitem][ModelID], VehicleInfo[playerid][listitem][Pos][0], VehicleInfo[playerid][listitem][Pos][1], VehicleInfo[playerid][listitem][Pos][2], VehicleInfo[playerid][listitem][Pos][3], VehicleInfo[playerid][listitem][Colours][0], VehicleInfo[playerid][listitem][Colours][1], -1);
                    
SetVehicleHealth(VehicleInfo[playerid][listitem][VehicleID], VehicleInfo[playerid][listitem][Health]);
                    for(new 
016m++) { AddVehicleComponent(VehicleInfo[playerid][listitem][VehicleID], VehicleInfo[playerid][listitem][Mods][m]); }
                    if(
VehicleInfo[playerid][listitem][PaintJob] != -1) { ChangeVehiclePaintjob(VehicleInfo[playerid][listitem][VehicleID], VehicleInfo[playerid][listitem][PaintJob]); }
                    
SendPlayerMessage(playerid"You have spawned that vehicle.");
                    
iVehicleFuel[VehicleInfo[playerid][listitem][VehicleID]] = VehicleInfo[playerid][listitem][Fuel];
                    
iVehicleMileage[VehicleInfo[playerid][listitem][VehicleID]] = VehicleInfo[playerid][listitem][Mileage];
                }
                else { 
// Spawned
                    
VehicleInfo[playerid][listitem][Fuel] = iVehicleFuel[VehicleInfo[playerid][listitem][VehicleID]];
                    
VehicleInfo[playerid][listitem][Mileage] = iVehicleMileage[VehicleInfo[playerid][listitem][VehicleID]];
                    
GetVehicleHealth(VehicleInfo[playerid][listitem][VehicleID], VehicleInfo[playerid][listitem][Health]);
                    
VehicleInfo[playerid][listitem][Spawned] = 0;
                    
DestroyVehicle(VehicleInfo[playerid][listitem][VehicleID]);
                    
VehicleInfo[playerid][listitem][VehicleID] = -1;
                    
SendPlayerMessage(playerid"You have stored that vehicle.");
                }
            }
        } 
this is the thread to load player vehicles when he connect

PHP код:
        case THREAD_LOAD_PVEHICLES:
        {
            if(
IsPlayerConnected(extraid))
            {
                new 
0;
                while(
cache_num_rows())
                {
                    if(
>= MAX_PLAYER_VEHICLES)
                        break;
                    
cache_get_field_content(i"model"ResultiConnection); VehicleInfo[extraid][i][ModelID] = strval(Result);
                    
cache_get_field_content(i"slot_id"ResultiConnection); VehicleInfo[extraid][i][SlotID] = strval(Result);
                    if(
VehicleInfo[extraid][i][ModelID] != 0)
                    {
                        
cache_get_field_content(i"plate"ResultiConnection); format(VehicleInfo[extraid][i][Plate], 6"%s"Result);
                        
cache_get_field_content(i"colour1"ResultiConnection); VehicleInfo[extraid][i][Colours][0] = strval(Result);
                        
cache_get_field_content(i"colour2"ResultiConnection); VehicleInfo[extraid][i][Colours][1] = strval(Result);
                        
cache_get_field_content(i"interior"ResultiConnection); VehicleInfo[extraid][i][Interior] = strval(Result);
                        
cache_get_field_content(i"vw"ResultiConnection); VehicleInfo[extraid][i][VW] = strval(Result);
                        
cache_get_field_content(i"paintjob"ResultiConnection); VehicleInfo[extraid][i][PaintJob] = strval(Result);
                        
cache_get_field_content(i"tickets"ResultiConnection); VehicleInfo[extraid][i][Tickets] = strval(Result);
                        
cache_get_field_content(i"mileage"ResultiConnection); VehicleInfo[extraid][i][Mileage] = strval(Result);
                        
cache_get_field_content(i"insurance"ResultiConnection); VehicleInfo[extraid][i][Insurance] = strval(Result);
                        
cache_get_field_content(i"disabled"ResultiConnection); VehicleInfo[extraid][i][Disabled] = strval(Result);
                        
cache_get_field_content(i"fuel"ResultiConnection); VehicleInfo[extraid][i][Fuel] = floatstr(Result);
                        
cache_get_field_content(i"health"ResultiConnection); VehicleInfo[extraid][i][Health] = floatstr(Result);
                        
cache_get_field_content(i"pos_x"ResultiConnection); VehicleInfo[extraid][i][Pos][0] = floatstr(Result);
                        
cache_get_field_content(i"pos_y"ResultiConnection); VehicleInfo[extraid][i][Pos][1] = floatstr(Result);
                        
cache_get_field_content(i"pos_z"ResultiConnection); VehicleInfo[extraid][i][Pos][2] = floatstr(Result);
                        
cache_get_field_content(i"pos_a"ResultiConnection); VehicleInfo[extraid][i][Pos][3] = floatstr(Result);
                        for(new 
016m++) {
                            
format(Labelsizeof(Label), "mod%d"m+1);
                            
cache_get_field_content(iLabelResultiConnection); VehicleInfo[extraid][i][Mods][m] = strval(Result);
                        }
                        if(
VehicleInfo[extraid][i][Health] < 300VehicleInfo[extraid][i][Health] = 300;
                        
format(Querysizeof(Query), "SELECT * FROM `vehicle_storage` WHERE `vehicle_id` = %d AND `owner_id` = %d"iGetPlayerSQLID(extraid));
                        
mysql_function_query(iConnectionQuerytrue"OnQueryFinish""ii"THREAD_LOAD_VSTORAGEi);
                    }
                    else { 
// Invalid vehicle - remove it!
                        
format(Querysizeof(Query), "DELETE FROM `player_vehicles` WHERE `slot_id` = %d AND `account_id` = %d"VehicleInfo[extraid][i][SlotID], GetPlayerSQLID(extraid));
                        
mysql_function_query(iConnectionQueryfalse"OnQueryFinish""ii"THREAD_NO_QUERYextraid);
                    }
                    
i++;
                }
            }
        } 
this is when player logged in ( load stats and load the vehicles ) :

PHP код:
                    format(szQuerysizeof(szQuery), "SELECT * FROM `player_vehicles` WHERE `account_id` = %d"GetPlayerSQLID(playerid));
                    
mysql_tquery(iConnectionszQuery"OnQueryFinish""ii"THREAD_LOAD_PVEHICLESplayerid); 
Thank's for reading.
Reply
#2

Add this code on Public OnPlayerSpawn or after ur stats is loaded and vehicles:

pawn Код:
for(new litems = 0; litems <= MAX_PLAYER_VEHICLES; litems++)
{
if(VehicleInfo[playerid][litems][Spawned] == 0)
{
                    if(VehicleInfo[playerid][litems][Disabled] != 0)
                    {
                        switch(VehicleInfo[playerid][litems][Disabled])
                        {
                            case 1: szOutput = "This vehicle is currently impounded by the LSPD.";
                            case 2: szOutput = "This vehicle is currently repossessed by the GOV.";
                            case 3: szOutput = "This vehicle is currently disabled by an Admin.";
                        }
                        SendPlayerMessage(playerid, szOutput);
                    }
                    else
                    {
                    VehicleInfo[playerid][litems][Spawned] = 1;

                    VehicleInfo[playerid][litems][VehicleID] = CreateVehicle(VehicleInfo[playerid][litems][ModelID], VehicleInfo[playerid][litems][Pos][0], VehicleInfo[playerid][litems][Pos][1], VehicleInfo[playerid][litems][Pos][2], VehicleInfo[playerid][litems][Pos][3], VehicleInfo[playerid][litems][Colours][0], VehicleInfo[playerid][litems][Colours][1], -1);
                    SetVehicleHealth(VehicleInfo[playerid][litems][VehicleID], VehicleInfo[playerid][litems][Health]);

                    for(new m = 0; m < 16; m++) { AddVehicleComponent(VehicleInfo[playerid][litems][VehicleID], VehicleInfo[playerid][litems][Mods][m]); }
                    if(VehicleInfo[playerid][litems][PaintJob] != -1) { ChangeVehiclePaintjob(VehicleInfo[playerid][litems][VehicleID], VehicleInfo[playerid][litems][PaintJob]); }

                    SendPlayerMessage(playerid, "Your vehicle has been spawned");
                    iVehicleFuel[VehicleInfo[playerid][litems][VehicleID]] = VehicleInfo[playerid][litems][Fuel];
                    iVehicleMileage[VehicleInfo[playerid][litems][VehicleID]] = VehicleInfo[playerid][litems][Mileage];
                    }
}
}
Reply
#3

i want to make when the gamemode launch all vehicles will be loaded not when he logged in.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)