Adding VRP permissions check to scripts?

Okay, so I’ve found some wonderful scripts on this fine forum and they’ve helped me out a lot with my server development. My issue is some of these don’t check permissions and I would like to add that – or at least add a password or something to the commands. I’ve peered through some other scripts that have done it successfully, but I’m unable to get it working as intended on my server.

This is what I’ve tried for grabbing vRP permissions and checking them before allowing the use of the /drag command.

local Tunnel = module("vrp", "lib/Tunnel")
local Proxy = module("vrp", "lib/Proxy")
 
vRP = Proxy.getInterface("vRP")
vRPclient = Tunnel.getInterface("vRP","dragvrp")

TriggerEvent('es:addCommand', 'drag', function(source, args, user)

	local argument = args[2] -- player id to check license
	local savedsource = source

	if argument == nil or type(tonumber(argument)) == nil then
	
		TriggerClientEvent("chatMessage", source, "SYSTEM", { 0, 141, 155 }, "example: /drag <id>")
		
	elseif (permissions={"police.handcuff"}) then                               <-- add your permissions here
	
	--	TriggerClientEvent("chatMessage", source, "SYSTEM", { 0, 141, 155 }, "^3Civilians are not allowed to use /drag")
		
	else 
			
		if(GetPlayerName(tonumber(argument)))then
			TriggerEvent('es:getPlayerFromId', tonumber(argument), function(target)
				if argument == savedsource then
					TriggerClientEvent('chatMessage', source, "SYSTEM", { 0, 141, 155 }, "You cannot drag yourself.")
				else
					TriggerClientEvent("dr:drag", tonumber(argument), source)
				end
			end)
		else
			TriggerClientEvent('chatMessage', source, "SYSTEM", { 0, 141, 155 }, "Incorrect Player ID")
		end		
	end
end)

This is from a drag command script that I’ve found on here that works quite well, the problem is I’d only want police to be able to use it. I thought that by adding the vRP tunnels and the permissions line that everything would work, but it does not. It doesn’t function at all in game. Can anyone point me in the right direction for fixing this? I’ve pored over the vRP documentation and I’m unable to figure out on my own what’s wrong.

Alternatively if that’s not working I’d like to add a password to the command (so that only my police force can use it and the password can be changed, etc) and I’ve tried this code, but with the same (not working) result.

local dragPassword = "cops"

TriggerEvent('es:addCommand', 'drag', function(source, args, user)

	local argument = args[2] -- player id to check license
	local savedsource = source

	if argument == nil or type(tonumber(argument)) == nil then
	
		TriggerClientEvent("chatMessage", source, "SYSTEM", { 0, 141, 155 }, "example: /drag password <id>")
		
	--elseif (permissions={"police.handcuff"}) then                               <-- add your permissions here
	
	--	TriggerClientEvent("chatMessage", source, "SYSTEM", { 0, 141, 155 }, "^3Civilians are not allowed to use /drag")
		
	else 
			
		if(GetPlayerName(tonumber(argument)))then
			TriggerEvent('es:getPlayerFromId', tonumber(argument), function(target)
				if argument == savedsource then
					TriggerClientEvent('chatMessage', source, "SYSTEM", { 0, 141, 155 }, "You cannot drag yourself.")
				else
				if cm[2] == dragPassword then
					TriggerClientEvent("dr:drag", tonumber(argument), source)
				end
			end)
		else
			TriggerClientEvent('chatMessage', source, "SYSTEM", { 0, 141, 155 }, "Incorrect Player ID")
		end		
	end
end)

I am not entirely sure, as I have not looked in the documentation…
But why call for an essentialMode event multiple places, if you use VRP?

TriggerEvent(‘es:addCommand’)
TriggerEvent(‘es:getPlayerFromId’)

I’m not sure. It’s my understanding that that particular script relies on essentialmode to function. It is not my script, but one I found here. It works as is, but I’d like to add a vrp permissions check or a password to the command.

it’s using essentialmode functions with those two events, you’ll need to create those events yourself (or by looking at how essentialmode does it.). You could also see if vrp has those events (it probably doesn’t have the addcommand one due to the framework being menu only.)