08.03.2013, 14:38
So, I wrote this command to spawn cars..
How can I make it so that if the car that is spawned is left abandond for, say, 5 minutes, it gets destroyed? Cause as it is right now, if I spawn a vehicle, then drive around a while, and the vehicle blows up, it gets respawned where it was originally spawned, resulting in many many cars in the map.
pawn Код:
CMD:v(playerid, params[])
{
new
toid,
toname[MAX_PLAYER_NAME],
carid[20],
color1,
color2,
vid;
if(pInfo[playerid][Admin] > 1){
new randcolor1 = randomEx(1, 253);
new randcolor2 = randomEx(1, 253);
new test[128];
format(test, sizeof(test), "s[45]s[20]I(%i)I(%i)", randcolor1, randcolor2);
if(!sscanf(params, test, toname, carid, color1, color2)) {
toid = GetPlayerIdFromName(toname);
if(!strcmp(toname, "me", true, 3)){
toid = playerid;
}
if(IsPlayerConnected(toid)){
vid = FindVehicleByNameID(carid);
if(399 < vid < 612){
new
NewV,
Float: curX,
Float: curY,
Float: curZ,
Float: curR,
Float: curVX,
Float: curVY,
Float: curVZ,
MessageToSender[128],
MessageToReciever[128],
allmessage[128],
SenderName[25],
RecieverName[25];
GetPlayerName(playerid, SenderName, 18);
GetPlayerName(toid, RecieverName, 18);
GetPlayerPos(toid, curX, curY, curZ);
GetPlayerFacingAngle(playerid, curR);
WasInVehicle[toid] = 0;
//get any passengers
new
pass1 = 0,
pass2 = 0,
pass3 = 0,
pass1id,
pass2id,
pass3id;
if(IsPlayerInAnyVehicle(toid)){
if(GetPlayerState(toid) == 2){
new ocarid;
ocarid = GetPlayerVehicleID(toid);
GetVehicleVelocity(ocarid, curVX, curVY, curVZ);
GetVehicleZAngle(ocarid, curR);
RemovePlayerFromVehicle(ocarid);
DestroyVehicle(ocarid);
WasInVehicle[toid] = 1;
for(new i = 0; i < MAX_PLAYERS; i++) {
if(IsPlayerInAnyVehicle(i)){
if(IsPlayerInVehicle(i, ocarid)){
if(GetPlayerVehicleSeat(i) == 1){
pass1 = 1;
pass1id = i;
}
if(GetPlayerVehicleSeat(i) == 2){
pass2 = 1;
pass2id = i;
}
if(GetPlayerVehicleSeat(i) == 3){
pass3 = 1;
pass3id = i;
}
}
}
}
}
}
NewV = CreateVehicle(vid, curX+1, curY+1, curZ, curR, color1, color2, -1);
SetVehicleNumberPlate(NewV, RecieverName);
SetVehicleToRespawn(NewV);
PutPlayerInVehicle(toid, NewV, 0);
if(WasInVehicle[toid] == 1){
SetVehicleVelocity(NewV, curVX, curVY, curVZ);
WasInVehicle[toid] = 0;
if(pass1 == 1){
PutPlayerInVehicle(pass1id, NewV, 1);
}
if(pass2 == 2){
PutPlayerInVehicle(pass2id, NewV, 2);
}
if(pass3 == 3){
PutPlayerInVehicle(pass3id, NewV, 3);
}
}
format(MessageToSender, sizeof(MessageToSender), "Car '%s' sent to %s.", GetVehicleName(vid), RecieverName);
format(MessageToReciever, sizeof(MessageToReciever), "%s has just spawned you a car (%s).", SenderName, GetVehicleName(vid));
format(allmessage, sizeof(allmessage), "%s has sent a(n) %s to %s!", SenderName, GetVehicleName(vid), RecieverName);
SendClientMessage(playerid, COLOR_LIGHTPINK, MessageToSender);
SendClientMessage(toid, COLOR_LIGHTPINK, MessageToReciever);
SendClientMessageToAllButTwo(playerid, toid, COLOR_LIGHTPINK, allmessage);
return true;
} else {
new errorstring[128];
format(errorstring, sizeof(errorstring), "ERROR: %s is not a valid car name!");
SendClientMessage(playerid, COLOR_LIGHTPINK, errorstring);
SendClientMessage(playerid, COLOR_LIGHTPINK, "Don't use spaces, use '_' instead. EX: Hotring_Racer_A");
}
} else {
new errorstring[128];
format(errorstring, sizeof(errorstring), "ERROR: %i is not a valid player!", toid);
SendClientMessage(playerid, COLOR_LIGHTPINK, errorstring);
}
} else {
SendClientMessage(playerid, -1, "USAGE: /v [Playername / me] [car name / part of name] [color1] [color2]");
}
} else {
SendClientMessage(playerid, COLOR_LIGHTBLUE, "You don't have access to this command.");
}
return 1;
}