Respawn 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: Respawn Vehicles? (
/showthread.php?tid=299487)
Respawn Vehicles? -
Xx_OutLawZ_xX - 26.11.2011
Hello,
Well I have been undergoing vehicles everywhere without respawning, So how do I make them all respawn?
I use CreateVehicleEx and AddStaticVehicleEx.
Thanks
Re: Respawn Vehicles? -
Rob_Maate - 26.11.2011
pawn Code:
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(i != INVALID_VEHICLE_ID)
{
SetVehicleToRespawn(i);
}
}
Just incorporate that into a simple command like /respawnallcars
Re: Respawn Vehicles? -
Kostas' - 26.11.2011
If you mean by respawning with a command, something like this
pawn Code:
CMD:respawncars(playerid, params[])
{
if(IsPlayerConnected(playerid)) {
for(new x = 0; x < MAX_VEHICLES; x++) {
if(IsVehicleEmpty(x)) {
SetVehicleToRespawn(x);
}
}
SendClientMessage(playerid, COLOR_ORANGE, "Vehicles Respawned!");
}
return 1;
}
pawn Code:
stock IsVehicleEmpty(vehicleid)
{
if(IsVehicleOccupied[vehicleid])return 0;
else return 1;
}
Re: Respawn Vehicles? -
Rob_Maate - 26.11.2011
I revised it a little - This will check through each vehicle and then check if any players are in it.
If it finds any, leaves the car alone
If it doesn't, respawns it
pawn Code:
CMD:respawncars(playerid, params[])
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(i != INVALID_VEHICLE_ID)
{
new IsVehicleEmpty = 0;
for(new j=0; j<MAX_PLAYERS; j++)
{
if(GetPlayerVehicleID(j) != i)
{
IsVehicleEmpty = 1;
}
else
{
IsVehicleEmpty = 0;
}
}
if(IsVehicleEmpty = 0)
{
SetVehicleToRespawn(i);
}
else
{
//If you need to perform an action on a used-car during the respawn, place it here
}
SendClientMessage(playerid, COLOR_ORANGE, "Vehicles Respawned!");
}
}
return 1;
}
Re: Respawn Vehicles? -
Xx_OutLawZ_xX - 26.11.2011
Ok thankyou but,
warning 219: local variable "IsVehicleEmpty" shadows a variable at a preceding level
warning 211: possibly unintended assignment
warning 204: symbol is assigned a value that is never used: "IsVehicleEmpty"
Re: Respawn Vehicles? -
Rob_Maate - 26.11.2011
Try that
pawn Code:
CMD:respawncars(playerid, params[])
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(i != INVALID_VEHICLE_ID)
{
new bool: IsVehicleEmpty;
for(new j=0; j<MAX_PLAYERS; j++)
{
if(GetPlayerVehicleID(j) != i)
{
IsVehicleEmpty = true;
}
else
{
IsVehicleEmpty = false;
}
}
if(IsVehicleEmpty = true)
{
SetVehicleToRespawn(i);
}
else
{
//If you need to perform an action on a used-car during the respawn, place it here
}
SendClientMessage(playerid, COLOR_ORANGE, "Vehicles Respawned!");
}
}
return 1;
}
Re: Respawn Vehicles? -
Xx_OutLawZ_xX - 26.11.2011
I still get them 3 warnings :S
Re: Respawn Vehicles? -
Kostas' - 26.11.2011
Did you try my way?
Re: Respawn Vehicles? -
Rob_Maate - 26.11.2011
@Kostas, you used
pawn Code:
if(IsVehicleOccupied[vehicleid])return 0;
How does that variable get it's value?
@Outlawz - Try running it, see if it works... I'll have another look, I don't really see why it's giving warnings at all
Re: Respawn Vehicles? -
Kostas' - 26.11.2011
Quote:
Originally Posted by Rob_Maate
@Kostas, you used
pawn Code:
if(IsVehicleOccupied[vehicleid])return 0;
How does that variable get it's value?
|
I have tested and it works. It respawns vehicles that are empty. If there is player inside nothing happens.