-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclient.lua
244 lines (224 loc) · 11 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
local gunsmiths = {
{ x = -282.28, y = 780.59, z = 118.53 }, --val
{ x = 2715.9, y = -1285.04, z = 49.63 }, --saint
{ x = -856.95, y = -1391.59, z = 43.49 }, --blackwater
{ x = 1323.01, y = -1321.53, z = 77.89 }, --Rhodes
}
local active = false
local ShopPrompt
local hasAlreadyEnteredMarker, lastZone
local currentZone = nil
MenuData = {}
TriggerEvent("redemrp_menu_base:getData",function(call)
MenuData = call
end)
function SetupShopPrompt()
Citizen.CreateThread(function()
local str = 'Open Shop'
ShopPrompt = PromptRegisterBegin()
PromptSetControlAction(ShopPrompt, 0xE8342FF2)
str = CreateVarString(10, 'LITERAL_STRING', str)
PromptSetText(ShopPrompt, str)
PromptSetEnabled(ShopPrompt, false)
PromptSetVisible(ShopPrompt, false)
PromptSetHoldMode(ShopPrompt, true)
PromptRegisterEnd(ShopPrompt)
end)
end
AddEventHandler('redemrp_gunshop:hasEnteredMarker', function(zone)
currentZone = zone
end)
AddEventHandler('redemrp_gunshop:hasExitedMarker', function(zone)
if active == true then
PromptSetEnabled(ShopPrompt, false)
PromptSetVisible(ShopPrompt, false)
active = false
end
MenuData.CloseAll()
currentZone = nil
end)
Citizen.CreateThread(function()
SetupShopPrompt()
while true do
Citizen.Wait(0)
local player = PlayerPedId()
local coords = GetEntityCoords(player)
local isInMarker, currentZone = false
for k,v in ipairs(gunsmiths) do
if (Vdist(coords.x, coords.y, coords.z, v.x, v.y, v.z) < 1.5) then
isInMarker = true
currentZone = 'gunsmiths'
lastZone = 'gunsmiths'
end
end
if isInMarker and not hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = true
TriggerEvent('redemrp_gunshop:hasEnteredMarker', currentZone)
end
if not isInMarker and hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = false
TriggerEvent('redemrp_gunshop:hasExitedMarker', lastZone)
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if currentZone then
if active == false then
PromptSetEnabled(ShopPrompt, true)
PromptSetVisible(ShopPrompt, true)
active = true
end
if PromptHasHoldModeCompleted(ShopPrompt) then
ShopMenu()
PromptSetEnabled(ShopPrompt, false)
PromptSetVisible(ShopPrompt, false)
active = false
currentZone = nil
end
else
Citizen.Wait(500)
end
end
end)
function ShopMenu()
MenuData.CloseAll()
local elements = {
{label = "Pistols", value = 'pistols'},
{label = "Long Guns", value = 'longguns'},
{label = "Melee Weapons", value = 'handguns'},
{label = "Ammo", value = 'ammo'}
}
MenuData.Open('default', GetCurrentResourceName(), 'weaponshop_main', {
title = 'Weapon Shop',
subtext = 'choose a category',
align = 'top-left',
elements = elements,
}, function(data, menu)
local elements2 = {}
local OpenSub = false
local category = data.current.value
if category == 'pistols' then
elements2 = {
{label = "Cattleman Revolver", value = 'cattleman_w', weapon = 'WEAPON_REVOLVER_CATTLEMAN', price = 10, lvl = 1, subtext = '$10 LvL 1'},
{label = "Double Action Revolver", value = 'doubleaction_w', weapon = 'WEAPON_REVOLVER_DOUBLEACTION', price = 12, lvl = 5, subtext = '$12 LvL 5'},
{label = "Volcanic", value = 'volcanic_w', weapon = 'WEAPON_PISTOL_VOLCANIC', price = 20, lvl = 10, subtext = '$20 LvL 10'},
{label = "Semi-auto Pistol", value = 'semiauto-p_w', weapon = 'WEAPON_PISTOL_SEMIAUTO', price = 22, lvl = 15, subtext = '$22 LvL 15'},
{label = "Mauser", value = 'mauser_w', weapon = 'WEAPON_PISTOL_MAUSER', price = 30, lvl = 20, subtext = '$30 LvL 20'},
{label = "M 1899", value = 'm1899_w', weapon = 'WEAPON_PISTOL_M1899', price = 40, lvl = 30, subtext = '$40 LvL 30'},
{label = "Lemat Revolver", value = 'lemat_w', weapon = 'WEAPON_REVOLVER_LEMAT', price = 50, lvl = 40, subtext = "$50 LvL 40"}
}
OpenSub = true
elseif category == 'longguns' then
elements2 = {
{label = "Carbine Repeator", value = 'carbine_w', weapon = 'WEAPON_REPEATER_CARBINE', price = 20, lvl = 1, subtext = '$20 LvL 1'},
{label = "Varmint Rifle", value = 'varmint_w', weapon = 'WEAPON_RIFLE_VARMINT', price = 15, lvl = 1, subtext = "$15 LvL 1"},
{label = "Evans Repeater", value = 'evans_w', weapon = 'WEAPON_REPEATER_EVANS', price = 30, lvl = 5, subtext = "$30 LvL 5"},
{label = "Bolt Action Rifle", value = 'bolt_w', weapon = 'WEAPON_RIFLE_BOLTACTION', price = 40, lvl = 10, subtext = "$40 LvL 10"},
{label = "Carcano Rifle", value = 'carcano_w', weapon = 'WEAPON_SNIPERRIFLE_CARCANO', price = 70, lvl = 30, subtext = "$70 LvL 30"},
{label = "Rolling Block Rifle", value = 'rolling_w', weapon = 'WEAPON_SNIPERRIFLE_ROLLINGBLOCK', price = 100, lvl = 50, subtext = "$100 LvL 50"},
{label = "Pump Shotgun", value = 'pump_w', weapon = 'WEAPON_SHOTGUN_PUMP', price = 25, lvl = 10, subtext = "$25 LvL 10"},
{label = "Repeating Shotgun", value = 'repeating_w', weapon = 'WEAPON_SHOTGUN_REPEATING', price = 40, lvl = 20, subtext = "$40 LvL 20"},
{label = "Semi-auto Shotgun", value = 'semiauto-s_w', weapon = 'WEAPON_SHOTGUN_SEMIAUTO', price = 55, lvl = 30, subtext = "$55 LvL 30"},
{label = "Sawed-off Shotgun", value = 'sawedoff_w', weapon = 'WEAPON_SHOTGUN_SAWEDOFF', price = 70, lvl = 50, subtext = "$70 LvL 50"}
}
OpenSub = true
elseif category == 'handguns' then
elements2 = {
{label = "Knife", value = 'knife_w', weapon = 'WEAPON_MELEE_KNIFE', price = 2, lvl = 1, subtext = '$2 LvL 1'},
{label = "Lantern", value = 'lantern_r_w', weapon = 'WEAPON_MELEE_DAVY_LANTERN', price = 10, lvl = 1, subtext = "$10 LvL 1"},
{label = "Bow", value = 'bow_w', weapon = 'WEAPON_BOW', price = 10, lvl = 5, subtext = "$10 LvL 5"},
{label = "Lasso", value = 'lasso_w', weapon = 'WEAPON_LASSO', price = 10, lvl = 10, subtext = "$10 LvL 10"},
{label = "Hatchet", value = 'hatchet_w', weapon = 'WEAPON_MELEE_HATCHET', price = 10, lvl = 15, subtext = "$10 LvL 15"},
{label = "Throwing knives", value = 'throwing_w', weapon = 'WEAPON_THROWN_THROWING_KNIVES', price = 25, lvl = 25, subtext = "$25 LvL 25"},
{label = "Electric Lantern", value = 'lantern_w', weapon = 'WEAPON_MELEE_LANTERN_ELECTRIC', price = 30, lvl = 25, subtext = "$30 LvL 25"},
{label = "Tomahawk", value = 'tomahawk_w', weapon = 'WEAPON_THROWN_TOMAHAWK', price = 25, lvl = 30, subtext = "$25 LvL 30"}
}
OpenSub = true
elseif category == 'ammo' then
local options = {
{label = 'Pistols', value = 'pistols'},
{label = 'Long Guns', value = 'longgunsammo'},
{label = 'Melee Weapons', value = 'handgunsammo'},
}
MenuData.Open('default', GetCurrentResourceName(), 'weaponshop_ammo', {
title = 'Ammo Shop',
align = 'top-left',
elements = options,
}, function(data2, menu2)
local choice = data2.current.value
local ammochoices = {}
if choice == 'pistols' then
ammochoices = {
{label = "Revolver", value = 'revolver_ammo', price = 3, subtext = '$3'},
{label = "Pistol", value = 'pistol_ammo', price = 4, subtext = '$4'}
}
elseif choice == 'longgunsammo' then
ammochoices = {
{label = "Repeator", value = 'repeator_ammo', price = 2, subtext = '$2'},
{label = "22 Rifle", value = '22_ammo', price = 2, subtext = '$2'},
{label = "Rifle", value = 'rifle_ammo', price = 3, subtext = '$3'},
{label = "Sniper Rifle", value = 'snipe_ammo', price = 4, subtext = '$4'},
{label = "Shotgun Shells", value = 'shotgun_ammo', price = 3, subtext = '$3'}
}
elseif choice == 'handgunsammo' then
ammochoices = {
{label = "Arrows", value = 'arrows', price = 5, subtext = '$5'},
{label = "Throwing knives", value = 'knives', price = 5, subtext = '$5'},
}
end
MenuData.Open('default', GetCurrentResourceName(), 'weaponshop_'..category, {
title = category..' Shop',
align = 'top-left',
elements = ammochoices,
}, function(data3, menu3)
local item = data3.current.value
local price = data3.current.price
TriggerServerEvent("redemrp_gunshop:buyammo", tonumber(price), item)
end, function(data3, menu3)
menu3.close()
end)
end, function(data3, menu3)
menu3.close()
end)
end
if OpenSub == true then
OpenSub = false
MenuData.Open('default', GetCurrentResourceName(), 'weaponshop_'..category, {
title = category..' Shop',
align = 'top-left',
elements = elements2,
}, function(data2, menu2)
local weapon = data2.current.weapon
local item = data2.current.value
local price = data2.current.price
local lvl = data2.current.lvl
TriggerServerEvent("redemrp_gunshop:buygun", item, tonumber(price), weapon, tonumber(lvl))
end, function(data2, menu2)
menu2.close()
end)
end
end, function(data, menu)
menu.close()
end)
end
RegisterNetEvent('redemrp_gunshop:alert')
AddEventHandler('redemrp_gunshop:alert', function(txt)
SetTextScale(0.5, 0.5)
local str = Citizen.InvokeNative(0xFA925AC00EB830B9, 10, "LITERAL_STRING", txt, Citizen.ResultAsLong())
Citizen.InvokeNative(0xFA233F8FE190514C, str)
Citizen.InvokeNative(0xE9990552DEC71600)
end)
RegisterNetEvent('redemrp_gunshop:giveammo')
AddEventHandler('redemrp_gunshop:giveammo', function(type)
local player = GetPlayerPed()
local ammo = GetHashKey(type)
SetPedAmmo(player, ammo, 100)
end)
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
PromptSetEnabled(ShopPrompt, false)
PromptSetVisible(ShopPrompt, false)
end
end)