· 6 years ago · Jul 22, 2019, 08:02 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 for veh_model,_ in pairs(vehicles) do
50 if not veh_models[veh_model] and veh_model ~= "_config" then
51 veh_models[veh_model] = veh_models_ids:gen()
52 end
53 end
54
55 local gtypes = vehicles._config.gtype
56
57 local menu = {
58 name=lang.garage.title({group}),
59 css={top = "75px", header_color="rgba(255,125,0,0.75)"}
60 }
61 garage_menus[group] = menu
62
63 for _,gtype in pairs(gtypes) do
64
65 if gtype == "personal" then
66 menu[lang.garage.owned.title()] = {function(player,choice)
67 local user_id = vRP.getUserId(player)
68 if user_id ~= nil then
69 local tmpdata = vRP.getUserTmpTable(user_id)
70 if tmpdata.rent_vehicles == nil then
71 tmpdata.rent_vehicles = {}
72 end
73
74
75 -- build nested menu
76 local kitems = {}
77 local submenu = {name=lang.garage.title({lang.garage.owned.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
78 submenu.onclose = function()
79 --vRP.openMenu(player,menu)
80 end
81
82 local choose = function(player, choice)
83 local vname = kitems[choice]
84 if vname then
85 MySQL.query("vRP/get_vehicle_seized", {userid = user_id, vehicle = vname}, function(rows, affected)
86 if #rows > 0 then -- has vehicle
87 for k,v in ipairs(rows) do
88 local seized = v.seized
89 if seized then
90 TriggerClientEvent('chatMessage', player, '', {255, 0, 0}, "Esse veículo foi apreendido pela Polícia.", {255, 255, 255, 0.5,'',100,0,0, 0.5}, "Hit", "RESPAWN_SOUNDSET")
91 else
92 -------------------------------------------------------------------------
93 vRP.closeMenu(player)
94 vRP.getUData(user_id,"custom:u"..user_id.."veh_"..vname, function(data)
95 local custom = json.decode(data) or {}
96
97 vRPclient.spawnGarageVehicle(player,{vname}, function(result)
98 if result then
99 vRPclient.setVehicleMods(player,{custom})
100 else
101 vRPclient.notify(player,{lang.garage.personal.out()})
102 end
103 end)
104 end)
105 -------------------------------------------------------------------------
106 end
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
134 menu[lang.garage.store.title()] = {function(player,choice)
135 -- old vRPclient.despawnGarageVehicle(player,{veh_type,15})
136 vRPclient.getNearestOwnedVehicle(player, {15}, function(ok, name)
137 if ok then
138 vRPclient.despawnGarageVehicle(player, {name})
139 else
140 vRPclient.notify(player, {"Veículo muito longe."})
141 end
142 end)
143 end, lang.garage.store.description()}
144 elseif gtype == "store" then
145 menu[lang.garage.buy.title()] = {function(player,choice)
146 local user_id = vRP.getUserId(player)
147 if user_id ~= nil then
148
149 -- build nested menu
150 local kitems = {}
151 local submenu = {name=lang.garage.title({lang.garage.buy.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
152 submenu.onclose = function()
153 vRP.openMenu(player,menu)
154 end
155
156 local choose = function(player, choice)
157 local vname = kitems[choice]
158 if vname then
159 -- spawn vehicle
160 local vehicle = vehicles[vname]
161 if vehicle then
162 vRP.closeMenu(player)
163 vRPclient.spawnGarageVehicle(player,{veh_type,vname})
164 end
165 end
166 end
167
168 local choose = function(player, choice)
169 local vname = kitems[choice]
170 if vname then
171 -- buy vehicle
172 local vehicle = vehicles[vname]
173 if vehicle then
174 MySQL.query("vRP/count_vehicle", {vehicle = vname}, function(row, affected)
175 if vehicle[4] ~= -1 and row[1].qtd >= vehicle[4] then
176 vRPclient.notify(player,{"~r~Sem estoque para este modelo."})
177 else
178 local priceBuyCar = vehicle[2]
179 local discountBuyCar = 0
180 local maxCarsPerm = 100
181
182 if vRP.hasPermission(user_id, "vip.10carros") then
183 discountBuyCar = priceBuyCar * 0.10
184 maxCarsPerm = 100
185 end
186 if vRP.hasPermission(user_id, "vip.20carros") then
187 discountBuyCar = priceBuyCar * 0.20
188 maxCarsPerm = 100
189 end
190 if vRP.hasPermission(user_id, "vip.30carros") then
191 discountBuyCar = priceBuyCar * 0.30
192 maxCarsPerm = 100
193 end
194
195 priceBuyCar = priceBuyCar - discountBuyCar
196
197 MySQL.query("vRP/count_user_vehicles", {user_id = user_id}, function(row2, affected)
198
199 if vRP.hasPermission(user_id, "vip.unlimitedcars") then
200 maxCarsPerm = -1
201 end
202
203 if maxCarsPerm ~= -1 and row[1].qtd >= maxCarsPerm then
204 vRPclient.notify(player,{"~r~Limite de Veículos por Dono atingido. (Max: " .. maxCarsPerm ..")"})
205 else
206 if vRP.tryPayment(user_id,priceBuyCar) then
207 MySQL.execute("vRP/add_vehicle", {user_id = user_id, vehicle = vname})
208 vRPclient.notify(player,{lang.money.paid({priceBuyCar})})
209 vRP.closeMenu(player)
210 else
211 vRPclient.notify(player,{lang.money.not_enough()})
212 end
213 end
214 end)
215 end
216 end)
217 end
218 end
219 end
220
221 -- get player owned vehicles (indexed by vehicle type name in lower case)
222 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(_pvehicles, affected)
223 local pvehicles = {}
224 for k,v in pairs(_pvehicles) do
225 pvehicles[string.lower(v.vehicle)] = true
226 end
227
228 -- for each existing vehicle in the garage group
229 for k,v in pairs(vehicles) do
230 if k ~= "_config" and pvehicles[string.lower(k)] == nil then -- not already owned
231 submenu[v[1]] = {choose,lang.garage.buy.info({v[2],v[3]})}
232 kitems[v[1]] = k
233 end
234 end
235
236 vRP.openMenu(player,submenu)
237 end)
238 end
239 end,lang.garage.buy.description()}
240
241 menu[lang.garage.sell.title()] = {function(player,choice)
242 local user_id = vRP.getUserId(player)
243 if user_id ~= nil then
244
245 -- build nested menu
246 local kitems = {}
247 local submenu = {name=lang.garage.title({lang.garage.sell.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
248 submenu.onclose = function()
249 vRP.openMenu(player,menu)
250 end
251
252 local choose = function(player, choice)
253 vRP.request(player,"Certeza que deseja vender este veículo?",30,function(player,ok)
254 if ok then
255 local vname = kitems[choice]
256 if vname then
257 -- sell vehicle
258 local vehicle = vehicles[vname]
259 if vehicle then
260 local price = math.ceil((vehicle[2]*cfg.sell_factor)*1)
261
262 MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = vname}, function(rows, affected)
263 if #rows > 0 then -- has vehicle
264 vRP.giveMoney(user_id,price)
265 MySQL.execute("vRP/remove_vehicle", {user_id = user_id, vehicle = vname})
266 vRPclient.notify(player,{lang.money.received({price})})
267 vRP.closeMenu(player)
268 else
269 vRPclient.notify(player,{lang.common.not_found()})
270 end
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)