-
Notifications
You must be signed in to change notification settings - Fork 17
/
cl_utils.lua
157 lines (117 loc) · 3.85 KB
/
cl_utils.lua
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
Utils = {}
local function WaitForModel(model)
if IsModelValid(model) then
RequestModel(model)
while not HasModelLoaded(model) do
Wait(0)
end
end
end
function Utils.CreatePed(model, pedType, pos, heading)
if IsModelAPed(model) then
WaitForModel(model)
local ped = CreatePed(pedType, model, pos.x, pos.y, pos.z, heading, true)
SetModelAsNoLongerNeeded(model)
return ped
end
end
function Utils.CreateVehicle(model, pos, heading)
if IsModelAVehicle(model) then
WaitForModel(model)
local veh = CreateVehicle(model, table.unpack(pos), heading, true)
SetModelAsNoLongerNeeded(model)
return veh
end
end
function Utils.CreateProp(model, pos, dynamic, placeOnGround)
if IsModelValid(model) then
WaitForModel(model)
local x, y, z = table.unpack(pos)
local prop = CreateObject(model, x, y, GetGroundZFor_3dCoord(x, y, z), true, false, dynamic)
SetModelAsNoLongerNeeded(model)
return prop
end
end
function Utils.GetDistanceBetweenCoords(pos1, pos2)
return math.abs(#pos1 - #pos2)
end
function Utils.GetRandomPosOffsetFromEntity(entity, minDistance, maxDistance)
local angle = math.random() * math.pi * 2
local r = math.sqrt(math.random()) * maxDistance
local x = r * math.cos(angle)
local y = r * math.sin(angle)
return GetOffsetFromEntityInWorldCoords(entity, x, y, 0.0)
end
function Utils.FindGoodSpawnPos(minDistance)
local goodSpawnFound = false
local maxDistance = Config.Spawning.Zombies.DESPAWN_DISTANCE
local newPos
local mPlayerPedId = PlayerPedId()
local tries = 5
while not goodSpawnFound do
goodSpawnFound = true
newPos = Utils.GetRandomPosOffsetFromEntity(mPlayerPedId, minDistance, maxDistance)
if not newPos then
goodSpawnFound = false
tries = tries - 1
else
for _, playerId in ipairs(GetActivePlayers()) do
if Utils.GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(playerId)), newPos) < minDistance then
goodSpawnFound = false
tries = tries - 1
break
end
end
end
if tries == 0 then
return nil
end
end
return newPos
end
function Utils.ZToGround(pos)
local found, z = GetGroundZFor_3dCoord(table.unpack(pos))
if found then
return z
end
end
function Utils.IsPosNearAPlayer(pos, maxDistance)
local nearbyPlayer = false
for _, playerId in ipairs(GetActivePlayers()) do
if Utils.GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(playerId)), pos) < maxDistance then
nearbyPlayer = true
break
end
end
return nearbyPlayer
end
function Utils.GetRandomPlayer()
return math.random(#GetActivePlayers())
end
function Utils.CreateLoadedInThread(func)
Citizen.CreateThread(function()
while not NetworkIsSessionActive() do
Wait(100)
end
func()
end)
end
function Utils.LoadInteriors()
RequestIpl("shr_int")
local PDM = GetInteriorAtCoords(-59.7936, -1098.784, 27.2612)
LoadInterior(PDM)
while not IsInteriorReady(PDM) do
Wait(0)
end
EnableInteriorProp(PDM, "csr_beforeMission")
EnableInteriorProp(PDM, "shutter_closed")
RefreshInterior(PDM)
RequestIpl("id2_14_during_door")
RequestIpl("id2_14_during1")
RequestIpl("sp1_10_real_interior")
RequestIpl("sp1_10_real_interior_lod")
RequestIpl("methtrailer_grp1")
RequestIpl("bkr_bi_hw1_13_int")
RequestIpl("RC12B_Destroyed")
RequestIpl("RC12B_HospitalInterior")
end