Remove empty cars
#1

I would like a script that will be able to tell if a car is completely empty, and will remove it, I can't seem to figure out how to do it
Reply
#2

public OnGameModeInit()
{

*stuff here*
*classes here i guess*
CreateVehicle(400, 2037.1477, 1339.6534, 10.8203, 0.4726, 1, 5, 10);
The first one is the vehicle model id.
Then the "2037.1477, 1339.6534, 10.8203, 0.4726" is the X,Y,Z and the Angle.
"1, 5" is the color
And "10" means that it will re-spawn, if a player leaves/exits the car, and hasn't went back into it in 10seconds
[At least that's how it works for me xd]
Basically:
Spawns model 400 at * numbers * coordinates / position, with the color 1 and 5.
I get into it, and step out of it.
And watch the car re-spawn in 10seconds [The timer 'starts' when you're fully out of the vehicle]
Reply
#3

pawn Код:
stock IsVehicleOccupied( vehicleid )
{
    for( new i = 0; i < MAX_PLAYERS; i++ )
    {
        if( IsPlayerInVehicle( i, vehicleid ) ) return 1;
    }
    return 0;
}
pawn Код:
// Where you want to remove the vehicle
// let's say "vehicle" stores the vehicleid (you need to get the vehicleid)
if( !IsVehicleOccupied( vehicle ) DestroyVehicle( vehicle );
// If nobody is in that vehicle, it will destroy/remove it.
Reply
#4

Код:
forward VehicleOccupied(vehicleid);

public VehicleOccupied(vehicleid)
{
   for(new i=0;i<MAX_PLAYERS;i++)
   { 
        if(IsPlayerInVehicle(i,vehicleid)) return 1;
   }
   return 0;
}

for(new veh = 0; veh < MAX_VEHICLES; veh++)
{
    if(!VehicleOccupied(veh)) return SetVehicleToRespawn(veh);
}
You can use it as a command or put it in a timer for automatic respawn.
Reply
#5

I am getting errors on your script,
pawn Код:
forward VehicleOccupied(vehicleid);

public VehicleOccupied(vehicleid)
{
   for(new i=0;i<MAX_PLAYERS;i++)
   {
        if(IsPlayerInVehicle(i,vehicleid)) return 1;
   }
   return 0;
}

for(new veh = 0; veh < MAX_VEHICLES; veh++)
{
    if(!VehicleOccupied(veh)) return SetVehicleToRespawn(veh);
}
The errors:

C:\Downloads\pstudio-0.8.3\temp119.pwn(333) : error 010: invalid function or declaration
C:\Downloads\pstudio-0.8.3\temp119.pwn(335) : error 010: invalid function or declaration
2 Errors.

Line 333 is: for(new veh = 0; veh < MAX_VEHICLES; veh++)
Line 335 is: if(!VehicleOccupied(veh)) return SetVehicleToRespawn(veh);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)