Hello everybody! I have trying but unfortunately I have been unable to get my code to work. I am new to Verse and programming in general. I have been following a bunch of tutorials to learn as much as I can. I have commented every step of the code to hopefully explain what I am trying to accomplish. I have included my code below.
If you have any questions please let me know! I appreciate any help I can get! Thanks!!
Hi Drew, Beautiful Code! Welcome to the Forums.
Consider pasting this code as text so people could easily copy.paste + experiment with it.
When writing a message you can click the settings cog and âHide Detailsâ (Also there is the ability to convert into âpreformatted textâ as well.
Summary
Really long block of code
Neat and tidy behind Hide Details
Ready for scraping and feeding into AI? :wink:
Thanks @Astrotronic! Here is the code!
Summary
using { /Fortnite.com/Devices }
using { /Fortnite.com/Characters }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /UnrealEngine.com/Temporary/SpatialMath }
# See https://dev.epicgames.com/documentation/en-us/uefn/create-your-own-device-in-verse for how to create a verse device.
# A Verse-authored creative device that can be placed in a level
test_code := class(creative_device):
# Commented out because I don't think I need to have this.
#@editable var TreeProp : creative_prop = creative_prop{}
@editable TreeAsset : creative_prop_asset = DefaultCreativePropAsset
# This is where you enter the size of game area
@editable var MinimumPositions : vector3 = vector3{}
@editable var MaximumPositions : vector3 = vector3{}
# In Editor you can adjust the Minimum and Maximum range for the Assets to be placed at OnBegin()
@editable var MinAssets : int = 0 #Set to 0 In Editor
@editable var MaxAssets : int = 0 #Set to 10 In Editor
@editable var NewScale : vector3 = vector3{}
# This works however... I would like to randomize NewPosition, NewRotation which affect all props, and I would like to beable to @editable the Scale for each Prop of all the differetnt types of Props Individually if I choose
# NewPosition : vector3 = vector3 { X := 250.0, Y := -1250.0, Z := 0.0}
# NewRotation : rotation = IdentityRotation()
# NewScale : vector3 = vector3 {X := 1.0, Y :=1.0, Z := 1.0}
# Runs when the device is started in a running game
# OnBegin<override>()<suspends>:void=
# # SpawnTree()
# SpawnProp(TreeAsset, transform{Translation := NewPosition, Rotation := NewRotation, Scale := NewScale})
# block:
RandomAsset() : void =
# Getting random number to know how many of each asset to spawn
AssetCount := GetRandomInt(MinAssets, MaxAssets)
# NewPosition() : void =
# # Getting RandomFloat to randomly place Assets
# RandX := GetRandomFloat(MinimumPositions.X, MaximumPositions.X)
# RandY := GetRandomFloat(MinimumPositions.Y, MaximumPositions.Y)
# RandZ := GetRandomFloat(MinimumPositions.Z, MaximumPositions.Z)
# NewPosition := vector3{X := RandX, Y:= RandY, Z :=RandZ }
# NewRotation() :void =
# RandomRotation := GetRandomFloat(0.0, 360.0) # Trying to get a random Number between 0 and 360 degrees. Should it start at 1?
# NewRotation : rotation = RandomRotation
# Print("RandomRotation Value: {NewRotation}")
<#
I want to have an @editable option for each type of prop so i can adjust the scale to exact value but also the option to put a range so it will randomly scale when an individual prop is spawned
NewScale() : void =
NewScale : vector3 = vector3 {X := 1.0, Y := 1.0, Z:=1.0}
#>
# This is an example of Spawning a tree and I would like to use this as a template for each type of prop I want to spawn. I want to check the random Asset count so if it is greater than 0 I want to continue calculating the location and rotation of the prop otherwise if it is zero I would like to skip to the next prop.
# SpawnTree() : void =
# loop:
# if (AssetCount > 0):
# # I commented this out because of the errors
# SpawnProp(TreeAsset, transform{Translation := NewPosition, Rotation := NewRotation, Scale := NewScale})
# else:
# return
#####
# HELP - Is this possible??
#####
# I would like to create a Play Area volume which is connected to the player that randomly moves around the island at the start of every game. Within the volume I would randomly spawn the props and any animals. Then after the round I would like all props to stay in their spawned spot until the game is over just in case you randomly move close by and see part of the area you were just playing in.
@JustDrewTV you can only have 100 props spawned at a time from a device, will this be enough for what you want here?
Cool, thanks for the information. Do you know where to find any piece of documentation covering this aspect of the editor? I didnât know and I stumbled here by chance.
In the /Fortnite.digest.verse file you can view the documentation comments for spawn_prop_result
:
Also worth noting if you spawn a prop with scale zero or lower it will return a
SpawnPointOutOfBounds
error.
Thank you so much, I didnât notice the comment at all!
That should be plenty! Right now I am thinking maybe 50 Max however may end up to be a lot less.
I was having a little look at your code snippet, but Iâm not totally clear on what youâre trying to do from the comments. You say itâs connected to the player, which I assumed to mean the spawn area translation would follow the playerâs translation, but you also say the spawn area moves randomly around the map. Did you intend for it to be tracking a player translation and spawning the objects around the player?
This may not work for your general needs, but if I were say hiding Easter eggs on an Island and I wanted to place them randomly for each round, Iâd make a bunch of hiding places using an âegg spotâ creative_object that was only visible in the editor. Then Iâd put them in an array and randomly display a given number each round. Finding suitable random points in real time may be more difficult.
That said, this approach doesnât work in every case.
Hopefully this will help explain what I am trying to do. I want to create a Buck Hunter Style Game. I want to have a basic island, which spawns the player in first person view and a static camera so the player only aims and does not physically move around. This is where I would like to randomly spawn props like trees, rocks, animals, etc. into the play area. This would make every game 100% random so every time you play it is different.
Ah I see, that makes sense! Does the spawn position randomization options provided on Wildlife Spawner Devices do what you want? A great benefit of that is it will use the nav mesh.
I think soâŚI had to look into everything the Wildlife Spawner Device does but I think it would work. Eventually I do want to import my own models however that would allow me to get everything else to work.