Veichle despawn

How do I make it so if a player exits a veichle, for example the sports car, the veichle despawns after 15 seconds, but if the player re enter the veichle, it is no long set to despawn.

Here is an example:

After the player exits the vehicle, add a delay node that’s set to 15s. Then add a check if the player entered the vehicle again, if they did - don’t despawn the vechile, but if they didnt reenter the vehicle despawn it.

how do i get to that menu?

Hey @UEFN_LOVER how are you?

If you are using Unreal Engine, you need to add the nodes suggested by @XxpiingyxX to your vehicle blueprint. But if you are using UEFN with Verse, you won’t be able to use blueprints to do this.

If UEFN is your engine, you will need to use Verse with the following code:


using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }

# Custom device that destroys a spawned vehicle after a delay
# when the relevant player exits it.
vehicle_destroy_device := class(creative_device):

    # Reference to the vehicle spawner device
    @editable
    Vehicle : vehicle_spawner_nitro_drifter_sedan_device = vehicle_spawner_nitro_drifter_sedan_device{}

    # Timer used to delay the destruction of the vehicle
    @editable
    Timer : timer_device = timer_device{}

    # Time (in seconds) before the vehicle is destroyed
    @editable
    TimeToDestroy : float = 5.0

    # Team allowed to interact with the destruction logic
    @editable
    VehicleTeam : int = 1

    # Enables or disables team checking
    @editable
    UseTeam : logic = true

    # Runs when the device is started in a running game
    OnBegin<override>()<suspends>:void=

        # Subscribe to vehicle enter/exit events
        Vehicle.AgentEntersVehicleEvent.Subscribe(OnPlayerEntersVehicle)
        Vehicle.AgentExitsVehicleEvent.Subscribe(OnPlayerExitsVehicle)

        # Subscribe to the timer completion event
        Timer.SuccessEvent.Subscribe(OnTimerFinished)

    # Called when a player enters the vehicle
    OnPlayerEntersVehicle( Agent : agent ) : void =

        # If team filtering is enabled
        if ( UseTeam = true ):
            # Get the player's team
            PlayersTeam : int = GetPlayerTeam(Agent)
            # If the player belongs to the configured team
            if ( PlayersTeam = VehicleTeam ):
                # Stop the destruction timer
                Timer.Reset()
                Timer.Pause()
        else:
            # Stop the destruction timer regardless of team
            Timer.Reset()
            Timer.Pause()

    # Called when a player exits the vehicle
    OnPlayerExitsVehicle( Agent : agent ) : void =
        # If team filtering is enabled
        if ( UseTeam = true ):
            # Get the player's team
            PlayersTeam : int = GetPlayerTeam(Agent)
            # If the player belongs to the configured team
            if ( PlayersTeam = VehicleTeam ):
                # Start the timer that will destroy the vehicle
                Timer.SetActiveDuration(TimeToDestroy)
                Timer.Start()
        else:
            # Start the destruction timer regardless of team
            Timer.SetActiveDuration(TimeToDestroy)
            Timer.Start()

    # Called when the timer finishes
    OnTimerFinished( Agent : ?agent ) : void =
        # Destroy the currently spawned vehicle
        Vehicle.DestroyVehicle()

    # Returns the team index of a player
    GetPlayerTeam( Player : agent ) : int =
        var PlayersTeamInt : int = 0
        # Get the playspace team collection
        TeamCollection := GetPlayspace().GetTeamCollection() 
            # Get the player's team object
            if ( PlayersTeam := TeamCollection.GetTeam[Player] ):
                Teams := TeamCollection.GetTeams()
                # Find the index of the team in the team array
                for (I := 0..Teams.Length - 1):
                    if ( PlayersTeam = Teams[I] ):
                        set PlayersTeamInt = I+1
        # Returns the current player's team with type Int
        return PlayersTeamInt

Each part of the code is explained with comments, but let me clarify some aspects:

  1. If you are putting more than one vehicle in your Island, you will need to add one device for each vehicle and configure it accordingly with its timer, vehicle spawner, etc.

  2. With this exact code, you can only use the Nitro Drifter car. If you want to use different vehicles, you will need to create a new device for each type of them, as you cannot use the “vehicle_spawner_device” type for this. Here is the list of vehicles you can use:

    # Spawns a lightweight vehicle made for defying gravity with its rocket boosting, jumping, and aerial maneuverability capabilities.
    vehicle_spawner_octane_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows a Hammerhead Choppa to be configured and spawned.
    vehicle_spawner_hammerhead_choppa_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows an armored battle bus to be configured and spawned.
    vehicle_spawner_armored_battle_bus_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows a dirtbike to be configured and spawned.
    vehicle_spawner_dirtbike_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows a helicopter to be configured and spawned.
    vehicle_spawner_helicopter_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows a UFO to be configured and spawned.
    vehicle_spawner_ufo_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows an anti-vehicle turret to be configured and spawned.
    vehicle_spawner_heavy_turret_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows a siege cannon to be configured and spawned.
    vehicle_spawner_siege_cannon_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows a Nitro Drifter sedan to be configured and spawned.
    vehicle_spawner_nitro_drifter_sedan_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows a sportbike to be configured and spawned.
    vehicle_spawner_sportbike_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows a valet SUV to be configured and spawned.
    vehicle_spawner_valet_suv_device<public> := class<concrete><final>(vehicle_spawner_device):

    # Specialized `vehicle_spawner_device` that allows a tank to be configured and spawned.
    vehicle_spawner_tank_device<public> := class<concrete><final>(vehicle_spawner_device):

You only need to replace the type of your “Vehicle” variable for the type you want to use.

For example, the variable is now of type “vehicle_spawner_nitro_drifter_sedan_device”, but if you want to use the Hammerhead Choppa instead, you need to replace it by “vehicle_spawner_hammerhead_choppa_device”.

  1. In addition to the base functionality, I added an option to make it work for a specific team that you can enable/dissable by checking/unchecking the “Use Team” variable.

This is hwo it should look in your Island:

And this is how it works:

Hope this helps you! Let me know if you need more help with this!

2 Likes

does every one see the hud countdown or is it just the player that has left the car?

Hello again @UEFN_LOVER !

Sorry for the delay!

If you want to show the timer only for the corresponding team, you can configure that direcly on the timer itself, you don’t need Verse for that!

To do that, go to your Timer’s details and set the “Activating Team” option to “Team Index” and indicate the corresponding team number:

If you want to do it by player, you will need to use Verse to create a “map” variable to store the vehicle’s owner player.

Hope this helps you!!

And please, don’t forget to mark my previos answer as “Solution”! Thank you!