SA-MP Forums Archive
help with a command[ RPP + ezz] - 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: help with a command[ RPP + ezz] (/showthread.php?tid=617664)



help with a command[ RPP + ezz] - ThatFag - 24.09.2016

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 **


Re: help with a command[ RPP + ezz] - K0P - 24.09.2016

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));
	}



Re: help with a command[ RPP + ezz] - SickAttack - 24.09.2016

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).


Re: help with a command[ RPP + ezz] - ThatFag - 24.09.2016

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



Re: help with a command[ RPP + ezz] - K0P - 24.09.2016

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



Re: help with a command[ RPP + ezz] - Shinja - 24.09.2016

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



Re: help with a command[ RPP + ezz] - K0P - 24.09.2016

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



Re: help with a command[ RPP + ezz] - ThatFag - 24.09.2016

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


Re: help with a command[ RPP + ezz] - Shinja - 24.09.2016

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


Re: help with a command[ RPP + ezz] - ThatFag - 24.09.2016

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
}