hi , i want add a new shop for cops , i using the script vehshop , but i think there are many error in my script i change the name of file the coords and car but i don’t work a local ped
`local vehpol = {
opened = false,
title = "Policegarage",
currentmenu = "main",
lastmenu = nil,
currentpos = nil,
selectedbutton = 0,
marker = { r = 0, g = 155, b = 255, a = 200, type = 1 },
menu = {
x = 0.9,
y = 0.08,
width = 0.2,
height = 0.05,
buttons = 10,
from = 1,
to = 10,
scale = 0.4,
font = 0,
["main"] = {
title = "CATEGORIES",
name = "main",
buttons = {
{name = "Vehicles", description = ""},
{name = "Motorcycles", description = ""},
}
},
["vehicles"] = {
title = "VEHICLES",
name = "vehicles",
buttons = {
{name = "Compacts", description = ''},
{name = "SUVs", description = ''},
{name = "Vans", description = ''},
}
},
["compacts"] = {
title = "compacts",
name = "compacts",
buttons = {
{name = "policeold2", costs = 0, description = {}, model = "policeold2"},
{name = "police4", costs = 0, description = {}, model = "police4"},
{name = "police2", costs = 0, description = {}, model = "police2"},
{name = "hwaycar20", costs = 0, description = {}, model = "hwaycar20"},
{name = "hwaycar7", costs = 0, description = {}, model = "hwaycar7"},
{name = "hwaycar2", costs = 0, description = {}, model = "hwaycar2"},
{name = "hwaycar", costs = 0, description = {}, model = "hwaycar"},
}
},
["suvs"] = {
title = "suvs",
name = "suvs",
buttons = {
{name = "hwaycar6", costs = 0, description = {}, model = "hwaycar6"},
{name = "hwaycar5", costs = 0, description = {}, model = "hwaycar5"},
{name = "hwaycar4", costs = 0, description = {}, model = "hwaycar4"},
{name = "hwaycar3", costs = 0, description = {}, model = "hwaycar3"},
}
},
["vans"] = {
title = "vans",
name = "vans",
buttons = {
{name = "sheriffinsurgent2", costs = 0, description = {}, model = "sheriffinsurgent255"},
{name = "policeinsurgent", costs = 0, description = {}, model = "policeinsurgent"},
}
},
["motorcycles"] = {
title = "MOTORCYCLES",
name = "motorcycles",
buttons = {
{name = "hwaycar23", costs = 0, description = {}, model = "hwaycar23"},
}
},
}
}
local fakecar = {model = '', car = nil}
local vehpol_locations = {
{entering = {448.804,-1020.32,28.4669}, inside = {448.805,-1021.35,28.4669,120.1953}, outside = {448.804,-1020.31,28.4668,322.345}},
}
local vehshop_blips ={}
local inrangeofvehpol = false
local currentlocation = nil
local boughtcar = false
local function LocalPed()
return GetPlayerPed(-1)
end
function drawTxt(text,font,centre,x,y,scale,r,g,b,a)
SetTextFont(font)
SetTextProportional(0)
SetTextScale(scale, scale)
SetTextColour(r, g, b, a)
SetTextDropShadow(0, 0, 0, 0,255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextCentre(centre)
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(x , y)
end
function IsPlayerInRangeOfVehpol()
return inrangeofvehpol
end
function ShowVehshopBlips(bool)
if bool and #vehshop_blips == 0 then
for station,pos in pairs(vehpol_locations) do
local loc = pos
pos = pos.entering
local blip = AddBlipForCoord(pos[1],pos[2],pos[3])
-- 60 58 137
SetBlipSprite(blip,326)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString('Policegarage')
EndTextCommandSetBlipName(blip)
SetBlipAsShortRange(blip,true)
SetBlipAsMissionCreatorBlip(blip,true)
table.insert(vehshop_blips, {blip = blip, pos = loc})
end
Citizen.CreateThread(function()
while #vehshop_blips > 0 do
Citizen.Wait(0)
local inrange = false
for i,b in ipairs(vehshop_blips) do
if IsPlayerWantedLevelGreater(GetPlayerIndex(),0) == false and vehpol.opened == false and IsPedInAnyVehicle(LocalPed(), true) == false and GetDistanceBetweenCoords(b.pos.entering[1],b.pos.entering[2],b.pos.entering[3],GetEntityCoords(LocalPed())) < 5 then
DrawMarker(1,b.pos.entering[1],b.pos.entering[2],b.pos.entering[3],0,0,0,0,0,0,2.001,2.0001,0.5001,0,155,255,200,0,0,0,0)
drawTxt('Press ~g~ENTER~s~ to buy ~b~vehicle',0,1,0.5,0.8,0.6,255,255,255,255)
currentlocation = b
inrange = true
end
end
inrangeofvehôl = inrange
end
end)
elseif bool == false and #vehshop_blips > 0 then
for i,b in ipairs(vehshop_blips) do
if DoesBlipExist(b.blip) then
SetBlipAsMissionCreatorBlip(b.blip,false)
Citizen.InvokeNative(0x86A652570E5F25DD, Citizen.PointerValueIntInitialized(b.blip))
end
end
vehshop_blips = {}
end
end
function f(n)
return n + 0.0001
end
function LocalPed()
return GetPlayerPed(-1)
end
function try(f, catch_f)
local status, exception = pcall(f)
if not status then
catch_f(exception)
end
end
function firstToUpper(str)
return (str:gsub("^%l", string.upper))
end
--local veh = nil
function OpenCreator()
boughtcar = false
local ped = LocalPed()
local pos = currentlocation.pos.inside
FreezeEntityPosition(ped,true)
SetEntityVisible(ped,false)
local g = Citizen.InvokeNative(0xC906A7DAB05C8D2B,pos[1],pos[2],pos[3],Citizen.PointerValueFloat(),0)
SetEntityCoords(ped,pos[1],pos[2],g)
SetEntityHeading(ped,pos[4])
vehpol.currentmenu = "main"
vehpol.opened = true
vehpol.selectedbutton = 0
--[[Citizen.CreateThread(function()
RequestModel(GetHashKey('t20'))
while not HasModelLoaded(GetHashKey('t20')) do
Citizen.Wait(0)
end
veh = CreateVehicle(GetHashKey('t20'),GetOffsetFromEntityInWorldCoords(ped,2.001,0,0),false,true)
SetModelAsNoLongerNeeded(GetHashKey('t20'))
SetEntityHeading(veh,pos[4])
FreezeEntityPosition(veh,true)
SetEntityCollision(veh,false,false)
SetEntityInvincible(veh,true)
end)]]
end
local vehicle_price = 0
function CloseCreator()
Citizen.CreateThread(function()
local ped = LocalPed()
if not boughtcar then
local pos = currentlocation.pos.entering
SetEntityCoords(ped,pos[1],pos[2],pos[3])
FreezeEntityPosition(ped,false)
SetEntityVisible(ped,true)
else
local veh = GetVehiclePedIsUsing(ped)
local model = GetEntityModel(veh)
local colors = table.pack(GetVehicleColours(veh))
local extra_colors = table.pack(GetVehicleExtraColours(veh))
local mods = {}
for i = 0,24 do
mods[i] = GetVehicleMod(veh,i)
end
Citizen.InvokeNative(0xEA386986E786A54F, Citizen.PointerValueIntInitialized(veh))
local pos = currentlocation.pos.outside
FreezeEntityPosition(ped,false)
RequestModel(model)
while not HasModelLoaded(model) do
Citizen.Wait(0)
end
personalvehicle = CreateVehicle(model,pos[1],pos[2],pos[3],pos[4],true,false)
SetModelAsNoLongerNeeded(model)
for i,mod in pairs(mods) do
SetVehicleModKit(personalvehicle,0)
SetVehicleMod(personalvehicle,i,mod)
end
SetVehicleOnGroundProperly(personalvehicle)
SetVehicleHasBeenOwnedByPlayer(personalvehicle,true)
local id = NetworkGetNetworkIdFromEntity(personalvehicle)
SetNetworkIdCanMigrate(id, true)
Citizen.InvokeNative(0x629BFA74418D6239,Citizen.PointerValueIntInitialized(personalvehicle))
SetVehicleColours(personalvehicle,colors[1],colors[2])
SetVehicleExtraColours(personalvehicle,extra_colors[1],extra_colors[2])
--local blip = AddBlipForEntity(personalvehicle)
--SetBlipSprite(blip,326)
--BeginTextCommandSetBlipName("STRING")
--AddTextComponentString('Personal vehicle')
--EndTextCommandSetBlipName(blip)
--personalvehicle_blip = blip
TaskWarpPedIntoVehicle(GetPlayerPed(-1),personalvehicle,-1)
SetEntityVisible(ped,true)
end
vehpol.opened = false
vehpol.menu.from = 1
vehpol.menu.to = 10
end)
end
function drawMenuButton(button,x,y,selected)
local menu = vehpol.menu
SetTextFont(menu.font)
SetTextProportional(0)
SetTextScale(menu.scale, menu.scale)
if selected then
SetTextColour(0, 0, 0, 255)
else
SetTextColour(255, 255, 255, 255)
end
SetTextCentre(0)
SetTextEntry("STRING")
AddTextComponentString(button.name)
if selected then
DrawRect(x,y,menu.width,menu.height,255,255,255,255)
else
DrawRect(x,y,menu.width,menu.height,0,0,0,150)
end
DrawText(x - menu.width/2 + 0.005, y - menu.height/2 + 0.0028)
end
function drawMenuInfo(text)
local menu = vehpol.menu
SetTextFont(menu.font)
SetTextProportional(0)
SetTextScale(0.45, 0.45)
SetTextColour(255, 255, 255, 255)
SetTextCentre(0)
SetTextEntry("STRING")
AddTextComponentString(text)
DrawRect(0.675, 0.95,0.65,0.050,0,0,0,150)
DrawText(0.365, 0.934)
end
function drawMenuRight(txt,x,y,selected)
local menu = vehpol.menu
SetTextFont(menu.font)
SetTextProportional(0)
SetTextScale(menu.scale, menu.scale)
SetTextRightJustify(1)
if selected then
SetTextColour(0, 0, 0, 255)
else
SetTextColour(255, 255, 255, 255)
end
SetTextCentre(0)
SetTextEntry("STRING")
AddTextComponentString(txt)
DrawText(x + menu.width/2 - 0.03, y - menu.height/2 + 0.0028)
end
function drawMenuTitle(txt,x,y)
local menu = vehpol.menu
SetTextFont(2)
SetTextProportional(0)
SetTextScale(0.5, 0.5)
SetTextColour(255, 255, 255, 255)
SetTextEntry("STRING")
AddTextComponentString(txt)
DrawRect(x,y,menu.width,menu.height,0,0,0,150)
DrawText(x - menu.width/2 + 0.005, y - menu.height/2 + 0.0028)
end
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function Notify(text)
SetNotificationTextEntry('STRING')
AddTextComponentString(text)
DrawNotification(false, false)
end
function DoesPlayerHaveVehicle(model,button,y,selected)
local t = false
--TODO:check if player own car
if t then
drawMenuRight("OWNED",vehpol.menu.x,y,selected)
else
drawMenuRight(button.costs.."$",vehpol.menu.x,y,selected)
end
end
local backlock = false
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlJustPressed(1,201) and IsPlayerInRangeOfVehpol() then
if vehpol.opened then
CloseCreator()
else
OpenCreator()
end
end
if vehpol.opened then
local ped = LocalPed()
local menu = vehpol.menu[vehpol.currentmenu]
drawTxt(vehpol.title,1,1,vehpol.menu.x,vehpol.menu.y,1.0, 255,255,255,255)
drawMenuTitle(menu.title, vehpol.menu.x,vehpol.menu.y + 0.08)
drawTxt(vehpol.selectedbutton.."/"..tablelength(menu.buttons),0,0,vehpol.menu.x + vehpol.menu.width/2 - 0.0385,vehpol.menu.y + 0.067,0.4, 255,255,255,255)
local y = vehpol.menu.y + 0.12
buttoncount = tablelength(menu.buttons)
local selected = false
for i,button in pairs(menu.buttons) do
if i >= vehpol.menu.from and i <= vehpol.menu.to then
if i == vehpol.selectedbutton then
selected = true
else
selected = false
end
drawMenuButton(button,vehpol.menu.x,y,selected)
if button.costs ~= nil then
if vehpol.currentmenu == "compacts" or vehpol.currentmenu == "suvs" or vehpol.currentmenu == "vans" or vehpol.currentmenu == "motorcycles" then
DoesPlayerHaveVehicle(button.model,button,y,selected)
else
drawMenuRight(button.costs.."$",vehpol.menu.x,y,selected)
end
end
y = y + 0.04
if vehpol.currentmenu == "compacts" or vehpol.currentmenu == "suvs" or vehpol.currentmenu == "vans" or vehpol.currentmenu == "motorcycles" then
if selected then
if fakecar.model ~= button.model then
if DoesEntityExist(fakecar.car) then
Citizen.InvokeNative(0xEA386986E786A54F, Citizen.PointerValueIntInitialized(fakecar.car))
end
local pos = currentlocation.pos.inside
local hash = GetHashKey(button.model)
RequestModel(hash)
while not HasModelLoaded(hash) do
Citizen.Wait(0)
drawTxt("~b~Loading...",0,1,0.5,0.5,1.5,255,255,255,255)
end
local veh = CreateVehicle(hash,pos[1],pos[2],pos[3],pos[4],false,false)
while not DoesEntityExist(veh) do
Citizen.Wait(0)
drawTxt("~b~Loading...",0,1,0.5,0.5,1.5,255,255,255,255)
end
FreezeEntityPosition(veh,true)
SetEntityInvincible(veh,true)
SetVehicleDoorsLocked(veh,4)
--SetEntityCollision(veh,false,false)
TaskWarpPedIntoVehicle(LocalPed(),veh,-1)
for i = 0,24 do
SetVehicleModKit(veh,0)
RemoveVehicleMod(veh,i)
end
fakecar = { model = button.model, car = veh}
end
end
end
if selected and IsControlJustPressed(1,201) then
ButtonSelected(button)
end
end
end
end
if vehpol.opened then
if IsControlJustPressed(1,202) then
Back()
end
if IsControlJustReleased(1,202) then
backlock = false
end
if IsControlJustPressed(1,188) then
if vehpol.selectedbutton > 1 then
vehpol.selectedbutton = vehpol.selectedbutton -1
if buttoncount > 10 and vehpol.selectedbutton < vehpol.menu.from then
vehpol.menu.from = vehpol.menu.from -1
vehpol.menu.to = vehpol.menu.to - 1
end
end
end
if IsControlJustPressed(1,187)then
if vehpol.selectedbutton < buttoncount then
vehpol.selectedbutton = vehpol.selectedbutton +1
if buttoncount > 10 and vehpol.selectedbutton > vehpol.menu.to then
vehpol.menu.to = vehpol.menu.to + 1
vehpol.menu.from = vehpol.menu.from + 1
end
end
end
end
end
end)
function round(num, idp)
if idp and idp>0 then
local mult = 10^idp
return math.floor(num * mult + 0.5) / mult
end
return math.floor(num + 0.5)
end
function ButtonSelected(button)
local ped = GetPlayerPed(-1)
local this = vehpol.currentmenu
local btn = button.name
if this == "main" then
if btn == "Vehicles" then
OpenMenu('vehicles')
elseif btn == "Motorcycles" then
OpenMenu('motorcycles')
end
elseif this == "vehicles" then
if btn == "Compacts" then
OpenMenu('compacts')
elseif btn == "SUVs" then
OpenMenu('suvs')
elseif btn == "Vans" then
OpenMenu('vans')
end
elseif this == "compacts" or this == "suvs" or this == "vans" or this == "motorcycles" then
--if playermoney >= button.costs then
vehicle_price = 0--button.costs
boughtcar = true
CloseCreator()
--else
-- Notify('~r~Not enough money')
--end
end
end
function OpenMenu(menu)
fakecar = {model = '', car = nil}
vehpol.lastmenu = vehpol.currentmenu
if menu == "vehicles" then
vehpol.lastmenu = "main"
elseif menu == "bikes" then
vehpol.lastmenu = "main"
elseif menu == 'race_create_objects' then
vehpol.lastmenu = "main"
elseif menu == "race_create_objects_spawn" then
vehpol.lastmenu = "race_create_objects"
end
vehpol.menu.from = 1
vehpol.menu.to = 10
vehpol.selectedbutton = 0
vehpol.currentmenu = menu
end
function Back()
if backlock then
return
end
backlock = true
if vehpol.currentmenu == "main" then
CloseCreator()
elseif vehpol.currentmenu == "compacts" or vehpol.currentmenu == "suvs" or vehpol.currentmenu == "vans" or vehpol.currentmenu == "motorcycles" then
if DoesEntityExist(fakecar.car) then
Citizen.InvokeNative(0xEA386986E786A54F, Citizen.PointerValueIntInitialized(fakecar.car))
end
fakecar = {model = '', car = nil}
OpenMenu(vehpol.lastmenu)
else
OpenMenu(vehpol.lastmenu)
end
end
function stringstarts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
local firstspawn = 0
AddEventHandler('playerSpawned', function(spawn)
if firstspawn == 0 then
RemoveIpl('v_carshowroom')
RemoveIpl('shutter_open')
RemoveIpl('shutter_closed')
RemoveIpl('shr_int')
RemoveIpl('csr_inMission')
RequestIpl('v_carshowroom')
RequestIpl('shr_int')
--RequestIpl('csr_inMission')
RequestIpl('shutter_closed')
--326 car blip 227 225
ShowVehshopBlips(true)
firstspawn = 1
end
end)
thanks