· 6 years ago · Nov 26, 2019, 07:26 PM
1-- a basic garage implementation
2
3local Proxy = module("lib/Proxy")
4local Tunnel = module("lib/Tunnel")
5
6vRPlogs = Proxy.getInterface("vRP_logs")
7
8-- vehicle db
9MySQL.createCommand("vRP/vehicles_table", [[
10CREATE TABLE IF NOT EXISTS vrp_user_vehicles(
11 user_id INTEGER,
12 vehicle VARCHAR(100),
13 CONSTRAINT pk_user_vehicles PRIMARY KEY(user_id,vehicle),
14 CONSTRAINT fk_user_vehicles_users FOREIGN KEY(user_id) REFERENCES vrp_users(id) ON DELETE CASCADE
15);
16]])
17
18MySQL.createCommand("vRP/add_vehicle","INSERT IGNORE INTO vrp_user_vehicles(user_id,vehicle) VALUES(@user_id,@vehicle)")
19MySQL.createCommand("vRP/remove_vehicle","DELETE FROM vrp_user_vehicles WHERE user_id = @user_id AND vehicle = @vehicle")
20MySQL.createCommand("vRP/get_vehicles","SELECT vehicle FROM vrp_user_vehicles WHERE user_id = @user_id")
21MySQL.createCommand("vRP/get_vehicle","SELECT * FROM vrp_user_vehicles WHERE user_id = @user_id AND vehicle = @vehicle")
22MySQL.createCommand("vRP/sell_vehicle_player","UPDATE vrp_user_vehicles SET user_id = @user_id WHERE user_id = @oldUser AND vehicle = @vehicle")
23MySQL.createCommand("vRP/change_veh_plate","UPDATE vrp_user_vehicles SET vehicle_plate = @vehicle_plate WHERE user_id = @user_id AND vehicle = @vehicle")
24--MySQL.createCommand("vRP/get_p_vehicle","SELECT vehicle FROM vrp_user_vehicles WHERE user_id = @user_id AND vehicle = @vehicle")
25
26MySQL.createCommand("vRP/add_special_vehicle","INSERT IGNORE INTO vrp_user_vehicles(user_id,vehicle,vehicle_plate,veh_type) VALUES(@user_id,@vehicle,@vehicle_plate,@veh_type)")
27
28MySQL.createCommand("vRP/get_garages","SELECT * FROM vrp_garages")
29MySQL.createCommand("vRP/add_garage","INSERT INTO vrp_garages(x,y,z,gtype) VALUES(@x,@y,@z,@gtype)")
30
31MySQL.createCommand("vRP/get_user_vehicles","SELECT * FROM vrp_user_vehicles WHERE user_id = @user_id")
32
33MySQL.createCommand("vRP/get_vehTax_ex","SELECT * FROM vrp_users WHERE id = @user_id")
34MySQL.createCommand("vRP/update_vehTax_ex","UPDATE vrp_users SET vehTaxEx = @vehTaxEx WHERE id = @user_id")
35
36MySQL.createCommand("vRP/get_vehLim","SELECT * FROM vrp_users WHERE id = @user_id")
37MySQL.createCommand("vRP/set_vehLim","UPDATE vrp_users SET vehLim = @vehLim WHERE id = @user_id")
38-- init
39MySQL.execute("vRP/vehicles_table")
40
41-- load config
42
43garages = {}
44
45local cfg = module("cfg/garages")
46local cfg_inventory = module("cfg/inventory")
47local vehicle_groups = cfg.garage_types
48local lang = vRP.lang
49
50-- garage menus
51function initGarages()
52 MySQL.query("vRP/get_garages", {}, function(result, affected)
53 if(#result ~= 0)then
54 garages = result
55 end
56 end)
57end
58
59function vRP.checkVehicleName(veh)
60 for i, v in pairs(vehicle_groups) do
61 local vehicle = v[veh]
62 if vehicle then
63 return tostring(vehicle[1]), tonumber(vehicle[2])
64 end
65 end
66 return "STEARSA (Model: "..veh..")", 0
67end
68
69function vRP.getNumberOfVehs(user_id)
70 local vehCount = 0
71 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(pvehicles, affected)
72 for i, v in pairs(vehicle_groups["House Garage"]) do
73 for index, value in pairs(pvehicles) do
74 if(i == tostring(value.vehicle))then
75 vehCount = vehCount + 1
76 end
77 end
78 end
79 end)
80 Citizen.Wait(100)
81 return vehCount
82end
83
84function vRP.getPlayerVehLimit(user_id)
85 local tmp = vRP.getUserTmpTable(user_id)
86 if tmp then
87 return tonumber(tmp.vehLim)
88 end
89 return 0
90end
91
92RegisterCommand("myvehlim", function(source)
93 user_id = vRP.getUserId(source)
94 local vehLim = vRP.getPlayerVehLimit(user_id)
95 local myVehs = vRP.getNumberOfVehs(user_id)
96 vRPclient.notify(source, {"Ai ~y~"..myVehs.." Masini ~g~si limita de ~r~"..vehLim})
97end)
98
99function vRP.setPlayerVehLimit(user_id, limit)
100 MySQL.execute("vRP/set_vehLim", {vehLim = limit, user_id = user_id})
101 local tmp = vRP.getUserTmpTable(user_id)
102 if tmp then
103 tmp.vehLim = tonumber(limit)
104 end
105end
106
107AddEventHandler("vRP:playerJoin",function(user_id,source,name,last_login)
108 local tmp = vRP.getUserTmpTable(user_id)
109 if tmp then
110 MySQL.query("vRP/get_vehLim", {user_id = user_id}, function(result, affected)
111 if #result > 0 then
112 tmp.vehLim = tonumber(result[1].vehLim)
113 tmp.bizLim = tonumber(result[1].bizLim)
114 end
115 end)
116 end
117end)
118
119AddEventHandler("onResourceStart", function(res)
120 if(res == "vrp")then
121 Citizen.Wait(2000)
122 initGarages()
123 end
124end)
125
126local garage_menus = {}
127
128for group,vehicles in pairs(vehicle_groups) do
129 local veh_type = vehicles._config.vtype or "default"
130
131 local menu = {
132 name=lang.garage.title({group}),
133 css={top = "75px", header_color="rgba(255,125,0,0.75)"}
134 }
135 garage_menus[group] = menu
136
137 menu[lang.garage.owned.title()] = {function(player,choice)
138 local user_id = vRP.getUserId(player)
139 if user_id ~= nil then
140 -- init tmpdata for rents
141 local tmpdata = vRP.getUserTmpTable(user_id)
142 if tmpdata.rent_vehicles == nil then
143 tmpdata.rent_vehicles = {}
144 end
145
146
147 -- build nested menu
148 local kitems = {}
149 local submenu = {name=lang.garage.title({lang.garage.owned.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
150 submenu.onclose = function()
151 vRP.openMenu(player,menu)
152 end
153
154 local choose = function(player, choice)
155 local vname = kitems[choice]
156 if vname then
157 -- spawn vehicle
158 local vehicle = vehicles[vname]
159 if vehicle then
160 vRP.closeMenu(player)
161 TriggerEvent('ply_garages:CheckForSpawnBasicVeh', user_id, vname)
162 end
163 end
164 end
165
166 -- get player owned vehicles
167 MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(pvehicles, affected)
168 for k,v in pairs(pvehicles) do
169 local vehicle = vehicles[v.vehicle]
170 if vehicle then
171 submenu[vehicle[1]] = {choose,vehicle[3]}
172 kitems[vehicle[1]] = v.vehicle
173 end
174 end
175
176 vRP.openMenu(player,submenu)
177 end)
178 end
179 end,lang.garage.owned.description()}
180
181 menu[lang.garage.store.title()] = {function(player,choice)
182 vRPclient.despawnGarageVehicle(player,{veh_type,15})
183 end, lang.garage.store.description()}
184end
185
186function round(x)
187 return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
188end
189
190
191theGroups = {"sponsors"}
192function checkTaxEvasionGroups(user_id)
193 if(vRP.isUserGoldVip(user_id))then
194 return true
195 end
196 for i, v in pairs(theGroups) do
197 if(vRP.hasGroup(user_id, v))then
198 return true
199 end
200 end
201 return false
202end
203
204function payVehicleTax(user_id)
205 thePlayer = vRP.getUserSource(user_id)
206 if (checkTaxEvasionGroups(user_id) == false) then
207 MySQL.query("vRP/get_vehTax_ex", {user_id = user_id}, function(result, affected)
208 if(tonumber(result[1].vehTaxEx) <= 0)then
209 MySQL.query("vRP/get_user_vehicles", {user_id = user_id}, function(theVehicles, affected)
210 totalTax = 0
211 for i, v in pairs(theVehicles) do
212 vehModel = tostring(v.vehicle)
213 vehName, vehPrice = vRP.checkVehicleName(vehModel)
214 vehTax = vehPrice * 0.0025
215 totalTax = round(totalTax + vehTax)
216 end
217 if (vRP.tryFullPayment(user_id, totalTax))then
218 vRPclient.notifyPicture(thePlayer, {"CHAR_CARSITE", 9, "FLEECA BANK", false, "Impozit Auto: ~r~-$"..vRP.formatMoney(totalTax)})
219 else
220 walletMoney = vRP.getMoney(user_id)
221 bankMoney = vRP.getBankMoney(user_id)
222 totalMoney = round(bankMoney + walletMoney)
223 if(vRP.tryFullPayment(user_id, totalMoney))then
224 vRPclient.notifyPicture(thePlayer, {"CHAR_CARSITE", 9, "FLEECA BANK", false, "Impozit Auto: ~r~-$"..vRP.formatMoney(totalTax)})
225 end
226 end
227 end)
228 else
229 vehTaxEx = tonumber(result[1].vehTaxEx) - 1
230 MySQL.execute("vRP/update_vehTax_ex", {vehTaxEx = vehTaxEx, user_id = user_id})
231 end
232 end)
233 end
234end
235
236--[[Citizen.CreateThread(function()
237 while true do
238 taxTime = math.random(2100000,3600000)
239 Citizen.Wait(taxTime)
240 users = vRP.getUsers()
241 for i, v in pairs(users) do
242 user_id = tonumber(i)
243 payVehicleTax(user_id)
244 Citizen.Wait(1600)
245 end
246 end
247end)
248
249RegisterCommand("mytax", function(source)
250 user_id = vRP.getUserId(source)
251 MySQL.query("vRP/get_user_vehicles", {user_id = user_id}, function(theVehicles, affected)
252 totalTax = 0
253 for i, v in pairs(theVehicles) do
254 vehModel = tostring(v.vehicle)
255 vehName, vehPrice = vRP.checkVehicleName(vehModel)
256 vehTax = vehPrice * 0.0025
257 print(vehName)
258 totalTax = round(totalTax + vehTax)
259 end
260 vRPclient.notifyPicture(source, {"CHAR_CARSITE", 9, "FLEECA BANK", false, "Impozit Auto $"..vRP.formatMoney(totalTax)})
261 end)
262end)
263
264RegisterCommand("mytax2", function(source)
265 user_id = vRP.getUserId(source)
266 MySQL.query("vRP/get_user_vehicles", {user_id = user_id}, function(theVehicles, affected)
267 totalTax = 0
268 for i, v in pairs(theVehicles) do
269 vehModel = tostring(v.vehicle)
270 vehName, vehPrice = vRP.checkVehicleName(vehModel)
271 vehTax = vehPrice * 0.0025
272 print(vehName.." : $"..vehTax)
273 end
274 end)
275end)
276
277RegisterCommand("txe", function(source)
278 user_id = vRP.getUserId(source)
279 MySQL.query("vRP/get_vehTax_ex", {user_id = user_id}, function(result, affected)
280 if(tonumber(result[1].vehTaxEx) <= 0)then
281 vehTaxDays = 0
282 else
283 vehTaxDays = 0
284 taxHours = tonumber(result[1].vehTaxEx)
285 if(taxHours <= 24 and taxHours > 0)then
286 vehTaxDays = 1
287 elseif(taxHours > 24)then
288 vehTaxDays = math.floor(taxHours/24)
289 end
290 end
291 vRPclient.notifyPicture(source, {"CHAR_CARSITE", 9, "FLEECA BANK", false, "Scutire Impozit Auto: "..vehTaxDays.." Zile"})
292 end)
293end)
294
295RegisterCommand("dovehtax", function(source)
296 usrID = vRP.getUserId(source)
297 if(vRP.hasGroup(usrID, "bozz"))then
298 users = vRP.getUsers()
299 for i, v in pairs(users) do
300 user_id = tonumber(i)
301 payVehicleTax(user_id)
302 Citizen.Wait(2000)
303 end
304 end
305end)]]
306
307function vRP.spawnCreatedGarage(x, y, z, gtype)
308 local group = vehicle_groups[gtype]
309 if group then
310 local gcfg = group._config
311
312 local icon = gcfg.icon
313
314 local garage_enter = function(player,area)
315 local user_id = vRP.getUserId(player)
316 if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) and gcfg.faction == nil and gcfg.vip == nil then
317 local menu = garage_menus[gtype]
318 if menu then
319 vRP.openMenu(player,menu)
320 end
321 elseif (gcfg.faction ~= nil or gcfg.faction ~= "") and gcfg.vip == nil then
322 if(vRP.isUserInFaction(user_id,gcfg.faction))then
323 local menu = garage_menus[gtype]
324 if menu then
325 vRP.openMenu(player,menu)
326 end
327 end
328 elseif (gcfg.vip ~= nil or gcfg.vip ~= 0) then
329 if(vRP.getUserVipRank(user_id) == gcfg.vip)then
330 local menu = garage_menus[gtype]
331 if menu then
332 vRP.openMenu(player,menu)
333 end
334 end
335 end
336 end
337
338 -- leave
339 local garage_leave = function(player,area)
340 vRP.closeMenu(player)
341 end
342
343 MySQL.query("vRP/add_garage", {x = x, y = y, z = z, gtype = gtype})
344 lastID = #garages + 1
345
346 table.insert(garages, {x = x, y = y, z = z, gtype = gtype})
347
348 users = vRP.getUsers()
349 for i, v in pairs(users) do
350 vRPclient.addMarker(v,{x,y,z-1,0.7,0.7,0.5,0,255,125,125,150})
351 if(icon ~= nil)then
352 local iC1, iC2, iC3 = gcfg.iconColor[1], gcfg.iconColor[2], gcfg.iconColor[3]
353 if(gtype == "VIP Garage 1")then
354 vRPclient.addMarkerSign(v,{11,x,y,z-0.8,0.18,0.18,0.18,iC1, iC2, iC3,150,150,0,true,0})
355 elseif(gtype == "VIP Garage 2")then
356 vRPclient.addMarkerSign(v,{12,x,y,z-0.8,0.18,0.18,0.18,iC1, iC2, iC3,150,150,0,true,0})
357 elseif(gtype == "VIP Garage 3")then
358 vRPclient.addMarkerSign(v,{13,x,y,z-0.8,0.18,0.18,0.18,iC1, iC2, iC3,150,150,0,true,0})
359 elseif(gtype == "VIP Garage 4")then
360 vRPclient.addMarkerSign(v,{14,x,y,z-0.8,0.18,0.18,0.18,iC1, iC2, iC3,150,150,0,true,0})
361 end
362 vRPclient.addMarkerSign(v,{icon,x,y,z-1.3,0.7,0.5,0.7,iC1, iC2, iC3,150,150,true,0,0})
363 else
364 vRPclient.addMarkerNames(v,{x, y, z, "~g~Garaj ~b~"..gtype, 0, 0.9})
365 end
366 vRPclient.addBlip(v,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.garage.title({gtype})})
367 vRP.setArea(v,"vRP:garage"..lastID,x,y,z,1,1.5,garage_enter,garage_leave)
368 end
369 end
370end
371
372local function build_db_garages(source)
373 local user_id = vRP.getUserId(source)
374 if user_id ~= nil then
375 for i, v in pairs(garages) do
376 local x, y, z = v.x, v.y, v.z
377 local gtype = v.gtype
378 local group = vehicle_groups[gtype]
379 if group then
380 local gcfg = group._config
381 local garage_enter = function(player,area)
382 local user_id = vRP.getUserId(source)
383 if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) and gcfg.faction == nil and gcfg.vip == nil then
384 local menu = garage_menus[gtype]
385 if menu then
386 vRP.openMenu(player,menu)
387 end
388 elseif (gcfg.group ~= nil or gcfg.group ~= "") and gcfg.vip == nil then
389 if(vRP.hasGroup(user_id,gcfg.group))then
390 local menu = garage_menus[gtype]
391 if menu then
392 vRP.openMenu(player,menu)
393 end
394 end
395 elseif (gcfg.vip ~= nil or gcfg.vip ~= 0) then
396 if(vRP.getUserVipRank(user_id) == gcfg.vip)then
397 local menu = garage_menus[gtype]
398 if menu then
399 vRP.openMenu(player,menu)
400 end
401 end
402 end
403 end
404
405 -- leave
406 local garage_leave = function(player,area)
407 vRP.closeMenu(player)
408 end
409
410 vRPclient.addMarker(source,{x,y,z-1,0.7,0.7,0.5,0,255,125,125,150})
411 if(gcfg.icon ~= nil)then
412 local iC1, iC2, iC3 = gcfg.iconColor[1], gcfg.iconColor[2], gcfg.iconColor[3]
413 if(gtype == "VIP Garage 1")then
414 vRPclient.addMarkerSign(source,{11,x,y,z-0.84,0.18,0.18,0.18,iC1, iC2, iC3,150,150,0,true,0})
415 elseif(gtype == "VIP Garage 2")then
416 vRPclient.addMarkerSign(source,{12,x,y,z-0.84,0.18,0.18,0.18,iC1, iC2, iC3,150,150,0,true,0})
417 elseif(gtype == "VIP Garage 3")then
418 vRPclient.addMarkerSign(source,{13,x,y,z-0.84,0.18,0.18,0.18,iC1, iC2, iC3,150,150,0,true,0})
419 elseif(gtype == "VIP Garage 4")then
420 vRPclient.addMarkerSign(source,{14,x,y,z-0.84,0.18,0.18,0.18,iC1, iC2, iC3,150,150,0,true,0})
421 end
422 vRPclient.addMarkerSign(source,{gcfg.icon,x,y,z-1.3,0.7,0.5,0.7,iC1, iC2, iC3,150,150,true,0,0})
423 else
424 vRPclient.addMarkerNames(source,{x, y, z, "~g~GARAJ: ~b~"..tostring(gtype), 0, 0.8})
425 end
426 vRPclient.addBlip(source,{363.40353393555,-590.07110595703,28.680046081543,61,75,"Spital"})
427 vRPclient.addBlip(source,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.garage.title({gtype})})
428 vRP.setArea(source,"vRP:garage"..i,x,y,z,1,1.5,garage_enter,garage_leave)
429 end
430 end
431 end
432end
433
434AddEventHandler("vRP:playerSpawn",function(user_id,source,first_spawn)
435 if first_spawn then
436 build_db_garages(source)
437 end
438end)
439
440-- VEHICLE MENU
441
442-- define vehicle actions
443-- action => {cb(user_id,player,veh_group,veh_name),desc}
444local veh_actions = {}
445
446-- open trunk
447veh_actions[lang.vehicle.trunk.title()] = {function(user_id,player,vtype,name)
448 local chestname = "u"..user_id.."veh_"..string.lower(name)
449 local max_weight = cfg_inventory.vehicle_chest_weights[string.lower(name)] or cfg_inventory.default_vehicle_chest_weight
450
451 -- open chest
452 vRPclient.vc_openDoor(player, {vtype,5})
453 vRP.openChest(player, chestname, max_weight, function()
454 vRPclient.vc_closeDoor(player, {vtype,5})
455 end)
456end, lang.vehicle.trunk.description()}
457
458
459-- open trunk
460veh_actions["Change Number Plate XZ"] = {function(user_id,player,vtype,name)
461 --vRPclient.getNearestOwnedVehicle(player,{7},function(ok,vtype,name)
462 -- if ok then
463 MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = name}, function(result, affected)
464 vRP.prompt(player,"Plate:","",function(player,vehPlate)
465 local vehicle = name
466 local vehicle_plate = vehPlate
467 local player = vRP.getUserSource(user_id)
468 if(string.len(vehicle_plate)<=8)then
469 if(string.len(vehicle_plate)<=0)then
470 return
471 else
472 local xz = tonumber(vRP.getXZCoins(user_id))
473 if(vehicle_plate:match("%W")) then
474 vRPclient.notify(player,{"~r~Placuta poate contine doar numere si litere!"})
475 else
476 if(xz >= 2) then
477 MySQL.execute("vRP/change_veh_plate", {vehicle = vehicle, user_id = user_id, vehicle_plate = vehicle_plate})
478 vRPclient.notify(player,{"~g~Placuta de inmatriculare a fost schimbata in: ~y~"..vehicle_plate})
479 vRPclient.despawnGarageVehicle(player,{vtype,15})
480 vRP.setXZCoins(user_id, xz-2)
481 vRP.closeMenu({player})
482 else
483 vRPclient.notify(player,{"~r~Nu ai destule monede XZ!"})
484 vRP.closeMenu({player})
485 end
486 end
487 end
488 else
489 vRPclient.notify(player,{"~r~Placuta de inmatriculare nu poate avea mai mult de 8 caractere!"})
490 end
491 end)
492 end)
493 -- else
494 -- vRPclient.notify(player, {"~r~No owned vehicle nearby"})
495 -- end
496 --end)
497end, "Schimbare numar inmatriculare\nPret: 2 XZ"}
498
499veh_actions["Change Number Plate DM"] = {function(user_id,player,vtype,name)
500 --vRPclient.getNearestOwnedVehicle(player,{7},function(ok,vtype,name)
501 -- if ok then
502 MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = name}, function(result, affected)
503 vRP.prompt(player,"Plate:","",function(player,vehPlate)
504 local vehicle = name
505 local vehicle_plate = vehPlate
506 local player = vRP.getUserSource(user_id)
507 if(string.len(vehicle_plate)<=8)then
508 if(string.len(vehicle_plate)<=0)then
509 return
510 else
511 local dm = tonumber(vRP.getdiamonds(user_id))
512 if(vehicle_plate:match("%W")) then
513 vRPclient.notify(player,{"~r~Placuta poate contine doar numere si litere!"})
514 else
515 if(dm >= 270) then
516 MySQL.execute("vRP/change_veh_plate", {vehicle = vehicle, user_id = user_id, vehicle_plate = vehicle_plate})
517 vRPclient.notify(player,{"~g~Placuta de inmatriculare a fost schimbata in: ~y~"..vehicle_plate})
518 vRPclient.despawnGarageVehicle(player,{vtype,15})
519 vRP.setdiamonds(user_id, dm-270)
520 vRP.closeMenu({player})
521 else
522 vRPclient.notify(player,{"~r~Nu ai destule Diamante!"})
523 vRP.closeMenu({player})
524 end
525 end
526 end
527 else
528 vRPclient.notify(player,{"~r~Placuta de inmatriculare nu poate avea mai mult de 8 caractere!"})
529 end
530 end)
531 end)
532 -- else
533 -- vRPclient.notify(player, {"~r~No owned vehicle nearby"})
534 -- end
535 --end)
536end, "Schimbare numar inmatriculare\nPret: 270 Diamante"}
537
538-- sell vehicle
539veh_actions[lang.vehicle.sellTP.title()] = {function(playerID,player,vtype,name)
540 if playerID ~= nil then
541 vRPclient.getNearestPlayers(player,{15},function(nplayers)
542 --vRPclient.getNearestOwnedVehicle(nplayer,{7},function(ok,vtype,name)
543 --if ok then
544 usrList = ""
545 for k,v in pairs(nplayers) do
546 usrList = usrList .. "[" .. vRP.getUserId(k) .. "]" .. GetPlayerName(k) .. " | "
547 end
548 if usrList ~= "" then
549 vRP.prompt(player,"Players Nearby: " .. usrList .. "","",function(player,user_id)
550 user_id = user_id
551 if user_id ~= nil and user_id ~= "" then
552 local target = vRP.getUserSource(tonumber(user_id))
553 if target ~= nil then
554 vRP.prompt(player,"Price $: ","",function(player,amount)
555 if (tonumber(amount)) then
556 if(tonumber(amount) < 0)then
557 vRPclient.notify(player, {"~r~Pretul nu poate fii sub $0!"})
558 return
559 else
560 MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = name}, function(pvehicle, affected)
561 if #pvehicle > 0 then
562 vRPclient.notify(player,{"~r~The player already has this vehicle type."})
563 else
564 local tVehs = vRP.getNumberOfVehs(tonumber(user_id))
565 local tVehLimit = vRP.getPlayerVehLimit(tonumber(user_id))
566 if(tVehs < tVehLimit)then
567 local vehName, vehPrice = vRP.checkVehicleName(name)
568 vRP.request(target,GetPlayerName(player).." wants to sell: " ..vehName.. " Price: $"..amount, 10, function(target,ok)
569 if ok then
570 local pID = vRP.getUserId(target)
571 local money = vRP.getMoney(pID)
572 if (tonumber(money) >= tonumber(amount)) then
573 vRPclient.despawnGarageVehicle(player,{vtype,15})
574 user_id = tonumber(user_id)
575 vRP.getUserIdentity(pID, function(identity)
576 MySQL.execute("vRP/sell_vehicle_player", {user_id = user_id, oldUser = playerID, vehicle = name})
577 end)
578 logText = GetPlayerName(player).."("..playerID..") ia vandut lui "..GetPlayerName(target).."("..user_id..") un |"..vehName.."| pentru $"..amount
579 vRPlogs.createLog({playerID,logText,"Vanzare Masina"})
580 vRP.giveMoney(playerID, amount)
581 vRP.setMoney(pID,money-amount)
582 vRPclient.notify(player,{"~g~You have successfully sold the vehicle to ".. GetPlayerName(target).." for $"..amount.."!"})
583 vRPclient.notify(target,{"~g~"..GetPlayerName(player).." has successfully sold you the car for $"..amount.."!"})
584 vRPnos.updateVehicleOwner({playerID, user_id, name})
585 local myName = GetPlayerName(target).."("..user_id..")" or "Nume_Prenume"
586 local vehPlate = tostring(pvehicle[1].vehicle_plate) or "Placuta Buguita"
587 vRP.tryGetInventoryItem(playerID,"veh_key|"..name,1,false)
588 vRP.tryGetInventoryItem(playerID,"car_doc|"..name,1,false)
589 vRP.giveInventoryItem(user_id,"veh_key|"..name,1,true,vehName)
590 vRP.giveInventoryItem(user_id,"car_doc|"..name,1,true,"<br/><font color ='white'>Titular:</font> <font color='green'>"..myName.."</font><br/><font color ='white'>Marca: </font><font color ='green'>"..vehName.."</font><br/><font color ='white'>Numar Inmatriculare: </font><font color ='green'>"..vehPlate.."</font>")
591 else
592 vRPclient.notify(player,{"~r~".. GetPlayerName(target).." doesn't have enough money!"})
593 vRPclient.notify(target,{"~r~You don't have enough money!"})
594 end
595 else
596 vRPclient.notify(player,{"~r~"..GetPlayerName(target).." has refused to buy the car."})
597 vRPclient.notify(target,{"~r~You have refused to buy "..GetPlayerName(player).."'s car."})
598 end
599 end)
600 else
601 vRPclient.notify(player, {"~r~Jucatorul are deja maximul de masini pe care le poate detine!"})
602 end
603 vRP.closeMenu(player)
604 end
605 end)
606 end
607 else
608 vRPclient.notify(player,{"~r~The price of the car has to be a number."})
609 end
610 end)
611 else
612 vRPclient.notify(player,{"~r~That ID seems invalid."})
613 end
614 else
615 vRPclient.notify(player,{"~r~No player ID selected."})
616 end
617 end)
618 else
619 vRPclient.notify(player,{"~r~No player nearby."})
620 end
621 -- else
622 -- vRPclient.notify(player,{"~r~No owned vehicle nearby."})
623 -- end
624 --end)
625 end)
626 end
627end, lang.vehicle.sellTP.description()}
628
629-- detach trailer
630veh_actions[lang.vehicle.detach_trailer.title()] = {function(user_id,player,vtype,name)
631 vRPclient.vc_detachTrailer(player, {vtype})
632end, lang.vehicle.detach_trailer.description()}
633
634-- detach towtruck
635veh_actions[lang.vehicle.detach_towtruck.title()] = {function(user_id,player,vtype,name)
636 vRPclient.vc_detachTowTruck(player, {vtype})
637end, lang.vehicle.detach_towtruck.description()}
638
639-- detach cargobob
640veh_actions[lang.vehicle.detach_cargobob.title()] = {function(user_id,player,vtype,name)
641 vRPclient.vc_detachCargobob(player, {vtype})
642end, lang.vehicle.detach_cargobob.description()}
643
644-- lock/unlock
645veh_actions[lang.vehicle.lock.title()] = {function(user_id,player,vtype,name)
646 vRPclient.vc_toggleLock(player, {vtype})
647end, lang.vehicle.lock.description()}
648
649-- engine on/off
650veh_actions[lang.vehicle.engine.title()] = {function(user_id,player,vtype,name)
651 vRPclient.vc_toggleEngine(player, {vtype})
652end, lang.vehicle.engine.description()}
653
654local function ch_vehicle(player,choice)
655 local user_id = vRP.getUserId(player)
656 if user_id ~= nil then
657 -- check vehicle
658 vRPclient.getNearestOwnedVehicle(player,{7},function(ok,vtype,name)
659 if ok then
660 -- build vehicle menu
661 vRP.buildMenu("vehicle", {user_id = user_id, player = player, vtype = vtype, vname = name}, function(menu)
662 menu.name=lang.vehicle.title()
663 menu.css={top="75px",header_color="rgba(255,125,0,0.75)"}
664
665 for k,v in pairs(veh_actions) do
666 menu[k] = {function(player,choice) v[1](user_id,player,vtype,name) end, v[2]}
667 end
668
669 vRP.openMenu(player,menu)
670 end)
671 else
672 vRPclient.notify(player,{lang.vehicle.no_owned_near()})
673 end
674 end)
675 end
676end
677
678-- ask trunk (open other user car chest)
679local function ch_asktrunk(player,choice)
680 vRPclient.getNearestPlayer(player,{10},function(nplayer)
681 local nuser_id = vRP.getUserId(nplayer)
682 if nuser_id ~= nil then
683 vRPclient.notify(player,{lang.vehicle.asktrunk.asked()})
684 vRP.request(nplayer,lang.vehicle.asktrunk.request(),15,function(nplayer,ok)
685 if ok then -- request accepted, open trunk
686 vRPclient.getNearestOwnedVehicle(nplayer,{7},function(ok,vtype,name)
687 if ok then
688 local chestname = "u"..nuser_id.."veh_"..string.lower(name)
689 local max_weight = cfg_inventory.vehicle_chest_weights[string.lower(name)] or cfg_inventory.default_vehicle_chest_weight
690
691 -- open chest
692 local cb_out = function(idname,amount)
693 vRPclient.notify(nplayer,{lang.inventory.give.given({vRP.getItemName(idname),amount})})
694 end
695
696 local cb_in = function(idname,amount)
697 vRPclient.notify(nplayer,{lang.inventory.give.received({vRP.getItemName(idname),amount})})
698 end
699
700 vRPclient.vc_openDoor(nplayer, {vtype,5})
701 vRP.openChest(player, chestname, max_weight, function()
702 vRPclient.vc_closeDoor(nplayer, {vtype,5})
703 end,cb_in,cb_out)
704 else
705 vRPclient.notify(player,{lang.vehicle.no_owned_near()})
706 vRPclient.notify(nplayer,{lang.vehicle.no_owned_near()})
707 end
708 end)
709 else
710 vRPclient.notify(player,{lang.common.request_refused()})
711 end
712 end)
713 else
714 vRPclient.notify(player,{lang.common.no_player_near()})
715 end
716 end)
717end
718
719-- repair nearest vehicle
720local function ch_repair(player,choice)
721 local user_id = vRP.getUserId(player)
722 if user_id ~= nil then
723 -- anim and repair
724 if vRP.tryGetInventoryItem(user_id,"repairkit",1,true) then
725 vRPclient.playAnim(player,{false,{task="WORLD_HUMAN_WELDING"},false})
726 SetTimeout(15000, function()
727 vRPclient.fixeNearestVehicle(player,{7})
728 vRPclient.stopAnim(player,{false})
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
739function vRP.givePlayerSpecialVeh(user_id, vehName)
740 vRP.getUserIdentity(user_id, function(identity)
741 MySQL.query("vRP/add_special_vehicle", {user_id = user_id, vehicle = vehName, vehicle_plate = "P "..identity.registration, veh_type = "car"})
742 end)
743end
744
745function vRP.hasPlayerCar(user_id, vehName)
746 hasCar = false
747 MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = vehName}, function(pvehicle, affected)
748 if #pvehicle > 0 then
749 hasCar = true
750 else
751 hasCar = false
752 end
753 end)
754 return hasCar
755end
756
757vRP.registerMenuBuilder("main", function(add, data)
758 local user_id = vRP.getUserId(data.player)
759 if user_id ~= nil then
760 -- add vehicle entry
761 local choices = {}
762 choices[lang.vehicle.title()] = {ch_vehicle}
763
764 -- add ask trunk
765 choices[lang.vehicle.asktrunk.title()] = {ch_asktrunk}
766
767 -- add repair functions
768 if vRP.hasPermission(user_id, "vehicle.repair") then
769 choices[lang.vehicle.repair.title()] = {ch_repair, lang.vehicle.repair.description()}
770 end
771
772 if vRP.hasPermission(user_id, "vehicle.replace") then
773 choices[lang.vehicle.replace.title()] = {ch_replace, lang.vehicle.replace.description()}
774 end
775
776 add(choices)
777 end
778end)
779
780
781----------------- IN-GAME GARAGE SPAWN--------------------
782MySQL.createCommand("vRP/get_garages","SELECT * FROM vrp_garages")
783MySQL.createCommand("vRP/add_garage","INSERT INTO vrp_garages(x,y,z,gtype) VALUES(@x,@y,@z,@gtype)")
784
785garages = {}
786
787function initGarages()
788 MySQL.query("vRP/get_garages", {}, function(result, affected)
789 if(#result ~= 0)then
790 garages = result
791 end
792 end)
793end
794
795AddEventHandler("onResourceStart", function(res)
796 if(res == "vrp")then
797 Citizen.Wait(2000)
798 initGarages()
799 end
800end)
801
802function vRP.spawnCreatedGarage(x, y, z, gtype)
803 local group = vehicle_groups[gtype]
804 if group then
805 local gcfg = group._config
806
807 -- enter
808 local garage_enter = function(player,area)
809 local user_id = vRP.getUserId(source)
810 if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) then
811 local menu = garage_menus[gtype]
812 if menu then
813 vRP.openMenu(player,menu)
814 end
815 end
816 end
817
818 -- leave
819 local garage_leave = function(player,area)
820 vRP.closeMenu(player)
821 end
822
823 local garage_enter = function(player,area)
824 local user_id = vRP.getUserId(source)
825 if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) then
826 local menu = garage_menus[gtype]
827 if menu then
828 vRP.openMenu(player,menu)
829 end
830 end
831 end
832
833 -- leave
834 local garage_leave = function(player,area)
835 vRP.closeMenu(player)
836 end
837
838 MySQL.query("vRP/add_garage", {x = x, y = y, z = z, gtype = gtype})
839 lastID = #garages + 1
840
841 table.insert(garages, {x = x, y = y, z = z, gtype = gtype})
842
843 users = vRP.getUsers()
844 for i, v in pairs(users) do
845 vRPclient.addMarker(v,{x,y,z-1,0.7,0.7,0.5,0,255,125,125,150})
846 vRPclient.addBlip(v,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.garage.title({gtype})})
847 vRP.setArea(v,"vRP:garage:"..lastID,x,y,z,1,1.5,garage_enter,garage_leave)
848 end
849 end
850end
851
852local function build_client_garages(source)
853 local user_id = vRP.getUserId(source)
854 if user_id ~= nil then
855 for i, v in pairs(garages) do
856 local x, y, z = v.x, v.y, v.z
857 local gtype = v.gtype
858 local group = vehicle_groups[gtype]
859 if group then
860 local gcfg = group._config
861
862 -- enter
863 local garage_enter = function(player,area)
864 local user_id = vRP.getUserId(source)
865 if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) then
866 local menu = garage_menus[gtype]
867 if menu then
868 vRP.openMenu(player,menu)
869 end
870 end
871 end
872
873 -- leave
874 local garage_leave = function(player,area)
875 vRP.closeMenu(player)
876 end
877
878 vRPclient.addBlip(source,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.garage.title({gtype})})
879 vRPclient.addMarker(source,{x,y,z-1,0.7,0.7,0.5,0,255,125,125,150})
880
881 vRP.setArea(source,"vRP:garage:"..i,x,y,z,1,1.5,garage_enter,garage_leave)
882 end
883 end
884 end
885end
886
887AddEventHandler("vRP:playerSpawn",function(user_id,source,first_spawn)
888 if first_spawn then
889 build_client_garages(source)
890 end
891end)
892
893local function ch_createGarage(player,choice)
894 local user_id = vRP.getUserId(player)
895 if user_id ~= nil then
896 vRP.prompt(player,"Garage Type: ","",function(player,gType)
897 gType = tostring(gType)
898 if(gType ~= "") and (gType ~= nil)then
899 local group = vehicle_groups[gType]
900 if group then
901 vRPclient.getPosition(player,{},function(x,y,z)
902 x, y, z = x, y, z
903 vRP.spawnCreatedGarage(x, y, z, gType)
904 vRPclient.notify(player, {"~g~Garage created with type: ~y~"..gType})
905 end)
906 else
907 vRPclient.notify(player, {"~r~There is no garage with the type: ~y~"..gType})
908 end
909 end
910 end)
911 end
912end
913
914vRP.registerMenuBuilder("admin", function(add, data)
915 local user_id = vRP.getUserId(data.player)
916 if user_id ~= nil then
917 local choices = {}
918
919 if vRP.hasPermission(user_id, "admin.createGarage") then
920 choices["Create Garage"] = {ch_createGarage}
921 end
922 add(choices)
923 end
924end)
925
926------------------------------------------------------------------------