My issue/question is that VehicleSpawnedEvent does not give an Agent, of course. However, I need the agent to be able to set it back into the car. How would I be able to reference the agent?
Essentially it returns all the fort_characters in an array.
Here’s an example code that should get the fort characters from a vehicle, goes through the entire list and checks if they have a valid agent associated and if true runs the .Respawn() function on them
To explain further, in my project, I have 5 cars. The player needs to be in the car, always. They select a vehicle by going Into a class selector, and from that point forward the player needs to stay in the car. The car can be destroyed, so every time it respawns, it needs to put the player back into the car he selected.
I think for me the solution would be to assign the player to an ID, that ID is also linked to the vehicle. Then I would always be able to call the Player from anywhere.
In that case you should use a CustomPlayer class that you store in a map with
var CustomPlayers : [agent]CustomPlayer = map{}
Have a pool of vehicle spawners so you have enough for each player, and when players are added assign them a vehicle spawner from the pool that you store in your CustomPlayer class, along with any other assets or info you need to know for each character. You can subscribe to AgentEntersVehicleEvent, AgentExitsVehicleEvent, and Destroyed event to run logic on these events.
Hi, I have made a custom player/game manager script according to the video, but I still don’t know how I can get the player from the map.
What I’d need is a way to call a function that returns the player
If the players are stored in an array I could Assign every player to the array[0-4], and so calling the function would require an int that returns the player accordingly.
Not sure what you mean by get the player from the map. If you can share your code and what function you need the player for I can take a look. The vehicle events like AgentEntersVehicle and AgentExitsVehicle return an agent which is interchangeable with player, so you should be able to get what you need from those.
What I need, is to be able to put the agent into the car (SuvSpawner.AssignDriver(Agent) when the car respawns (VehicleSpawnedEvent). But when I call AssignDriver there is no agent, so I need to get the agent from somewhere.
What I think could be a solution is to store the agent into an array based on what car it got into, so let’s say you choose car 3 out of 5, it will store you in in array[2] (since the index starts at 0)
Would this be possible or do you have another solution in mind?
The code I’m referring to:
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
player_car_handler := class(creative_device):
@editable SuvSpawner : vehicle_spawner_valet_suv_device = vehicle_spawner_valet_suv_device{}
OnBegin<override>()<suspends>:void=
SuvSpawner.AgentExitsVehicleEvent.Subscribe(RespawnCar)
SuvSpawner.VehicleSpawnedEvent.Subscribe(PutPlayerIntoCar) # Puts player into car when spawned
RespawnCar(Agent : agent): void =
SuvSpawner.RespawnVehicle
PutPlayerIntoCar(): void =
SuvSpawner.AssignDriver(Agent) # Gives error since agent is not defined
First off if you want 5 players you’ll need 5 suv spawners as I suggested above, have a pool @editable SUVPool : []vehicle_spawner_valet_suv_device = array{}
As I also said above you’ll also need the CustomPlayer data class and an [agent]CustomPlayers map to track which is assigned to what player.
In my projects I have a Verse device Asset_Pool that stores all the devices needed in arrays like this, and then you have a function for CheckOut(id : int) and Return(id : int) that tracks the index of your array (if it is checked out) and assigns the asset to the CustomPlayer data. Here is what my customplayer looks like:
CustomPlayer:= class():
var Assets : PlayerAssets = PlayerAssets{}
var AssetsID : int = 0
FC : fort_character
var vehicle : ?vehicle_spawner_device = false
Once you figure out how to assign data and devices to players through a map you’ll be able to do all the things you’re looking for and more, it is a crucial part of learning Verse.
Also, as the VehicleSpawnedEvent does not pass an agent, you’ll want to call SuvSpawner.Respawn() manually in Verse somewhere you already have the Agent reference.
I will handle the respawning of the car myself, if the player dies it will respawn the car and put the player into the car again.
But one more question if you don’t mind , do you know how I can detect if the player has died? The elim manager only sends an event when another agent has killed the player. But in my case the player dies because of a damage barrier or the expotion of the car, so there is no other agent involved.
I tried looking at this function, but I don’t really know how I could use it. One thing I need is the agent that has died.
Another thing is that DestroyVehicle and RespawnVehicle from class vehicle_spawner_device do not work for me. Only AssignDriver does
My code (Modified for example):
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/Diagnostics }
player_car_handler := class(creative_device):
@editable SuvSpawner : vehicle_spawner_valet_suv_device = vehicle_spawner_valet_suv_device{}
@editable TestTrigger : trigger_device = trigger_device{}
OnBegin<override>()<suspends>:void=
SuvSpawner.AgentExitsVehicleEvent.Subscribe(RespawnCar)
TestTrigger.TriggeredEvent.Subscribe(PutPlayerIntoCar)
RespawnCar(Agent : agent): void =
Print("Respawning Vehicle")
SuvSpawner.DestroyVehicle # This does not work
SuvSpawner.RespawnVehicle # Also does not work
PutPlayerIntoCar(Agent : ?agent): void =
Print("Assing Player to car test")
if (TestAgent := Agent?):
SuvSpawner.AssignDriver(TestAgent) # Does work
You can take the Agent and do .GetFortCharacter, and with the fort character you can subscribe to EliminatedEvent. This returns an elimResult, then you can get result.EliminatedCharacter to get the character who died. The EliminatingCharacter is an optional so if a barrier killed the player it will return false