Skip to content

Commit

Permalink
Update v2.4.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Musiker15 committed Sep 22, 2024
1 parent b0a0b33 commit f03b986
Show file tree
Hide file tree
Showing 24 changed files with 837 additions and 154 deletions.
2 changes: 1 addition & 1 deletion client/functions/disconnectlogger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ local display = function(data)
end
end)
end
RegisterNetEvent('msk_core:anticombatlog', display)
RegisterNetEvent('msk_core:discLogger', display)
112 changes: 112 additions & 0 deletions client/functions/entities.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
GetEntities = function(isPlayerEntity)
local entities = {}

if isPlayerEntity then
for _, player in ipairs(GetActivePlayers()) do
local ped = GetPlayerPed(player)

if DoesEntityExist(ped) and ped ~= PlayerPedId() then
entities[player] = ped
end
end
else
entities = GetGamePool('CVehicle')
end

return entities
end

GetClosestEntity = function(isPlayerEntity, coords)
local closestEntity, closestDistance = -1, -1
local entites = GetEntities(isPlayerEntity)

if coords then
coords = vector3(coords.x, coords.y, coords.z)
else
coords = GetEntityCoords(PlayerPedId())
end

for k, entity in pairs(entites) do
local distance = #(coords - GetEntityCoords(entity))

if closestDistance == -1 or distance <= closestDistance then
closestEntity, closestDistance = isPlayerEntity and k or entity, distance
end
end

return closestEntity, closestDistance
end

GetClosestEntities = function(isPlayerEntity, coords, distance)
local entites = GetEntities(isPlayerEntity)
local closestEntities = {}

if coords then
coords = vector3(coords.x, coords.y, coords.z)
else
coords = GetEntityCoords(PlayerPedId())
end

for k, entity in pairs(entites) do
local dist = #(coords - GetEntityCoords(entity))

if dist <= distance then
closestEntities[#closestEntities + 1] = isPlayerEntity and k or entity
end
end

return closestEntities
end

PlayerDied = function(deathCause, killer, killerServerId)
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)

local data = {
killedByPlayer = false,
victim = playerPed,
victimCoords = playerCoords,
victimServerId = GetPlayerServerId(PlayerId())
}

if killer and killerServerId then
local killerPed = GetPlayerPed(killer)
local killerCoords = GetEntityCoords(killerPed)
local dist = #(playerCoords - killerCoords)

data.killedByPlayer = true
data.killer = killerPed
data.killerCoords = killerCoords
data.killerServerId = killerServerId
data.distance = MSK.Math.Round(dist, 2)
end

TriggerEvent('msk_core:onPlayerDeath', data)
TriggerServerEvent('msk_core:onPlayerDeath', data)
end

AddEventHandler('gameEventTriggered', function(event, data)
if event == 'CEventNetworkEntityDamage' then
local entity, model = data[1], data[7]

if IsEntityAPed(entity) and IsPedAPlayer(entity) then
local playerPed = entity
local playerDied = data[4]

if playerDied and NetworkGetPlayerIndexFromPed(playerPed) == PlayerId() and (IsPedDeadOrDying(playerPed, true) or IsPedFatallyInjured(playerPed)) then
local deathCause, killerEntity = GetPedCauseOfDeath(playerPed), GetPedSourceOfDeath(playerPed)
local killer = NetworkGetPlayerIndexFromPed(killerEntity)

if killerEntity ~= playerPed and killer and NetworkIsPlayerActive(killer) then
PlayerDied(deathCause, killer, GetPlayerServerId(killer))
else
PlayerDied(deathCause)
end
end
elseif IsEntityAVehicle(entity) then
local vehicle = entity

-- Do something with the vehicle...
end
end
end)
33 changes: 20 additions & 13 deletions client/functions/input.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
MSK.Input = {}

local isInputOpen = false
local callback = nil

MSK.Input = function(header, placeholder, field, cb)
MSK.Input.Open = function(header, placeholder, field, cb)
if isInputOpen then return end
logging('debug', 'MSK.Input')
isInputOpen = true
callback = cb
if not callback then callback = field end
Expand All @@ -27,38 +28,44 @@ MSK.Input = function(header, placeholder, field, cb)
return result
end
end
exports('Input', MSK.Input)
exports('openInput', MSK.Input) -- Support for old Scripts
exports('Input', MSK.Input.Open)
exports('openInput', MSK.Input.Open) -- Support for old Scripts

-- Support for old Scripts
setmetatable(MSK.Input, {
__call = function(_, header, placeholder, field, cb)
return MSK.Input.Open(header, placeholder, field, cb)
end
})

MSK.CloseInput = function()
logging('debug', 'MSK.CloseInput')
MSK.Input.Close = function()
isInputOpen = false
callback = nil
SetNuiFocus(false, false)
SendNUIMessage({
action = 'closeInput'
})
end
exports('CloseInput', MSK.CloseInput)
exports('closeInput', MSK.CloseInput) -- Support for old Scripts
RegisterNetEvent('msk_core:closeInput', MSK.CloseInput)
MSK.CloseInput = MSK.Input.Close -- Support for old Scripts
exports('CloseInput', MSK.Input.Close)
RegisterNetEvent('msk_core:closeInput', MSK.Input.Close)

MSK.Register('msk_core:input', function(source, header, placeholder, field)
return MSK.Input(header, placeholder, field)
return MSK.Input.Open(header, placeholder, field)
end)

RegisterNUICallback('submitInput', function(data)
if data.input == '' then data.input = nil end
if tonumber(data.input) then data.input = tonumber(data.input) end
callback(data.input)
MSK.CloseInput()
MSK.Input.Close()
end)

RegisterNUICallback('closeInput', function(data)
MSK.CloseInput()
MSK.Input.Close()
end)

AddEventHandler('onResourceStop', function(resource)
if GetCurrentResourceName() ~= resource then return end
MSK.CloseInput()
MSK.Input.Close()
end)
49 changes: 11 additions & 38 deletions client/functions/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -167,32 +167,6 @@ MSK.HasItem = function(item)
end
exports('HasItem', MSK.HasItem)

MSK.GetVehicleInDirection = function()
local playerPed = PlayerPedId()
local playerCoords = GetEntityCoords(playerPed)
local inDirection = GetOffsetFromEntityInWorldCoords(playerPed, 0.0, 5.0, 0.0)
local rayHandle = StartExpensiveSynchronousShapeTestLosProbe(playerCoords, inDirection, 10, playerPed, 0)
local numRayHandle, hit, endCoords, surfaceNormal, entityHit = GetShapeTestResult(rayHandle)

if hit == 1 and GetEntityType(entityHit) == 2 then
local entityCoords = GetEntityCoords(entityHit)
local entityDistance = #(playerCoords - entityCoords)
return entityHit, entityCoords, entityDistance
end

return nil
end
exports('GetVehicleInDirection', MSK.GetVehicleInDirection)

MSK.IsVehicleEmpty = function(vehicle)
assert(vehicle and DoesEntityExist(vehicle), 'Parameter "vehicle" is nil or the Vehicle does not exist')
local passengers = GetVehicleNumberOfPassengers(vehicle)
local driverSeatFree = IsVehicleSeatFree(vehicle, -1)

return passengers == 0 and driverSeatFree
end
exports('IsVehicleEmpty', MSK.IsVehicleEmpty)

MSK.IsSpawnPointClear = function(coords, maxDistance)
local nearbyVehicles = {}

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

MSK.GetPedVehicleSeat = function(ped, vehicle)
if not ped then ped = PlayerPedId() end
if not vehicle then GetVehiclePedIsIn(ped, false) end

for i = -1, 16 do
if (GetPedInVehicleSeat(vehicle, i) == ped) then return i end
end
return -1
end
exports('GetPedVehicleSeat', MSK.GetPedVehicleSeat)

MSK.GetPedMugshot = function(ped, transparent)
assert(ped and DoesEntityExist(ped), 'Parameter "ped" is nil or the PlayerPed does not exist')
local mugshot = transparent and RegisterPedheadshotTransparent(ped) or RegisterPedheadshot(ped)
Expand Down Expand Up @@ -282,4 +245,14 @@ MSK.LoadModel = function(modelHash)
end
end
end
exports('LoadModel', MSK.LoadModel)
exports('LoadModel', MSK.LoadModel)

MSK.GetClosestPlayer = function(coords)
return GetClosestEntity(true, coords)
end
exports('GetClosestPlayer', MSK.GetClosestPlayer)

MSK.GetClosestPlayers = function(coords, distance)
return GetClosestEntities(true, coords, distance)
end
exports('GetClosestPlayers', MSK.GetClosestPlayers)
31 changes: 20 additions & 11 deletions client/functions/numpad.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
MSK.Numpad = {}

local isNumpadOpen = false
local callback = nil

MSK.Numpad = function(pin, show, cb)
MSK.Numpad.Open = function(pin, show, cb)
if isNumpadOpen then return end
logging('debug', 'MSK.Numpad')
isNumpadOpen = true
callback = cb

Expand All @@ -28,35 +29,43 @@ MSK.Numpad = function(pin, show, cb)
return result
end
end
exports('Numpad', MSK.Numpad)
exports('Numpad', MSK.Numpad.Open)

-- Support for old Scripts
setmetatable(MSK.Numpad, {
__call = function(_, pin, show, cb)
-- Ruft MSK.Numpad.Open auf, wenn MSK.Numpad() aufgerufen wird
return MSK.Numpad.Open(pin, show, cb)
end
})

MSK.CloseNumpad = function()
logging('debug', 'MSK.CloseNumpad')
MSK.Numpad.Close = function()
isNumpadOpen = false
callback = nil
SetNuiFocus(false, false)
SendNUIMessage({
action = 'closeNumpad'
})
end
exports('CloseNumpad', MSK.CloseNumpad)
RegisterNetEvent('msk_core:closeNumpad', MSK.CloseNumpad)
MSK.CloseNumpad = MSK.Numpad.Close
exports('CloseNumpad', MSK.Numpad.Close)
RegisterNetEvent('msk_core:closeNumpad', MSK.Numpad.Close)

MSK.Register('msk_core:numpad', function(source, pin, show)
return MSK.Numpad(pin, show)
return MSK.Numpad.Open(pin, show)
end)

RegisterNUICallback('submitNumpad', function(data)
callback(true)
MSK.CloseNumpad()
MSK.Numpad.Close()
end)

RegisterNUICallback('closeNumpad', function()
MSK.CloseNumpad()
MSK.Numpad.Close()
end)

AddEventHandler('onResourceStop', function(resource)
if GetCurrentResourceName() ~= resource then return end
MSK.CloseNumpad()
MSK.Numpad.Close()
end)

31 changes: 22 additions & 9 deletions client/functions/showCoords.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@
local showCoords = false
MSK.Coords = {}

MSK.ShowCoords = function()
showCoords = not showCoords
local showCoords = false

MSK.Coords.Show = function()
if showCoords then
CreateThread(startShowCoordsThread)
showCoords = false
return
end

showCoords = true
CreateThread(startShowCoordsThread)
end
exports('ShowCoords', MSK.ShowCoords)
RegisterNetEvent('msk_core:showCoords', MSK.ShowCoords)
MSK.ShowCoords = MSK.Coords.Show -- Support for old Scripts
exports('ShowCoords', MSK.Coords.Show)
RegisterNetEvent('msk_core:showCoords', MSK.Coords.Show)

MSK.DoesShowCoords = function()
MSK.Coords.Active = function()
return showCoords
end
exports('DoesShowCoords', MSK.DoesShowCoords)
MSK.DoesShowCoords = MSK.Coords.Active -- Support for old Scripts
exports('CoordsActive', MSK.Coords.Active)
exports('DoesShowCoords', MSK.Coords.Active) -- Support for old Scripts

MSK.Coords.Hide = function()
showCoords = false
end
exports('HideCoords', MSK.Coords.Hide)
RegisterNetEvent('msk_core:hideCoords', MSK.Coords.Hide)

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

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)))
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)))

Wait(sleep)
end
Expand Down
Loading

0 comments on commit f03b986

Please sign in to comment.