Hi, I need help. I want to create a police garage on my server. I use vRP, but I do not want the garage with all the sales or rental options. I just want the cop to go there and get the vehicle for $0.
What should I change in the code to remove all sales and rental options?
-- a basic garage implementation
-- vehicle db
MySQL.createCommand("vRP/vehicles_table", [[
CREATE TABLE IF NOT EXISTS vrp_user_vehicles(
user_id INTEGER,
vehicle VARCHAR(100),
CONSTRAINT pk_user_vehicles PRIMARY KEY(user_id,vehicle),
CONSTRAINT fk_user_vehicles_users FOREIGN KEY(user_id) REFERENCES vrp_users(id) ON DELETE CASCADE
);
]])
MySQL.createCommand("vRP/add_vehicle","INSERT IGNORE INTO vrp_user_vehicles(user_id,vehicle) VALUES(@user_id,@vehicle)")
MySQL.createCommand("vRP/remove_vehicle","DELETE FROM vrp_user_vehicles WHERE user_id = @user_id AND vehicle = @vehicle")
MySQL.createCommand("vRP/get_vehicles","SELECT vehicle FROM vrp_user_vehicles WHERE user_id = @user_id")
MySQL.createCommand("vRP/get_vehicle","SELECT vehicle FROM vrp_user_vehicles WHERE user_id = @user_id AND vehicle = @vehicle")
-- init
MySQL.execute("vRP/vehicles_table")
-- load config
local cfg = module("cfg/garages")
local cfg_inventory = module("cfg/inventory")
local vehicle_groups = cfg.garage_types
local lang = vRP.lang
local garages = cfg.garages
-- garage menus
local garage_menus = {}
for group,vehicles in pairs(vehicle_groups) do
local veh_type = vehicles._config.vtype or "default"
local menu = {
name=lang.garage.title({group}),
css={top = "75px", header_color="rgba(255,125,0,0.75)"}
}
garage_menus[group] = menu
menu[lang.garage.owned.title()] = {function(player,choice)
local user_id = vRP.getUserId(player)
if user_id ~= nil then
-- init tmpdata for rents
local tmpdata = vRP.getUserTmpTable(user_id)
if tmpdata.rent_vehicles == nil then
tmpdata.rent_vehicles = {}
end
-- build nested menu
local kitems = {}
local submenu = {name=lang.garage.title({lang.garage.owned.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
submenu.onclose = function()
vRP.openMenu(player,menu)
end
local choose = function(player, choice)
local vname = kitems[choice]
if vname then
-- spawn vehicle
local vehicle = vehicles[vname]
if vehicle then
vRP.closeMenu(player)
TriggerEvent('ply_garages:CheckForSpawnBasicVeh', user_id, vname)
end
end
end
-- get player owned vehicles
MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(pvehicles, affected)
-- add rents to whitelist
for k,v in pairs(tmpdata.rent_vehicles) do
if v then -- check true, prevent future neolua issues
table.insert(pvehicles,{vehicle = k})
end
end
for k,v in pairs(pvehicles) do
local vehicle = vehicles[v.vehicle]
if vehicle then
submenu[vehicle[1]] = {choose,vehicle[3]}
kitems[vehicle[1]] = v.vehicle
end
end
vRP.openMenu(player,submenu)
end)
end
end,lang.garage.owned.description()}
menu[lang.garage.buy.title()] = {function(player,choice)
local user_id = vRP.getUserId(player)
if user_id ~= nil then
-- build nested menu
local kitems = {}
local submenu = {name=lang.garage.title({lang.garage.buy.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
submenu.onclose = function()
vRP.openMenu(player,menu)
end
local choose = function(player, choice)
local vname = kitems[choice]
if vname then
-- buy vehicle
local vehicle = vehicles[vname]
if vehicle and vRP.tryPayment(user_id,vehicle[2]) then
MySQL.execute("vRP/add_vehicle", {user_id = user_id, vehicle = vname})
vRPclient.notify(player,{lang.money.paid({vehicle[2]})})
vRP.closeMenu(player)
else
vRPclient.notify(player,{lang.money.not_enough()})
end
end
end
-- get player owned vehicles (indexed by vehicle type name in lower case)
MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(_pvehicles, affected)
local pvehicles = {}
for k,v in pairs(_pvehicles) do
pvehicles[string.lower(v.vehicle)] = true
end
-- for each existing vehicle in the garage group
for k,v in pairs(vehicles) do
if k ~= "_config" and pvehicles[string.lower(k)] == nil then -- not already owned
submenu[v[1]] = {choose,lang.garage.buy.info({v[2],v[3]})}
kitems[v[1]] = k
end
end
vRP.openMenu(player,submenu)
end)
end
end,lang.garage.buy.description()}
menu[lang.garage.sell.title()] = {function(player,choice)
local user_id = vRP.getUserId(player)
if user_id ~= nil then
-- build nested menu
local kitems = {}
local submenu = {name=lang.garage.title({lang.garage.sell.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
submenu.onclose = function()
vRP.openMenu(player,menu)
end
local choose = function(player, choice)
vRP.request(player,"Are you sure that you want to sell this vehicle?",30,function(player,ok)
if ok then
local vname = kitems[choice]
if vname then
-- sell vehicle
local vehicle = vehicles[vname]
if vehicle then
local price = math.ceil((vehicle[2]*cfg.sell_factor)*1)
MySQL.query("vRP/get_vehicle", {user_id = user_id, vehicle = vname}, function(rows, affected)
if #rows > 0 then -- has vehicle
vRP.giveMoney(user_id,price)
MySQL.execute("vRP/remove_vehicle", {user_id = user_id, vehicle = vname})
vRPclient.notify(player,{lang.money.received({price})})
vRP.closeMenu(player)
else
vRPclient.notify(player,{lang.common.not_found()})
end
end)
end
end
end
end)
end
-- get player owned vehicles (indexed by vehicle type name in lower case)
MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(_pvehicles, affected)
local pvehicles = {}
for k,v in pairs(_pvehicles) do
pvehicles[string.lower(v.vehicle)] = true
end
-- for each existing vehicle in the garage group
for k,v in pairs(pvehicles) do
local vehicle = vehicles[k]
if vehicle then -- not already owned
local price = math.ceil((vehicle[2]*cfg.sell_factor)*1)
submenu[vehicle[1]] = {choose,lang.garage.buy.info({price,vehicle[3]})}
kitems[vehicle[1]] = k
end
end
vRP.openMenu(player,submenu)
end)
end
end,lang.garage.sell.description()}
menu[lang.garage.rent.title()] = {function(player,choice)
local user_id = vRP.getUserId(player)
if user_id ~= nil then
-- init tmpdata for rents
local tmpdata = vRP.getUserTmpTable(user_id)
if tmpdata.rent_vehicles == nil then
tmpdata.rent_vehicles = {}
end
-- build nested menu
local kitems = {}
local submenu = {name=lang.garage.title({lang.garage.rent.title()}), css={top="75px",header_color="rgba(255,125,0,0.75)"}}
submenu.onclose = function()
vRP.openMenu(player,menu)
end
local choose = function(player, choice)
local vname = kitems[choice]
if vname then
-- rent vehicle
local vehicle = vehicles[vname]
if vehicle then
local price = math.ceil((vehicle[2]*cfg.rent_factor)*1)
if vRP.tryPayment(user_id,price) then
-- add vehicle to rent tmp data
tmpdata.rent_vehicles[vname] = true
vRPclient.notify(player,{lang.money.paid({price})})
vRP.closeMenu(player)
else
vRPclient.notify(player,{lang.money.not_enough()})
end
end
end
end
-- get player owned vehicles (indexed by vehicle type name in lower case)
MySQL.query("vRP/get_vehicles", {user_id = user_id}, function(_pvehicles, affected)
local pvehicles = {}
for k,v in pairs(_pvehicles) do
pvehicles[string.lower(v.vehicle)] = true
end
-- add rents to blacklist
for k,v in pairs(tmpdata.rent_vehicles) do
pvehicles[string.lower(k)] = true
end
-- for each existing vehicle in the garage group
for k,v in pairs(vehicles) do
if k ~= "_config" and pvehicles[string.lower(k)] == nil then -- not already owned
local price = math.ceil((v[2]*cfg.rent_factor)*1)
submenu[v[1]] = {choose,lang.garage.buy.info({price,v[3]})}
kitems[v[1]] = k
end
end
vRP.openMenu(player,submenu)
end)
end
end,lang.garage.rent.description()}
menu[lang.garage.store.title()] = {function(player,choice)
vRPclient.despawnGarageVehicle(player,{veh_type,15})
end, lang.garage.store.description()}
end
local function build_client_garages(source)
local user_id = vRP.getUserId(source)
if user_id ~= nil then
for k,v in pairs(garages) do
local gtype,x,y,z = table.unpack(v)
local group = vehicle_groups[gtype]
if group then
local gcfg = group._config
-- enter
local garage_enter = function(player,area)
local user_id = vRP.getUserId(source)
if user_id ~= nil and vRP.hasPermissions(user_id,gcfg.permissions or {}) then
local menu = garage_menus[gtype]
if menu then
vRP.openMenu(player,menu)
end
end
end
-- leave
local garage_leave = function(player,area)
vRP.closeMenu(player)
end
vRPclient.addBlip(source,{x,y,z,gcfg.blipid,gcfg.blipcolor,lang.garage.title({gtype})})
vRPclient.addMarker(source,{x,y,z-1,0.7,0.7,0.5,0,255,125,125,150})
vRP.setArea(source,"vRP:garage"..k,x,y,z,1,1.5,garage_enter,garage_leave)
end
end
end
end
AddEventHandler("vRP:playerSpawn",function(user_id,source,first_spawn)
if first_spawn then
build_client_garages(source)
end
end)