Help for a command - 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: Help for a command (
/showthread.php?tid=567302)
Help for a command -
HailPutin - 12.03.2015
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
Re: Help for a command -
Smileys - 12.03.2015
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.
Re: Help for a command -
FOTIS6 - 12.03.2015
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;
}