Need help (SetVehicleToRespawn) - 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: Need help (SetVehicleToRespawn) (
/showthread.php?tid=508810)
Need help (SetVehicleToRespawn) -
Useryy - 24.04.2014
When i do /REUNCARS it respawns all cars ... but it should only respawn UNOCCUPIED cars
it would be verry nice if someone can help
PHP код:
//RESPAWN ALL UNOCCUPIED CARS
if(!strcmp("/REUNCARS", cmdtext, true))
{
new AdminChk = AdminStatus(playerid);
if(AdminChk >= 5 && AdminChk <= 7)
{
new PlayerName[P_MAX_NAMELEN], Message[100];
GetPVarString(playerid, "P_JoinName", PlayerName, sizeof(PlayerName));
for(new Veh = 0; Veh <= MAX_VEHICLES; Veh++)
{
for(new Pla = 0; Pla <= S_MAX_PLAYERS; Pla++)
{
if(!IsPlayerInVehicle(Pla, Veh))
{
SetVehicleToRespawn(Veh);
}
}
}
format(Message, sizeof(Message),"ADMIN: %s(%i) Respawned all unoccupied cars", PlayerName, playerid);
SndAdminMgs(Message, 2);
return 1;
}
}
Re: Need help (SetVehicleToRespawn) -
Abagail - 24.04.2014
Use IsVehicleOccupied or something to detect if it's occupied or not. Also, your code is very stretched out when it doesn't have to be so confusing, and stretched out because your not using a stock to detect if it's taken.
After a quick ****** search I found this:
pawn Код:
stock IsVehicleOccupied(vehicleid) // Returns 1 if there is anyone in the vehicle
{
foreach(Player,i)
{
if(IsPlayerInAnyVehicle(i))
{
if(GetPlayerVehicleID(i)==vehicleid)
{
return 1;
}
else
{
return 0;
}
}
}
}
Source:
https://sampforum.blast.hk/showthread.php?tid=235783
Re: Need help (SetVehicleToRespawn) -
xVIP3Rx - 24.04.2014
pawn Код:
//RESPAWN ALL UNOCCUPIED CARS
if(!strcmp("/REUNCARS", cmdtext, true))
{
new AdminChk = AdminStatus(playerid);
if(AdminChk >= 5 && AdminChk <= 7)
{
new PlayerName[P_MAX_NAMELEN], Message[100];
GetPVarString(playerid, "P_JoinName", PlayerName, sizeof(PlayerName));
for(new Veh = 0; Veh <= MAX_VEHICLES; Veh++)
{
if(UnoccupiedVehicle(Pla))
{
SetVehicleToRespawn(Veh);
}
}
format(Message, sizeof(Message),"ADMIN: %s(%i) Respawned all unoccupied cars", PlayerName, playerid);
SndAdminMgs(Message, 2);
return 1;
}
}
stock UnoccupiedVehicle(vehicleid)
{
foreach(Player, i) if(IsPlayerInVehicle(i,vehicleid)) return 0;
return 1;
}
Re: Need help (SetVehicleToRespawn) -
Useryy - 24.04.2014
thanks ill try that
Re: Need help (SetVehicleToRespawn) -
Jefff - 24.04.2014
pawn Код:
//RESPAWN ALL UNOCCUPIED CARS
if(!strcmp("/REUNCARS", cmdtext, true))
{
if(5 <= AdminStatus(playerid) <= 7)
{
new PlayerName[P_MAX_NAMELEN], bool:VehUsed[MAX_VEHICLES char], Message[100];
GetPVarString(playerid, "P_JoinName", PlayerName, sizeof(PlayerName));
for(new Pla = 0; Pla < S_MAX_PLAYERS; Pla++)
if(IsPlayerConnected(Pla) && GetPlayerVehicleID(Pla))
VehUsed{GetPlayerVehicleID(Pla)} = true;
for(new Veh = 1; Veh < MAX_VEHICLES; Veh++)
if(!VehUsed{Veh})
SetVehicleToRespawn(Veh);
format(Message, sizeof(Message),"ADMIN: %s(%i) Respawned all unoccupied cars", PlayerName, playerid);
SndAdminMgs(Message, 2);
return 1;
}
}