Respawn all cars - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Respawn all cars (
/showthread.php?tid=66404)
Respawn all cars -
Danut - 21.02.2009
I've created this cmd , but i don't know why he didn't respawn all my 500's cars
pawn Код:
if (strcmp(cmdtext, "/rac", true) == 0 || strcmp(cmdtext, "/respawnallcars", true) == 0)
{
if(PlayerInfo[playerid][pAdmin] >= 1337)
{
SendClientMessage(playerid,UNKNOWN_CMD," All cars respawned !");
for(new i = 0; i < 500; i++)
{
SetVehicleToRespawn(i);
return 1;
}
}
else
{
SendClientMessage(playerid,COLOR_WHITE,ADMIN_TEXT);
return 1;
}
}
Re: Respawn all cars -
Finn - 21.02.2009
Using return in a loop will stop the loop.
FIXED:
pawn Код:
for(new i = 0; i < 500; i++) SetVehicleToRespawn(i);
Re: Respawn all cars -
x-cutter - 22.02.2009
Quote:
Originally Posted by Danut
I've created this cmd , but i don't know why he didn't respawn all my 500's cars
pawn Код:
if (strcmp(cmdtext, "/rac", true) == 0 || strcmp(cmdtext, "/respawnallcars", true) == 0) { if(PlayerInfo[playerid][pAdmin] >= 1337) { SendClientMessage(playerid,UNKNOWN_CMD," All cars respawned !"); for(new i = 0; i < 500; i++) { SetVehicleToRespawn(i); return 1; } } else { SendClientMessage(playerid,COLOR_WHITE,ADMIN_TEXT); return 1; } }
|
This will kill your server, even with Finn's fix, because you can't SetVehicleToRespawn if there's someone in it, so you should rather check if the vehicle is occupied. Here is a working command
pawn Код:
// You need this
stock IsVehicleOccupied(vehicleid)
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInVehicle(i,vehicleid)) return 1;
}
return 0;
}
// if you use the commented way below
stock GetVehicleDriver(vehicleid)
{
for(new i; i<MAX_PLAYERS; i++)
{
if (IsPlayerInVehicle(i, vehicleid))
{
if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
{
return i;
}
}
}
return -1;
}
pawn Код:
// the cmd
if (!strcmp(cmdtext, "/rac", true) || !strcmp(cmdtext, "/respawnallcars", true))
{
if(PlayerInfo[playerid][pAdmin] >= 1337)
{
SendClientMessage(playerid,UNKNOWN_CMD," All empty cars were respawned !");
for(new i = 0; i < 500; i++) if(!IsVehicleOccupied(i)) SetVehicleToRespawn(i);
// if you want all cars to respawn
// for(new i;i<500;i++)
// {
// if(IsVehicleOccupied(i)) RemovePlayerFromVehicle(GetVehicleDriver(i));
// SetVehicleToRespawn(i);
// }
}
else
{
SendClientMessage(playerid,COLOR_WHITE,ADMIN_TEXT);
return 1;
}
}
Re: Respawn all cars -
ICECOLDKILLAK8 - 22.02.2009
Or just RemovePlayerFromVehicle before you do it
Re: Respawn all cars -
Danut - 22.02.2009
yea thx
Re: Respawn all cars -
Danut - 22.02.2009
Quote:
Originally Posted by JeNkStAX
Or just RemovePlayerFromVehicle before you do it
|
He automatly remove you from vehicle ...
Re: Respawn all cars -
Mikep - 22.02.2009
Quote:
Originally Posted by Danut
What's mean loop ?
|
Are you serious?
Re: Respawn all cars -
Danut - 22.02.2009
yep
Re: Respawn all cars -
Mikep - 22.02.2009
If you dont know what a loop is, you have alot to learn.
https://sampwiki.blast.hk/wiki/Loop
Re: Respawn all cars -
Danut - 22.02.2009
thx