forked from Elipse458/el_bwh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
179 lines (163 loc) · 6.72 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
ESX = nil
local pos_before_assist,assisting,assist_target,last_assist = nil, false, nil, nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
SetNuiFocus(false, false)
end)
function GetIndexedPlayerList()
local players = {}
for k,v in ipairs(GetActivePlayers()) do
players[tostring(GetPlayerServerId(v))]=GetPlayerName(v)..(v==PlayerId() and " (self)" or "")
end
return json.encode(players)
end
RegisterNUICallback("ban", function(data,cb)
if not data.target or not data.reason then return end
ESX.TriggerServerCallback("el_bwh:ban",function(success,reason)
if success then ESX.ShowNotification("~g~Successfully banned player") else ESX.ShowNotification(reason) end -- dont ask why i did it this way, im a bit retarded
end, data.target, data.reason, data.length, data.offline)
end)
RegisterNUICallback("warn", function(data,cb)
if not data.target or not data.message then return end
ESX.TriggerServerCallback("el_bwh:warn",function(success)
if success then ESX.ShowNotification("~g~Successfully warned player") else ESX.ShowNotification("~r~Something went wrong") end
end, data.target, data.message, data.anon)
end)
RegisterNUICallback("unban", function(data,cb)
if not data.id then return end
ESX.TriggerServerCallback("el_bwh:unban",function(success)
if success then ESX.ShowNotification("~g~Successfully unbanned player") else ESX.ShowNotification("~r~Something went wrong") end
end, data.id)
end)
RegisterNUICallback("getListData", function(data,cb)
if not data.list or not data.page then cb(nil); return end
ESX.TriggerServerCallback("el_bwh:getListData",function(data)
cb(data)
end, data.list, data.page)
end)
RegisterNUICallback("hidecursor", function(data,cb)
SetNuiFocus(false, false)
end)
RegisterNetEvent("el_bwh:gotBanned")
AddEventHandler("el_bwh:gotBanned",function(rsn)
Citizen.CreateThread(function()
local scaleform = RequestScaleformMovie("mp_big_message_freemode")
while not HasScaleformMovieLoaded(scaleform) do Citizen.Wait(0) end
BeginScaleformMovieMethod(scaleform, "SHOW_SHARD_WASTED_MP_MESSAGE")
PushScaleformMovieMethodParameterString("~r~BANNED")
PushScaleformMovieMethodParameterString(rsn)
PushScaleformMovieMethodParameterInt(5)
EndScaleformMovieMethod()
PlaySoundFrontend(-1, "LOSER", "HUD_AWARDS")
ClearDrawOrigin()
ESX.UI.HUD.SetDisplay(0)
while true do
Citizen.Wait(0)
DisableAllControlActions(0)
DisableFrontendThisFrame()
local ped = GetPlayerPed(-1)
ESX.UI.Menu.CloseAll()
SetEntityCoords(ped, 0, 0, 0, 0, 0, 0, false)
FreezeEntityPosition(ped, true)
DrawRect(0.0,0.0,2.0,2.0,0,0,0,255)
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255)
end
SetScaleformMovieAsNoLongerNeeded(scaleform)
end)
end)
RegisterNetEvent("el_bwh:receiveWarn")
AddEventHandler("el_bwh:receiveWarn",function(sender,message)
TriggerEvent("chat:addMessage",{color={255,255,0},multiline=true,args={"BWH","You received a warning"..(sender~="" and " from "..sender or "").."!\n-> "..message}})
Citizen.CreateThread(function()
local scaleform = RequestScaleformMovie("mp_big_message_freemode")
while not HasScaleformMovieLoaded(scaleform) do Citizen.Wait(0) end
BeginScaleformMovieMethod(scaleform, "SHOW_SHARD_WASTED_MP_MESSAGE")
PushScaleformMovieMethodParameterString("~y~WARNING")
PushScaleformMovieMethodParameterString(message)
PushScaleformMovieMethodParameterInt(5)
EndScaleformMovieMethod()
PlaySoundFrontend(-1, "LOSER", "HUD_AWARDS")
local drawing = true
Citizen.SetTimeout(Config.warning_screentime,function() drawing = false end)
while drawing do
Citizen.Wait(0)
DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255)
end
SetScaleformMovieAsNoLongerNeeded(scaleform)
end)
end)
RegisterNetEvent("el_bwh:requestedAssist")
AddEventHandler("el_bwh:requestedAssist",function(t)
SendNUIMessage({show=true,window="assistreq",data=Config.popassistformat:format(GetPlayerName(GetPlayerFromServerId(t)),t)})
last_assist=t
end)
RegisterNetEvent("el_bwh:acceptedAssist")
AddEventHandler("el_bwh:acceptedAssist",function(t)
if assisting then return end
local target = GetPlayerFromServerId(t)
if target then
local ped = GetPlayerPed(-1)
pos_before_assist = GetEntityCoords(ped)
assisting = true
assist_target = t
ESX.Game.Teleport(ped,GetEntityCoords(GetPlayerPed(target))+vector3(0,0.5,0))
end
end)
RegisterNetEvent("el_bwh:assistDone")
AddEventHandler("el_bwh:assistDone",function()
if assisting then
assisting = false
if pos_before_assist~=nil then ESX.Game.Teleport(GetPlayerPed(-1),pos_before_assist+vector3(0,0.5,0)); pos_before_assist = nil end
assist_target = nil
end
end)
RegisterNetEvent("el_bwh:hideAssistPopup")
AddEventHandler("el_bwh:hideAssistPopup",function(t)
SendNUIMessage({hide=true})
last_assist=nil
end)
RegisterNetEvent("el_bwh:showWindow")
AddEventHandler("el_bwh:showWindow",function(win)
if win=="ban" or win=="warn" then
SendNUIMessage({show=true,window=win,players=GetIndexedPlayerList()})
elseif win=="banlist" or win=="warnlist" then
SendNUIMessage({loading=true,window=win})
ESX.TriggerServerCallback(win=="banlist" and "el_bwh:getBanList" or "el_bwh:getWarnList",function(list,pages)
SendNUIMessage({show=true,window=win,list=list,pages=pages})
end)
end
SetNuiFocus(true, true)
end)
RegisterCommand("decassist",function(a,b,c)
TriggerEvent("el_bwh:hideAssistPopup")
end, false)
if Config.assist_keys then
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlJustPressed(0, Config.assist_keys.accept) then
if not last_assist then
ESX.ShowNotification("~r~Noone requested assistance yet")
elseif not NetworkIsPlayerActive(GetPlayerFromServerId(last_assist)) then
ESX.ShowNotification("~r~The player that requested assistance is not online anymore")
last_assist=nil
else
TriggerServerEvent("el_bwh:acceptAssistKey",last_assist)
end
end
if IsControlJustPressed(0, Config.assist_keys.decline) then
TriggerEvent("el_bwh:hideAssistPopup")
end
end
end)
end
Citizen.CreateThread(function()
TriggerEvent('chat:addSuggestion', '/decassist', 'Hide assist popup',{})
TriggerEvent('chat:addSuggestion', '/assist', 'Request help from admins',{{name="Reason", help="Why do you need help?"}})
TriggerEvent('chat:addSuggestion', '/cassist', 'Cancel your pending help request',{})
TriggerEvent('chat:addSuggestion', '/finassist', 'Finish assist and tp back',{})
TriggerEvent('chat:addSuggestion', '/accassist', 'Accept a players help request', {{name="Player ID", help="ID of the player you want to help"}})
end)