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