Totaled Scripts
#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


Messages In This Thread
Totaled Scripts - by Jizz - 17.06.2013, 01:37
Re: Totaled Scripts - by DobbysGamertag - 17.06.2013, 01:40
Re: Totaled Scripts - by Jizz - 17.06.2013, 03:27
Re: Totaled Scripts - by nmader - 17.06.2013, 03:38
Re: Totaled Scripts - by Alternative112 - 17.06.2013, 05:00
Re: Totaled Scripts - by Pottus - 17.06.2013, 05:59
Re: Totaled Scripts - by Alternative112 - 17.06.2013, 17:55
Re: Totaled Scripts - by DobbysGamertag - 18.06.2013, 02:50

Forum Jump:


Users browsing this thread: 3 Guest(s)