-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.lua
118 lines (88 loc) · 3.15 KB
/
client.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
local myScore = 0
local bScoreboardIsOpen = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlPressed(1, 243) and not bScoreboardIsOpen then
SendNUIMessage({name = 'showScoreboard'})
bScoreboardIsOpen = true
elseif bScoreboardIsOpen and IsControlReleased(1, 243) then
bScoreboardIsOpen = false
SendNUIMessage({name = 'hideScoreboard'})
end
end
end)
function onResetRound()
myScore = 0
TriggerEvent("factions:updateMood", Global.Round.CurrentMood)
respawnPed()
SetPlayerControl(PlayerId(), true)
SendNUIMessage({name = 'onResetRound'})
end
AddEventHandler('gameEventTriggered', function (name, args)
if name == 'CEventNetworkStartMatch' and Global.Round == nil then
end
end)
AddEventHandler("playerSpawned", function(spawn)
TriggerServerEvent('factions:playerJoined')
Call('factions:getRoundInfo', {}, function(RoundInfo)
Global.Round = RoundInfo
onResetRound()
end)
end)
RegisterNUICallback('getRoundTimeLeft', function(data, cb)
-- and so does callback response data
--cb(256)
local callbackId = randomString(8)
CallbackTable[callbackId] = cb
TriggerServerEvent('factions:getRoundTimeLeft', callbackId)
end)
AddEventHandler("factions:cl_getRoundTimeLeft", function(timeLeft, cbId)
-- Call from the callback table and then delete it
CallbackTable[cbId](timeLeft)
CallbackTable[cbId] = nil
end)
RegisterNetEvent("factions:cl_getRoundTimeLeft")
AddEventHandler("factions:cl_onRoundEnd", function(timeLeft, cbId)
SetPlayerControl(PlayerId(), false)
SendNUIMessage({name = 'onRoundEnd'})
end)
RegisterNetEvent("factions:cl_onRoundEnd")
AddEventHandler("factions:cl_onResetRound", function(newRoundInfo)
Global.Round = newRoundInfo
onResetRound()
end)
RegisterNetEvent("factions:cl_onResetRound")
RegisterNUICallback('getScoreboard', function(data, cb)
Call('factions:getScoreboard', {}, function(scoreboard)
-- Stupid fix. Unlike Lua, javascript requires strings as keys NOT numbers
local sb = {}
for playerId, score in pairs(scoreboard) do
sb[tostring(playerId)] = scoreboard[playerId];
end
cb(sb)
end)
end)
AddEventHandler("getWeaponLoadout", function()
print("GET WEAPON LOADOUT!? ")
local loadout = {}
local playerPed = GetPlayerPed(-1)
for _, rank in ipairs(Config.Ranks) do
--rank.MinScore
--rank.Unlocks
for __, weapon in ipairs(rank.Unlocks) do
if weapon[2] == nil then weapon[2] = 1 end
GiveWeaponToPed(playerPed, GetHashKey( weapon[1] ), weapon[2], false, false)
if weapon[3] ~= nil then
GiveWeaponComponentToPed(playerPed, GetHashKey(weapon[1]), GetHashKey(weapon[3]))
end
end
print('rank.MinScore:' .. rank.MinScore .. ', myScore:'..myScore)
if rank.MinScore >= myScore then break end
end
end)
AddEventHandler("factions:cl_killReward", function(totalKills)
myScore = totalKills
TriggerEvent("getWeaponLoadout")
end)
RegisterNetEvent("factions:cl_killReward")