[Release] SpawnSelector

Hello,

Today I am going to realease my Spawnselector.
I originally made it for some mili-sim projects I was or am part of, but I reworked it over the past few months, gave it some new functionalities and I think it is time for me to release it.
This is one of my first ever scripts, so it is not very optimized and the code is probably pretty messed up.
But it works. I am going to try and fix some of the bugs that are currently in.
It is not very user freindly, so if you are not familiar with NativeUI or scripting it might be a bit compicated to edit the spawn points. I tried to add as many comments on how to edit the spawnselector tho.

The SpawnSelector looks like this

Uppon opening the menu, you find yourself in a default camera and see all the different spawn points.
The original way of entering the selector as by joining the server. But I also added some other ways of opening it, wich you can find in the client.lua. You just have to uncomment them.

There is also a command, wich allows you to open the selector at any time.

After you clicked on your desired spawn point, the camera changes and you will see a comfirmation menu.

By clicking β€œYes”, you spawn at the location you chose, and by clicking β€œNo”, you will go back to the main menu.

NOTE: The menu banner is not included in here

If you want to download it, here you go:
SpawnSelector.zip (3.7 KB)
Hope I didnt forget anything.

Requirements are:
[Release][Dev] NativeUILua - FiveM Resource Development & Modding / Releases - Cfx.re Community

I hope you have fun with this, and that there are not too many problems.
Please do not re-release it, at least not without linking the original post. (This one)

4 Likes

As his friend and colleague in Developing, I can say the script is worth it!

2 Likes

You have not put the code on GitHub, so I cannot make a Pull Request, but I would suggest looking into loops. There is a lot of duplicate lines in this code, which is not inherently bad, but you can save yourself some time by, for example, storing: the name and description of the spawn, the coordinates of the spawn, the heading, and the camera position, inside a table, and then iterate (loop) over the table to first execute all your CreateItems, and then your AddItems. Finally, if the values were inside a table, you would not need all the ifs inside your mainMenu.OnItemSelect and SetCamera(), you could just do something like:

if myTable[item] ~= nil then
    mainMenu:Visible(false)
    Citizen.Wait(100)
    DoScreenFadeOut(1000)
    Citizen.Wait(1000)
    SetCamera(item)
    Citizen.Wait(100)
    DoScreenFadeIn(1000)
    Citizen.Wait(100)
    ConfirmationMenu:Visible(true)
end

And then inside SetCamera(), something like:

status = true
SetEntityVisible(player, false, 0)
FreezeEntityPosition(player, true)
SetEntityCoordsNoOffset(player, myTable[item].spawnCoords, false, false, false, true)
SetEntityHeading(player, myTable[item].spawnHeading)
SetCamCoord(cam, myTable[item].cameraCoords)
PointCamAtEntity(cam, player)
RenderScriptCams(1, 0, 0, 1, 1)