├── businesses.json ├── business_license.png ├── fxmanifest.lua ├── README.md ├── config.lua ├── client.lua └── server.lua /businesses.json: -------------------------------------------------------------------------------- 1 | [[],[]] -------------------------------------------------------------------------------- /business_license.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TropicGalxy/tropic-business/HEAD/business_license.png -------------------------------------------------------------------------------- /fxmanifest.lua: -------------------------------------------------------------------------------- 1 | fx_version 'cerulean' 2 | game 'gta5' 3 | 4 | lua54 'yes' 5 | author 'tropicgalxy' 6 | description 'a very simple script to buy multiple business' 7 | version '1.1' 8 | 9 | shared_scripts { 10 | 'config.lua' 11 | } 12 | 13 | client_scripts { 14 | 'client.lua' 15 | } 16 | 17 | server_scripts { 18 | '@ox_lib/init.lua', 19 | 'server.lua' 20 | } 21 | 22 | dependencies { 23 | 'qb-core', 24 | 'ox_target', -- comment out if using qb target 25 | -- 'qb-target' -- comment out if using ox target 26 | } 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tropic-business 2 | 3 | 4 | A simple way to buy businesses 5 | 6 | # Dependencies: 7 | 8 | - [ox target](https://github.com/overextended/ox_target) 9 | 10 | or 11 | 12 | - [qb target](https://github.com/qbcore-framework/qb-target) 13 | 14 | # Installation 15 | 16 | https://tropical-productions.gitbook.io/tropical-productions/free-scripts/businesses 17 | 18 | # Links 19 | 20 | Preview: https://youtu.be/WGHvTcwtjpw 21 | 22 | Support: https://dsc.gg/tropicgalxy 23 | 24 | # Most Recent Update 25 | 26 | added a config option for how you would like to buy businesses 27 | -------------------------------------------------------------------------------- /config.lua: -------------------------------------------------------------------------------- 1 | Config = {} 2 | 3 | Config.Target = "ox" -- Set to either "qb" or "ox" 4 | 5 | Config.RequireBusinessLicense = true -- Set to true if a business license is required 6 | 7 | Config.Inventory = "ox" -- Set to "qb" or "ox" based on your preference, only needed if RequireBusinessLicense = true 8 | 9 | Config.Notify = "qb" -- currently supports: qb, okok 10 | 11 | Config.PayOption = "cash" -- cash or bank 12 | 13 | Config.Businesses = { 14 | { 15 | EnableBlip = true, 16 | BusinessName = "Burgershot", 17 | BusinessPrice = 75000, 18 | BusinessJob = "burgershot", 19 | BusinessGrade = 4, 20 | PedCoords = vector4(-1187.4, -877.69, 12.83, 34.2), -- Set your ped coordinates here 21 | PedModel = "u_m_y_burgerdrug_01", -- Set your ped model here, https://docs.fivem.net/docs/game-references/ped-models/ 22 | BlipCoords = vector3(-1189.14, -890.5, 13.89), -- Set your blip coordinates here 23 | BlipSprite = 106, -- Set your blip sprite here, https://docs.fivem.net/docs/game-references/blips/ 24 | BlipColor = 1, -- Set your blip color here 25 | BlipName = "Burgershot", -- Set your blip name here 26 | SellBackPercentage = 75 27 | }, 28 | { 29 | EnableBlip = false, 30 | BusinessName = "My Business 2", 31 | BusinessPrice = 75000, 32 | BusinessJob = "businessowner2", 33 | BusinessGrade = 4, 34 | PedCoords = vector4(0.0, 0.0, 0.0, 0.0), -- Set your ped coordinates here 35 | PedModel = "a_f_y_business_02", -- Set your ped model here 36 | BlipCoords = vector3(0.0, 0.0, 0.0), -- Set your blip coordinates here 37 | BlipSprite = 475, -- Set your blip sprite here 38 | BlipColor = 2, -- Set your blip color here 39 | BlipName = "Business 2", -- Set your blip name here 40 | SellBackPercentage = 40 41 | } 42 | -- Add more businesses as needed 43 | } 44 | -------------------------------------------------------------------------------- /client.lua: -------------------------------------------------------------------------------- 1 | local QBCore = exports['qb-core']:GetCoreObject() 2 | 3 | local function isBusinessOwned(index) 4 | local Player = QBCore.Functions.GetPlayerData() 5 | return businesses[index] and businesses[index].owner == Player.citizenid 6 | end 7 | 8 | CreateThread(function() 9 | print("Config.Target: " .. tostring(Config.Target)) 10 | for i, business in ipairs(Config.Businesses) do 11 | local pedModel = business.PedModel 12 | RequestModel(pedModel) 13 | while not HasModelLoaded(pedModel) do 14 | Wait(100) 15 | end 16 | local ped = CreatePed(4, pedModel, business.PedCoords.x, business.PedCoords.y, business.PedCoords.z, business.PedCoords.w, false, true) 17 | SetEntityAsMissionEntity(ped, true, true) 18 | SetPedFleeAttributes(ped, 0, 0) 19 | SetBlockingOfNonTemporaryEvents(ped, true) 20 | FreezeEntityPosition(ped, true) 21 | SetEntityInvincible(ped, true) 22 | 23 | local buyLabel = "Buy Business ($" .. business.BusinessPrice .. ")" 24 | local sellLabel = "Sell Business ($" .. (business.BusinessPrice * (business.SellBackPercentage / 100)) .. ")" -- if you want to show how much you get from selling then change line 38 and 61 to: label = sellLabel 25 | 26 | if Config.Target == "ox" then 27 | print("Registering ox_target for business: " .. business.BusinessName) 28 | exports.ox_target:addLocalEntity(ped, { 29 | { 30 | name = 'business:buy', 31 | event = 'business:buy', 32 | icon = 'fas fa-shopping-cart', 33 | label = buyLabel, 34 | args = { index = i }, 35 | distance = 2.5, 36 | onSelect = function() 37 | TriggerServerEvent('business:buyBusiness', i) 38 | end 39 | }, 40 | { 41 | event = "business:sell", 42 | icon = "fas fa-dollar-sign", 43 | label = "Sell Business", 44 | args = { index = i }, 45 | distance = 2.5, 46 | onSelect = function() 47 | TriggerServerEvent('business:sellBusiness', i) 48 | end 49 | } 50 | }) 51 | elseif Config.Target == "qb" then 52 | print("Registering qb-target for business: " .. business.BusinessName) 53 | exports['qb-target']:AddTargetEntity(ped, { 54 | options = { 55 | { 56 | event = "business:buy", 57 | icon = "fas fa-shopping-cart", 58 | label = buyLabel, 59 | action = function() 60 | TriggerServerEvent('business:buyBusiness', i) 61 | end 62 | }, 63 | { 64 | event = "business:sell", 65 | icon = "fas fa-dollar-sign", 66 | label = sellLabel, 67 | action = function() 68 | TriggerServerEvent('business:sellBusiness', i) 69 | end 70 | } 71 | }, 72 | distance = 2.5 73 | }) 74 | else 75 | print("Invalid target system specified in config.") 76 | end 77 | 78 | if business.EnableBlip then 79 | local blip = AddBlipForCoord(business.BlipCoords.x, business.BlipCoords.y, business.BlipCoords.z) 80 | SetBlipSprite(blip, business.BlipSprite) 81 | SetBlipDisplay(blip, 4) 82 | SetBlipScale(blip, 0.75) 83 | SetBlipColour(blip, business.BlipColor) 84 | SetBlipAsShortRange(blip, true) 85 | BeginTextCommandSetBlipName("STRING") 86 | AddTextComponentString(business.BlipName) 87 | EndTextCommandSetBlipName(blip) 88 | end 89 | end 90 | end) 91 | -------------------------------------------------------------------------------- /server.lua: -------------------------------------------------------------------------------- 1 | local QBCore = exports['qb-core']:GetCoreObject() 2 | local businesses = {} 3 | 4 | local function loadBusinesses() 5 | local file = LoadResourceFile(GetCurrentResourceName(), 'businesses.json') 6 | if file then 7 | businesses = json.decode(file) or {} 8 | else 9 | businesses = {} 10 | end 11 | end 12 | 13 | local function saveBusinesses() 14 | local jsonData = json.encode(businesses) 15 | SaveResourceFile(GetCurrentResourceName(), 'businesses.json', jsonData, -1) 16 | end 17 | 18 | local function initializeBusinesses() 19 | for index, business in ipairs(Config.Businesses) do 20 | if not businesses[index] then 21 | businesses[index] = { owner = nil, job = nil } 22 | end 23 | end 24 | saveBusinesses() 25 | end 26 | 27 | AddEventHandler('onResourceStart', function(resource) 28 | if resource == GetCurrentResourceName() then 29 | loadBusinesses() 30 | initializeBusinesses() 31 | end 32 | end) 33 | 34 | RegisterNetEvent('business:buyBusiness', function(index) 35 | local src = source 36 | local Player = QBCore.Functions.GetPlayer(src) 37 | local business = Config.Businesses[index] 38 | local money = Player.PlayerData.money['cash'] 39 | 40 | if Config.RequireBusinessLicense then 41 | local hasLicense = false 42 | 43 | if Config.Inventory == "qb" then 44 | hasLicense = exports['qb-inventory']:HasItem(source, 'business_license', 1) 45 | elseif Config.Inventory == "ox" then 46 | hasLicense = Player.Functions.GetItemByName('business_license') and Player.Functions.GetItemByName('business_license').amount > 0 47 | end 48 | 49 | if not hasLicense then 50 | if Config.Notify == "qb" then 51 | TriggerClientEvent('QBCore:Notify', src, "You need a business license to purchase this", 'error') 52 | elseif Config.Notify == "okok" then 53 | TriggerClientEvent('okokNotify:Alert', src, 'Error', 'You need a business license to purchase this', 1000, 'error', false) 54 | else 55 | print("There is no valid notify script enabled") 56 | end 57 | return 58 | end 59 | end 60 | 61 | if businesses[index] and businesses[index].owner == Player.PlayerData.citizenid then 62 | if Config.Notify == "qb" then 63 | TriggerClientEvent('QBCore:Notify', src, "You already own this business", 'error') 64 | elseif Config.Notify == "okok" then 65 | TriggerClientEvent('okokNotify:Alert', src, 'Error', 'You already own this business', 1000, 'error', false) 66 | else 67 | print("There is no valid notify script enabled") 68 | end 69 | return 70 | end 71 | 72 | if money >= business.BusinessPrice then 73 | if Config.PayOption == "cash" then 74 | Player.Functions.RemoveMoney('cash', business.BusinessPrice) 75 | Player.Functions.SetJob(business.BusinessJob, business.BusinessGrade) 76 | elseif Config.PayOption == "bank" then 77 | Player.Functions.RemoveMoney('bank', business.BusinessPrice) 78 | Player.Functions.SetJob(business.BusinessJob, business.BusinessGrade) 79 | else 80 | print("Incorrect payment option selected") 81 | return 82 | end 83 | 84 | businesses[index] = { 85 | owner = Player.PlayerData.citizenid, 86 | job = business.BusinessJob 87 | } 88 | 89 | saveBusinesses() 90 | 91 | if Config.Notify == "qb" then 92 | TriggerClientEvent('QBCore:Notify', src, "You have purchased the business and are now the owner of " .. business.BusinessJob, 'success') 93 | elseif Config.Notify == "okok" then 94 | TriggerClientEvent('okokNotify:Alert', src, 'Success', "You have purchased the business and are now the owner of " .. business.BusinessJob, 1000, 'success', false) 95 | else 96 | print("There is no valid notify script enabled") 97 | end 98 | else 99 | if Config.Notify == "qb" then 100 | TriggerClientEvent('QBCore:Notify', src, "You don't have enough money", 'error') 101 | elseif Config.Notify == "okok" then 102 | TriggerClientEvent('okokNotify:Alert', src, 'Error', "You don't have enough money", 1000, 'error', false) 103 | else 104 | print("There is no valid notify script enabled") 105 | end 106 | end 107 | end) 108 | 109 | RegisterNetEvent('business:sellBusiness', function(index) 110 | local src = source 111 | local Player = QBCore.Functions.GetPlayer(src) 112 | local business = Config.Businesses[index] 113 | local job = Player.PlayerData.job.name 114 | 115 | -- Check if the player owns the business 116 | if businesses[index] and businesses[index].owner == Player.PlayerData.citizenid then 117 | local refund = business.BusinessPrice * (business.SellBackPercentage / 100) 118 | if Config.PayOption == "cash" then 119 | Player.Functions.AddMoney('cash', refund) 120 | Player.Functions.SetJob('unemployed', 0) 121 | elseif Config.PayOption == "bank" then 122 | Player.Functions.AddMoney('bank', refund) 123 | Player.Functions.SetJob('unemployed', 0) 124 | else 125 | print("Incorrect payment option selected") 126 | return 127 | end 128 | 129 | 130 | businesses[index] = { owner = nil, job = nil } 131 | saveBusinesses() 132 | if Config.Notify == "qb" then 133 | TriggerClientEvent('QBCore:Notify', src, "You have sold the business and received $" .. refund, 'success') 134 | elseif Config.Notify == "okok" then 135 | TriggerClientEvent('okokNotify:Alert', src, 'Success', "You have sold the business and received $" .. refund, 1000, 'success', false) 136 | else 137 | print("There is no valid notify script enabled") 138 | end 139 | else 140 | if Config.Notify == "qb" then 141 | TriggerClientEvent('QBCore:Notify', src, "You don't own this business", 'error') 142 | elseif Config.Notify == "okok" then 143 | TriggerClientEvent('okokNotify:Alert', src, 'Error', "You don't own this business", 1000, 'error', false) 144 | else 145 | print("There is no valid notify script enabled") 146 | end 147 | end 148 | end) 149 | 150 | RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function() 151 | local src = source 152 | local Player = QBCore.Functions.GetPlayer(src) 153 | 154 | for index, data in pairs(businesses) do 155 | if data.owner == Player.PlayerData.citizenid then 156 | Player.Functions.SetJob(data.job, Config.Businesses[index].BusinessGrade) 157 | end 158 | end 159 | end) 160 | --------------------------------------------------------------------------------