Need Help Loading Vehicles on GameModeInit
#1

in my server when players joins the server it loads his owned vehicles and when he quit the game his vehicles disappearing so i want to make it when i start the server it can load all players vehicles here is the code

Код:
stock LoadPlayerVehicles(playerid)
{
    GetPlayerVehicles{playerid} = 0;
    verifydestroycar{playerid} = 0;
	new vehcount = 0;
    for(new v = 0; v < MAX_SHOP_VEHICLES; v++)
	{
	    new file[40];
		format(file, sizeof(file), VEH_FILE, v);
		if(fexist(file))
		{
        	INI_ParseFile(file, "LoadVeh_%s", .bExtra = true, .extra = v);

            if(!strcmp(GetName(playerid), VehicleInfo[v][vOwner], false))
			{
				new newveh = CreateVehicle(VehicleInfo[v][vModel], VehicleInfo[v][vPosX], VehicleInfo[v][vPosY], VehicleInfo[v][vPosZ], VehicleInfo[v][vPosA], VehicleInfo[v][vColor1], VehicleInfo[v][vColor2], 500000);
				SetVehicleNumberPlate(newveh, VehicleInfo[v][vPlate]);
				if(VehicleInfo[v][vPaintJob] != 0)
				{
					ChangeVehiclePaintjob(newveh, VehicleInfo[v][vPaintJob]);
				}

				if(VehicleInfo[v][vHealth] <= 251.0)
				{
					SetVehicleHealth(newveh, 1000.0);
					VehicleInfo[v][vHealth] = 1000.0;
				}
				else
				{
					SetVehicleHealth(newveh, VehicleInfo[v][vHealth]);
				}

				for(new m = 0; m < 12; m++)
				{
					if(GetVehicleMods[v][m] > 0)
					{
						AddVehicleComponent(newveh, GetVehicleMods[v][m]);
					}
				}

				if(VehicleInfo[v][vLocked] == 1)
				{
					SetVehicleParamsForAll(newveh, 0, 1);
        			GetVehicleParamsEx(newveh, engine, lights, alarm, doors, bonnet, boot, condition);
					SetVehicleParamsEx(newveh, engine, lights, alarm, ON, bonnet, boot, condition);
				}
				else if(VehicleInfo[v][vLocked] == 0)
				{
					SetVehicleParamsForAll(newveh, 0, 0);
        			GetVehicleParamsEx(newveh, engine, lights, alarm, doors, bonnet, boot, condition);
					SetVehicleParamsEx(newveh, engine, lights, alarm, OFF, bonnet, boot, condition);
				}

				if(VehicleInfo[v][vNeons] != NO_NEONS && VehicleInfo[v][vNeons] == BLUE_NEONS)
				{
				    blueneons[newveh] = CreateObject(18648,0,0,0,0,0,0);
            		blueneons2[newveh] = CreateObject(18648,0,0,0,0,0,0);
            		AttachObjectToVehicle(blueneons[newveh], newveh, -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
            		AttachObjectToVehicle(blueneons2[newveh], newveh, 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
				}
				else if(VehicleInfo[v][vNeons] != NO_NEONS && VehicleInfo[v][vNeons] == RED_NEONS)
				{
				    redneons[newveh] = CreateObject(18647,0,0,0,0,0,0);
            		redneons2[newveh] = CreateObject(18647,0,0,0,0,0,0);
            		AttachObjectToVehicle(redneons[newveh], newveh, -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
            		AttachObjectToVehicle(redneons2[newveh], newveh, 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
				}
				else if(VehicleInfo[v][vNeons] != NO_NEONS && VehicleInfo[v][vNeons] == GREEN_NEONS)
				{
				    greenneons[newveh] = CreateObject(18649,0,0,0,0,0,0);
            		greenneons2[newveh] = CreateObject(18649,0,0,0,0,0,0);
            		AttachObjectToVehicle(greenneons[newveh], newveh, -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
            		AttachObjectToVehicle(greenneons2[newveh], newveh, 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
				}
				else if(VehicleInfo[v][vNeons] != NO_NEONS && VehicleInfo[v][vNeons] == YELLOW_NEONS)
				{
				    yellowneons[newveh] = CreateObject(18650,0,0,0,0,0,0);
            		yellowneons2[newveh] = CreateObject(18650,0,0,0,0,0,0);
            		AttachObjectToVehicle(yellowneons[newveh], newveh, -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
            		AttachObjectToVehicle(yellowneons2[newveh], newveh, 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
				}
				else if(VehicleInfo[v][vNeons] != NO_NEONS && VehicleInfo[v][vNeons] == PINK_NEONS)
				{
				    pinkneons[newveh] = CreateObject(18651,0,0,0,0,0,0);
            		pinkneons2[newveh] = CreateObject(18651,0,0,0,0,0,0);
            		AttachObjectToVehicle(pinkneons[newveh], newveh, -0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
            		AttachObjectToVehicle(pinkneons2[newveh], newveh, 0.8, 0.0, -0.70, 0.0, 0.0, 0.0);
				}

	        	IsShopVehicle[newveh] = v;
	        	GetPlayerVehicles{playerid}++;
	        	GetServerVehicles++;

				GetVehicleFuel[newveh] = VehicleInfo[v][vFuel];
				GetVehicleCurrentHealth[newveh] = VehicleInfo[v][vHealth];

				vehcount++;

	        	if(vehcount == MAX_VIP_VEHS)
				{
				    return 1;
				}
	        }
        }
    }
	return 1;
}
Код:
stock UnloadPlayerVehicles(playerid)
{
	new vehcount = 0;
	for(new v = 0; v < MAX_VEHICLES; v++)
	{
	    if(IsShopVehicle[v] != -1)
		{
		    if(!strcmp(GetName(playerid), VehicleInfo[IsShopVehicle[v]][vOwner], false))
		    {
		        new color1, color2;
		        if(GetVehicleColor(v, color1, color2))
				{
	    			VehicleInfo[IsShopVehicle[v]][vColor1] = color1;
	    			VehicleInfo[IsShopVehicle[v]][vColor2] = color2;
	    		}
	    		new Float:health;
    			GetVehicleHealth(v, health);
    			VehicleInfo[IsShopVehicle[v]][vHealth] = health;
		        SaveVehicleStats(IsShopVehicle[v]);
		        DestroyNeons(v);
		        DestroyVehicle(v);
		        GetPlayerVehicles{playerid}--;
	        	GetServerVehicles--;
	        	IsShopVehicle[v] = -1;

				vehcount++;

	        	if(vehcount == MAX_VIP_VEHS)
				{
				    return 1;
				}
		    }
		}
	}
	return 1;
}
Код:
public OnPlayerDisconnect(playerid, reason)
{
UnloadPlayerVehicles(playerid);
}

Код:
OnPlayerConnect
{
LoadPlayerVehicles(playerid);
}
so anyone convert it that when i start server it loads users vehicles please?
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)