Skip to content

Commit 32c9595

Browse files
committed
Update v2.4.10
1 parent 1f9e0a3 commit 32c9595

File tree

6 files changed

+160
-73
lines changed

6 files changed

+160
-73
lines changed

client/functions/main.lua

+7-40
Original file line numberDiff line numberDiff line change
@@ -47,39 +47,32 @@ exports('AdvancedNotification', MSK.AdvancedNotification)
4747
RegisterNetEvent("msk_core:advancedNotification", MSK.AdvancedNotification)
4848

4949
MSK.ScaleformAnnounce = function(header, text, typ, duration)
50-
local scaleform = ''
51-
52-
local loadScaleform = function(sclform)
53-
if not HasScaleformMovieLoaded(scaleform) then
54-
scaleform = RequestScaleformMovie(sclform)
55-
while not HasScaleformMovieLoaded(scaleform) do
56-
Wait(1)
57-
end
58-
end
59-
end
50+
local scaleform = nil
6051

6152
if typ == 1 then
62-
loadScaleform("MP_BIG_MESSAGE_FREEMODE")
53+
scaleform = MSK.Request.ScaleformMovie("MP_BIG_MESSAGE_FREEMODE")
6354
BeginScaleformMovieMethod(scaleform, "SHOW_SHARD_WASTED_MP_MESSAGE")
6455
ScaleformMovieMethodAddParamTextureNameString(header)
6556
ScaleformMovieMethodAddParamTextureNameString(text)
6657
EndScaleformMovieMethod()
6758
elseif typ == 2 then
68-
loadScaleform("POPUP_WARNING")
59+
scaleform = MSK.Request.ScaleformMovie("POPUP_WARNING")
6960
BeginScaleformMovieMethod(scaleform, "SHOW_POPUP_WARNING")
7061
ScaleformMovieMethodAddParamFloat(500.0)
7162
ScaleformMovieMethodAddParamTextureNameString(header)
7263
ScaleformMovieMethodAddParamTextureNameString(text)
7364
EndScaleformMovieMethod()
7465
end
7566

67+
if not scaleform then return end
68+
7669
local draw = true
7770
while draw do
7871
local sleep = 1
7972

8073
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255, 0)
8174

82-
MSK.SetTimeout(duration or 8000, function()
75+
MSK.Timeout.Set(duration or 8000, function()
8376
draw = false
8477
end)
8578

@@ -103,7 +96,7 @@ MSK.Spinner = function(text, typ, duration)
10396
AddTextComponentSubstringPlayerName(text)
10497
EndTextCommandBusyspinnerOn(typ or 4) -- 4 or 5, all others are useless // 4 = orange // 5 = white
10598

106-
MSK.SetTimeout(duration or 5000, function()
99+
MSK.Timeout.Set(duration or 5000, function()
107100
BusyspinnerOff()
108101
end)
109102
end
@@ -200,32 +193,6 @@ MSK.GetPedMugshot = function(ped, transparent)
200193
end
201194
exports('GetPedMugshot', MSK.GetPedMugshot)
202195

203-
MSK.LoadAnimDict = function(dict)
204-
assert(dict and DoesAnimDictExist(dict), 'Parameter "dict" is nil or the AnimDict does not exist')
205-
206-
if not HasAnimDictLoaded(dict) then
207-
RequestAnimDict(dict)
208-
209-
while not HasAnimDictLoaded(dict) do
210-
Wait(1)
211-
end
212-
end
213-
end
214-
exports('LoadAnimDict', MSK.LoadAnimDict)
215-
216-
MSK.LoadModel = function(modelHash)
217-
assert(modelHash and IsModelValid(modelHash), 'Parameter "modelHash" is nil or the Model does not exist')
218-
219-
if not HasModelLoaded(modelHash) then
220-
RequestModel(modelHash)
221-
222-
while not HasModelLoaded(modelHash) do
223-
Wait(1)
224-
end
225-
end
226-
end
227-
exports('LoadModel', MSK.LoadModel)
228-
229196
MSK.GetClosestPlayer = function(coords)
230197
return GetClosestEntity(true, coords)
231198
end

client/functions/request.lua

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
MSK.Request = {}
2+
3+
MSK.Request.Streaming = function(request, hasLoaded, assetType, asset, timeout, ...)
4+
if hasLoaded(asset) then return asset end
5+
request(asset, ...)
6+
7+
MSK.Logging('info', ("Loading %s '%s' - remember to release it when done."):format(assetType, asset))
8+
9+
return MSK.Timeout.Await(timeout or 5000, function()
10+
if hasLoaded(asset) then return asset end
11+
end, ("failed to load %s '%s' - this is likely caused by unreleased assets"):format(assetType, asset))
12+
end
13+
exports('RequestStreaming', MSK.Request.Streaming)
14+
15+
MSK.Request.ScaleformMovie = function(scaleformName, timeout)
16+
assert(scaleformName and type(scaleformName) == 'string', ("Parameter 'scaleformName' has to be a 'string' (reveived %s)"):format(type(scaleformName)))
17+
18+
local scaleform = RequestScaleformMovie(scaleformName)
19+
20+
return MSK.Timeout.Await(timeout or 5000, function()
21+
if HasScaleformMovieLoaded(asset) then return scaleform end
22+
end, ("failed to load scaleformMovie '%s'"):format(scaleformName))
23+
end
24+
exports('RequestScaleformMovie', MSK.Request.ScaleformMovie)
25+
26+
setmetatable(MSK.Request, {
27+
__call = function(_, request, hasLoaded, assetType, asset, timeout, ...)
28+
return MSK.Request.Streaming(request, hasLoaded, assetType, asset, timeout, ...)
29+
end
30+
})
31+
32+
MSK.Request.AnimDict = function(animDict)
33+
assert(animDict and type(animDict) == 'string', ("Parameter 'animDict' has to be a 'string' (reveived %s)"):format(type(animDict)))
34+
assert(DoesAnimDictExist(animDict), ("attempted to load invalid animDict '%s'"):format(animDict))
35+
36+
if HasAnimDictLoaded(animDict) then return animDict end
37+
38+
return MSK.Request(RequestAnimDict, HasAnimDictLoaded, 'animDict', animDict)
39+
end
40+
MSK.LoadAnimDict = MSK.Request.AnimDict -- Support for old Versions
41+
exports('LoadAnimDict', MSK.Request.AnimDict) -- Support for old Versions
42+
exports('RequestAnimDict', MSK.Request.AnimDict)
43+
44+
MSK.Request.Model = function(model)
45+
assert(model, 'Parameter "model" is nil')
46+
if type(model) ~= 'number' then model = joaat(model) end
47+
assert(IsModelValid(model) and IsModelInCdimage(model), ("attempted to load invalid model '%s'"):format(model))
48+
49+
if HasModelLoaded(model) then return model end
50+
51+
return MSK.Request(RequestModel, HasModelLoaded, 'model', model)
52+
end
53+
MSK.LoadModel = MSK.Request.Model -- Support for old Versions
54+
exports('LoadModel', MSK.Request.Model) -- Support for old Versions
55+
exports('RequestModel', MSK.Request.Model)
56+
57+
MSK.Request.AnimSet = function(animSet)
58+
assert(animSet and type(animSet) == 'string', ("Parameter 'animSet' has to be a 'string' (reveived %s)"):format(type(animSet)))
59+
if HasAnimSetLoaded(animSet) then return animSet end
60+
61+
return MSK.Request(RequestAnimSet, HasAnimSetLoaded, 'animSet', animSet)
62+
end
63+
exports('RequestAnimSet', MSK.Request.AnimSet)
64+
65+
MSK.Request.PtfxAsset = function(ptFxName)
66+
assert(ptFxName and type(ptFxName) == 'string', ("Parameter 'ptFxName' has to be a 'string' (reveived %s)"):format(type(ptFxName)))
67+
68+
if HasNamedPtfxAssetLoaded(ptFxName) then return ptFxName end
69+
70+
return MSK.Request(RequestNamedPtfxAsset, HasNamedPtfxAssetLoaded, 'ptFxName', ptFxName)
71+
end
72+
exports('RequestPtfxAsset', MSK.Request.PtfxAsset)
73+
74+
MSK.Request.TextureDict = function(textureDict)
75+
assert(textureDict and type(textureDict) == 'string', ("Parameter 'textureDict' has to be a 'string' (reveived %s)"):format(type(textureDict)))
76+
77+
if HasStreamedTextureDictLoaded(textureDict) then return textureDict end
78+
79+
return MSK.Request(RequestStreamedTextureDict, HasStreamedTextureDictLoaded, 'textureDict', textureDict)
80+
end
81+
exports('RequestTextureDict', MSK.Request.TextureDict)

config.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Config.NotifyTypes = {
3737

3838
Config.customNotification = function(title, message, typ, duration)
3939
-- Set Config.Notification = 'custom'
40-
-- Add your own clientside Notification here
40+
-- Add your own clientside Notification here
4141
end
4242
----------------------------------------------------------------
4343
Config.progressColor = "#5eb131" -- Default Color for ProgressBar

fxmanifest.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ games { 'gta5' }
44
author 'Musiker15 - MSK Scripts'
55
name 'msk_core'
66
description 'Functions for MSK Scripts'
7-
version '2.4.9'
7+
version '2.4.10'
88

99
lua54 'yes'
1010

shared/functions.lua

+1-31
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,6 @@ MSK.GetConfig = function()
33
end
44
exports('GetConfig', MSK.GetConfig)
55

6-
local Timeouts = {}
7-
local TimeoutId = 0
8-
MSK.SetTimeout = function(ms, cb, data)
9-
assert(ms and tonumber(ms), 'Parameter "ms" has to be a number on function MSK.SetTimeout')
10-
local requestId = TimeoutId + 1
11-
12-
SetTimeout(ms, function()
13-
if Timeouts[requestId] then
14-
Timeouts[requestId] = nil
15-
return
16-
end
17-
18-
cb(data)
19-
end)
20-
21-
TimeoutId = requestId
22-
23-
return requestId
24-
end
25-
MSK.AddTimeout = MSK.SetTimeout -- Support for old Versions
26-
exports('SetTimeout', MSK.SetTimeout)
27-
28-
MSK.ClearTimeout = function(requestId)
29-
assert(requestId, 'Parameter "requestId" is nil on function MSK.ClearTimeout')
30-
Timeouts[requestId] = true
31-
end
32-
MSK.DelTimeout = MSK.ClearTimeout -- Support for old Versions
33-
exports('DelTimeout', MSK.ClearTimeout) -- Support for old Versions
34-
exports('ClearTimeout', MSK.ClearTimeout)
35-
366
MSK.Logging = function(code, ...)
377
assert(code and type(code) == 'string', 'Parameter "code" has to be a string on function MSK.Logging')
388
local script = ('[^2%s^0]'):format(GetInvokingResource() or 'msk_core')
@@ -42,6 +12,6 @@ MSK.logging = MSK.Logging -- Support for old Versions
4212
exports('Logging', MSK.Logging)
4313

4414
logging = function(code, ...)
45-
if not Config.Debug and code == 'debug' then return end
15+
if not Config.Debug then return end
4616
MSK.Logging(code, ...)
4717
end

shared/timeout.lua

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
MSK.Timeout = {}
2+
3+
local Timeouts = {}
4+
local TimeoutId = 0
5+
6+
MSK.Timeout.Set = function(ms, cb, data)
7+
assert(ms and tonumber(ms), 'Parameter "ms" has to be a number on function MSK.Timeout.Set')
8+
local requestId = TimeoutId + 1
9+
10+
SetTimeout(ms, function()
11+
if Timeouts[requestId] then
12+
Timeouts[requestId] = nil
13+
return
14+
end
15+
16+
cb(data)
17+
end)
18+
19+
TimeoutId = requestId
20+
21+
return requestId
22+
end
23+
MSK.SetTimeout = MSK.Timeout.Set -- Support for old Versions
24+
MSK.AddTimeout = MSK.Timeout.Set -- Support for old Versions
25+
exports('SetTimeout', MSK.SetTimeout)
26+
27+
setmetatable(MSK.Timeout, {
28+
__call = function(_, ms, cb, data)
29+
return MSK.Timeout.Set(ms, cb, data)
30+
end
31+
})
32+
33+
MSK.Timeout.Clear = function(requestId)
34+
assert(requestId, 'Parameter "requestId" is nil on function MSK.Timeout.Clear')
35+
Timeouts[requestId] = true
36+
end
37+
MSK.ClearTimeout = MSK.Timeout.Clear -- Support for old Versions
38+
MSK.DelTimeout = MSK.Timeout.Clear -- Support for old Versions
39+
exports('DelTimeout', MSK.Timeout.Clear) -- Support for old Versions
40+
exports('ClearTimeout', MSK.Timeout.Clear)
41+
42+
-- Thanks to ox_lib (https://overextended.dev/ox_lib/Modules/WaitFor/Shared)
43+
MSK.Timeout.Await = function(ms, cb, errMessage)
44+
assert(ms and tonumber(ms), 'Parameter "ms" has to be a number on function MSK.Timeout.Await')
45+
local value = cb()
46+
47+
if value ~= nil then return value end
48+
49+
if timeout or timeout == nil then
50+
if type(timeout) ~= 'number' then timeout = 1000 end
51+
end
52+
53+
local start = timeout and GetGameTimer()
54+
55+
while value == nil do
56+
Wait(0)
57+
58+
local elapsed = timeout and GetGameTimer() - start
59+
60+
if elapsed and elapsed > timeout then
61+
return error(('%s (waited %.1fms)'):format(errMessage or 'failed to resolve callback', elapsed), 2)
62+
end
63+
64+
value = cb()
65+
end
66+
67+
return value
68+
end
69+
exports('AwaitTimeout', MSK.Timeout.Await)

0 commit comments

Comments
 (0)