help with a command[ RPP + ezz]
#1

hej
i have a command which allows admins to respawn the vehicles but now the problem is that when admin respawns the car it respawns all vehicles expect the one that is occupied
i want to make a command which stops a vehicle from respawn for example /stoprespawn
when players types stoprespawn his last used vehicle will not be respawned when admin typed /respawncars

here is the respawn cmd

Код:
COMMAND:respawncars(playerid, params[])
{
    if(PlayerInfo[playerid][admlvl] < 8) return SendClientError(playerid, CANT_USE_CMD);
    SetTimer("RespawnAll", 15000, false);
	SendClientMessageToAll(-1, "{ff0000}(( WARNING: {FFFFFF}Unoccupied vehicles will be respawned in 20 seconds! {ff0000}))");
	PlayerLoop(i)
	{
	    TDWarning(i, "Unoccupied vehicles respawn in 18 seconds.", 16000);
	}
	return 1;
}
Код:
{
    VehicleLoop(v)
	{
	    if(VehicleInfo[v][vActive] != true) continue;
	    if(VehicleInfo[v][vSpawned] != true) continue;
		if(IsVehicleOccupied(GetCarID(v))) continue;
		if(GetVehicleModel(GetCarID(v)) == 435 && !CanTrailerBeRespawned(GetCarID(v))) continue;
		SetVehicleToRespawn(GetCarID(v));
	}
respawn all **
Reply
#2

Not tested
Check for errors
Sorry for mistakes (Im tired,its 12:30 AM in my country)
Код:
new LastUsedVehicle[MAX_PLAYERS];
new AntiRespawn[MAX_VEHICLES];

public OnPlayerDisconnect(playerid, reason)
{
	LastUsedVehicle[playerid] = -1;
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(newstate == PLAYER_STATE_DRIVER /* aka state '2' */)
	{
		LastUsedVehicle = GetPlayerVehicleID(playerid);
	}
	return 1;
}

CMD:stoprespawn(playerid)
{
	if(LastUsedVehicle[playerid] == -1) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR] You never used a vehicle in this session.");

	new Vehicle = LastUsedVehicle[playerid]; //Did this to avoid errors

	AntiRespawn[Vehicle] = 1;
	
	SendClientMessage(playerid, 0xFFFFFFFF, "[INFO] This vehicle will not respawn from now.");
	return 1;
}

//And...

    VehicleLoop(v)
	{
	    if(VehicleInfo[v][vActive] != true) continue;
	    if(VehicleInfo[v][vSpawned] != true) continue;
		if(IsVehicleOccupied(GetCarID(v))) continue;
		if(GetVehicleModel(GetCarID(v)) == 435 && !CanTrailerBeRespawned(GetCarID(v))) continue;
		if(AntiRespawn[GetCarID(v)] == 0) continue;
		SetVehicleToRespawn(GetCarID(v));
	}
Reply
#3

Use a variable with max index MAX_VEHICLES, set to true when a player uses the command, loop through vehicles and check if the variable is true, if it is, set it back to false and respawn the vehicle otherwise (if false).
Reply
#4

Код:
 warning 213: tag mismatch
here
Код:
if(LastUsedVehicle[playerid] == -1) return SendClientMessage(playerid,-1, "You havent used a vehicle to stop from respawning");
Reply
#5

Quote:
Originally Posted by ThatFag
Посмотреть сообщение
Код:
 warning 213: tag mismatch
here
Код:
if(LastUsedVehicle[playerid] == -1) return SendClientMessage(playerid,-1, "You havent used a vehicle to stop from respawning");
Try this:

Код:
CMD:stoprespawn(playerid, params[])
{
	if(LastUsedVehicle[playerid] == -1) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR] You never used a vehicle in this session.");

	new Vehicle = LastUsedVehicle[playerid]; //Did this to avoid errors

	AntiRespawn[Vehicle] = 1;
	
	SendClientMessage(playerid, 0xFFFFFFFF, "[INFO] This vehicle will not respawn from now.");
	return 1;
}
Reply
#6

K0P you made a little mistake OnPlayerKeyStateChange
PHP код:
LastUsedVehicle GetPlayerVehicleID(playerid); // LastUsedVehicle must be indexed 
Reply
#7

Quote:
Originally Posted by Shinja
Посмотреть сообщение
K0P you made a little mistake OnPlayerKeyStateChange
PHP код:
LastUsedVehicle GetPlayerVehicleID(playerid); // LastUsedVehicle must be indexed 
ooo Thanks :P

@ThatFag

Use this

Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	if(newstate == PLAYER_STATE_DRIVER /* aka state '2' */)
	{
		LastUsedVehicle[playerid] = GetPlayerVehicleID(playerid);
	}
	return 1;
}
Reply
#8

i indexed it but still having same problem
also tried ur other code but same
Reply
#9

I tried K0P's code, it gives no error except the one i mentioned, show the whole code you that contain the error line
Reply
#10

same problem both error tag mismatch
Код:
COMMAND::stoprespawn(playerid)
{
	if(LastUsedVehicle[playerid] == -1) return SendClientMessage(playerid, 0xFFFFFFFF, "[ERROR] You never used a vehicle in this session."); // line error 1

	new Vehicle = LastUsedVehicle[playerid]; //Did this to avoid errors

	AntiRespawn[Vehicle] = 1;

	SendClientMessage(playerid, 0xFFFFFFFF, "[INFO] This vehicle will not respawn from now.");
	return 1; // line error 2
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)