SA-MP Forums Archive
Remove all unused 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)
+--- Thread: Remove all unused vehicles. (/showthread.php?tid=438880)



Remove all unused vehicles. - NicholasA - 22.05.2013

How can I remove all unoccupied vehicles?


Re: Remove all unused vehicles. - Scenario - 22.05.2013

pawn Код:
CMD:despawnvehicles(playerid, params[])
{
    new
        Iterator:UnoccupiedVehicles<MAX_VEHICLES>;
   
    foreach(new i : Player) Iter_Add(UnoccupiedVehicles, GetPlayerVehicleID(i));
   
    for(new v = 0; v < MAX_VEHICLES; v++)
    {
        if(!Iter_Contains(UnoccupiedVehicles, v))
        {
            DestroyVehicle(v);
        }
    }
    return 1;
}
A little searching is all you had to do. You'll need y_iterate (part of the YSI library) to use this.


Re: Remove all unused vehicles. - whando - 22.05.2013

Код:
  	if(strcmp(cmd, "/vehdespawn", true) == 0 || strcmp(cmd, "/rav", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] < 1)
			{
			    SendClientMessage(playerid, COLOR_GRAD1, "   you are not authorized to use that command!");
			    return 1;
			}
			new bool:unwanted[CAR_AMOUNT];
			for(new player=0; player<MAX_PLAYERS; player++)
     		{
            	if(IsPlayerInAnyVehicle(player)) { unwanted[GetPlayerVehicleID(player)]=true; }
     		}
			for(new car = 1; car <= 268; car++)
			{
				if(!unwanted[car]) SetVehicleToRespawn(car);
			}
			GetPlayerName(playerid, sendername, sizeof(sendername));
			format(string, sizeof(string), "Server action: "COL_RED"All unused vehicles were respawned by Administrator %s.", RemoveUnderScore(playerid));
			SendClientMessageToAll(COLOR_RED,string);
		}
		return 1;
	}
Change;

if(PlayerInfo[playerid][pAdmin] < 1)

To;

if(PlayerInfo[playerid][pAdmin] < 0)

To make the command used by anyone, a higher number requires a higher admin level to use it


Re: Remove all unused vehicles. - CreativityLacker - 22.05.2013

pawn Код:
CMD:respawnunused(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be RCON admin to use this command! ");
    else
    {
        new bool:vad[MAX_VEHICLES] = false;
        for(new x=0; x < MAX_VEHICLES; x++)
        {
            for(new p = 0; p < MAX_PLAYERS; p++)
            {
                if(GetPlayerVehicleID(p) == x) vad[x] = true;
                if(vad[x] == false) SetVehicleToRespawn(x);
            }
        }
    }
    return 1;
}



Re: Remove all unused vehicles. - Scenario - 22.05.2013

Oh yeah, let's keep giving pieces of code even though I already gave him a working one. Nice post count raising, guys! Keep it up.


Re: Remove all unused vehicles. - CreativityLacker - 22.05.2013

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
Oh yeah, let's keep giving pieces of code even though I already gave him a working one. Nice post count raising, guys! Keep it up.
Nice attitude, thumbs up for that, the code you gave him contains shit he won't even need.

What if he doesn't use Y_ITERATE?
If he actually knew how to read/use that kind of code, why would he ask a question such as this one?

Oh yeah, let's keep giving bullshit pieces of code even though he's a newbie scripter.
Nice attitude, guys! Keep it up.


Re: Remove all unused vehicles. - Scenario - 22.05.2013

Quote:
Originally Posted by CreativityLacker
Посмотреть сообщение
Nice attitude, thumbs up for that, the code you gave him contains shit he won't even need.

What if he doesn't use Y_ITERATE?
If he actually knew how to read/use that kind of code, why would he ask a question such as this one?

Oh yeah, let's keep giving bullshit pieces of code even though he's a newbie scripter.
Nice attitude, guys! Keep it up.
YOU are an absolute fucking moron. Why don't you take your attitude and shove it right up your ass?

y_iterate is FOREACH, but it's the newest version. I use y_iterate because regular for loops are INEFFICIENT AS HELL. If he's a new scripter, he should be learning the NEW stuff, not the inefficient bullshit you and everyone else in this topic posted. Go get a little experience under your belt before you go off on me and make a complete fool out of yourself you moron.

EDIT: Whoever the hell -repped me with the reason "that's not even correct" you need to go learn a bit.


Re: Remove all unused vehicles. - CreativityLacker - 23.05.2013

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
YOU are an absolute fucking moron. Why don't you take your attitude and shove it right up your ass?

y_iterate is FOREACH, but it's the newest version. I use y_iterate because regular for loops are INEFFICIENT AS HELL. If he's a new scripter, he should be learning the NEW stuff, not the inefficient bullshit you and everyone else in this topic posted. Go get a little experience under your belt before you go off on me and make a complete fool out of yourself you moron.

EDIT: Whoever the hell -repped me with the reason "that's not even correct" you need to go learn a bit.
Quote:

Remove all unused... 23/05/2013 12:42 AM no u.

It's not inefficient bullshit, but only a scripter would know that. Not gonna argue anymore, reported your post.

Quote:
Originally Posted by NicholasA
Код:
CMD:respawnunused(playerid, params[])
{
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You need to be RCON admin to use this command! ");
    else
    {
        new bool:vad[MAX_VEHICLES] = false;
        for(new x=0; x < MAX_VEHICLES; x++)
        {
            for(new p = 0; p < MAX_PLAYERS; p++)
            {
                if(GetPlayerVehicleID(p) == x) vad[x] = true;
                if(vad[x] == false) SetVehicleToRespawn(x);
            }
        }
    }
    return 1;
}
Thanks! The other dude was putting in stuff i didnt understand
=)
...


Re: Remove all unused vehicles. - Scenario - 23.05.2013

Quote:
Originally Posted by CreativityLacker
Посмотреть сообщение
It's not inefficient bullshit
It is. You're running a loop that's going to execute 2000 times. Inside of that loop, you're running ANOTHER loop that will execute 500 times (unless you have re-defined MAX_PLAYERS), however that MAX_PLAYERS loop also executes 2000 times.

No, that's not inefficient! Of course not! /endsarcasm

Quote:
Originally Posted by CreativityLacker
Посмотреть сообщение
but only a scripter would know that.
I've been doing this longer than you have.

Quote:
Originally Posted by CreativityLacker
Посмотреть сообщение
Not gonna argue anymore, reported your post.
I really don't care. I know I'm right in calling you an idiot. The reason that many people on this forum can't do anything for themselves is because of people like YOU giving them inefficient scripts and saying "they don't know that other stuff." If they don't know it they need to learn it over the older methods.