SA-MP Forums Archive
Setting vehicle health so it dont blow up - 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: Setting vehicle health so it dont blow up (/showthread.php?tid=449704)



Setting vehicle health so it dont blow up - OpticKiller - 09.07.2013

Hello guys


i am needing a little help here well i have a car engine lights hood & trunk system but its all in a dialog i will post the code below now what i want is a vehicle health limit ones the vehicle is damaged such as vehicle health at 300 or something like that. i just want it so the cars dont blow up cos i really hate it



Код:
if(dialogid == DIALOG_VEHICLE)
	{
		if(response)
		{
			switch(listitem)
			{
				case 0:
				{
					new vehicleid = GetPlayerVehicleID(playerid);
					new engine, lights, alarm, doors, bonnet, boot, objective;
					GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
					if(engine == 0 && Fuel[vehicleid] <= 0)
					{
						ShowErrorDialog(playerid, "This vehicle is out of fuel!");
						return 1;
					}
					if(engine == 1) { engine = 0; lights = 0; }
					else { engine = 1; lights = 1; }
					SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
				}
				case 1:
				{
					new vehicleid = GetPlayerVehicleID(playerid);
					new engine, lights, alarm, doors, bonnet, boot, objective;
					GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
					if(lights == 1) lights = 0; else lights = 1;
					SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
				}
				case 2:
				{
					new vehicleid = GetPlayerVehicleID(playerid);
					new engine, lights, alarm, doors, bonnet, boot, objective;
					GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
					if(bonnet == 1) bonnet = 0; else bonnet = 1;
					SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
				}
				case 3:
				{
					new vehicleid = GetPlayerVehicleID(playerid);
					new engine, lights, alarm, doors, bonnet, boot, objective;
					GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
					if(boot == 1) boot = 0; else boot = 1;
					SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
				}
				case 4:
				{
					if(!GetPVarInt(playerid, "GasCan"))
					{
						ShowErrorDialog(playerid, "You don't have a gas can!");
						return 1;
					}
					new vehicleid = GetPlayerVehicleID(playerid);
					if(Fuel[vehicleid] < 80.0) Fuel[vehicleid] += 20.0;
					else Fuel[vehicleid] = 100.0;
					SetPVarInt(playerid, "GasCan", 0);
					SendClientMessage(playerid, COLOR_WHITE, "You have filled the fuel tank with 20 fuel");
				}
				case 5:
				{
					new id = GetPVarInt(playerid, "DialogValue1");
					if(GetPlayerVehicleAccess(playerid, id) < 2)
					{
						ShowErrorDialog(playerid, "You are not the owner of this vehicle!");
						return 1;
					}
					new msg[128];
					VehicleCreated[id] = 0;
					new money = VehicleValue[id]/2;
					GivePlayerMoney(playerid, money);
					format(msg, sizeof(msg), "You have sold your vehicle for $%d", money);
					SendClientMessage(playerid, COLOR_WHITE, msg);
					RemovePlayerFromVehicle(playerid);
					DestroyVehicle(VehicleID[id]);
					SaveVehicle(id);
				}
				case 6:
				{
					new vehicleid = GetPVarInt(playerid, "DialogValue1");
					if(GetPlayerVehicleAccess(playerid, vehicleid) < 2)
					{
						ShowErrorDialog(playerid, "You are not the owner of this vehicle!");
						return 1;
					}
					GetVehiclePos(VehicleID[vehicleid], VehiclePos[vehicleid][0], VehiclePos[vehicleid][1], VehiclePos[vehicleid][2]);
					GetVehicleZAngle(VehicleID[vehicleid], VehiclePos[vehicleid][3]);
					VehicleInterior[vehicleid] = GetPlayerInterior(playerid);
					VehicleWorld[vehicleid] = GetPlayerVirtualWorld(playerid);
					SendClientMessage(playerid, COLOR_WHITE, "You have parked this vehicle here");
					UpdateVehicle(vehicleid, 1);
					PutPlayerInVehicle(playerid, VehicleID[vehicleid], 0);
					SaveVehicle(vehicleid);
				}
				case 7:
				{
					ShowDialog(playerid, DIALOG_VEHICLE_PLATE);
				}
			}
		}
		return 1;
	}
Код:
ShowDialog(playerid, dialogid)
{
	switch(dialogid)
	{
		case DIALOG_VEHICLE:
		{
			new vehicleid = GetPVarInt(playerid, "DialogValue1");
			new caption[32], info[256];
			format(caption, sizeof(caption), "Vehicle ID %d", vehicleid);
			strcat(info, "Engine\nLights\nHood\nTrunk", sizeof(info));
			strcat(info, "\nFill Tank", sizeof(info));
			if(GetPlayerVehicleAccess(playerid, vehicleid) >= 2)
			{
				new value = VehicleValue[vehicleid]/2;
				format(info, sizeof(info), "%s\nSell Vehicle  ($%d)\nPark Vehicle\nEdit License Plate", info, value);
			}
			ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, caption, info, "Select", "Cancel");
		}
		case DIALOG_VEHICLE_BUY:
		{
			new vehicleid = GetPVarInt(playerid, "DialogValue1");
			new caption[32], info[256];
			format(caption, sizeof(caption), "Vehicle ID %d", vehicleid);
			format(info, sizeof(info), "This vehicle is for sale ($%d)\nWould you like to buy it?", VehicleValue[vehicleid]);
			ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, caption, info, "Yes", "No");
		}
		case DIALOG_VEHICLE_SELL:
		{
			new targetid = GetPVarInt(playerid, "DialogValue1");
			new id = GetPVarInt(playerid, "DialogValue2");
			new price = GetPVarInt(playerid, "DialogValue3");
			new info[256];
			format(info, sizeof(info), "%s (%d) wants to sell you a %s for $%d.", PlayerName(targetid), targetid,
				VehicleNames[VehicleModel[id]-400], price);
			strcat(info, "\n\nWould you like to buy?", sizeof(info));
			ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_MSGBOX, "Buy Vehicle", info, "Yes", "No");
		}
		case DIALOG_TRUNK:
		{
			new vehicleid = GetPVarInt(playerid, "DialogValue1");
			new name[32], info[256];
			for(new i=0; i < sizeof(VehicleTrunk[]); i++)
			{
				if(VehicleTrunk[vehicleid][i][1] > 0)
				{
					GetWeaponName(VehicleTrunk[vehicleid][i][0], name, sizeof(name));
					format(info, sizeof(info), "%s%d. %s (%d)\n", info, i+1, name, VehicleTrunk[vehicleid][i][1]);
				}
				else
				{
					format(info, sizeof(info), "%s%d. Empty\n", info, i+1);
				}
			}
			ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, "Trunk", info, "Select", "Cancel");
		}
		case DIALOG_TRUNK_ACTION:
		{
			new info[128];
			strcat(info, "Put Into Trunk\nTake From Trunk", sizeof(info));
			ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, "Trunk", info, "Select", "Cancel");
		}
		case DIALOG_VEHICLE_PLATE:
		{
			ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, "Edit License Plate", "Enter new license plate:", "Change", "Back");
		}
		case DIALOG_FUEL:
		{
			new info[128];
			strcat(info, "Refuel Vehicle  ($" #FUEL_PRICE ")\nBuy Gas Can  ($" #GAS_CAN_PRICE ")", sizeof(info));
			ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_LIST, "Fuel Station", info, "OK", "Cancel");
		}
		case DIALOG_EDITVEHICLE:
		{
			new vehicleid = GetPVarInt(playerid, "DialogValue1");
			new caption[32], info[256];
			format(caption, sizeof(caption), "Edit Vehicle ID %d", vehicleid);
			format(info, sizeof(info), "1. Value: [$%d]\n2. Model: [%d (%s)]\n3. Colors: [%d]  [%d]\n4. License Plate: [%s]",
				VehicleValue[vehicleid], VehicleModel[vehicleid], VehicleNames[VehicleModel[vehicleid]-400],
				VehicleColor[vehicleid][0], VehicleColor[vehicleid][1], VehicleNumberPlate[vehicleid]);
			strcat(info, "\n5. Delete Vehicle\n6. Park Vehicle\n7. Go To Vehicle", sizeof(info));
			strcat(info, "\n\nEnter: [nr] [value1] [value2]", sizeof(info));
			ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, caption, info, "OK", "Cancel");
		}
	}
	return 1;
}



Re: Setting vehicle health so it dont blow up - Deathstalker - 09.07.2013

I guess you're looking for OnVehicleDamageStatusUpdate?


Re: Setting vehicle health so it dont blow up - OpticKiller - 10.07.2013

nah its more like if the Damage gets to a level it will cut out the engine etc,


Re: Setting vehicle health so it dont blow up - drichie - 10.07.2013

by this way whenever it gets damage and the vehicle health becom equals or less than 300 it will set the engine off then set the vehicle helath to 300
pawn Код:
new Float:health;
new veh;
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(veh, engine, lights, alarm, doors, bonnet, boot, objective);
GetVehicleHealth(veh, health);
if(health <=300)
{
SetVehicleHealth(veh,300);
SetVehicleParamsEx(veh, 1, lights, alarm, doors, bonnet, boot, objective)
}



Re: Setting vehicle health so it dont blow up - OpticKiller - 10.07.2013

Quote:
Originally Posted by drichie
Посмотреть сообщение
by this way whenever it gets damage and the vehicle health becom equals or less than 300 it will set the engine off then set the vehicle helath to 300
pawn Код:
new Float:health;
new veh;
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(veh, engine, lights, alarm, doors, bonnet, boot, objective);
GetVehicleHealth(veh, health);
if(health <=300)
{
SetVehicleHealth(veh,300);
SetVehicleParamsEx(veh, 1, lights, alarm, doors, bonnet, boot, objective)
}
thanks i forgot were should this go??


Re: Setting vehicle health so it dont blow up - drichie - 10.07.2013

pawn Код:
public ongamemodeinit()
{
SetTimer("VehHealth",500,true);
}

public VehHealth()
{
new Float:health;
new veh;
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(veh, engine, lights, alarm, doors, bonnet, boot, objective);
GetVehicleHealth(veh, health);
if(health <=300)
{
SetVehicleHealth(veh,300);
SetVehicleParamsEx(veh, 1, lights, alarm, doors, bonnet, boot, objective)
}
}



Re: Setting vehicle health so it dont blow up - OpticKiller - 11.07.2013

it works however, it dont turn the engine off etc, i am gonna need help with defining it together like as you do see all my vehicles commands are in a dialog "engine"lights"trunk"lights" etc, so if the player types CMD:v he will see the list of "engine"lights"trunk"lights" now if the vehicles hit to that level and he trys to turn on the engine i want it so he wouldnt bell to turn it on when the vehicle health is at 300


Re: Setting vehicle health so it dont blow up - drichie - 11.07.2013

add this to the engine part on your dialog
pawn Код:
new health
GetVehicleHealth(veh, health);
if(health <=300) return 0;
ow i have a mistake here change this SetVehicleParamsEx(veh, 1, lights, alarm, doors, bonnet, boot, objective)
to this SetVehicleParamsEx(veh, 0, lights, alarm, doors, bonnet, boot, objective)


Re: Setting vehicle health so it dont blow up - OpticKiller - 11.07.2013

Alright thanks mate for replying back


Re: Setting vehicle health so it dont blow up - drichie - 11.07.2013

pawn Код:
public ongamemodeinit()
{
    SetTimer("VehHealth",500,true);
}

public VehHealth()
{
    new Float:health;
    new vehicleid = GetPlayerVehicleID(playerid);
    new engine, lights, alarm, doors, bonnet, boot, objective;
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    GetVehicleHealth(vehicleid, health);
    if(health <=300)
    {
        SetVehicleHealth(vehicleid,300);
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective)
    }
}

if(dialogid == DIALOG_VEHICLE)
    {
        if(response)
        {
            switch(listitem)
            {
                case 0:
                {
                    new Float:health;
                    new vehicleid = GetPlayerVehicleID(playerid);
                    new engine, lights, alarm, doors, bonnet, boot, objective;
                    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                    GetVehicleHealth(vehicleid, health);
                    if(engine == 0 && Fuel[vehicleid] <= 0)
                    {
                        ShowErrorDialog(playerid, "This vehicle is out of fuel!");
                        return 1;
                    }
                    if(health <=300) return SetVehicleParamsEx(vehicleid, 0, 0, alarm, doors, bonnet, boot, objective)
                    if(engine == 1) { engine = 0; lights = 0; }
                    else { engine = 1; lights = 1; }
                    SetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
                }