Totaled Scripts
#1

I need totaled scripts. Can someone help me?
Reply
#2

As in, if the car gets damaged too much, turn off the engine?
Reply
#3

Yes, VehHealth = 300.
It will turns off the engine and they can't /engine

Sorry, my bad english
Reply
#4

Alright, the first thing you should do is have a vehicle engine variable, in my case I use:
pawn Код:
new vehEngine[MAX_PLAYERS];
At the top portion of the script.
Then I would create a timer when a player gets into a vehicle:
pawn Код:
SetTimerEx("Total", 1000, true, "i", playerid);
And then forward it with all your other forwards:
pawn Код:
forward Total(playerid);
Then I would create the public for that.
pawn Код:
Public Total (playerid) //This is probably not right, I'm typing it in this textbox, not the compiler.
{
    new VehHealth = GetVehicleHealth(playerid);
    if (VehHealth <= 300)
    {
        SetVehicleParams(vehicleid, 0, -1, -1, -1, -1, -1);
    }
    return 1;
}
Also be sure to make it to where the "Total" timer stops when the player exits the vehicle.

Note that this is probably buggy as I havn't scripted in a while, lemme know of any bugs or issues and I will gladly fix them.
Reply
#5

^that seems like a LOT of extra work for a very simple process.

There's two ways you can do it, by detecting physical damage of the car (less processes required) or just checking the car every x seconds (the only real way to detect if it loses health from bullets).

Method 1:

Код:
new bool:disabled[MAX_VEHICLES];

public OnVehicleDamageStatusUpdate(vehicleid, playerid) {
	//Will ONLY trigger when the car takes physical damage (no bullets)
	new Float:vHealth;
	GetVehicleHealth(vehicleid, vHealth);
	
	if (health =< 300.0) {
		disabled[vehicleid] = true;
	}
	
	return 1;
}

CMD:engine(playerid, params) {
	//Do your validation stuff here
	
	if (disabled[GetPlayerVehicleID(playerid)]) {
		SendClientMessage(playerid, 0xCC0000FF, "The car's engine is too damaged to start!");
		//Anything else you want to do
	}
	else {
		//What to do when car is healthy
	}
	return 1;
}
Method 2:

Код:
new bool:disabled[MAX_VEHICLES];

public OnGameModeInit() {
    SetTimer("vCheck", 1000, true);
    return 1;
}

forward vCheck;
public vCheck() {
    for (new i = 1; i <= MAX_VEHICLES; i++) {
		if (!disabled[i]) {
			new Float:health;
			GetVehicleHealth(i, health);
			if (health <= 300.0) {
				disabled[i] = true;
			}
		}
    }
    return 1;
}

CMD:engine(playerid, params) {
	//Do your validation stuff here
	
	if (disabled[GetPlayerVehicleID(playerid)]) {
		SendClientMessage(playerid, 0xCC0000FF, "The car's engine is too damaged to start!");
		//Anything else you want to do
	}
	else {
		//What to do when car is healthy
	}
	return 1;
}
Reply
#6

Quote:
Originally Posted by Alternative112
Посмотреть сообщение
^that seems like a LOT of extra work for a very simple process.

There's two ways you can do it, by detecting physical damage of the car (less processes required) or just checking the car every x seconds (the only real way to detect if it loses health from bullets).

Method 1:

Код:
new bool:disabled[MAX_VEHICLES];

public OnVehicleDamageStatusUpdate(vehicleid, playerid) {
	//Will ONLY trigger when the car takes physical damage (no bullets)
	new Float:vHealth;
	GetVehicleHealth(vehicleid, vHealth);
	
	if (health =< 300.0) {
		disabled[vehicleid] = true;
	}
	
	return 1;
}

CMD:engine(playerid, params) {
	//Do your validation stuff here
	
	if (disabled[GetPlayerVehicleID(playerid)]) {
		SendClientMessage(playerid, 0xCC0000FF, "The car's engine is too damaged to start!");
		//Anything else you want to do
	}
	else {
		//What to do when car is healthy
	}
	return 1;
}
Method 2:

Код:
new bool:disabled[MAX_VEHICLES];

public OnGameModeInit() {
    SetTimer("vCheck", 1000, true);
    return 1;
}

forward vCheck;
public vCheck() {
    for (new i = 1; i <= MAX_VEHICLES; i++) {
		if (!disabled[i]) {
			new Float:health;
			GetVehicleHealth(i, health);
			if (health <= 300.0) {
				disabled[i] = true;
			}
		}
    }
    return 1;
}

CMD:engine(playerid, params) {
	//Do your validation stuff here
	
	if (disabled[GetPlayerVehicleID(playerid)]) {
		SendClientMessage(playerid, 0xCC0000FF, "The car's engine is too damaged to start!");
		//Anything else you want to do
	}
	else {
		//What to do when car is healthy
	}
	return 1;
}
Your forgetting method #3 the dynamic approach with a custom iterator as the first method is a lousy implementation used that way and the second method makes no sense to keep checking all the vehicles when a custom iterator ex foreach(new i : Vehicle) could be used.
Reply
#7

could you show a better way? it could help me with a few older commands that I have. I'm trying to get rid of my foreaches that some of my scripts have, but I'm looking for the best way to do it.
Reply
#8

Personally, i'd use the method above by Alternative112

pawn Код:
new bool:disabled[MAX_VEHICLES];

public OnVehicleDamageStatusUpdate(vehicleid, playerid) {
    //Will ONLY trigger when the car takes physical damage (no bullets)
    new Float:vHealth;
    GetVehicleHealth(vehicleid, vHealth);
   
    if (health =< 300.0) {
        disabled[vehicleid] = true;
    }
   
    return 1;
}

CMD:engine(playerid, params) {
    //Do your validation stuff here
   
    if (disabled[GetPlayerVehicleID(playerid)]) {
        SendClientMessage(playerid, 0xCC0000FF, "The car's engine is too damaged to start!");
        //Anything else you want to do
    }
    else {
        //What to do when car is healthy
    }
    return 1;
}
Then use in place of the "anything else", SetVehicleParams. Kind of like this:

pawn Код:
new bool:disabled[MAX_VEHICLES];

public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    new Float:vHealth;
    GetVehicleHealth(vehicleid, vHealth);
    if (health =< 300.0)
    {
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid,0,0,0,0,0,0,objective);           
        disabled[vehicleid] = true;
    }
   
    return 1;
}

CMD:engine(playerid, params)
{
    if (disabled[GetPlayerVehicleID(playerid)]) return SendClientMessage(playerid, 0xCC0000FF, "The car's engine is too damaged to start!");
    else
    {
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid,1, lights, alarm, doors, bonnet, boot, objective);
    }
    return 1;
}
So if the car gets damaged too much it'll disable everything, or set it to "off". EG: alarm off, doors closed, bonnet closed etc. Then when you type /engine to turn it back on, it'll check if its disabled. If it isnt, it'll start the engine

You may want to add this though for it to work:
pawn Код:
public OnGameModeInit()
{
    ManualVehicleEngineAndLights();
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)