You can configure this to register a usable item that fits your framework if enabled in the shared/config.lua file.
-- Purpose: Framework specific usable item creation. if Config.EnableStandaloneTablet and Config.TabletItemName thenif Config.Framework =="qbcore" then Framework.Functions.CreateUseableItem(Config.TabletItemName, function(source)TriggerClientEvent("gs-trucking:client:openTablet", source)end)elseif Config.Framework =="esx" then Framework.RegisterUsableItem(Config.TabletItemName, function(source)TriggerClientEvent("gs-trucking:client:openTablet", source)end)endend
Get Player
This is used to get framework specific data for the players source ID
-- Purpose: Function to get the player object from the source ID.-- source [int]: Players source IDfunctionGetPlayer(source)ifnot source thenreturnnilendif Config.Framework =="qbcore" thenreturn Framework.Functions.GetPlayer(source)elseif Config.Framework =="esx" thenreturn Framework.GetPlayerFromId(source)endend
Get Identifier
This is used mostly in the reputation system as it stores reputation in the database connected to their character identifier. You can modify to your requirements if they are different from the default
-- Purpose: Function to get the players identifier from the source ID.-- source [int]: Players source IDfunctionGetxPlayerIdentifier(source)local xPlayer =GetPlayer(source)if xPlayer thenif Config.Framework =="qbcore" thenreturn xPlayer.PlayerData.citizenidelseif Config.Framework =="esx" thenreturn xPlayer.identifierendendreturnnilend
Get Players Money
Checks a players account as configured, mostly used for the truck rental system
-- Purpose: Function to get the players money from the source ID.-- source [int]: Players source IDfunctionGetPlayerMoney(source)local xPlayer =GetPlayer(source)if xPlayer thenif Config.Framework =="qbcore" thenreturn xPlayer.Functions.GetMoney('bank')elseif Config.Framework =="esx" thenreturn xPlayer.getAccount('bank').moneyendendreturn0end
Give Player Money
This is triggered when a job is completed or a rental truck is returned. It passes an extra argument to indicate whether or not a job is illegal or not. You can configure this however you need. (Does not get triggered if the payout is $0)
-- Purpose: Function to give the player money.-- souce [int]: Players source ID-- amount [int]: Amount of money to pay the player-- illegal [bool]: Type of job the player is doing (always false if it's from rental return)functionGivePlayerMoney(source,amount,illegal)local xPlayer =GetPlayer(source)if xPlayer thenif Config.Framework =="qbcore" then xPlayer.Functions.AddMoney((not illegal and'bank' or'crypto'), amount)elseif Config.Framework =="esx" then xPlayer.addAccountMoney((not illegal and'bank' or'black_money'), amount)endendend
Remove Player Money
This is triggered when a player rents a truck and the rental fee is more than $0
-- Purpose: Function to remove the players money.-- souce [int]: Players source ID-- amount [int]: Amount of money to remove from the playerfunctionRemovePlayerMoney(source,amount)local xPlayer =GetPlayer(source)if xPlayer thenif Config.Framework =="qbcore" then xPlayer.Functions.RemoveMoney('bank', amount)elseif Config.Framework =="esx" then xPlayer.removeAccountMoney('bank', amount)endendend
Player Reputation (Add/Remove)
These functions are only triggered when the reputation system is enabled. I added them incase you want to configure anything else such as the notification or for example QBCore has its own 'jobrep' metadata that you can also update here.
-- Purpose: Function triggered when player reputation has been added. (Doesnt trigger if reputation is disabled)-- source [int]: Players source ID-- added [int]: Amount of reputation to add to the player-- total [int]: The new amount of reputation the player hasfunctionAddedPlayerReputation(source,added,total)local xPlayer =GetPlayer(source)if xPlayer then--QBCore hass a metadata system to store player job reputation data. (Uncomment if you wish to use it)--if Config.Framework == "qbcore" then-- if Config.RequireJob then-- xPlayer.PlayerData.metadata.jobrep[Config.RequireJob] = total-- xPlayer.Functions.SetMetaData("jobrep", xPlayer.PlayerData.metadata.jobrep)-- end--endTriggerClientEvent('gs-trucking:client:notify', source, locale('earned_reputation', added, total), 'success') endend-- Purpose: Function triggered when player reputation has been removed. (Doesnt trigger if reputation is disabled) -- source [int]: Players source ID-- removed [int]: Amount of reputation to remove from the player-- total [int]: The new amount of reputation the player hasfunctionRemovedPlayerReputation(source,removed,total)local xPlayer =GetPlayer(source)if xPlayer then--QBCore hass a metadata system to store player job reputation data. (Uncomment if you wish to use it)--if Config.Framework == "qbcore" then-- if Config.RequireJob then-- xPlayer.PlayerData.metadata.jobrep[Config.RequireJob] = total-- xPlayer.Functions.SetMetaData("jobrep", xPlayer.PlayerData.metadata.jobrep)-- end--endTriggerClientEvent('gs-trucking:client:notify', source, locale('lost_reputation', removed, total), 'error') endend
Police Count
This is where you can configure the function that checks to see if there's enough police on duty for an illegal job to be started
-- Purpose: Function to check if there enough police on duty to do the job.functionPoliceCheck()local needed = Config.PoliceRequiredlocal quickTable = {}if needed ==0thenreturntrueendfor _, jobName inipairs(Config.PoliceJobs) do quickTable[jobName] =trueendlocal found =0for _, playerId inipairs(GetPlayers()) dolocal xPlayer =GetPlayer(playerId)if xPlayer thenif Config.Framework =="qbcore" thenif quickTable[xPlayer.PlayerData.job.name] then found = found +1endelseif Config.Framework =="esx" thenif quickTable[xPlayer.job.name] then found = found +1endendif found >= needed thenreturntrueendendendreturnfalseend