Destroying idle vehicles
#1

So, I wrote this command to spawn cars..
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;
    }
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.
Reply
#2

bumpppp
Reply
#3

nvm.
Reply
#4

https://sampwiki.blast.hk/wiki/CreateVehicle

See the respawn delay argument? Just set that to five minutes (so 60000*5 since PAWN deals in milliseconds). This:

pawn Код:
CreateVehicle(vid, curX+1, curY+1, curZ, curR, color1, color2, -1);
Should become:

pawn Код:
CreateVehicle(vid, curX+1, curY+1, curZ, curR, color1, color2, 60000*5);
Here's a hint for the future, double-check the function's your using with the Wiki page to make sure there aren't any arguments to do what you want!
Reply
#5

Correcet me if I am wrong, but won't this just respawn the cars? Or will it actually remove them?
Reply
#6

Just DestroyVehicle when they respawn (OnVehicleSpawn)
Reply
#7

pawn Код:
/*
Parameters:
--------------------------------------------------------------------------
(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
modelid The model for the vehicle.
Float:X The X coordinate for the vehicle.
Float:Y The Y coordinate for the vehicle.
Float:Z The Z coordinate for the vehicle.
Float:angle The facing angle for the vehicle.
color1  The primary color ID.
color2  The secondary color ID.

respawn_delay   The delay until the car is respawned without a driver in seconds.

#from Wiki_Samp*/
Код:
respawn_delay	The delay until the car is respawned without a driver in seconds.
= CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60);
60 = 60seconds (one minutes)
So yes, it's will be respawned.
Reply
#8

Well, if I had it like tihs
pawn Код:
OnVehicleSpawn(vehicleid)
{
 destroyvehicle(vehicleid);
}
That will destroy each vehicle every time it spawns, so every time I used "/v" to spawn a car, it would just disappear. Right?
Reply
#9

Quote:
Originally Posted by thegreathom
Посмотреть сообщение
pawn Код:
/*
Parameters:
--------------------------------------------------------------------------
(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay)
modelid The model for the vehicle.
Float:X The X coordinate for the vehicle.
Float:Y The Y coordinate for the vehicle.
Float:Z The Z coordinate for the vehicle.
Float:angle The facing angle for the vehicle.
color1  The primary color ID.
color2  The secondary color ID.

respawn_delay   The delay until the car is respawned without a driver in seconds.

#from Wiki_Samp*/
Код:
respawn_delay	The delay until the car is respawned without a driver in seconds.
= CreateVehicle(520, 2109.1763, 1503.0453, 32.2887, 82.2873, 0, 1, 60);
60 = 60seconds (one minutes)
So yes, it's will be respawned.
That is what I thought, I don't want it respawned, it want it destroyed.
Reply
#10

Quote:
Originally Posted by Nathan_Taylor
Посмотреть сообщение
Well, if I had it like tihs
pawn Код:
OnVehicleSpawn(vehicleid)
{
 destroyvehicle(vehicleid);
}
That will destroy each vehicle every time it spawns, so every time I used "/v" to spawn a car, it would just disappear. Right?
No. If you had checked the wiki page for OnVehicleSpawn you would know that it gets called when a vehicle respawns, not when it is created
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)