SA-MP Forums Archive
Respawning 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: Respawning vehicles (/showthread.php?tid=494740)



Respawning vehicles - rakshith122 - 14.02.2014

Well, Alright, I'll make it short and say it simple.
This is my code for respawning cars,
pawn Код:
dcmd_respawncars(playerid,params[])
{
    #pragma unused params
    #pragma unused playerid
    for(new i = 1; i <= MAX_VEHICLES; i++)
    {
       SetVehicleToRespawn(i);
    }
    SendClientMessageToAll(0x00E800C8, "[ADMIN] Administrator has respawned all non-occupied vehicles");
    return 1;
}
When I use this command, The NPC bot is removed from its vehicle, I want to respawn all the vehicles except the NPC's tram.

Hope someone would help me,
Thanks.


Re: Respawning vehicles - BigGroter - 14.02.2014

Check if the vehicle is occupied and check if the player is an NPC.


Re: Respawning vehicles - Clad - 14.02.2014

You use U-RP GameMode ?


Re: Respawning vehicles - Konstantinos - 14.02.2014

Create a global variable that will hold the vehicleid of that tram that the NPC is going to drive. Then in the loop:
pawn Код:
// global:
new NPC_TramVehicle;

// when creating the vehicle assign its vehicleid to "NPC_TramVehicle".

// in the loop:
for(new i = 1; i < MAX_VEHICLES; i++)
{
    if (NPC_TramVehicle == i) continue;
    SetVehicleToRespawn(i);
}
That's the best way of doing it, looping through all the players and checking if the player in in that vehicle and the player is an NPC is kind of a bad idea.


Re: Respawning vehicles - rakshith122 - 14.02.2014

So,
I use new NPCTram; as a global variable
and vehicle
pawn Код:
//Tram
    NPCTram = AddStaticVehicle(449,-1539.1951,791.7335,7.4973,354.2815,1,74); // Tram
So, Is the code correct entered below?
pawn Код:
dcmd_respawncars(playerid,params[])
{
    #pragma unused params
    #pragma unused playerid
    for(new i = 1; i <= MAX_VEHICLES; i++)
    {
       if(NPCTram == i) continue;
       SetVehicleToRespawn(i);
    }
    SendClientMessageToAll(0x00E800C8, "[ADMIN] Administrator has respawned all non-occupied vehicles");
    return 1;
}
I guess it is right, Confirming it is a good idea though. Thanks for the help and thanks in advance for answer this question!


Re: Respawning vehicles - Clad - 14.02.2014

You can use this also, It doesn't spawn NPC vehicles
Код:
if(strcmp(cmd, "/RespawnAllCars", true) == 0 || strcmp(cmd, "/RAC", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
	        if(PlayerInfo[playerid][pAdmin] < 3)
			{
			    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: "COL_WHITE"All unused vehicles were respawned by Administrator %s.", sendername);
			SendClientMessageToAll(COLOR_YELLOW,string);
		}
		return 1;
	}



Re: Respawning vehicles - rakshith122 - 14.02.2014

I use dcmd, and
pawn Код:
dcmd_respawncars(playerid,params[])
{
    #pragma unused params
    #pragma unused playerid
    for(new i = 1; i <= MAX_VEHICLES; i++)
    {
       if(NPCTram == i) continue;
       SetVehicleToRespawn(i);
    }
    SendClientMessageToAll(0x00E800C8, "[ADMIN] Administrator has respawned all non-occupied vehicles");
    return 1;
}
This type of line doesn't even exist on my gamemode.
Thanks for trying your best though.. I appreciate it!


Re: Respawning vehicles - Clad - 14.02.2014

You can edit it as your gamemode is, The idea is to know the main command