Respawning vehicles
#1

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.
Reply
#2

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

You use U-RP GameMode ?
Reply
#4

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.
Reply
#5

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!
Reply
#6

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;
	}
Reply
#7

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!
Reply
#8

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


Forum Jump:


Users browsing this thread: 1 Guest(s)