How do I add job locking to any vorp core based script?
If you are adding it to one of my scripts, these are the steps.
If you are adding it to someone elses scripts, then the steps may be different.
config.lua
Add the following code to the config.lua.
--------------------------------------------------
Config = {}
Config.allowedjobs = {'police'}
Config.ScriptName = GetCurrentResourceName()
server.lua
Add the following code to the server.lua.
Character = {}
VorpCore = {}
Citizen.CreateThread(function()
MyCore = "VORP"
TriggerEvent("getCore",function(core)
VorpCore = core
end)
print("^4["..Config.ScriptName.."]^0 ^2Framework: "..MyCore.."^0")
end)
RegisterServerEvent(Config.ScriptName..':get_job')
AddEventHandler(Config.ScriptName..':get_job', function(--[[source]])
print(Config.ScriptName..':get_job')
local _source = source
if _source == nil then
print("Err: Source failed. ")
else
if Character[_source] == nil then
Character[_source] = {}
end
Character[_source] = VorpCore.getUser(_source).getUsedCharacter -- server side
end
if Character[_source]~= nil and Character[_source].job ~= nil then
TriggerClientEvent(Config.ScriptName..':recjob', _source, Character[_source].job)
end
end)
This connects to vorp core, creates the variables, and pulls out the players job and sends it to the client.
client.lua
Add the following code to the client.lua.
RegisterNetEvent(Config.ScriptName..':recjob')
AddEventHandler(Config.ScriptName..':recjob', function(p_job)
playerjob = p_job
end)
The client event to catch the job.
In client.lua add something like this example to check for matching jobs, where you need to check for jobs.
for job_key, job_name in pairs (Config.allowedjobs) do
if job_name == playerjob then
--- do the thing.
else
print("Permission denied")
end
end
Some where before you need the job information, but inside all the action so it can pick up job changes.
TriggerServerEvent(Config.ScriptName..':get_job')
If you create any files make sure to add them to the fxmanifest.lua file under client or server scripts.
— Want more help? we are here: dragon code https://discord.gg/WPtnPbXhWY