PDA

View Full Version : Autorespawn vehicles and respawn at a command - question


Dystans
01/09/2011, 02:44 PM
Hello again, I would like to ask how often the little things ...

So. I've in a gamemode this function:
class respawn_all_vehicles()
{
new vehicles_map[MAX_VEHICLES];
foreach(Player, Forrespawn_all_vehicles)
//for(new playerid = 0, max_players = GetMaxPlayers(); playerid < max_players; playerid++)
if(IsPlayerInAnyVehicle(Forrespawn_all_vehicles))
vehicles_map[GetPlayerVehicleID(Forrespawn_all_vehicles)] = 1;

for(new vehicleid = 0; vehicleid < MAX_VEHICLES; vehicleid++)
if(!vehicles_map[vehicleid])
SetVehicleToRespawn(vehicleid);
return 1;
}

And this Timer in OnGameModeInit which run every 30 minutes:
SetTimer ("respawn_all_vehicles", 30 * 60 * 1000, true);

First question is: How to do - ONLY newly created vehicle were be destroyed/removed?

Second question is, how to make a function to spawn vehicles with the command?

Command to spawn vehicles:
CMD:v(playerid, params[])
{
if(IsPlayerInAnyVehicle(playerid))
return SendClientMessage(playerid, -1, "Musisz wysiąść z TEGO pojazdu aby stworzyć kolejny!");

int
name[20],
sCar,
CarID,
Float:V_X,
Float:V_Y,
Float:V_Z,
Float:V_Ang,
Int;

if(sscanf(params, "s[20]", name))
return SendClientMessage(playerid, Jasnoniebieski, "Błędna nazwa pojazdu!");

sCar = GetVehicleModelIDFromName(name);

if(sCar < 400 || sCar > 611)
return SendClientMessage(playerid, Jasnoniebieski, ""#CRED"UŻYJ: "#CORANGE"/V < Nazwa pojazdu >");

if(sCar == 425 || sCar == 432 || sCar == 447 || sCar == 520 || sCar == 577 && !IsPlayerAdmin(playerid))
return SendClientMessage(playerid, Jasnoniebieski, "Nie możesz stworzyć tego pojazdu, ponieważ nie jesteś administratorem!");

int vehicleid;
SetVehicleToRespawn(vehicleid);
GetPlayerPos(playerid,V_X, V_Y, V_Z);
GetPlayerFacingAngle(playerid, V_Ang);
Int = GetPlayerInterior(playerid);
CarID = CreateVehicle(sCar, V_X, V_Y, V_Z, V_Ang, -1, -1, -1);
SetVehicleNumberPlate(CarID,"{000000}XF");
SetVehicleVirtualWorld(CarID, GetPlayerVirtualWorld(playerid));

PutPlayerInVehicle(playerid, CarID, 0);
LinkVehicleToInterior(CarID, Int);
int u_Message[128];

format(u_Message, sizeof(u_Message), ""#CORANGE"Stworzyłeś(aś): "#CBLUE"%s", VehicleNames[sCar - 400]);
SendClientMessage(playerid, -1, u_Message);

return 1;
}

Thank you in advance for help.

=WoR=Varth
03/09/2011, 02:43 AM
You mean you only want to respawn vehicles that spawned by command?

Dystans
03/09/2011, 09:30 AM
You mean you only want to respawn vehicles that spawned by command?

Yes.

=WoR=Varth
03/09/2011, 09:40 AM
new bool:Commanded[MAX_VEHICLES;//This

CMD:v(playerid, params[])
{
if(IsPlayerInAnyVehicle(playerid))
return SendClientMessage(playerid, -1, "Musisz wysiasc z TEGO pojazdu aby stworzyc kolejny!");

int
name[20],
sCar,
CarID,
Float:V_X,
Float:V_Y,
Float:V_Z,
Float:V_Ang,
Int;

if(sscanf(params, "s[20]", name))
return SendClientMessage(playerid, Jasnoniebieski, "Bledna nazwa pojazdu!");

sCar = GetVehicleModelIDFromName(name);

if(sCar < 400 || sCar > 611)
return SendClientMessage(playerid, Jasnoniebieski, ""#CRED"UZYJ: "#CORANGE"/V < Nazwa pojazdu >");

if(sCar == 425 || sCar == 432 || sCar == 447 || sCar == 520 || sCar == 577 && !IsPlayerAdmin(playerid))
return SendClientMessage(playerid, Jasnoniebieski, "Nie mozesz stworzyc tego pojazdu, poniewaz nie jestes administratorem!");

int vehicleid;
SetVehicleToRespawn(vehicleid);
GetPlayerPos(playerid,V_X, V_Y, V_Z);
GetPlayerFacingAngle(playerid, V_Ang);
Int = GetPlayerInterior(playerid);
CarID = CreateVehicle(sCar, V_X, V_Y, V_Z, V_Ang, -1, -1, -1);
SetVehicleNumberPlate(CarID,"{000000}XF");
SetVehicleVirtualWorld(CarID, GetPlayerVirtualWorld(playerid));

PutPlayerInVehicle(playerid, CarID, 0);
LinkVehicleToInterior(CarID, Int);
int u_Message[128];

format(u_Message, sizeof(u_Message), ""#CORANGE"Stworzyles(as): "#CBLUE"%s", VehicleNames[sCar - 400]);
SendClientMessage(playerid, -1, u_Message);

Commanded[CarID] = true;//This

return 1;
}

CMD:respawn(playerid,params[])
{
for(new i=1;i<MAX_VEHICLES+1;i++)
{
if(Commanded[i])
{
DestroyVehicle(i);
Commanded[i] = false;
}
}
return 1;
}

Dystans
03/09/2011, 11:21 AM
Works good, but is one problem. Now command looks that:

CMD:respawn(playerid,params[])
{
if(!IsPlayerAdmin(playerid)) return 0; // returns 0 - command not work

else SendClientMessage(playerid, Kolor_Administratora, "All cars spawned by /v are removed.");
for(new i = 1; i < MAX_VEHICLES + 1; i++)
{
if(Commanded[i])
{
DestroyVehicle(i);
Commanded[i] = false;
continue;
}
}
return true;
}

When I'm not logged in on RCON - works good - show in chat info about this command not work, but when I'm logged in, this destroy all cars properly, but hm... still show in chat info about not working command and under this information show "All cars spawned by /v are removed"... What I doing bad?

=WoR=Varth
03/09/2011, 11:26 AM
CMD:respawn(playerid,params[])
{
if(!IsPlayerAdmin(playerid)) return 0; // returns 0 - command not work
SendClientMessage(playerid, Kolor_Administratora, "All cars spawned by /v are removed.");
for(new i = 1; i < MAX_VEHICLES + 1; i++)
{
if(Commanded[i])
{
DestroyVehicle(i);
Commanded[i] = false;
}
}
return true;
}

If you still get the message, show us your OnPlayerCommandPerformed.

Dystans
03/09/2011, 11:43 AM
So... I still get that message... - Firstly - "All cars spawned by /v are removed." and Secondly - "Command not exist!" - only this command not work, each other command works fine...

OnPlayerCommandPerformed:

public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(!success)
{
SendClientMessage(playerid, Kolor_Administratora, ""MAP_NAME": Command not exist!");
}
else // this is for eye, when I write /eye 1 - and I'm logged in on a rcon - I see which command wrote a player
{
int String[255];
format(String, sizeof(String), " [EYE] %s (ID: %d) -> %s", Player[playerid][NameOfPlayer], playerid, cmdtext);
foreach(Player, PlayerId)
if(PlayerId != playerid)
if(IsPlayerAdmin(PlayerId) && Player[PlayerId][Eye])
SendClientMessage(PlayerId, Kolor_Administratora, String);
}

return true;
}

=WoR=Varth
03/09/2011, 11:50 AM
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(!success)
{
/*SendClientMessage(playerid, Kolor_Administratora, ""MAP_NAME": Command not exist!");*/
}
else // this is for eye, when I write /eye 1 - and I'm logged in on a rcon - I see which command wrote a player
{
int String[255];
format(String, sizeof(String), " [EYE] %s (ID: %d) -> %s", Player[playerid][NameOfPlayer], playerid, cmdtext);
foreach(Player, PlayerId)
if(PlayerId != playerid)
if(IsPlayerAdmin(PlayerId) && Player[PlayerId][Eye])
SendClientMessage(PlayerId, Kolor_Administratora, String);
}

return true;
}

Comment that line and see if you still get the message. We just need to make sure the message come from there.

Dystans
03/09/2011, 11:57 AM
I don't see that message "Command not exist", but it's work on every, bad written too, command, so I need this in my script. And, if I write this command /respawn while I'm logged in on RCON - shows only "All cars spawned by /v are removed.", but when I'm not logged in, I don't see any message...

=WoR=Varth
03/09/2011, 12:12 PM
I'm not sure but try to change this:
for(new i = 1; i < MAX_VEHICLES + 1; i++)
to
for(new i = 1; i < MAX_VEHICLES; i++)

Dystans
03/09/2011, 12:36 PM
Yes, it was that bug, now that command works perfectly. Thank you, thread may be closed. :)

=WoR=Varth
03/09/2011, 12:42 PM
Yes, it was that bug, now that command works perfectly. Thank you, thread may be closed. :)

FYI vehicleid is start from 1. So if your MAX_VEHICLES is 200, there'll be vehicleid 200 (If you have a lot of vehicle) and your /respawn command will bugged for vehicleid 200.

Dystans
03/09/2011, 12:52 PM
My MAX_VEHICLES is equal 2000 (default by SA-MP), but thanks for this useful information, and, hm... Maybe don't close this thread, because I've an idea. It's possible to make an timer in command /respawn, which, when once started, will remove these cars every ~ 25 minutes until to exit the server or restart?

=WoR=Varth
03/09/2011, 12:56 PM
My MAX_VEHICLES is equal 2000 (default by SA-MP), but thanks for this useful information, and, hm... Maybe don't close this thread, because I've an idea. It's possible to make an timer in command /respawn, which, when once started, will remove these cars every ~ 25 minutes until to exit the server or restart?

Why don't just start the timer when the server started?

Dystans
03/09/2011, 01:03 PM
I will do that, and finally, I thank you very much for your help. Now the thread may be closed.