· 6 years ago · Jun 04, 2019, 04:08 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 -- open chest
490 vRPclient.vc_openDoor(player, {name, 5})
491 vRP.openChest(player, chestname, max_weight, function()
492 vRPclient.vc_closeDoor(player, {name, 5})
493 end)
494end, lang.vehicle.trunk.description()}
495
496-- detach trailer
497veh_actions[lang.vehicle.detach_trailer.title()] = {function(user_id,player,name)
498 vRPclient.vc_detachTrailer(player, {name})
499end, lang.vehicle.detach_trailer.description()}
500
501-- detach towtruck
502veh_actions[lang.vehicle.detach_towtruck.title()] = {function(user_id,player,name)
503 vRPclient.vc_detachTowTruck(player, {name})
504end, lang.vehicle.detach_towtruck.description()}
505
506-- detach cargobob
507veh_actions[lang.vehicle.detach_cargobob.title()] = {function(user_id,player,name)
508 vRPclient.vc_detachCargobob(player, {name})
509end, lang.vehicle.detach_cargobob.description()}
510
511-- lock/unlock
512veh_actions[lang.vehicle.lock.title()] = {function(user_id,player,name)
513 vRPclient.vc_toggleLock(player, {name})
514end, lang.vehicle.lock.description()}
515
516-- engine on/off
517veh_actions[lang.vehicle.engine.title()] = {function(user_id,player,name)
518 vRPclient.vc_toggleEngine(player, {name})
519end, lang.vehicle.engine.description()}
520
521local function ch_vehicle(player,choice)
522 local user_id = vRP.getUserId(player)
523 if user_id ~= nil then
524 -- check vehicle
525 vRPclient.getNearestOwnedVehicle(player,{7},function(ok,name)
526
527 -- build vehicle menu
528 vRP.buildMenu("vehicle", {user_id = user_id, player = player, vname = name}, function(menu)
529 menu.name=lang.vehicle.title()
530 menu.css={top="75px",header_color="rgba(255,125,0,0.75)"}
531
532 if ok then
533 for k,v in pairs(veh_actions) do
534 menu[k] = {function(player,choice) v[1](user_id,player,name) end, v[2]}
535 end
536 end
537
538 local ch_keys = function(player,choice)
539 local user_id = vRP.getUserId(player)
540 if user_id ~= nil then
541 local kitems = {}
542 local tosub = false
543 local submenu = {name=lang.garage.keys.title(), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
544 submenu.onclose = function()
545 if not tosub then
546 vRP.openMenu(player,menu)
547 end
548 end
549
550 local choose = function(player, choice)
551 local vehicle = choice
552 local vname = kitems[vehicle]
553 local subsubmenu = {name=lang.garage.keys.key({vehicle}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
554 subsubmenu.onclose = function()
555 tosub = false
556 vRP.openMenu(player,submenu)
557 end
558
559 local ch_sell = function(player, choice)
560 vRPclient.getNearestPlayer(player, {5}, function(nplayer)
561 if nplayer then
562 local tuser_id = vRP.getUserId(nplayer)
563 MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = vname}, function(rowss, affected)
564 if #rowss > 0 then
565 MySQL.query("vRP/get_vehicle", {user_id = tuser_id, vehicle = vname}, function(rows, affected)
566 if #rows == 0 then
567 vRP.prompt(player,lang.garage.keys.sell.prompt(),"",function(player,price)
568 local price = tonumber(sanitizeString(price,"\"[]{}+=?!_()#@%/\\|,.",false))
569 vRP.request(nplayer, lang.garage.keys.sell.request({vehicle,price}), 30,function(nplayer,ok)
570 if ok then
571 if vRP.tryFullPayment(tuser_id,price) then
572 MySQL.execute("vRP/move_vehicle", {user_id = user_id, tuser_id = tuser_id, vehicle = vname})
573 vRP.delUData(tuser_id,"custom:u"..tuser_id.."veh_"..vname) -- try delete old car history
574 vRP.delSData(user_id,"chest:u"..user_id.."veh_"..vname)
575 vRP.getUData(user_id,"custom:u"..user_id.."veh_"..vname, function(data)
576 local custom = json.decode(data) or {}
577 vRP.setUData(tuser_id,"custom:u"..tuser_id.."veh_"..vname, json.encode(custom))
578 vRP.delUData(user_id,"custom:u"..user_id.."veh_"..vname)
579 end)
580 if price > 0 then
581 vRP.giveBankMoney(user_id,price)
582 vRPclient.notify(nplayer,{lang.money.paid({price})})
583 vRPclient.notify(player,{lang.money.received({price})})
584 end
585
586 vRPclient.isOwnedVehicleOut(player, {vname}, function(veh,netIdSent)
587 if veh then
588 vRPclient.forceDespawnGarageVehicle(player,{veh})
589 TriggerClientEvent("b2k:syncRemovedEntity", -1, netIdSent)
590 end
591 end)
592 vRP.closeMenu(player)
593 else
594 vRPclient.notify(player,{lang.money.not_enough()})
595 vRPclient.notify(nplayer,{lang.money.not_enough()})
596 end
597 else
598 vRPclient.notify(player,{lang.common.request_refused()})
599 end
600 end)
601 end)
602 else
603 vRPclient.notify(player,{"Nemas ovo vozilo."})
604 end
605 end)
606 else
607 vRPclient.notify(nplayer,{lang.garage.keys.sell.owned()})
608 vRPclient.notify(player,{lang.garage.keys.sell.owned()})
609 end
610 end)
611 else
612 vRPclient.notify(player,{lang.common.no_player_near()})
613 end
614 end)
615 end
616
617 subsubmenu[lang.garage.keys.sell.title()] = {ch_sell,lang.garage.keys.sell.description()}
618
619 tosub = true
620 vRP.openMenu(player,subsubmenu)
621 end
622
623 -- get player owned vehicles (indexed by vehicle type name in lower case)
624 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(pvehicles, affected)
625 for k,v in pairs(pvehicles) do
626 local vehicle
627 for x,garage in pairs(vehicle_groups) do
628 vehicle = garage[v.vehicle]
629 if vehicle then break end
630 end
631
632 if vehicle then
633 submenu[vehicle[1]] = {choose,vehicle[3]}
634 kitems[vehicle[1]] = v.vehicle
635 end
636 end
637
638 vRP.openMenu(player,submenu)
639 end)
640 end
641 end
642
643 menu[lang.garage.keys.title()] = {ch_keys, lang.garage.keys.description()}
644
645 vRP.openMenu(player,menu)
646 end)
647 --else
648 -- vRPclient.notify(player,{lang.vehicle.no_owned_near()})
649 --end
650 end)
651
652 end
653end
654
655-- ask trunk (open other user car chest)
656local function ch_asktrunk(player,choice)
657 vRPclient.getNearestPlayer(player,{10},function(nplayer)
658 local nuser_id = vRP.getUserId(nplayer)
659 if nuser_id ~= nil then
660 vRPclient.notify(player,{lang.vehicle.asktrunk.asked()})
661 vRP.request(nplayer,lang.vehicle.asktrunk.request(),15,function(nplayer,ok)
662 if ok then -- request accepted, open trunk
663 vRPclient.getNearestOwnedVehicle(nplayer,{7},function(ok,name)
664 if ok then
665 local tmpdata = vRP.getUserTmpTable(nuser_id)
666 if tmpdata.rent_vehicles[name] == true then
667 vRPclient.notify(player,{"~r~Iznajmljena vozila nemaju gepek."})
668 return
669 else
670 local chestname = "u"..nuser_id.."veh_"..string.lower(name)
671 local max_weight = cfg_inventory.vehicle_chest_weights[string.lower(name)] or cfg_inventory.default_vehicle_chest_weight
672
673 -- open chest
674 local cb_out = function(idname,amount)
675 vRPclient.notify(nplayer,{lang.inventory.give.given({vRP.getItemName(idname),amount})})
676 end
677
678 local cb_in = function(idname,amount)
679 vRPclient.notify(nplayer,{lang.inventory.give.received({vRP.getItemName(idname),amount})})
680 end
681
682 vRPclient.vc_openDoor(nplayer, {name,5})
683 vRP.openChest(player, chestname, max_weight, function()
684 vRPclient.vc_closeDoor(nplayer, {name,5})
685 end,cb_in,cb_out)
686 end
687 else
688 vRPclient.notify(player,{lang.vehicle.no_owned_near()})
689 vRPclient.notify(nplayer,{lang.vehicle.no_owned_near()})
690 end
691 end)
692 else
693 vRPclient.notify(player,{lang.common.request_refused()})
694 end
695 end)
696 else
697 vRPclient.notify(player,{lang.common.no_player_near()})
698 end
699 end)
700end
701
702-- repair nearest vehicle
703local repair_seq = {
704 {"mini@repair","fixing_a_player",1}
705}
706
707local function ch_repair(player,choice)
708 local user_id = vRP.getUserId(player)
709 if user_id ~= nil then
710 -- anim and repair
711 vRPclient.getNearestVehicle(player,{4},function(vehicle)
712 if vehicle then
713 vRPclient.checkOffSetAndHoodOpen(player,{vehicle,true},function(isok,netid)
714 if isok then
715 if vRP.tryGetInventoryItem(user_id,"repairkit",1,true) then
716 vRPclient.playAnim(player,{false,repair_seq,false})
717 SetTimeout(15000, function()
718 TriggerClientEvent("b2k:fixeVehicleByNetId", -1, netid)
719 vRPclient.playSound(player,{"WEAPON_PURCHASE", "HUD_AMMO_SHOP_SOUNDSET"})
720 vRPclient.stopAnim(player,{false})
721 end)
722 end
723 else
724 vRPclient.notify(player,{"Morate da stojite kod prednjeg ili zadnjeg dela automobila."})
725 end
726 end)
727 else
728 vRPclient.notify(player,{"Nema vozila u okolini."})
729 end
730 end)
731 end
732end
733
734-- replace nearest vehicle
735local function ch_replace(player,choice)
736 vRPclient.replaceNearestVehicle(player,{7})
737end
738
739vRP.registerMenuBuilder("main", function(add, data)
740 local user_id = vRP.getUserId(data.player)
741 if user_id ~= nil then
742 -- add vehicle entry
743 local choices = {}
744 choices[lang.vehicle.title()] = {ch_vehicle}
745
746 -- add ask trunk
747 choices[lang.vehicle.asktrunk.title()] = {ch_asktrunk}
748
749 -- add repair functions
750 if vRP.hasPermission(user_id, "vehicle.repair") then
751 choices[lang.vehicle.repair.title()] = {ch_repair, lang.vehicle.repair.description()}
752 end
753
754 if vRP.hasPermission(user_id, "vehicle.replace") then
755 choices[lang.vehicle.replace.title()] = {ch_replace, lang.vehicle.replace.description()}
756 end
757
758 add(choices)
759 end
760end)
761
762RegisterServerEvent("b2k:pressLockCar")
763AddEventHandler("b2k:pressLockCar", function()
764 local player = source
765 local user_id = vRP.getUserId(player)
766 if user_id ~= nil then
767 vRPclient.getNearestOwnedVehicle(player, {7}, function(ok, name)
768 if ok then
769 vRPclient.vc_toggleLock(player, {name})
770 vRPclient.playSound(player,{"WEAPON_PURCHASE", "HUD_AMMO_SHOP_SOUNDSET"})
771 --vRPclient.playAnim(player,{true,{{"anim@mp_player_intincardancelow@ps@","idle_a_fp",1}},false})
772 --SetTimeout(1000, function()
773 -- vRPclient.stopAnim(player,{false})
774 --end)
775 end
776 end)
777 end
778end)
779
780RegisterServerEvent("b2k:trySyncLockVehicle")
781AddEventHandler("b2k:trySyncLockVehicle", function(nveh, cond)
782 local player = source
783 local user_id = vRP.getUserId(player)
784 if user_id ~= nil then
785 TriggerClientEvent("b2k:syncLockVehicle", -1, nveh, cond)
786 end
787end)