Skip to content

Commit

Permalink
Update v2.6.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Musiker15 committed Oct 23, 2024
1 parent c614156 commit 1080238
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 13 deletions.
16 changes: 11 additions & 5 deletions client/functions/request.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ MSK.Request.Streaming = function(request, hasLoaded, assetType, asset, timeout,
end
exports('RequestStreaming', MSK.Request.Streaming)

setmetatable(MSK.Request, {
__call = function(_, request, hasLoaded, assetType, asset, timeout, ...)
return MSK.Request.Streaming(request, hasLoaded, assetType, asset, timeout, ...)
end
})

MSK.Request.ScaleformMovie = function(scaleformName, timeout)
assert(scaleformName and type(scaleformName) == 'string', ("Parameter 'scaleformName' has to be a 'string' (reveived %s)"):format(type(scaleformName)))

Expand All @@ -29,7 +35,7 @@ MSK.Request.AnimDict = function(animDict)

if HasAnimDictLoaded(animDict) then return animDict end

return MSK.Request(RequestAnimDict, HasAnimDictLoaded, 'animDict', animDict)
return MSK.Request.Streaming(RequestAnimDict, HasAnimDictLoaded, 'animDict', animDict)
end
MSK.LoadAnimDict = MSK.Request.AnimDict -- Support for old Versions
exports('LoadAnimDict', MSK.Request.AnimDict) -- Support for old Versions
Expand All @@ -42,7 +48,7 @@ MSK.Request.Model = function(model)

if HasModelLoaded(model) then return model end

return MSK.Request(RequestModel, HasModelLoaded, 'model', model)
return MSK.Request.Streaming(RequestModel, HasModelLoaded, 'model', model)
end
MSK.LoadModel = MSK.Request.Model -- Support for old Versions
exports('LoadModel', MSK.Request.Model) -- Support for old Versions
Expand All @@ -52,7 +58,7 @@ MSK.Request.AnimSet = function(animSet)
assert(animSet and type(animSet) == 'string', ("Parameter 'animSet' has to be a 'string' (reveived %s)"):format(type(animSet)))
if HasAnimSetLoaded(animSet) then return animSet end

return MSK.Request(RequestAnimSet, HasAnimSetLoaded, 'animSet', animSet)
return MSK.Request.Streaming(RequestAnimSet, HasAnimSetLoaded, 'animSet', animSet)
end
exports('RequestAnimSet', MSK.Request.AnimSet)

Expand All @@ -61,7 +67,7 @@ MSK.Request.PtfxAsset = function(ptFxName)

if HasNamedPtfxAssetLoaded(ptFxName) then return ptFxName end

return MSK.Request(RequestNamedPtfxAsset, HasNamedPtfxAssetLoaded, 'ptFxName', ptFxName)
return MSK.Request.Streaming(RequestNamedPtfxAsset, HasNamedPtfxAssetLoaded, 'ptFxName', ptFxName)
end
exports('RequestPtfxAsset', MSK.Request.PtfxAsset)

Expand All @@ -70,7 +76,7 @@ MSK.Request.TextureDict = function(textureDict)

if HasStreamedTextureDictLoaded(textureDict) then return textureDict end

return MSK.Request(RequestStreamedTextureDict, HasStreamedTextureDictLoaded, 'textureDict', textureDict)
return MSK.Request.Streaming(RequestStreamedTextureDict, HasStreamedTextureDictLoaded, 'textureDict', textureDict)
end
exports('RequestTextureDict', MSK.Request.TextureDict)

Expand Down
14 changes: 14 additions & 0 deletions client/functions/showCoords.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ end
exports('HideCoords', MSK.Coords.Hide)
RegisterNetEvent('msk_core:hideCoords', MSK.Coords.Hide)

MSK.Coords.Copy = function(coords)
if not coords then coords = MSK.Player.coords end
local x, y, z, h = table.unpack(coords)
local newCoords = {x = MSK.Math.Round(x, 2), y = MSK.Math.Round(y, 2), z = MSK.Math.Round(z, 2)}
newCoords.h = h and MSK.Math.Round(h, 2)

SendNUIMessage({
action = "copyCoords",
value = MSK.CoordsToString(newCoords),
})
end
exports('CopyCoords', MSK.Coords.Copy)
RegisterNetEvent('msk_core:copyCoords', MSK.Coords.Copy)

MSK.Register('msk_core:doesShowCoords', function(source)
return showCoords
end)
Expand Down
6 changes: 6 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ Config.showCoords = {
command = 'coords',
groups = {'superadmin', 'admin'}
}

Config.copyCoords = {
enable = true,
command = 'copyCoords',
groups = {'superadmin', 'admin'}
}
----------------------------------------------------------------
-- Set to 'msk' for MSK UI Notification
-- Set to 'custom' for Config.customNotification()
Expand Down
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ games { 'gta5' }
author 'Musiker15 - MSK Scripts'
name 'msk_core'
description 'Functions for MSK Scripts'
version '2.6.7'
version '2.6.8'

lua54 'yes'

Expand Down
14 changes: 14 additions & 0 deletions html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ $(document).ready(function() {
openNumpad(data);
} else if (data.action == 'closeNumpad') {
closeNumpad();
} else if (data.action == 'copyCoords') {
copyCoords(data.value);
}
})
})
Expand All @@ -70,6 +72,18 @@ function playSound(sound, volume) {
audio.play();
}

function copyCoords(value) {
console.log(`Copying ${value} to your clipboard`);
const el = document.createElement('textarea');

el.value = value;
document.body.appendChild(el);
el.select();

document.execCommand('copy');
document.body.removeChild(el);
}

/* ----------------
MSK Notification
---------------- */
Expand Down
8 changes: 8 additions & 0 deletions import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ setmetatable(MSK.Progress, {
end
})

if context == 'client' then
setmetatable(MSK.Request, {
__call = function(_, request, hasLoaded, assetType, asset, timeout, ...)
return MSK.Request.Streaming(request, hasLoaded, assetType, asset, timeout, ...)
end
})
end

if context == 'server' then
-- MSK.Check(repo)
setmetatable(MSK.Check, {
Expand Down
4 changes: 2 additions & 2 deletions server/functions/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ local onPlayer = function(key, value, oldValue)
if key == 'ped' or key == 'playerPed' then
Player[playerId][key] = GetPlayerPed(playerId)
elseif key == 'Notify' then
Player[playerId][key] = value(function(...)
Player[playerId][key] = function(...)
MSK.Notification(playerId, ...)
end)
end
elseif key == 'vehicle' then
Player[playerId][key] = NetworkGetEntityFromNetworkId(value)
Player[playerId]['vehNetId'] = value
Expand Down
31 changes: 30 additions & 1 deletion server/functions/showCoords.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,19 @@ if Config.showCoords.enable then
})
end

if Config.copyCoords.enable then
MSK.RegisterCommand(Config.copyCoords.command, function(source, args, raw)
MSK.Coords.Copy(source, args.playerId)
end, {
allowConsole = false,
restricted = Config.copyCoords.groups,
help = 'Copy coords to clipboard',
params = {
{name = 'playerId', type = 'playerId', help = 'Target players server id', optional = true}
}
})
end

MSK.Coords.Show = function(playerId)
if not playerId or playerId == 0 then return end
TriggerClientEvent('msk_core:showCoords', playerId)
Expand All @@ -31,4 +44,20 @@ MSK.Coords.Hide = function(playerId)
if not playerId or playerId == 0 then return end
TriggerClientEvent('msk_core:hideCoords', playerId)
end
exports('HideCoords', MSK.Coords.Hide)
exports('HideCoords', MSK.Coords.Hide)

MSK.Coords.Copy = function(playerId, targetId)
if not playerId or playerId == 0 then return end
local coords

if targetId then
coords = MSK.Player[targetId].coords
else
coords = MSK.Player[playerId].coords
end

if coords then
TriggerClientEvent('msk_core:copyCoords', playerId, coords)
end
end
exports('CopyCoords', MSK.Coords.Copy)
4 changes: 2 additions & 2 deletions server/functions/version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ MSK.Check.Dependency = function(resource, minimumVersion, showMessage)
if currentVersion ~= minimumVersion then
local cV = MSK.String.Split(currentVersion, '.')
local mV = MSK.String.Split(minimumVersion, '.')
local errMsg = ("^1Resource %s requires a minimum version of '%s' of resource '%s'! ^5Current Version: ^1%s^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)
local errMsg = ("^1resource %s requires minimum version '%s' of resource '%s'! (current version: %s)^0"):format(GetInvokingResource() or GetCurrentResourceName(), minimumVersion, resource, currentVersion)

for i = 1, #cV do
local current, minimum = tonumber(cV[i]), tonumber(mV[i])

if current ~= minimum then
if not current or current < minimum then
if showMessage then
print(errMsg)
MSK.Logging('error', errMsg)
end

return false, errMsg
Expand Down
3 changes: 1 addition & 2 deletions shared/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ exports('Config', MSK.GetConfig)

MSK.Logging = function(code, ...)
assert(code and type(code) == 'string', 'Parameter "code" has to be a string on function MSK.Logging')
local script = ('[^2%s^0]'):format(GetInvokingResource() or 'msk_core')
print(('%s %s'):format(script, Config.LoggingTypes[code] or Config.LoggingTypes['debug']), ..., '^0')
print(('%s %s'):format(('[^2%s^0]'):format(GetInvokingResource() or 'msk_core'), Config.LoggingTypes[code] or Config.LoggingTypes['debug']), ..., '^0')
end
MSK.logging = MSK.Logging -- Support for old Versions
exports('Logging', MSK.Logging)
Expand Down
45 changes: 45 additions & 0 deletions shared/vector.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
local getTableHeading = function(coords)
return coords.h or coords.w or coords.heading or 0.0
end

MSK.CoordsToString = function(coords)
assert(coords, 'Parameter "coords" has to be a vector on function MSK.CoordsToString')
local typ = type(coords)

if typ == 'table' then
if coords.h or coords.w then
return string.format("vector4(%s, %s, %s, %s)", coords.x, coords.y, coords.z, getTableHeading(coords))
end

return string.format("vector3(%s, %s, %s)", coords.x, coords.y, coords.z)
elseif typ == 'vector3' then
return string.format("vector3(%s, %s, %s)", coords.x, coords.y, coords.z)
elseif typ == 'vector4' then
return string.format("vector4(%s, %s, %s, %s)", coords.x, coords.y, coords.z, coords.w)
end

return coords
end
exports('CoordsToString', MSK.CoordsToString)

MSK.VectorToVector = function(vec)
local typ = type(vec)

if typ == 'vec4' or typ == 'vector4' then
return vector3(vec.x, vec.y, vec.z)
end

return vec
end
exports('VectorToVector', MSK.VectorToVector)

MSK.TableToVector = function(coords, toType)
assert(coords and type(coords) == 'table', 'Parameter "tbl" has to be a table on function MSK.TableToVector')

if toType == 'vector3' then
return vector3(coords.x, coords.y, coords.z)
elseif toType == 'vector4' then
return vector4(coords.x, coords.y, coords.z, getTableHeading(coords))
end
end
exports('TableToVector', MSK.TableToVector)

0 comments on commit 1080238

Please sign in to comment.