-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathspawnselect_client.lua
More file actions
112 lines (102 loc) · 3.88 KB
/
spawnselect_client.lua
File metadata and controls
112 lines (102 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
--[[
Author: Thunderstorm441
https://github.com/Thunderstorm441/ts_spawnselect
]]--
--CONFIG
-- spawnX, spawnY, spawnZ are the coordinates at which the player will spawn. camX, camY, camZ are the coordinates at which the camera will be.
local spawnPoints = {
{name="Airport", spawnX=-1041.62,spawnY=-2737.6,spawnZ=13.8371,camX=-943.909,camY=-2709.79,camZ=51.3575},
{name="Pier", spawnX=-1845.17,spawnY=-1195.38,spawnZ=19.18,camX=-1959.24,camY=-1289.54,camZ=74.8558},
{name="Tequi-la-la", spawnX=-566.2,spawnY=295.83,spawnZ=83.03,camX=-521.855,camY=222.185,camZ=98.2189},
{name="Legion Square", spawnX=178.1,spawnY=-940.43,spawnZ=30.1,camX=80.1,camY=-1019.57,camZ=92.1},
{name="Sandy Shores", spawnX=1860.68,spawnY=3851.2,spawnZ=32.99,camX=1939.992,camY=3842.664,camZ=68.86},
{name="Paleto Bay", spawnX=-150.53,spawnY=6416.903,spawnZ=31.91,camX=-222.438,camY=6429.05,camZ=65.16},
}
local openOnPlayerSpawned = true --set to false if you do not want the menu to open on first spawn
--END OF CONFIG
local selectedSpawnPoint = 1
local spawnPointNames = {}
local firstSpawn = true
_menuPool = MenuPool.New()
spawnSelectMenu = UIMenu.New("Spawn", "~b~Select a spawnpoint", 1350, 0)
_menuPool:Add(spawnSelectMenu)
_menuPool:ControlDisablingEnabled(true)
_menuPool:MouseControlsEnabled(false)
function createLocationList(data)
for k, v in pairs(data) do
table.insert(spawnPointNames, v.name)
end
end
function addLocations(menu)
local locationItem = UIMenuListItem.New("Location", spawnPointNames, 1)
menu:AddItem(locationItem)
menu.OnListChange = function(sender, item, index)
if locationItem == item then
selectedSpawnPoint = index
drawCam(index)
end
end
end
function addSpawnButton(menu)
local spawnButton = UIMenuItem.New("Spawn", "Confirm Location Selection And Spawn.")
menu:AddItem(spawnButton)
menu.OnItemSelect = function(sender, item, index)
if item == spawnButton then
spawnPlayer()
end
end
end
function drawCam(index)
local playerPed = GetPlayerPed(-1)
local spawnCam = CreateCam("DEFAULT_SCRIPTED_CAMERA", true)
SetCamFov(spawnCam, 90.0)
RenderScriptCams(true, true, 3, 1, 0)
DoScreenFadeOut(800)
while not IsScreenFadedOut() do
Citizen.Wait(100)
end
SetEntityCoords(playerPed, spawnPoints[index].spawnX, spawnPoints[index].spawnY, spawnPoints[index].spawnZ)
SetCamCoord(spawnCam, spawnPoints[index].camX, spawnPoints[index].camY, spawnPoints[index].camZ)
PointCamAtCoord(spawnCam, spawnPoints[index].spawnX, spawnPoints[index].spawnY, spawnPoints[index].spawnZ)
DoScreenFadeIn(800)
end
function setupPlayer()
SetEntityVisible(GetPlayerPed(-1), false)
SetPlayerInvincible(PlayerId(), true)
FreezeEntityPosition(GetPlayerPed(-1), true)
spawnSelectMenu:Visible(true)
end
function spawnPlayer()
DoScreenFadeOut(800)
while not IsScreenFadedOut() do
Citizen.Wait(100)
end
SetEntityVisible(GetPlayerPed(-1), true)
SetPlayerInvincible(PlayerId(), false)
FreezeEntityPosition(GetPlayerPed(-1), false)
RenderScriptCams(false, false, 3, 1, 0)
DestroyAllCams(true)
spawnSelectMenu:Visible(false)
DoScreenFadeIn(800)
end
AddEventHandler('playerSpawned', function(spawn)
if firstSpawn and openOnPlayerSpawned then
TriggerEvent("ts_spawnselect:openMenu")
firstSpawn = false
end
end)
RegisterNetEvent("ts_spawnselect:openMenu")
AddEventHandler("ts_spawnselect:openMenu", function()
createLocationList(spawnPoints)
addLocations(spawnSelectMenu)
addSpawnButton(spawnSelectMenu)
_menuPool:RefreshIndex()
setupPlayer()
drawCam(1)
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
_menuPool:ProcessMenus()
end
end)