SA-MP Forums Archive
Destroying emtpy vehicles - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Destroying emtpy vehicles (/showthread.php?tid=256641)



Destroying emtpy vehicles - gamerhead - 21.05.2011

Hello all, i realy have no idea how to delete all empty vehicles.
I mean, on the 5 seconds all the vehicles that are emtpy get destroyed, not where the players are in.
Help me please.


Re: Destroying emtpy vehicles - xalith - 21.05.2011

you mean destroy the unoccupied vehicles which are not in range of any player?

if i were you i'd set the respawn time for the vehicles and that would make it auto respawn


Re: Destroying emtpy vehicles - Vince - 21.05.2011

Use AddStaticVehicleEx to add your vehicles, and set 5 seconds as respawn time. When the player leaves the vehicles, it'll be respawned after 5 seconds.

This forum requires that you wait .. Blah blah blah, waste of time.


Re: Destroying emtpy vehicles - gamerhead - 21.05.2011

No no, i mean delete all empty vehicles in the whole server. And i dont want respawn, because its stunt server ( /v and /sveh)


Re: Destroying emtpy vehicles - Mauzen - 21.05.2011

pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for (new i = 0; i < GetMaxPlayers(); i ++)
    {
        if (GetPlayerVehicleID(playerid) == vehicleid) return true;
    }
    return false;
}
Just written, so untested. This checks if a specific vehicle is occupied. You can use it in a loop through all vehicles to delete all unsused ones. Not the fastest method, but should be fine if you dont want to delete the vehicles every second


Re: Destroying emtpy vehicles - xalith - 21.05.2011

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
pawn Код:
stock IsVehicleOccupied(vehicleid)
{
    for (new i = 0; i < GetMaxPlayers(); i ++)
    {
        if (GetPlayerVehicleID(playerid) == vehicleid) return true;
    }
    return false;
}
Just written, so untested. This checks if a specific vehicle is occupied. You can use it in a loop through all vehicles to delete all unsused ones. Not the fastest method, but should be fine if you dont want to delete the vehicles every second
i think cpu usuage gets affected if he uses every second


Re: Destroying emtpy vehicles - gamerhead - 22.05.2011

Well i host on my friends vps, so not my problem. But where can i set it? Because i have when you leave a vehicle it removes. But /sveh makes a vehicle infront of you. So i need it to be done in about 10 seconds. So if player leave it, it stays for 10 seconds and he can get in in that 10 seconds. But if no one enters it, then it deletes it.
Because the /sveh is here, now they keep spawning andromada`s at the home spawn point -,-
So how to make in a timer?


Re: Destroying emtpy vehicles - Sascha - 22.05.2011

pawn Код:
forward DeleteEmptyVehicles();
public OnGameModeInit()
{
    SetTimer("DeleteEmtpyVehicles", 10000, true);
    return 1;
}

public DeleteEmptyVehicles()
{
    for(new v=0; v<MAX_VEHICLES; v++)
    {
        new count = 0;
        for(new i=0; i<GetMaxPlayers(); i++)
        {
            if(IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
            {
                if(GetPlayerVehicleID(i) == v) count++;
            }
        }
        if(count > 0)
        {
            DestroyVehicle(v);
        }
    }
    return 1;
}