· 6 years ago · Jul 25, 2019, 10:54 PM
1-- a basic garage implementation
2
3-- vehicle db
4MySQL.createCommand("vRP/vehicles_table", [[
5CREATE TABLE IF NOT EXISTS vrp_user_vehicles(
6 user_id INTEGER,
7 vehicle VARCHAR(255),
8 CONSTRAINT pk_user_vehicles PRIMARY KEY(user_id,vehicle),
9 CONSTRAINT fk_user_vehicles_users FOREIGN KEY(user_id) REFERENCES vrp_users(id) ON DELETE CASCADE
10);
11]])
12
13MySQL.createCommand("vRP/add_vehicle","INSERT IGNORE INTO vrp_user_vehicles(user_id,vehicle) VALUES(@user_id,@vehicle)")
14MySQL.createCommand("vRP/remove_vehicle","DELETE FROM vrp_user_vehicles WHERE user_id = @user_id AND vehicle = @vehicle")
15MySQL.createCommand("vRP/get_vehicles","SELECT vehicle FROM vrp_user_vehicles WHERE user_id = @user_id")
16MySQL.createCommand("vRP/get_vehicle","SELECT vehicle FROM vrp_user_vehicles WHERE user_id = @user_id AND vehicle = @vehicle")
17
18MySQL.createCommand("vRP/count_vehicle","SELECT COUNT(*) as qtd FROM vrp_user_vehicles WHERE vehicle = @vehicle")
19MySQL.createCommand("vRP/move_vehicle","UPDATE vrp_user_vehicles SET user_id = @tuser_id WHERE user_id = @user_id AND vehicle = @vehicle")
20
21MySQL.createCommand("vRP/count_user_vehicles","SELECT COUNT(*) as qtd FROM vrp_user_vehicles WHERE user_id = @user_id")
22
23-- init
24MySQL.execute("vRP/vehicles_table")
25
26-- load config
27local Tools = module("vrp","lib/Tools")
28local cfg = module("cfg/garages")
29local cfg_inventory = module("cfg/inventory")
30local vehicle_groups = cfg.garage_types
31local lang = vRP.lang
32
33local garages = cfg.garages
34
35-- vehicle models index
36local veh_models_ids = Tools.newIDGenerator()
37local veh_models = {}
38
39-- prepare garage menus
40
41local garage_menus = {}
42local cooldown = {}
43
44function tvRP.resetCooldown()
45 cooldown[source] = false
46end
47
48for group,vehicles in pairs(vehicle_groups) do
49 --old local veh_type = vehicles._config.vtype or "default"
50
51 -- fill vehicle models index
52 for veh_model,_ in pairs(vehicles) do
53 if not veh_models[veh_model] and veh_model ~= "_config" then
54 veh_models[veh_model] = veh_models_ids:gen()
55 end
56 end
57
58 local gtypes = vehicles._config.gtype
59
60 local menu = {
61 name=lang.garage.title({group}),
62 css={top = "75px", header_color="rgba(255,125,0,0.75)"}
63 }
64 garage_menus[group] = menu
65
66 for _,gtype in pairs(gtypes) do
67
68 if gtype == "personal" then
69 menu[lang.garage.owned.title()] = {function(player,choice)
70 local user_id = vRP.getUserId(player)
71 if user_id ~= nil then
72 -- init tmpdata for rents
73 local tmpdata = vRP.getUserTmpTable(user_id)
74 if tmpdata.rent_vehicles == nil then
75 tmpdata.rent_vehicles = {}
76 end
77
78
79 -- build nested menu
80 local kitems = {}
81 local submenu = {name=lang.garage.title({lang.garage.owned.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
82 submenu.onclose = function()
83 --vRP.openMenu(player,menu)
84 end
85
86 local choose = function(player, choice)
87 local vname = kitems[choice]
88 if vname then
89 -- spawn vehicle
90 --local vehicle = vehicles[vname]
91 --if vehicle then
92 --vRP.closeMenu(player)
93 --vRPclient.spawnGarageVehicle(player,{veh_type,vname})
94 --end
95
96 -- implementar carregar custom mods
97 vRP.closeMenu(player)
98 --vRPclient.spawnGarageVehicle(player,{veh_type,vname})
99 vRP.getUData(user_id,"custom:u"..user_id.."veh_"..vname, function(data)
100 local custom = json.decode(data) or {}
101
102 vRPclient.spawnGarageVehicle(player,{vname}, function(result)
103 if result then
104 vRPclient.setVehicleMods(player,{custom})
105 else
106 vRPclient.notify(player,{lang.garage.personal.out()})
107 end
108 end)
109 end)
110 end
111 end
112
113 -- get player owned vehicles
114 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(pvehicles, affected)
115
116 for k,v in pairs(pvehicles) do
117 local vehicle
118 for x,garage in pairs(vehicle_groups) do
119 vehicle = garage[v.vehicle]
120 if vehicle then break end
121 end
122
123 if vehicle then
124 submenu[vehicle[1]] = {choose,vehicle[3]}
125 kitems[vehicle[1]] = v.vehicle
126
127 end
128 end
129 vRP.openMenu(player,submenu)
130 end)
131 end
132 end,lang.garage.owned.description()}
133 menu[lang.garage.store.title()] = {function(player,choice)
134 -- old vRPclient.despawnGarageVehicle(player,{veh_type,15})
135 vRPclient.getNearestOwnedVehicle(player, {15}, function(ok, name)
136 if ok then
137 vRPclient.despawnGarageVehicle(player, {name})
138 else
139 vRPclient.notify(player, {"Veículo muito longe."})
140 end
141 end)
142 end, lang.garage.store.description()}
143 elseif gtype == "store" then
144 menu[lang.garage.buy.title()] = {function(player,choice)
145 local user_id = vRP.getUserId(player)
146 if user_id ~= nil then
147
148 -- build nested menu
149 local kitems = {}
150 local submenu = {name=lang.garage.title({lang.garage.buy.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
151 submenu.onclose = function()
152 vRP.openMenu(player,menu)
153 end
154
155 local choose = function(player, choice)
156 local vname = kitems[choice]
157 if vname then
158 -- buy vehicle
159 local vehicle = vehicles[vname]
160 if vehicle then
161 MySQL.query("vRP/count_vehicle", {vehicle = vname}, function(row, affected)
162 if vehicle[4] ~= -1 and row[1].qtd >= vehicle[4] then
163 vRPclient.notify(player,{"~r~Sem estoque para este modelo."})
164 else
165 local priceBuyCar = vehicle[2]
166 local discountBuyCar = 0
167 local maxCarsPerm = 3
168
169 if vRP.hasPermission(user_id, "vip.10carros") then
170 discountBuyCar = priceBuyCar * 0.10
171 maxCarsPerm = 4
172 end
173 if vRP.hasPermission(user_id, "vip.20carros") then
174 discountBuyCar = priceBuyCar * 0.20
175 maxCarsPerm = 5
176 end
177 if vRP.hasPermission(user_id, "vip.30carros") then
178 discountBuyCar = priceBuyCar * 0.30
179 maxCarsPerm = 6
180 end
181
182 priceBuyCar = priceBuyCar - discountBuyCar
183
184 MySQL.query("vRP/count_user_vehicles", {user_id = user_id}, function(row2, affected)
185
186 if vRP.hasPermission(user_id, "vip.unlimitedcars") then
187 maxCarsPerm = -1
188 end
189
190 if maxCarsPerm ~= -1 and row2[1].qtd >= maxCarsPerm then
191 vRPclient.notify(player,{"~r~Limite de Veículos por Dono atingido. (Max: " .. maxCarsPerm ..")"})
192 else
193 if vRP.tryPayment(user_id,priceBuyCar) then
194 MySQL.execute("vRP/add_vehicle", {user_id = user_id, vehicle = vname})
195 vRPclient.notify(player,{lang.money.paid({priceBuyCar})})
196 vRP.closeMenu(player)
197 else
198 vRPclient.notify(player,{lang.money.not_enough()})
199 end
200 end
201 end)
202 end
203 end)
204 end
205 end
206 end
207
208 -- get player owned vehicles (indexed by vehicle type name in lower case)
209 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(_pvehicles, affected)
210 local pvehicles = {}
211 for k,v in pairs(_pvehicles) do
212 pvehicles[string.lower(v.vehicle)] = true
213 end
214
215 -- for each existing vehicle in the garage group
216 for k,v in pairs(vehicles) do
217 if k ~= "_config" and pvehicles[string.lower(k)] == nil then -- not already owned
218 submenu[v[1]] = {choose,lang.garage.buy.info({v[2],v[3]})}
219 kitems[v[1]] = k
220 end
221 end
222
223 vRP.openMenu(player,submenu)
224 end)
225 end
226 end,lang.garage.buy.description()}
227
228 menu[lang.garage.sell.title()] = {function(player,choice)
229 local user_id = vRP.getUserId(player)
230 if user_id ~= nil then
231
232 -- build nested menu
233 local kitems = {}
234 local submenu = {name=lang.garage.title({lang.garage.sell.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
235 submenu.onclose = function()
236 vRP.openMenu(player,menu)
237 end
238
239 local choose = function(player, choice)
240 local vname = kitems[choice]
241 if vname then
242 -- sell vehicle
243 local vehicle = vehicles[vname]
244 if vehicle then
245 local price = math.ceil(vehicle[2]*cfg.sell_factor)
246 vRP.prompt(player,"Deseja vender o veiculo ? Digite SIM:","",function(player,cbd)
247 local cbd = cbd or ""
248 MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = vname}, function(rows, affected)
249 if #rows > 0 then
250 if cbd == 'SIM' or cbd == 'sim' or cbd == 'Sim'then
251 vRP.giveMoney(user_id,price)
252 MySQL.execute("vRP/remove_vehicle", {user_id = user_id, vehicle = vname})
253 vRP.delUData(user_id,"custom:u"..user_id.."veh_"..vname)
254 vRP.delSData(user_id,"chest:u"..user_id.."veh_"..vname)
255
256 vRPclient.isOwnedVehicleOut(player, {vname}, function(veh,netIdSent)
257 if veh then
258 vRPclient.forceDespawnGarageVehicle(player,{veh})
259 TriggerClientEvent("b2k:syncRemovedEntity", -1, netIdSent)
260 end
261 vRPclient.notify(player,{lang.money.received({price})})
262 vRP.closeMenu(player)
263
264 end)
265 end
266
267
268
269 else
270 vRPclient.notify(player,{lang.common.not_found()})
271 end
272 end)
273 end)
274 end
275 end
276 end
277
278 -- get player owned vehicles (indexed by vehicle type name in lower case)
279 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(_pvehicles, affected)
280 local pvehicles = {}
281 for k,v in pairs(_pvehicles) do
282 pvehicles[string.lower(v.vehicle)] = true
283 end
284
285 -- for each existing vehicle in the garage group
286 for k,v in pairs(pvehicles) do
287 local vehicle = vehicles[k]
288 if vehicle then -- not already owned
289 local price = math.ceil(vehicle[2]*cfg.sell_factor)
290 submenu[vehicle[1]] = {choose,lang.garage.buy.info({price,vehicle[3]})}
291 kitems[vehicle[1]] = k
292 end
293 end
294
295 vRP.openMenu(player,submenu)
296 end)
297 end
298 end,lang.garage.sell.description()}
299
300 elseif gtype == "rental" then
301 menu[lang.garage.rent.title()] = {function(player,choice)
302 local user_id = vRP.getUserId(player)
303 if user_id ~= nil then
304 -- init tmpdata for rents
305 local tmpdata = vRP.getUserTmpTable(user_id)
306 if tmpdata.rent_vehicles == nil then
307 tmpdata.rent_vehicles = {}
308 end
309
310 -- build nested menu
311 local kitems = {}
312 local submenu = {name=lang.garage.title({lang.garage.rent.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
313 submenu.onclose = function()
314 vRP.openMenu(player,menu)
315 end
316
317 local choose = function(player, choice)
318 local vname = kitems[choice]
319 if vname then
320 -- rent vehicle
321 local vehicle = vehicles[vname]
322 if vehicle then
323 local price = math.ceil(vehicle[2]*cfg.rent_factor)
324 if vRP.tryPayment(user_id,price) then
325 -- add vehicle to rent tmp data
326 tmpdata.rent_vehicles[vname] = true
327
328 vRPclient.notify(player,{lang.money.paid({price})})
329 vRP.closeMenu(player)
330 else
331 vRPclient.notify(player,{lang.money.not_enough()})
332 end
333 end
334 end
335 end
336
337 -- get player owned vehicles (indexed by vehicle type name in lower case)
338 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(_pvehicles, affected)
339 local pvehicles = {}
340 for k,v in pairs(_pvehicles) do
341 pvehicles[string.lower(v.vehicle)] = true
342 end
343
344 -- add rents to blacklist
345 for k,v in pairs(tmpdata.rent_vehicles) do
346 pvehicles[string.lower(k)] = true
347 end
348
349 -- for each existing vehicle in the garage group
350 for k,v in pairs(vehicles) do
351 if k ~= "_config" and pvehicles[string.lower(k)] == nil then -- not already owned
352 local price = math.ceil(v[2]*cfg.rent_factor)
353 submenu[v[1]] = {choose,lang.garage.buy.info({price,v[3]})}
354 kitems[v[1]] = k
355 end
356 end
357
358 vRP.openMenu(player,submenu)
359 end)
360 end
361 end,lang.garage.rent.description()}
362 menu[lang.garage.owned.title()] = {function(player,choice)
363 local user_id = vRP.getUserId(player)
364 if user_id ~= nil then
365 -- init tmpdata for rents
366 local tmpdata = vRP.getUserTmpTable(user_id)
367 if tmpdata.rent_vehicles == nil then
368 tmpdata.rent_vehicles = {}
369 end
370
371
372 -- build nested menu
373 local kitems = {}
374 local submenu = {name=lang.garage.title({lang.garage.owned.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
375 submenu.onclose = function()
376 --vRP.openMenu(player,menu)
377 end
378
379 local choose = function(player, choice)
380 local vname = kitems[choice]
381 if vname then
382 vRP.closeMenu(player)
383
384 vRP.getUData(user_id,"custom:u"..user_id.."veh_"..vname, function(data)
385 local custom = json.decode(data) or {}
386 vRPclient.spawnGarageVehicle(player,{vname}, function(result)
387 if result then
388 vRPclient.setVehicleMods(player,{custom})
389 else
390 vRPclient.notify(player,{lang.garage.personal.out()})
391 end
392 end)
393 end)
394 end
395 end
396
397 -- get player owned vehicles
398 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(pvehicles, affected)
399 -- add rents to whitelist
400 for k,v in pairs(tmpdata.rent_vehicles) do
401 if v then -- check true, prevent future neolua issues
402 table.insert(pvehicles,{vehicle = k})
403 end
404 end
405
406 for k,v in pairs(pvehicles) do
407 local vehicle = vehicles[v.vehicle]
408 if vehicle then
409 submenu[vehicle[1]] = {choose,vehicle[3]}
410 kitems[vehicle[1]] = v.vehicle
411 end
412 end
413
414 vRP.openMenu(player,submenu)
415 end)
416 end
417 end,lang.garage.owned.description()}
418 menu[lang.garage.store.title()] = {function(player,choice)
419 -- old vRPclient.despawnGarageVehicle(player,{veh_type,15})
420 vRPclient.getNearestOwnedVehicle(player, {15}, function(ok, name)
421 if ok then
422 vRPclient.despawnGarageVehicle(player, {name})
423 else
424 vRPclient.notify(player, {"Veículo muito longe."})
425 end
426 end)
427 end, lang.garage.store.description()}
428 end
429
430 end
431end
432
433local function build_client_garages(source)
434 local user_id = vRP.getUserId(source)
435 if user_id ~= nil then
436 for k,v in pairs(garages) do
437 local gtype,x,y,z = table.unpack(v)
438
439 local group = vehicle_groups[gtype]
440 if group then
441 local gcfg = group._config
442
443 -- enter
444 local garage_enter = function(player,area)
445 local user_id = vRP.getUserId(source)
446 if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) then
447 local menu = garage_menus[gtype]
448 if menu then
449 vRP.openMenu(player,menu)
450 end
451 end
452 end
453
454 -- leave
455 local garage_leave = function(player,area)
456 vRP.closeMenu(player)
457 end
458
459 if gcfg.blipid ~= nil then
460 vRPclient.addScaledBlip(source,{x,y,z,0.7,gcfg.blipid,gcfg.blipcolor,lang.garage.title({gtype})})
461 --vRPclient.addBlip(source,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.garage.title({gtype})})
462 end
463 if string.match(gtype, "Garagem") then
464 --vRPclient.addMarker(source,{x,y,z,1.5,1.5,0.7,0,125,255,125,150})
465 vRPclient.addCustomMarker(source,{27,x,y,z,0,0,0,2.5,2.5,0.7,0,125,255,125,150,1,0,0})
466 vRPclient.addCustomMarker(source,{36,x,y,z,0,0,0,1.5,1.5,1.5,0,125,255,125,150,0,1,0})
467 else
468 vRPclient.addMarker(source,{x,y,z,1.5,1.5,0.7,0,125,255,125,150})
469 end
470
471 vRP.setArea(source,"vRP:garage"..k,x,y,z,2.5,1.5,garage_enter,garage_leave)
472 end
473 end
474 end
475end
476
477AddEventHandler("vRP:playerSpawn",function(user_id,source,first_spawn)
478 if first_spawn then
479 build_client_garages(source)
480 vRPclient.setUserId(source, {user_id})
481 vRPclient.setVehicleModelsIndex(source, {veh_models})
482 end
483end)
484
485-- VEHICLE MENU
486
487-- define vehicle actions
488-- action => {cb(user_id,player,veh_group,veh_name),desc}
489local veh_actions = {}
490
491-- open trunk
492veh_actions[lang.vehicle.trunk.title()] = {function(user_id,player,name)
493 local chestname = "u"..user_id.."veh_"..string.lower(name)
494 local max_weight = cfg_inventory.vehicle_chest_weights[string.lower(name)] or cfg_inventory.default_vehicle_chest_weight
495
496 local tmpdata = vRP.getUserTmpTable(user_id)
497 if tmpdata.rent_vehicles[name] == true then
498 vRPclient.notify(player,{"~r~Carros Alugados não possuem Porta-Malas."})
499 return
500 else
501 -- open chest
502 vRPclient.vc_openDoor(player, {name, 5})
503 vRP.openChest(player, chestname, max_weight, function()
504 vRPclient.vc_closeDoor(player, {name, 5})
505 end)
506 end
507end, lang.vehicle.trunk.description()}
508
509-- detach trailer
510veh_actions[lang.vehicle.detach_trailer.title()] = {function(user_id,player,name)
511 vRPclient.vc_detachTrailer(player, {name})
512end, lang.vehicle.detach_trailer.description()}
513
514-- detach towtruck
515veh_actions[lang.vehicle.detach_towtruck.title()] = {function(user_id,player,name)
516 vRPclient.vc_detachTowTruck(player, {name})
517end, lang.vehicle.detach_towtruck.description()}
518
519-- detach cargobob
520veh_actions[lang.vehicle.detach_cargobob.title()] = {function(user_id,player,name)
521 vRPclient.vc_detachCargobob(player, {name})
522end, lang.vehicle.detach_cargobob.description()}
523
524-- lock/unlock
525veh_actions[lang.vehicle.lock.title()] = {function(user_id,player,name)
526 vRPclient.vc_toggleLock(player, {name})
527end, lang.vehicle.lock.description()}
528
529-- engine on/off
530veh_actions[lang.vehicle.engine.title()] = {function(user_id,player,name)
531 vRPclient.vc_toggleEngine(player, {name})
532end, lang.vehicle.engine.description()}
533
534local function ch_vehicle(player,choice)
535 local user_id = vRP.getUserId(player)
536 if user_id ~= nil then
537 -- check vehicle
538 vRPclient.getNearestOwnedVehicle(player,{7},function(ok,name)
539
540 -- build vehicle menu
541 vRP.buildMenu("vehicle", {user_id = user_id, player = player, vname = name}, function(menu)
542 menu.name=lang.vehicle.title()
543 menu.css={top="75px",header_color="rgba(255,125,0,0.75)"}
544
545 if ok then
546 for k,v in pairs(veh_actions) do
547 menu[k] = {function(player,choice) v[1](user_id,player,name) end, v[2]}
548 end
549 end
550
551 local ch_keys = function(player,choice)
552 local user_id = vRP.getUserId(player)
553 if user_id ~= nil then
554 local kitems = {}
555 local tosub = false
556 local submenu = {name=lang.garage.keys.title(), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
557 submenu.onclose = function()
558 if not tosub then
559 vRP.openMenu(player,menu)
560 end
561 end
562
563 local choose = function(player, choice)
564 local vehicle = choice
565 local vname = kitems[vehicle]
566 local subsubmenu = {name=lang.garage.keys.key({vehicle}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
567 subsubmenu.onclose = function()
568 tosub = false
569 vRP.openMenu(player,submenu)
570 end
571
572 local ch_sell = function(player, choice)
573 vRPclient.getNearestPlayer(player, {5}, function(nplayer)
574 if nplayer then
575 local tuser_id = vRP.getUserId(nplayer)
576 MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = vname}, function(rowss, affected)
577 if #rowss > 0 then
578 MySQL.query("vRP/get_vehicle", {user_id = tuser_id, vehicle = vname}, function(rows, affected)
579 if #rows == 0 then
580 vRP.prompt(player,lang.garage.keys.sell.prompt(),"",function(player,price)
581 local price = tonumber(sanitizeString(price,"\"[]{}+=?!_()#@%/\\|,.",false))
582 vRP.request(nplayer, lang.garage.keys.sell.request({vehicle,price}), 30,function(nplayer,ok)
583 if ok then
584 if vRP.tryFullPayment(tuser_id,price) then
585 MySQL.execute("vRP/move_vehicle", {user_id = user_id, tuser_id = tuser_id, vehicle = vname})
586 vRP.delUData(tuser_id,"custom:u"..tuser_id.."veh_"..vname) -- try delete old car history
587 vRP.delSData(user_id,"chest:u"..user_id.."veh_"..vname)
588 vRP.getUData(user_id,"custom:u"..user_id.."veh_"..vname, function(data)
589 local custom = json.decode(data) or {}
590 vRP.setUData(tuser_id,"custom:u"..tuser_id.."veh_"..vname, json.encode(custom))
591 vRP.delUData(user_id,"custom:u"..user_id.."veh_"..vname)
592 end)
593 if price > 0 then
594 vRP.giveBankMoney(user_id,price)
595 vRPclient.notify(nplayer,{lang.money.paid({price})})
596 vRPclient.notify(player,{lang.money.received({price})})
597 end
598
599 vRPclient.isOwnedVehicleOut(player, {vname}, function(veh,netIdSent)
600 if veh then
601 vRPclient.forceDespawnGarageVehicle(player,{veh})
602 TriggerClientEvent("b2k:syncRemovedEntity", -1, netIdSent)
603 end
604 end)
605 vRP.closeMenu(player)
606 else
607 vRPclient.notify(player,{lang.money.not_enough()})
608 vRPclient.notify(nplayer,{lang.money.not_enough()})
609 end
610 else
611 vRPclient.notify(player,{lang.common.request_refused()})
612 end
613 end)
614 end)
615 else
616 vRPclient.notify(player,{"Você não possui este veículo."})
617 end
618 end)
619 else
620 vRPclient.notify(nplayer,{lang.garage.keys.sell.owned()})
621 vRPclient.notify(player,{lang.garage.keys.sell.owned()})
622 end
623 end)
624 else
625 vRPclient.notify(player,{lang.common.no_player_near()})
626 end
627 end)
628 end
629
630 subsubmenu[lang.garage.keys.sell.title()] = {ch_sell,lang.garage.keys.sell.description()}
631
632 tosub = true
633 vRP.openMenu(player,subsubmenu)
634 end
635
636 -- get player owned vehicles (indexed by vehicle type name in lower case)
637 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(pvehicles, affected)
638 for k,v in pairs(pvehicles) do
639 local vehicle
640 for x,garage in pairs(vehicle_groups) do
641 vehicle = garage[v.vehicle]
642 if vehicle then break end
643 end
644
645 if vehicle then
646 submenu[vehicle[1]] = {choose,vehicle[3]}
647 kitems[vehicle[1]] = v.vehicle
648 end
649 end
650
651 vRP.openMenu(player,submenu)
652 end)
653 end
654 end
655
656 menu[lang.garage.keys.title()] = {ch_keys, lang.garage.keys.description()}
657
658 vRP.openMenu(player,menu)
659 end)
660 --else
661 -- vRPclient.notify(player,{lang.vehicle.no_owned_near()})
662 --end
663 end)
664
665 end
666end
667
668-- ask trunk (open other user car chest)
669local function ch_asktrunk(player,choice)
670 vRPclient.getNearestPlayer(player,{10},function(nplayer)
671 local nuser_id = vRP.getUserId(nplayer)
672 if nuser_id ~= nil then
673 vRPclient.notify(player,{lang.vehicle.asktrunk.asked()})
674 vRP.request(nplayer,lang.vehicle.asktrunk.request(),15,function(nplayer,ok)
675 if ok then -- request accepted, open trunk
676 vRPclient.getNearestOwnedVehicle(nplayer,{7},function(ok,name)
677 if ok then
678 local tmpdata = vRP.getUserTmpTable(nuser_id)
679 if tmpdata.rent_vehicles[name] == true then
680 vRPclient.notify(player,{"~r~Carros Alugados não possuem Porta-Malas."})
681 return
682 else
683 local chestname = "u"..nuser_id.."veh_"..string.lower(name)
684 local max_weight = cfg_inventory.vehicle_chest_weights[string.lower(name)] or cfg_inventory.default_vehicle_chest_weight
685
686 -- open chest
687 local cb_out = function(idname,amount)
688 vRPclient.notify(nplayer,{lang.inventory.give.given({vRP.getItemName(idname),amount})})
689 end
690
691 local cb_in = function(idname,amount)
692 vRPclient.notify(nplayer,{lang.inventory.give.received({vRP.getItemName(idname),amount})})
693 end
694
695 vRPclient.vc_openDoor(nplayer, {name,5})
696 vRP.openChest(player, chestname, max_weight, function()
697 vRPclient.vc_closeDoor(nplayer, {name,5})
698 end,cb_in,cb_out)
699 end
700 else
701 vRPclient.notify(player,{lang.vehicle.no_owned_near()})
702 vRPclient.notify(nplayer,{lang.vehicle.no_owned_near()})
703 end
704 end)
705 else
706 vRPclient.notify(player,{lang.common.request_refused()})
707 end
708 end)
709 else
710 vRPclient.notify(player,{lang.common.no_player_near()})
711 end
712 end)
713end
714
715-- repair nearest vehicle
716local repair_seq = {
717 {"mini@repair","fixing_a_player",1}
718}
719
720local function ch_repair(player,choice)
721 local user_id = vRP.getUserId(player)
722 if user_id ~= nil then
723 -- anim and repair
724 vRPclient.getNearestVehicle(player,{4},function(vehicle)
725 if vehicle then
726 vRPclient.checkOffSetAndHoodOpen(player,{vehicle,true},function(isok,netid)
727 if isok then
728 if vRP.tryGetInventoryItem(user_id,"repairkit",1,true) then
729 vRPclient.playAnim(player,{false,repair_seq,false})
730 SetTimeout(15000, function()
731 TriggerClientEvent("b2k:fixeVehicleByNetId", -1, netid)
732 vRPclient.playSound(player,{"WEAPON_PURCHASE", "HUD_AMMO_SHOP_SOUNDSET"})
733 vRPclient.stopAnim(player,{false})
734 end)
735 end
736 else
737 vRPclient.notify(player,{"Você precisa se posicionar na Frente ou Atrás do veículo."})
738 end
739 end)
740 else
741 vRPclient.notify(player,{"Nenhum veículo próximo."})
742 end
743 end)
744 end
745end
746
747-- replace nearest vehicle
748local function ch_replace(player,choice)
749 vRPclient.replaceNearestVehicle(player,{7})
750end
751
752vRP.registerMenuBuilder("main", function(add, data)
753 local user_id = vRP.getUserId(data.player)
754 if user_id ~= nil then
755 -- add vehicle entry
756 local choices = {}
757 choices[lang.vehicle.title()] = {ch_vehicle}
758
759 -- add ask trunk
760 choices[lang.vehicle.asktrunk.title()] = {ch_asktrunk}
761
762 -- add repair functions
763 if vRP.hasPermission(user_id, "vehicle.repair") then
764 choices[lang.vehicle.repair.title()] = {ch_repair, lang.vehicle.repair.description()}
765 end
766
767 if vRP.hasPermission(user_id, "vehicle.replace") then
768 choices[lang.vehicle.replace.title()] = {ch_replace, lang.vehicle.replace.description()}
769 end
770
771 add(choices)
772 end
773end)
774
775RegisterServerEvent("b2k:pressLockCar")
776AddEventHandler("b2k:pressLockCar", function()
777 local player = source
778 local user_id = vRP.getUserId(player)
779 if user_id ~= nil then
780 vRPclient.getNearestOwnedVehicle(player, {7}, function(ok, name)
781 if ok then
782 vRPclient.vc_toggleLock(player, {name})
783 vRPclient.playSound(player,{"WEAPON_PURCHASE", "HUD_AMMO_SHOP_SOUNDSET"})
784 --vRPclient.playAnim(player,{true,{{"anim@mp_player_intincardancelow@ps@","idle_a_fp",1}},false})
785 --SetTimeout(1000, function()
786 -- vRPclient.stopAnim(player,{false})
787 --end)
788 end
789 end)
790 end
791end)
792
793RegisterServerEvent("b2k:trySyncLockVehicle")
794AddEventHandler("b2k:trySyncLockVehicle", function(nveh, cond)
795 local player = source
796 local user_id = vRP.getUserId(player)
797 if user_id ~= nil then
798 TriggerClientEvent("b2k:syncLockVehicle", -1, nveh, cond)
799 end
800end)