forked from wowpanda/esx_slots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.lua
146 lines (128 loc) · 4.45 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
-- This resource was made by plesalex100#7387
-- Please respect it, don't repost it without my permission
-- This Resource started from: https://codepen.io/AdrianSandu/pen/MyBQYz
-- ESX Version: saNhje & wUNDER
ESX = nil
local PlayerData = {}
local open = false
Citizen.CreateThread(function()
while ESX == nil do
Citizen.Wait(10)
TriggerEvent("esx:getSharedObject", function(xPlayer)
ESX = xPlayer
end)
end
while not ESX.IsPlayerLoaded() do
Citizen.Wait(500)
end
if ESX.IsPlayerLoaded() then
PlayerData = ESX.GetPlayerData()
CreateBlip()
end
end)
-------------------------------------------------------------------------------
-- FUNCTIONS
-------------------------------------------------------------------------------
local function drawHint(text)
SetTextComponentFormat("STRING")
AddTextComponentString(text)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end
function CreateBlip()
if Config.blipsEnabled then
for k,v in ipairs(Config.Slots)do
local blip = AddBlipForCoord(v.x, v.y, v.z)
SetBlipSprite(blip, 436)
SetBlipDisplay(blip, 4)
SetBlipScale(blip, 1.0)
SetBlipColour(blip, 49)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString("Pacanele")
EndTextCommandSetBlipName(blip)
end
end
end
function KeyboardInput(textEntry, inputText, maxLength)
AddTextEntry('FMMC_KEY_TIP1', textEntry)
DisplayOnscreenKeyboard(1, "FMMC_KEY_TIP1", "", inputText, "", "", "", maxLength)
while UpdateOnscreenKeyboard() ~= 1 and UpdateOnscreenKeyboard() ~= 2 do
Citizen.Wait(0)
end
if UpdateOnscreenKeyboard() ~= 2 then
local result = GetOnscreenKeyboardResult()
Citizen.Wait(500)
return result
else
Citizen.Wait(500)
return nil
end
end
-------------------------------------------------------------------------------
-- NET EVENTS
-------------------------------------------------------------------------------
RegisterNetEvent("esx_slots:enterBets")
AddEventHandler("esx_slots:enterBets", function ()
local bets = KeyboardInput("Enter bet value:", "", Config.MaxBetNumbers)
if tonumber(bets) ~= nil then
TriggerServerEvent('esx_slots:BetsAndMoney', tonumber(bets))
else
TriggerEvent('esx:showNotification', "You need to enter numbers (9999 is max bet).")
end
end)
RegisterNetEvent("esx_slots:UpdateSlots")
AddEventHandler("esx_slots:UpdateSlots", function(lei)
SetNuiFocus(true, true)
open = true
SendNUIMessage({
showPacanele = "open",
coinAmount = tonumber(lei)
})
end)
-------------------------------------------------------------------------------
-- NUI CALLBACKS
-------------------------------------------------------------------------------
RegisterNUICallback('exitWith', function(data, cb)
cb('ok')
SetNuiFocus(false, false)
open = false
TriggerServerEvent("esx_slots:PayOutRewards", data.coinAmount)
end)
-------------------------------------------------------------------------------
-- THREADS
-------------------------------------------------------------------------------
Citizen.CreateThread(function ()
SetNuiFocus(false, false)
open = false
local wTime = 500
local x = 1
while true do
Citizen.Wait(wTime)
langaAparat = false
for i=1, #Config.Slots, 1 do
if GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), Config.Slots[i].x, Config.Slots[i].y, Config.Slots[i].z, true) < 2 then
x = i
wTime = 0
langaAparat = true
ESX.ShowHelpNotification('Press ~INPUT_PICKUP~ to test your luck at slot machine')
elseif GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), Config.Slots[x].x, Config.Slots[x].y, Config.Slots[x].z, true) > 4 then
wTime = 500
end
end
end
end)
Citizen.CreateThread(function ()
while true do
Citizen.Wait(1)
if open then
DisableControlAction(0, 1, true) -- LookLeftRight
DisableControlAction(0, 2, true) -- LookUpDown
DisableControlAction(0, 24, true) -- Attack
DisablePlayerFiring(GetPlayerPed(-1), true) -- Disable weapon firing
DisableControlAction(0, 142, true) -- MeleeAttackAlternate
DisableControlAction(0, 106, true) -- VehicleMouseControlOverride
elseif IsControlJustReleased(0, 38) and langaAparat then
TriggerEvent('esx_slots:enterBets')
end
end
end)