PDA

View Full Version : /respawnallcars


SomebodyAndMe
11/12/2011, 10:46 AM
I need some help of that command beacause I don't really understand it.

I wanna make a command like when u /respawnallcars all the cars getting respawned, but if someone is in it, it won't respawn that car.

Could someone give me some help with that, or just the code?

Ash.
11/12/2011, 11:06 AM
stock IsVehicleOccupied(vehicleid)
{
for(new i; i < GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i)) continue;
if(GetPlayerVehicleID(i) == vehicleid) return 1;
}
return 0;
}

CMD:respawnvehicles(playerid, params[])
{
#pragma unused params
for(new i; i < MAX_VEHICLES; i++) if(!IsVehicleOccupied(i)) SetVehicleToRespawn(i);
return 1;
}

Had this lying around. Hope it helps!

suhrab_mujeeb
11/12/2011, 11:07 AM
// Top of script
forward PlayerInCar(vehicleid);

// ZCMD command, anywhere in the script not under a function or callback
CMD:respawnvehicles(playerid,params[])
{
vehicles<MAX_VEHICLES; vehicles++)
{
if(!PlayerInCar(vehicles))
{
SetVehicleToRespawn(vehicles);
}
}
return 1;
}
else return 0;
}
// Bottom of the script
public PlayerInCar(vehicleid)
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInVehicle(i,vehicleid)) return 1;
}
return 0;
}

EDIT: funky was very fast. I recommend using his code rather than mine.

SomebodyAndMe
11/12/2011, 11:25 AM
@ funky code is kinda messed up, if I type /respawnvehicles it also respawn the cars with persons in it.

I guess the script code mistake has been placed here:
for(new i; i < MAX_VEHICLES; i++) if(!IsVehicleOccupied(i)) SetVehicleToRespawn(i);

Could u fix it couse I really don't understand it.

THE_KNOWN
11/12/2011, 11:27 AM
CMD:vrespawn(playerid, params[])
{
new sec,string[128];
if(sscanf(params,"i",sec)) return SendClientMessage(playerid, red, "USAGE:/vrespawn [seconds]");
SetTimer("vrespawn", sec*1000, false);
format(string, sizeof(string), "~All currently unoccupied vehicles will respawn in %d seconds.",sec);
SendClientMessageToAll(COLOR_ORANGE, string);
return 1;
}

forward vrespawn();
public vrespawn()
{
new u[MAX_VEHICLES];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInAnyVehicle(i)) u[GetPlayerVehicleID(i)]=1;
}
for(new i;i<MAX_VEHICLES;i++)
{
if(u[i] != 1) SetVehicleToRespawn(i); else continue;
}
SendClientMessageToAll(COLOR_ORANGE, "~All vehicles have been respawned.");
return 1;
}


respawn with timer

Ash.
11/12/2011, 11:58 AM
stock IsVehicleOccupied(vehicleid)
{
for(new i; i < GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i)) continue;
if(GetPlayerVehicleID(i) == vehicleid) return 1;
}
return 0;
}

CMD:respawnvehicles(playerid, params[])
{
#pragma unused params
for(new i; i < MAX_VEHICLES; i++)
{
if(!IsVehicleOccupied(i)) SetVehicleToRespawn(i);
}
return 1;
}

I'm not in a position to test at the moment, but try that.

SomebodyAndMe
11/12/2011, 07:25 PM
Not working though, still re-spawning cars when players are in it.

SnG.Scot_MisCuDI
11/12/2011, 07:36 PM
dcmd_respawncars(playerid,params[])
{
{
SendClientMessage(playerid, green, "Your have Successfully Respawned all Vehicles!");

for(new cars=0; cars<MAX_VEHICLES; cars++)
{
if(!VehicleOccupied(cars))
{
SetVehicleToRespawn(cars);
}
}
return 1;
}
else return ErrorMessages(playerid, 1);
}

Kostas'
11/12/2011, 07:38 PM
// At The Top
new bool:IsVehicleOccupied[MAX_VEHICLES];
// Somewhere In Your Script
CMD:respawnallcars(playerid, params[])
{
if(IsPlayerConnected(playerid)) {
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You cannot use this command.");
for(new x = 0; x < MAX_VEHICLES; x++) {
if(IsVehicleEmpty(x)) {
SetVehicleToRespawn(x);
}
}
SendClientMessage(playerid, -1, "Vehicles Respawned!");
}
return 1;
}
// At The Bottom
stock IsVehicleEmpty(vehicleid)
{
if(IsVehicleOccupied[vehicleid])return 0;
else return 1;
}

SomebodyAndMe
12/12/2011, 05:14 AM
Nope, still respawning cars when a guy is inside it. Damn thing.

suhrab_mujeeb
12/12/2011, 09:25 AM
Nope, still respawning cars when a guy is inside it. Damn thing.


// Top of script
forward PlayerInCar(vehicleid);

// ZCMD command, anywhere in the script not under a function or callback
CMD:respawnvehicles(playerid,params[])
{
vehicles<MAX_VEHICLES; vehicles++)
{
if(!PlayerInCar(vehicles))
{
SetVehicleToRespawn(vehicles);
}
}
return 1;
}
else return 0;
}
// Bottom of the script
public PlayerInCar(vehicleid)
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInVehicle(i,vehicleid)) return 1;
}
return 0;
}

EDIT: funky was very fast. I recommend using his code rather than mine.

Have you tried this?

SomebodyAndMe
12/12/2011, 09:34 AM
Getting the following errors:

C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(55) : error 017: undefined symbol "vehicles"
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(55) : warning 215: expression has no effect
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(55) : error 017: undefined symbol "vehicles"
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(55) : error 029: invalid expression, assumed zero
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(55) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.


Command now:


// ZCMD command, anywhere in the script not under a function or callback
CMD:respawnvehicles(playerid,params[])
{
vehicles<MAX_VEHICLES; vehicles++);
{
if(!PlayerInCar(vehicles))
{
SetVehicleToRespawn(vehicles);
}
}
return 1;
}
else return 0;
}

// Bottom of the script
public PlayerInCar(vehicleid)
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInVehicle(i,vehicleid)) return 1;
}
return 0;
}

suhrab_mujeeb
12/12/2011, 09:41 AM
// Top of script
forward PlayerInCar(vehicleid);

// ZCMD command, anywhere in the script not under a function or callback
CMD:respawnvehicles(playerid,params[])
{
for(new vehicles<MAX_VEHICLES; vehicles++);
{
if(!PlayerInCar(vehicles))
{
SetVehicleToRespawn(vehicles);
}
}
return 1;
}
else return 0;
}

// Bottom of the script
public PlayerInCar(vehicleid)
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInVehicle(i,vehicleid)) return 1;
}
return 0;
}

Sorry, my wrong. Try now.

SomebodyAndMe
12/12/2011, 09:45 AM
Getting even more errors now:


C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(55) : error 001: expected token: "-identifier-", but found "("
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(55) : warning 206: redundant test: constant expression is non-zero
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(55) : error 036: empty statement
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(57) : error 017: undefined symbol "vehicles"
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(59) : error 017: undefined symbol "vehicles"
C:\Users\Barbara\Desktop\SAMP Kevin\hoi\pawno\include\PPC_PlayerCommands.inc(64) : error 010: invalid function or declaration
Pawn compiler 3.2.3664 Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.

suhrab_mujeeb
12/12/2011, 09:55 AM
// At the very top of the script
#include <a_samp>
#include <zcmd>

// Top of script
forward PlayerInCar(vehicleid);

// ZCMD command, anywhere in the script not under a function or callback
CMD:respawnvehicles(playerid,params[])
{
for(new vehicles=0; vehicles<MAX_VEHICLES; vehicles++)
{
if(!PlayerInCar(vehicles))
{
SetVehicleToRespawn(vehicles);
}
}
return 1;
}

// Bottom of the script
public PlayerInCar(vehicleid)
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInVehicle(i,vehicleid)) return 1;
}
return 0;
}

Try this, btw next time mark out the lines with the errors too. You forgot the include zcmd -.-

SomebodyAndMe
12/12/2011, 10:01 AM
I already use ZCMD.

And thanks, it worked.

BUT, i don't know if it's possible, when a trailer is attached to a truck let them also not respawn? is that possible?

suhrab_mujeeb
12/12/2011, 10:18 AM
CMD:respawnallcars(playerid,params[])
{
new sendername[30],string[60];
if(APlayerData[playerid][PlayerLevel] < 3) return SendClientMessage(playerid, 0xFF0000FF, "You are not authorized to use that command!");
for(new car = 0; car <= 268; car++)
if((IsVehicleEmpty(car) && !IsTrailerAttachedToVehicle(car) && GetVehicleModel(car) !=435 && GetVehicleModel(car) !=450 && GetVehicleModel(car) !=584 && GetVehicleModel(car) !=591) || (IsVehicleEmpty(car) && IsTrailerAttachedToVehicle(car) !=GetVehicleTrailer(car)))
{
SetVehicleToRespawn(car);
}
GetPlayerName(playerid,sendername,sizeof(sendernam e));
format(string, sizeof(string), "SERVER: All unused cars respawned by %s.", sendername);
SendClientMessageToAll(0xFFFFFFFF,string);
return 1;
}

SomebodyAndMe
12/12/2011, 10:30 AM
Nvm fixed..

suhrab_mujeeb
12/12/2011, 10:37 AM
#include <a_samp>
#include <zcmd>

CMD:respawnallcars(playerid,params[])
{
if(IsPlayerAdmin(playerid))
{
new sendername[30],string[60];
for(new car = 0; car <= 268; car++){
if((IsPlayerInVehicle(playerid, car) && !IsTrailerAttachedToVehicle(car) && GetVehicleModel(car) !=435 && GetVehicleModel(car) !=450 && GetVehicleModel(car) !=584 && GetVehicleModel(car) !=591) || IsPlayerInVehicle(playerid, car) && IsTrailerAttachedToVehicle(car) !=GetVehicleTrailer(car))
{
SetVehicleToRespawn(car);
}
}
GetPlayerName(playerid,sendername,sizeof(sendernam e)); // line 63
format(string, sizeof(string), "SERVER: All unused cars respawned by %s.", sendername);
SendClientMessageToAll(0xFFFFFFFF,string);
return 1;
}
else return 0;
}

For RCON admins only.

SomebodyAndMe
12/12/2011, 10:43 AM
The car you are in with trailer respawns now. :l

suhrab_mujeeb
12/12/2011, 11:09 AM
The cars with trailer and no player don't respawn?

SomebodyAndMe
12/12/2011, 11:10 AM
No, listen, the car where I am in, respawns, the trailer stays, but gets detached. And the trailer stays on the same position.

suhrab_mujeeb
12/12/2011, 11:31 AM
// At the very top of the script
#include <a_samp>
#include <zcmd>

forward PlayerInCar(vehicleid);

// Command
CMD:respawnvehicles(playerid,params[])
{
for(new vehicles=0; vehicles<MAX_VEHICLES; vehicles++)
{
if(!PlayerInCar(vehicles) && !IsTrailerAttachedToVehicle(vehicles))
{
SetVehicleToRespawn(vehicles);
}
}
return 1;
}

// Bottom of the script
public PlayerInCar(vehicleid)
{
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerInVehicle(i,vehicleid)) return 1;
}
return 0;
}

SomebodyAndMe
12/12/2011, 11:49 AM
Now the trailer gets respawned. when I /respawnvehicles.

THE_KNOWN
12/12/2011, 11:51 AM
CMD:vrespawn(playerid, params[])
{
new sec,string[128];
if(sscanf(params,"i",sec)) return SendClientMessage(playerid, red, "USAGE:/vrespawn [seconds]");
SetTimer("vrespawn", sec*1000, false);
format(string, sizeof(string), "~All currently unoccupied vehicles will respawn in %d seconds.",sec);
SendClientMessageToAll(COLOR_ORANGE, string);
return 1;
}

forward vrespawn();
public vrespawn()
{
new u[MAX_VEHICLES];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInAnyVehicle(i)) u[GetPlayerVehicleID(i)]=1;
}
for(new i;i<MAX_VEHICLES;i++)
{
if(IsTrailerAttachedToVehicle(i))
{
u[GetVehicleTrailer(i)]=1;
}
if(u[i] != 1)
{
SetVehicleToRespawn(i);
}
else continue;
}
SendClientMessageToAll(COLOR_ORANGE, "~All vehicles have been respawned.");
return 1;
}

SomebodyAndMe
12/12/2011, 11:59 AM
Nope, still respawning the trailers.

THE_KNOWN
12/12/2011, 12:05 PM
stock IsTrailer(vehicleid)
{
new mdl = GetVehicleModel(vehicleid);
if(mdl == 435 || mdl == 450 || mdl == 569 || mdl == 570 || mdl == 584 ||
mdl == 590 || mdl == 591 || mdl == 606 || mdl == 607 || mdl == 608 ||
mdl == 610 || mdl == 611) return 1;
return -1;
}

CMD:vrespawn(playerid, params[])
{
new sec,string[128];
if(sscanf(params,"i",sec)) return SendClientMessage(playerid, red, "USAGE:/vrespawn [seconds]");
SetTimer("vrespawn", sec*1000, false);
format(string, sizeof(string), "~All currently unoccupied vehicles will respawn in %d seconds.",sec);
SendClientMessageToAll(COLOR_ORANGE, string);
return 1;
}

forward vrespawn();
public vrespawn()
{
new u[MAX_VEHICLES];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInAnyVehicle(i)) u[GetPlayerVehicleID(i)]=1;
}
for(new i;i<MAX_VEHICLES;i++)
{
if(IsTrailer(i))
{
u[i]=1;
}
if(u[i] != 1)
{
SetVehicleToRespawn(i);
}
else continue;
}
SendClientMessageToAll(COLOR_ORANGE, "~All vehicles have been respawned.");
return 1;
}

SomebodyAndMe
12/12/2011, 12:37 PM
Now it's respawning nothing, not even a plane or bike or car.

THE_KNOWN
12/12/2011, 01:05 PM
forward vrespawn();
public vrespawn()
{
new u[MAX_VEHICLES];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInAnyVehicle(i)) u[GetPlayerVehicleID(i)]=1;
}
for(new i;i<MAX_VEHICLES;i++)
{
if(IsTrailer(i) != -1)
{
u[i]=1;
}
if(u[i] != 1)
{
SetVehicleToRespawn(i);
}
else continue;
}
SendClientMessageToAll(COLOR_ORANGE, "~All vehicles have been respawned.");
return 1;
}


IF that doesnt work


try this ;p


stock IsTrailer(vehicleid)
{
new mdl = GetVehicleModel(vehicleid);
switch(mdl)
{
case 435,450, 569, 570, 584,590,591,606,607,608,610,611: return 1;
}
return 0;
}

CMD:vrespawn(playerid, params[])
{
new sec,string[128];
if(sscanf(params,"i",sec)) return SendClientMessage(playerid, red, "USAGE:/vrespawn [seconds]");
SetTimer("vrespawn", sec*1000, false);
format(string, sizeof(string), "~All currently unoccupied vehicles will respawn in %d seconds.",sec);
SendClientMessageToAll(COLOR_ORANGE, string);
return 1;
}

forward vrespawn();
public vrespawn()
{
new u[MAX_VEHICLES];
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInAnyVehicle(i)) u[GetPlayerVehicleID(i)]=1;
}
for(new i;i<MAX_VEHICLES;i++)
{
if(IsTrailer(i) == 1)
{
u[i]=1;
}
if(u[i] != 1)
{
SetVehicleToRespawn(i);
}
else continue;
}
SendClientMessageToAll(COLOR_ORANGE, "~All vehicles have been respawned.");
return 1;
}

OPremium
12/12/2011, 01:20 PM
Get this:

MathPlugin: http://forum.sa-mp.com/showthread.php?t=270508

And try using this code, it will respawn unoccupied vehicles and trailers that aren't attached:


#include <MathPlugin>

CMD:respawnall(playerid, params[])
{
#pragma unused params
if(APlayerData[playerid][PlayerLevel] < 3)
{
SendClientMessage(playerid, red, "ERROR: You can't use this command!");
}
else
{
new str[128];
GetPlayerName(playerid, str, sizeof(str));
format(str, sizeof(str), "Admin \"%s\" has respawned all unoccupied vehicles", str);
for(new i; i <= MAX_VEHICLES; i++)
{
if(GetVehicleModel(i) == 570 || IsPlayerNPC(MPGetVehicleDriver(i))) continue; //Avoids respawning NPC cars
if(MPGetTrailerTowingVehicle(i) != INVALID_VEHICLE_ID) continue;
if(!MPGetVehicleOccupantCnt(i)) SetVehicleToRespawn(i);
}
for(new i; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i) || IsPlayerNPC(i)) continue;
PlayerPlaySound(i, 1057, 0.0, 0.0, 0.0);
SendClientMessage(i, 0xFFFF00FF, str);
}
}
return 1;
}


I use something similar in my script, but I edited it so it works with the gamemode that you are using :)