07.06.2014, 08:57
I want a script of car spawn and auto destroy unused cars
#include <YSI\y_iterate>
#define CreateVehicle S_CreateVehicle
#define AddStaticVehicle S_AddStaticVehicle
#define AddStaticVehicleEx S_AddStaticVehicleEx
#define DestroyVehicle S_DestroyVehicle
new
Iterator:Vehicle,
bool:used[MAX_VEHICLES];
stock S_CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:a, col1, col2, respawn_delay)
{
new vid = CreateVehicle(modelid, x, y, z, a, col1, col2, respawn_delay);
Iter_Add(Vehicle, vid);
return vid;
}
stock S_AddStaticVehicle(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2)
{
new vid = AddStaticVehicle(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2);
Iter_Add(Vehicle, vid);
return vid;
}
stock S_AddStaticVehicleEx(modelid, Float:spawn_x, Float:spawn_y, Float:spawn_z, Float:angle, color1, color2, respawn_delay)
{
new vid = AddStaticVehicleEx(modelid, spawn_x, spawn_y, spawn_z, angle, color1, color2, respawn_delay);
Iter_Add(Vehicle, vid);
return vid;
}
stock S_DestroyVehicle(vehicleid)
{
if(DestroyVehicle(vehicleid)) Iter_Remove(Vehicle, vehicleid);
else return 0;
}
public OnPlayerEnterVehicle(playerid, vehicleid, bool:isapassenger)
{
used[vehicleid] = true;
return 1;
}
public OnPlayerExitVehicle(playerid, vehicleid)
{
foreach(new i : Player)
{
if(GetPlayerVehicleID(i) == vehicleid) return 1;
}
used[vehicleid] = false;
}
CMD:destroyunused(playerid, params[])
{
foreach(new v : Vehicle)
{
if(used[v]) continue;
else DestroyVehicle(v));
}
return 1;
}
CMD:carspawn(playerid, params[])
{
new vid, modelid, col1, col2, delay, Float:pos[4];
if(sscanf(params, "dDDD", vid, col1, col2, delay)) return SendClientMessage(playerid, -1, "SYNTAX : /carspawn [Modelid] [Color 1] [Color 2] [Respawn delay]");
GetPlayerPos(playerid, pos[0], pos[1], pos[2]);
GetPlayerFacingAngle(playerid, pos[4]);
vid = CreateVehicle(modelid, pos[0], pos[1], pos[2], pos[3], col1, col2, delay);
PutPlayerInVehicle(playerid, vid);
return 1;
}
if(VehicleInfo[vehicleid][Temp] == 1) SetTimerEx("EraseVehicle", 5000,0,"i",vehicleid);