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