-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.lua
77 lines (65 loc) · 2.97 KB
/
server.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
ESX = exports["es_extended"]:getSharedObject()
for item, v in pairs(Config.AmmoPacks) do
ESX.RegisterUsableItem(item, function(playerId)
local src = playerId
local xPlayer = ESX.GetPlayerFromId(src)
xPlayer.triggerEvent('msk_weaponammoitem:checkAmmo', item, v)
end)
end
RegisterNetEvent('msk_weaponammoitem:addWeaponAmmo')
AddEventHandler('msk_weaponammoitem:addWeaponAmmo', function(weaponName, item, data)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local hasItem = xPlayer.getInventoryItem(item)
if not hasItem or hasItem.count == 0 then return end
xPlayer.removeInventoryItem(item, 1)
xPlayer.addInventoryItem(data.item, data.amount)
local hasAmmo = xPlayer.getInventoryItem(data.item)
local ammoToAdd = data.amount
if hasAmmo and hasAmmo.count > 0 then ammoToAdd = ammoToAdd + hasAmmo.count end
xPlayer.updateWeaponAmmo(weaponName, ammoToAdd)
SetPedAmmo(GetPlayerPed(xPlayer.source), joaat(weaponName), ammoToAdd)
end)
RegisterNetEvent('msk_weaponammoitem:updateWeaponAmmo')
AddEventHandler('msk_weaponammoitem:updateWeaponAmmo', function(item, weaponName, isShooting)
local src = source
local xPlayer = ESX.GetPlayerFromId(src)
local hasItem = xPlayer.getInventoryItem(item)
if xPlayer then
if hasItem and hasItem.count > 0 then
if isShooting then
xPlayer.removeInventoryItem(item, 1)
end
xPlayer.updateWeaponAmmo(weaponName, hasItem.count)
SetPedAmmo(GetPlayerPed(xPlayer.source), joaat(weaponName), hasItem.count)
else
xPlayer.updateWeaponAmmo(weaponName, 0)
SetPedAmmo(GetPlayerPed(xPlayer.source), joaat(weaponName), 0)
end
end
end)
---- GitHub Updater ----
GithubUpdater = function()
GetCurrentVersion = function()
return GetResourceMetadata( GetCurrentResourceName(), "version" )
end
local CurrentVersion = GetCurrentVersion()
local resourceName = "^4["..GetCurrentResourceName().."]^0"
if Config.VersionChecker then
PerformHttpRequest('https://raw.githubusercontent.com/MSK-Scripts/msk_weaponammoitems/main/VERSION', function(Error, NewestVersion, Header)
print("###############################")
if CurrentVersion == NewestVersion then
print(resourceName .. '^2 ✓ Resource is Up to Date^0 - ^5Current Version: ^2' .. CurrentVersion .. '^0')
elseif CurrentVersion ~= NewestVersion then
print(resourceName .. '^1 ✗ Resource Outdated. Please Update!^0 - ^5Current Version: ^1' .. CurrentVersion .. '^0')
print('^5Newest Version: ^2' .. NewestVersion .. '^0 - ^6Download here:^9 https://github.com/MSK-Scripts/msk_weaponammoitems/releases/tag/v'.. NewestVersion .. '^0')
end
print("###############################")
end)
else
print("###############################")
print(resourceName .. '^2 ✓ Resource loaded^0')
print("###############################")
end
end
GithubUpdater()