· 6 years ago · Oct 06, 2019, 03:06 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 vRP.closeMenu(player)
421
422 vRP.getUData(user_id,"custom:u"..user_id.."veh_"..vname, function(data)
423 local custom = json.decode(data) or {}
424 if vRP.tryFullPayment(user_id,300) then
425 vRPclient.spawnGarageVehicle(player,{vname}, function(result)
426 if result then
427 vRPclient.setVehicleMods(player,{custom})
428 else
429 vRPclient.notify(player,{lang.garage.personal.out()})
430 end
431 end)
432 else
433 vRPclient.notify(player,{"Você não tem dinheiro!"})
434 end
435 end)
436 end
437 end
438
439 -- get player owned vehicles
440 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(pvehicles, affected)
441 -- add rents to whitelist
442 for k,v in pairs(tmpdata.rent_vehicles) do
443 if v then -- check true, prevent future neolua issues
444 table.insert(pvehicles,{vehicle = k})
445 end
446 end
447
448 for k,v in pairs(pvehicles) do
449 local vehicle = vehicles[v.vehicle]
450 if vehicle then
451 submenu[vehicle[1]] = {choose,vehicle[3]}
452 kitems[vehicle[1]] = v.vehicle
453 end
454 end
455
456 vRP.openMenu(player,submenu)
457 end)
458 end
459 end,lang.garage.owned.description()}
460 menu[lang.garage.store.title()] = {function(player,choice)
461 -- old vRPclient.despawnGarageVehicle(player,{veh_type,15})
462 vRPclient.getNearestOwnedVehicle(player, {15}, function(ok, name)
463 if ok then
464 vRPclient.despawnGarageVehicle(player, {name})
465 else
466 vRPclient.notify(player, {"Veículo muito longe."})
467 end
468 end)
469 end, lang.garage.store.description()}
470 end
471
472 end
473end
474
475local function build_client_garages(source)
476 local user_id = vRP.getUserId(source)
477 if user_id ~= nil then
478 for k,v in pairs(garages) do
479 local gtype,x,y,z = table.unpack(v)
480
481 local group = vehicle_groups[gtype]
482 if group then
483 local gcfg = group._config
484
485 -- enter
486 local garage_enter = function(player,area)
487 local user_id = vRP.getUserId(source)
488 if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) then
489 local menu = garage_menus[gtype]
490 if menu then
491 vRP.openMenu(player,menu)
492 end
493 end
494 end
495
496 -- leave
497 local garage_leave = function(player,area)
498 vRP.closeMenu(player)
499 end
500
501 if gcfg.blipid ~= nil then
502 vRPclient.addScaledBlip(source,{x,y,z,0.7,gcfg.blipid,gcfg.blipcolor,lang.garage.title({gtype})})
503 --vRPclient.addBlip(source,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.garage.title({gtype})})
504 end
505 if string.match(gtype, "Garagem") then
506 --vRPclient.addMarker(source,{x,y,z,1.5,1.5,0.7,0,125,255,125,150})
507 vRPclient.addCustomMarker(source,{27,x,y,z,0,0,0,2.5,2.5,0.7,0,125,255,125,150,1,0,0})
508 vRPclient.addCustomMarker(source,{36,x,y,z,0,0,0,1.5,1.5,1.5,0,125,255,125,150,0,1,0})
509 else
510 vRPclient.addMarker(source,{x,y,z,1.5,1.5,0.7,0,125,255,125,150})
511 end
512
513 vRP.setArea(source,"vRP:garage"..k,x,y,z,2.5,1.5,garage_enter,garage_leave)
514 end
515 end
516 end
517end
518
519AddEventHandler("vRP:playerSpawn",function(user_id,source,first_spawn)
520 if first_spawn then
521 build_client_garages(source)
522 vRPclient.setUserId(source, {user_id})
523 vRPclient.setVehicleModelsIndex(source, {veh_models})
524 end
525end)
526
527-- VEHICLE MENU
528
529-- define vehicle actions
530-- action => {cb(user_id,player,veh_group,veh_name),desc}
531local veh_actions = {}
532
533-- open trunk
534veh_actions[lang.vehicle.trunk.title()] = {function(user_id,player,name)
535 local chestname = "u"..user_id.."veh_"..string.lower(name)
536 local max_weight = cfg_inventory.vehicle_chest_weights[string.lower(name)] or cfg_inventory.default_vehicle_chest_weight
537
538 local tmpdata = vRP.getUserTmpTable(user_id)
539 if tmpdata.rent_vehicles[name] == true then
540 vRPclient.notify(player,{"~r~Carros Alugados não possuem Porta-Malas."})
541 return
542 else
543 -- open chest
544 vRPclient.vc_openDoor(player, {name, 5})
545 vRP.openChest(player, chestname, max_weight, function()
546 vRPclient.vc_closeDoor(player, {name, 5})
547 end)
548 end
549end, lang.vehicle.trunk.description()}
550
551-- detach trailer
552veh_actions[lang.vehicle.detach_trailer.title()] = {function(user_id,player,name)
553 vRPclient.vc_detachTrailer(player, {name})
554end, lang.vehicle.detach_trailer.description()}
555
556-- detach towtruck
557veh_actions[lang.vehicle.detach_towtruck.title()] = {function(user_id,player,name)
558 vRPclient.vc_detachTowTruck(player, {name})
559end, lang.vehicle.detach_towtruck.description()}
560
561-- detach cargobob
562veh_actions[lang.vehicle.detach_cargobob.title()] = {function(user_id,player,name)
563 vRPclient.vc_detachCargobob(player, {name})
564end, lang.vehicle.detach_cargobob.description()}
565
566-- lock/unlock
567veh_actions[lang.vehicle.lock.title()] = {function(user_id,player,name)
568 vRPclient.vc_toggleLock(player, {name})
569end, lang.vehicle.lock.description()}
570
571-- engine on/off
572veh_actions[lang.vehicle.engine.title()] = {function(user_id,player,name)
573 vRPclient.vc_toggleEngine(player, {name})
574end, lang.vehicle.engine.description()}
575
576local function ch_vehicle(player,choice)
577 local user_id = vRP.getUserId(player)
578 if user_id ~= nil then
579 -- check vehicle
580 vRPclient.getNearestOwnedVehicle(player,{7},function(ok,name)
581
582 -- build vehicle menu
583 vRP.buildMenu("vehicle", {user_id = user_id, player = player, vname = name}, function(menu)
584 menu.name=lang.vehicle.title()
585 menu.css={top="75px",header_color="rgba(255,125,0,0.75)"}
586
587 if ok then
588 for k,v in pairs(veh_actions) do
589 menu[k] = {function(player,choice) v[1](user_id,player,name) end, v[2]}
590 end
591 end
592
593 local ch_keys = function(player,choice)
594 local user_id = vRP.getUserId(player)
595 if user_id ~= nil then
596 local kitems = {}
597 local tosub = false
598 local submenu = {name=lang.garage.keys.title(), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
599 submenu.onclose = function()
600 if not tosub then
601 vRP.openMenu(player,menu)
602 end
603 end
604
605 local choose = function(player, choice)
606 local vehicle = choice
607 local vname = kitems[vehicle]
608 local subsubmenu = {name=lang.garage.keys.key({vehicle}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
609 subsubmenu.onclose = function()
610 tosub = false
611 vRP.openMenu(player,submenu)
612 end
613
614 local ch_sell = function(player, choice)
615 vRPclient.getNearestPlayer(player, {5}, function(nplayer)
616 if nplayer then
617 local tuser_id = vRP.getUserId(nplayer)
618 MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = vname}, function(rowss, affected)
619 if #rowss > 0 then
620 MySQL.query("vRP/get_vehicle", {user_id = tuser_id, vehicle = vname}, function(rows, affected)
621 if #rows == 0 then
622 vRP.prompt(player,lang.garage.keys.sell.prompt(),"",function(player,price)
623 local price = tonumber(sanitizeString(price,"\"[]{}+=?!_()#@%/\\|,.",false))
624 vRP.request(nplayer, lang.garage.keys.sell.request({vehicle,price}), 30,function(nplayer,ok)
625 if ok then
626 if vRP.tryFullPayment(tuser_id,price) then
627 MySQL.execute("vRP/move_vehicle", {user_id = user_id, tuser_id = tuser_id, vehicle = vname})
628 vRP.delUData(tuser_id,"custom:u"..tuser_id.."veh_"..vname) -- try delete old car history
629 vRP.delSData(user_id,"chest:u"..user_id.."veh_"..vname)
630 vRP.getUData(user_id,"custom:u"..user_id.."veh_"..vname, function(data)
631 local custom = json.decode(data) or {}
632 vRP.setUData(tuser_id,"custom:u"..tuser_id.."veh_"..vname, json.encode(custom))
633 vRP.delUData(user_id,"custom:u"..user_id.."veh_"..vname)
634 end)
635 if price > 0 then
636 vRP.giveBankMoney(user_id,price)
637 vRPclient.notify(nplayer,{lang.money.paid({price})})
638 vRPclient.notify(player,{lang.money.received({price})})
639 end
640
641 vRPclient.isOwnedVehicleOut(player, {vname}, function(veh,netIdSent)
642 if veh then
643 vRPclient.forceDespawnGarageVehicle(player,{veh})
644 TriggerClientEvent("b2k:syncRemovedEntity", -1, netIdSent)
645 end
646 end)
647 vRP.closeMenu(player)
648 else
649 vRPclient.notify(player,{lang.money.not_enough()})
650 vRPclient.notify(nplayer,{lang.money.not_enough()})
651 end
652 else
653 vRPclient.notify(player,{lang.common.request_refused()})
654 end
655 end)
656 end)
657 else
658 vRPclient.notify(player,{"Você não possui este veículo."})
659 end
660 end)
661 else
662 vRPclient.notify(nplayer,{lang.garage.keys.sell.owned()})
663 vRPclient.notify(player,{lang.garage.keys.sell.owned()})
664 end
665 end)
666 else
667 vRPclient.notify(player,{lang.common.no_player_near()})
668 end
669 end)
670 end
671
672 subsubmenu[lang.garage.keys.sell.title()] = {ch_sell,lang.garage.keys.sell.description()}
673
674 tosub = true
675 vRP.openMenu(player,subsubmenu)
676 end
677
678 -- get player owned vehicles (indexed by vehicle type name in lower case)
679 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(pvehicles, affected)
680 for k,v in pairs(pvehicles) do
681 local vehicle
682 for x,garage in pairs(vehicle_groups) do
683 vehicle = garage[v.vehicle]
684 if vehicle then break end
685 end
686
687 if vehicle then
688 submenu[vehicle[1]] = {choose,vehicle[3]}
689 kitems[vehicle[1]] = v.vehicle
690 end
691 end
692
693 vRP.openMenu(player,submenu)
694 end)
695 end
696 end
697
698 menu[lang.garage.keys.title()] = {ch_keys, lang.garage.keys.description()}
699
700 vRP.openMenu(player,menu)
701 end)
702 --else
703 -- vRPclient.notify(player,{lang.vehicle.no_owned_near()})
704 --end
705 end)
706
707 end
708end
709
710-- ask trunk (open other user car chest)
711local function ch_asktrunk(player,choice)
712 vRPclient.getNearestPlayer(player,{10},function(nplayer)
713 local nuser_id = vRP.getUserId(nplayer)
714 if nuser_id ~= nil then
715 vRPclient.notify(player,{lang.vehicle.asktrunk.asked()})
716 vRP.request(nplayer,lang.vehicle.asktrunk.request(),15,function(nplayer,ok)
717 if ok then -- request accepted, open trunk
718 vRPclient.getNearestOwnedVehicle(nplayer,{7},function(ok,name)
719 if ok then
720 local tmpdata = vRP.getUserTmpTable(nuser_id)
721 if tmpdata.rent_vehicles[name] == true then
722 vRPclient.notify(player,{"~r~Carros Alugados não possuem Porta-Malas."})
723 return
724 else
725 local chestname = "u"..nuser_id.."veh_"..string.lower(name)
726 local max_weight = cfg_inventory.vehicle_chest_weights[string.lower(name)] or cfg_inventory.default_vehicle_chest_weight
727
728 -- open chest
729 local cb_out = function(idname,amount)
730 vRPclient.notify(nplayer,{lang.inventory.give.given({vRP.getItemName(idname),amount})})
731 end
732
733 local cb_in = function(idname,amount)
734 vRPclient.notify(nplayer,{lang.inventory.give.received({vRP.getItemName(idname),amount})})
735 end
736
737 vRPclient.vc_openDoor(nplayer, {name,5})
738 vRP.openChest(player, chestname, max_weight, function()
739 vRPclient.vc_closeDoor(nplayer, {name,5})
740 end,cb_in,cb_out)
741 end
742 else
743 vRPclient.notify(player,{lang.vehicle.no_owned_near()})
744 vRPclient.notify(nplayer,{lang.vehicle.no_owned_near()})
745 end
746 end)
747 else
748 vRPclient.notify(player,{lang.common.request_refused()})
749 end
750 end)
751 else
752 vRPclient.notify(player,{lang.common.no_player_near()})
753 end
754 end)
755end
756
757-- repair nearest vehicle
758local repair_seq = {
759 {"mini@repair","fixing_a_player",1}
760}
761
762local function ch_repair(player,choice)
763 local user_id = vRP.getUserId(player)
764 if user_id ~= nil then
765 -- anim and repair
766 vRPclient.getNearestVehicle(player,{4},function(vehicle)
767 if vehicle then
768 vRPclient.checkOffSetAndHoodOpen(player,{vehicle,true},function(isok,netid)
769 if isok then
770 if vRP.tryGetInventoryItem(user_id,"repairkit",1,true) then
771 vRPclient.playAnim(player,{false,repair_seq,false})
772 SetTimeout(15000, function()
773 TriggerClientEvent("b2k:fixeVehicleByNetId", -1, netid)
774 vRPclient.playSound(player,{"WEAPON_PURCHASE", "HUD_AMMO_SHOP_SOUNDSET"})
775 vRPclient.stopAnim(player,{false})
776 end)
777 end
778 else
779 vRPclient.notify(player,{"Você precisa se posicionar na Frente ou Atrás do veículo."})
780 end
781 end)
782 else
783 vRPclient.notify(player,{"Nenhum veículo próximo."})
784 end
785 end)
786 end
787end
788
789-- replace nearest vehicle
790local function ch_replace(player,choice)
791 vRPclient.replaceNearestVehicle(player,{7})
792end
793
794vRP.registerMenuBuilder("main", function(add, data)
795 local user_id = vRP.getUserId(data.player)
796 if user_id ~= nil then
797 -- add vehicle entry
798 local choices = {}
799 choices[lang.vehicle.title()] = {ch_vehicle}
800
801 -- add ask trunk
802 choices[lang.vehicle.asktrunk.title()] = {ch_asktrunk}
803
804 -- add repair functions
805 if vRP.hasPermission(user_id, "vehicle.repair") then
806 choices[lang.vehicle.repair.title()] = {ch_repair, lang.vehicle.repair.description()}
807 end
808
809 if vRP.hasPermission(user_id, "vehicle.replace") then
810 choices[lang.vehicle.replace.title()] = {ch_replace, lang.vehicle.replace.description()}
811 end
812
813 add(choices)
814 end
815end)
816
817RegisterServerEvent("b2k:pressLockCar")
818AddEventHandler("b2k:pressLockCar", function()
819 local player = source
820 local user_id = vRP.getUserId(player)
821 if user_id ~= nil then
822 vRPclient.getNearestOwnedVehicle(player, {7}, function(ok, name)
823 if ok then
824 vRPclient.vc_toggleLock(player, {name})
825 vRPclient.playSound(player,{"WEAPON_PURCHASE", "HUD_AMMO_SHOP_SOUNDSET"})
826 --vRPclient.playAnim(player,{true,{{"anim@mp_player_intincardancelow@ps@","idle_a_fp",1}},false})
827 --SetTimeout(1000, function()
828 -- vRPclient.stopAnim(player,{false})
829 --end)
830 end
831 end)
832 end
833end)
834
835RegisterServerEvent("b2k:trySyncLockVehicle")
836AddEventHandler("b2k:trySyncLockVehicle", function(nveh, cond)
837 local player = source
838 local user_id = vRP.getUserId(player)
839 if user_id ~= nil then
840 TriggerClientEvent("b2k:syncLockVehicle", -1, nveh, cond)
841 end
842end)