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