Help for a command
#1

I just want a command for example if i use /fire it will set all nearby vehicles on fire but only if there are players in vehicles. Problem is i don't know what functions to use
Reply
#2

I'm on my phone atm, if nobody replied before tmr I'll type something for ya on my pc.

Basically what you wanna do is:

Loop through all vehicles;
Check if any vehicle is within a certain distance from the player;
Check if the vehicle is occupied(****** functions);
SetVehicleHealth( vehicleid, 240 ); // 240 = vehicle on fire, you can also do 0 or w.e you want.
Reply
#3

That should work. Didn't test it, didn't even compile it so if there are any errors report them here or fix them yourself.

Code:
#define DESTROY_VEHICLE_DISTANCE 50.0

COMMAND:fire(playerid, params[])
{
	for(new i = 0; i < MAX_VEHICLES; i++)
	{
		if(IsValidVehicle(i))
		{
			new Float:x, Float:y, Float:z;
			GetPlayerPos(playerid, x, y, z);
			if(GetVehicleDistanceFromPoint(i, x, y, z) < DESTROY_VEHICLE_DISTANCE && IsVehicleOccupied(i))
			{
				SetVehicleHealth(i, 0);
				SendClientMessage(playerid, -1, "Nearby vehicles are destroyed");
			}
		}
	}
	return 1;
}

stock IsVehicleOccupied(vehicleid)
{
     for(new i = 0; i < MAX_PLAYERS; i++) 
     {
          if(!IsPlayerConnected(i)) continue;
          if(vehicleid == GetPlayerVehicleID(i)) return true;
     }
     return false;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)