Posts: 383
Threads: 70
Joined: Feb 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 **
Posts: 596
Threads: 75
Joined: Nov 2015
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));
}
Posts: 4,759
Threads: 33
Joined: Dec 2013
Reputation:
0
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).
Posts: 383
Threads: 70
Joined: Feb 2016
Код:
warning 213: tag mismatch
here
Код:
if(LastUsedVehicle[playerid] == -1) return SendClientMessage(playerid,-1, "You havent used a vehicle to stop from respawning");
Posts: 596
Threads: 75
Joined: Nov 2015
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;
}
Posts: 596
Threads: 75
Joined: Nov 2015
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;
}
Posts: 383
Threads: 70
Joined: Feb 2016
i indexed it but still having same problem
also tried ur other code but same
Posts: 969
Threads: 26
Joined: Jan 2016
Reputation:
0
I tried K0P's code, it gives no error except the one i mentioned, show the whole code you that contain the error line
Posts: 383
Threads: 70
Joined: Feb 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
}