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 to config.lua
--------------------------------------------------
Config = {}
Config.allowedjobs = {'police'}
Config.ScriptName = GetCurrentResourceName()
** client.lua ***
Add the client event to catch the job.
RegisterNetEvent(Config.ScriptName..':recjob')
AddEventHandler(Config.ScriptName..':recjob', function(p_job)
playerjob = p_job
end)
** server.lua ***
If server.lua does not exist add it. Add these lines to the file.
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 ***
In client.lua add something like this example to check for matching 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')
— Want more help? we are here: dragon code https://discord.gg/WPtnPbXhWY
Hits: 55