Skip to content

Commit f03b986

Browse files
committed
Update v2.4.7
1 parent b0a0b33 commit f03b986

24 files changed

+837
-154
lines changed

client/functions/disconnectlogger.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ local display = function(data)
5252
end
5353
end)
5454
end
55-
RegisterNetEvent('msk_core:anticombatlog', display)
55+
RegisterNetEvent('msk_core:discLogger', display)

client/functions/entities.lua

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
GetEntities = function(isPlayerEntity)
2+
local entities = {}
3+
4+
if isPlayerEntity then
5+
for _, player in ipairs(GetActivePlayers()) do
6+
local ped = GetPlayerPed(player)
7+
8+
if DoesEntityExist(ped) and ped ~= PlayerPedId() then
9+
entities[player] = ped
10+
end
11+
end
12+
else
13+
entities = GetGamePool('CVehicle')
14+
end
15+
16+
return entities
17+
end
18+
19+
GetClosestEntity = function(isPlayerEntity, coords)
20+
local closestEntity, closestDistance = -1, -1
21+
local entites = GetEntities(isPlayerEntity)
22+
23+
if coords then
24+
coords = vector3(coords.x, coords.y, coords.z)
25+
else
26+
coords = GetEntityCoords(PlayerPedId())
27+
end
28+
29+
for k, entity in pairs(entites) do
30+
local distance = #(coords - GetEntityCoords(entity))
31+
32+
if closestDistance == -1 or distance <= closestDistance then
33+
closestEntity, closestDistance = isPlayerEntity and k or entity, distance
34+
end
35+
end
36+
37+
return closestEntity, closestDistance
38+
end
39+
40+
GetClosestEntities = function(isPlayerEntity, coords, distance)
41+
local entites = GetEntities(isPlayerEntity)
42+
local closestEntities = {}
43+
44+
if coords then
45+
coords = vector3(coords.x, coords.y, coords.z)
46+
else
47+
coords = GetEntityCoords(PlayerPedId())
48+
end
49+
50+
for k, entity in pairs(entites) do
51+
local dist = #(coords - GetEntityCoords(entity))
52+
53+
if dist <= distance then
54+
closestEntities[#closestEntities + 1] = isPlayerEntity and k or entity
55+
end
56+
end
57+
58+
return closestEntities
59+
end
60+
61+
PlayerDied = function(deathCause, killer, killerServerId)
62+
local playerPed = PlayerPedId()
63+
local playerCoords = GetEntityCoords(playerPed)
64+
65+
local data = {
66+
killedByPlayer = false,
67+
victim = playerPed,
68+
victimCoords = playerCoords,
69+
victimServerId = GetPlayerServerId(PlayerId())
70+
}
71+
72+
if killer and killerServerId then
73+
local killerPed = GetPlayerPed(killer)
74+
local killerCoords = GetEntityCoords(killerPed)
75+
local dist = #(playerCoords - killerCoords)
76+
77+
data.killedByPlayer = true
78+
data.killer = killerPed
79+
data.killerCoords = killerCoords
80+
data.killerServerId = killerServerId
81+
data.distance = MSK.Math.Round(dist, 2)
82+
end
83+
84+
TriggerEvent('msk_core:onPlayerDeath', data)
85+
TriggerServerEvent('msk_core:onPlayerDeath', data)
86+
end
87+
88+
AddEventHandler('gameEventTriggered', function(event, data)
89+
if event == 'CEventNetworkEntityDamage' then
90+
local entity, model = data[1], data[7]
91+
92+
if IsEntityAPed(entity) and IsPedAPlayer(entity) then
93+
local playerPed = entity
94+
local playerDied = data[4]
95+
96+
if playerDied and NetworkGetPlayerIndexFromPed(playerPed) == PlayerId() and (IsPedDeadOrDying(playerPed, true) or IsPedFatallyInjured(playerPed)) then
97+
local deathCause, killerEntity = GetPedCauseOfDeath(playerPed), GetPedSourceOfDeath(playerPed)
98+
local killer = NetworkGetPlayerIndexFromPed(killerEntity)
99+
100+
if killerEntity ~= playerPed and killer and NetworkIsPlayerActive(killer) then
101+
PlayerDied(deathCause, killer, GetPlayerServerId(killer))
102+
else
103+
PlayerDied(deathCause)
104+
end
105+
end
106+
elseif IsEntityAVehicle(entity) then
107+
local vehicle = entity
108+
109+
-- Do something with the vehicle...
110+
end
111+
end
112+
end)

client/functions/input.lua

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
MSK.Input = {}
2+
13
local isInputOpen = false
24
local callback = nil
35

4-
MSK.Input = function(header, placeholder, field, cb)
6+
MSK.Input.Open = function(header, placeholder, field, cb)
57
if isInputOpen then return end
6-
logging('debug', 'MSK.Input')
78
isInputOpen = true
89
callback = cb
910
if not callback then callback = field end
@@ -27,38 +28,44 @@ MSK.Input = function(header, placeholder, field, cb)
2728
return result
2829
end
2930
end
30-
exports('Input', MSK.Input)
31-
exports('openInput', MSK.Input) -- Support for old Scripts
31+
exports('Input', MSK.Input.Open)
32+
exports('openInput', MSK.Input.Open) -- Support for old Scripts
33+
34+
-- Support for old Scripts
35+
setmetatable(MSK.Input, {
36+
__call = function(_, header, placeholder, field, cb)
37+
return MSK.Input.Open(header, placeholder, field, cb)
38+
end
39+
})
3240

33-
MSK.CloseInput = function()
34-
logging('debug', 'MSK.CloseInput')
41+
MSK.Input.Close = function()
3542
isInputOpen = false
3643
callback = nil
3744
SetNuiFocus(false, false)
3845
SendNUIMessage({
3946
action = 'closeInput'
4047
})
4148
end
42-
exports('CloseInput', MSK.CloseInput)
43-
exports('closeInput', MSK.CloseInput) -- Support for old Scripts
44-
RegisterNetEvent('msk_core:closeInput', MSK.CloseInput)
49+
MSK.CloseInput = MSK.Input.Close -- Support for old Scripts
50+
exports('CloseInput', MSK.Input.Close)
51+
RegisterNetEvent('msk_core:closeInput', MSK.Input.Close)
4552

4653
MSK.Register('msk_core:input', function(source, header, placeholder, field)
47-
return MSK.Input(header, placeholder, field)
54+
return MSK.Input.Open(header, placeholder, field)
4855
end)
4956

5057
RegisterNUICallback('submitInput', function(data)
5158
if data.input == '' then data.input = nil end
5259
if tonumber(data.input) then data.input = tonumber(data.input) end
5360
callback(data.input)
54-
MSK.CloseInput()
61+
MSK.Input.Close()
5562
end)
5663

5764
RegisterNUICallback('closeInput', function(data)
58-
MSK.CloseInput()
65+
MSK.Input.Close()
5966
end)
6067

6168
AddEventHandler('onResourceStop', function(resource)
6269
if GetCurrentResourceName() ~= resource then return end
63-
MSK.CloseInput()
70+
MSK.Input.Close()
6471
end)

client/functions/main.lua

+11-38
Original file line numberDiff line numberDiff line change
@@ -167,32 +167,6 @@ MSK.HasItem = function(item)
167167
end
168168
exports('HasItem', MSK.HasItem)
169169

170-
MSK.GetVehicleInDirection = function()
171-
local playerPed = PlayerPedId()
172-
local playerCoords = GetEntityCoords(playerPed)
173-
local inDirection = GetOffsetFromEntityInWorldCoords(playerPed, 0.0, 5.0, 0.0)
174-
local rayHandle = StartExpensiveSynchronousShapeTestLosProbe(playerCoords, inDirection, 10, playerPed, 0)
175-
local numRayHandle, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(rayHandle)
176-
177-
if hit == 1 and GetEntityType(entityHit) == 2 then
178-
local entityCoords = GetEntityCoords(entityHit)
179-
local entityDistance = #(playerCoords - entityCoords)
180-
return entityHit, entityCoords, entityDistance
181-
end
182-
183-
return nil
184-
end
185-
exports('GetVehicleInDirection', MSK.GetVehicleInDirection)
186-
187-
MSK.IsVehicleEmpty = function(vehicle)
188-
assert(vehicle and DoesEntityExist(vehicle), 'Parameter "vehicle" is nil or the Vehicle does not exist')
189-
local passengers = GetVehicleNumberOfPassengers(vehicle)
190-
local driverSeatFree = IsVehicleSeatFree(vehicle, -1)
191-
192-
return passengers == 0 and driverSeatFree
193-
end
194-
exports('IsVehicleEmpty', MSK.IsVehicleEmpty)
195-
196170
MSK.IsSpawnPointClear = function(coords, maxDistance)
197171
local nearbyVehicles = {}
198172

@@ -214,17 +188,6 @@ MSK.IsSpawnPointClear = function(coords, maxDistance)
214188
end
215189
exports('IsSpawnPointClear', MSK.IsSpawnPointClear)
216190

217-
MSK.GetPedVehicleSeat = function(ped, vehicle)
218-
if not ped then ped = PlayerPedId() end
219-
if not vehicle then GetVehiclePedIsIn(ped, false) end
220-
221-
for i = -1, 16 do
222-
if (GetPedInVehicleSeat(vehicle, i) == ped) then return i end
223-
end
224-
return -1
225-
end
226-
exports('GetPedVehicleSeat', MSK.GetPedVehicleSeat)
227-
228191
MSK.GetPedMugshot = function(ped, transparent)
229192
assert(ped and DoesEntityExist(ped), 'Parameter "ped" is nil or the PlayerPed does not exist')
230193
local mugshot = transparent and RegisterPedheadshotTransparent(ped) or RegisterPedheadshot(ped)
@@ -282,4 +245,14 @@ MSK.LoadModel = function(modelHash)
282245
end
283246
end
284247
end
285-
exports('LoadModel', MSK.LoadModel)
248+
exports('LoadModel', MSK.LoadModel)
249+
250+
MSK.GetClosestPlayer = function(coords)
251+
return GetClosestEntity(true, coords)
252+
end
253+
exports('GetClosestPlayer', MSK.GetClosestPlayer)
254+
255+
MSK.GetClosestPlayers = function(coords, distance)
256+
return GetClosestEntities(true, coords, distance)
257+
end
258+
exports('GetClosestPlayers', MSK.GetClosestPlayers)

client/functions/numpad.lua

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
MSK.Numpad = {}
2+
13
local isNumpadOpen = false
24
local callback = nil
35

4-
MSK.Numpad = function(pin, show, cb)
6+
MSK.Numpad.Open = function(pin, show, cb)
57
if isNumpadOpen then return end
6-
logging('debug', 'MSK.Numpad')
78
isNumpadOpen = true
89
callback = cb
910

@@ -28,35 +29,43 @@ MSK.Numpad = function(pin, show, cb)
2829
return result
2930
end
3031
end
31-
exports('Numpad', MSK.Numpad)
32+
exports('Numpad', MSK.Numpad.Open)
33+
34+
-- Support for old Scripts
35+
setmetatable(MSK.Numpad, {
36+
__call = function(_, pin, show, cb)
37+
-- Ruft MSK.Numpad.Open auf, wenn MSK.Numpad() aufgerufen wird
38+
return MSK.Numpad.Open(pin, show, cb)
39+
end
40+
})
3241

33-
MSK.CloseNumpad = function()
34-
logging('debug', 'MSK.CloseNumpad')
42+
MSK.Numpad.Close = function()
3543
isNumpadOpen = false
3644
callback = nil
3745
SetNuiFocus(false, false)
3846
SendNUIMessage({
3947
action = 'closeNumpad'
4048
})
4149
end
42-
exports('CloseNumpad', MSK.CloseNumpad)
43-
RegisterNetEvent('msk_core:closeNumpad', MSK.CloseNumpad)
50+
MSK.CloseNumpad = MSK.Numpad.Close
51+
exports('CloseNumpad', MSK.Numpad.Close)
52+
RegisterNetEvent('msk_core:closeNumpad', MSK.Numpad.Close)
4453

4554
MSK.Register('msk_core:numpad', function(source, pin, show)
46-
return MSK.Numpad(pin, show)
55+
return MSK.Numpad.Open(pin, show)
4756
end)
4857

4958
RegisterNUICallback('submitNumpad', function(data)
5059
callback(true)
51-
MSK.CloseNumpad()
60+
MSK.Numpad.Close()
5261
end)
5362

5463
RegisterNUICallback('closeNumpad', function()
55-
MSK.CloseNumpad()
64+
MSK.Numpad.Close()
5665
end)
5766

5867
AddEventHandler('onResourceStop', function(resource)
5968
if GetCurrentResourceName() ~= resource then return end
60-
MSK.CloseNumpad()
69+
MSK.Numpad.Close()
6170
end)
6271

client/functions/showCoords.lua

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1-
local showCoords = false
1+
MSK.Coords = {}
22

3-
MSK.ShowCoords = function()
4-
showCoords = not showCoords
3+
local showCoords = false
54

5+
MSK.Coords.Show = function()
66
if showCoords then
7-
CreateThread(startShowCoordsThread)
7+
showCoords = false
8+
return
89
end
10+
11+
showCoords = true
12+
CreateThread(startShowCoordsThread)
913
end
10-
exports('ShowCoords', MSK.ShowCoords)
11-
RegisterNetEvent('msk_core:showCoords', MSK.ShowCoords)
14+
MSK.ShowCoords = MSK.Coords.Show -- Support for old Scripts
15+
exports('ShowCoords', MSK.Coords.Show)
16+
RegisterNetEvent('msk_core:showCoords', MSK.Coords.Show)
1217

13-
MSK.DoesShowCoords = function()
18+
MSK.Coords.Active = function()
1419
return showCoords
1520
end
16-
exports('DoesShowCoords', MSK.DoesShowCoords)
21+
MSK.DoesShowCoords = MSK.Coords.Active -- Support for old Scripts
22+
exports('CoordsActive', MSK.Coords.Active)
23+
exports('DoesShowCoords', MSK.Coords.Active) -- Support for old Scripts
24+
25+
MSK.Coords.Hide = function()
26+
showCoords = false
27+
end
28+
exports('HideCoords', MSK.Coords.Hide)
29+
RegisterNetEvent('msk_core:hideCoords', MSK.Coords.Hide)
1730

1831
MSK.Register('msk_core:doesShowCoords', function(source)
1932
return showCoords
@@ -39,7 +52,7 @@ startShowCoordsThread = function()
3952
local playerX, playerY, playerZ = table.unpack(GetEntityCoords(playerPed))
4053
local playerH = GetEntityHeading(playerPed)
4154

42-
DrawGenericText(("~g~X~w~ = ~r~%s ~g~Y~w~ = ~r~%s ~g~Z~w~ = ~r~%s ~g~H~w~ = ~r~%s~s~"):format(MSK.Round(playerX, 2), MSK.Round(playerY, 2), MSK.Round(playerZ, 2), MSK.Round(playerH, 2)))
55+
DrawGenericText(("~g~X~w~ = ~r~%s ~g~Y~w~ = ~r~%s ~g~Z~w~ = ~r~%s ~g~H~w~ = ~r~%s~s~"):format(MSK.Math.Round(playerX, 2), MSK.Math.Round(playerY, 2), MSK.Math.Round(playerZ, 2), MSK.Math.Round(playerH, 2)))
4356

4457
Wait(sleep)
4558
end

0 commit comments

Comments
 (0)