zfbx / zdiscord

A Discord bot that runs in FiveM for the purpose of whitelisting, moderation and utilties using discord.js
Other
211 stars 79 forks source link

[Question] Grant permission based on the role #54

Closed SrPeterr closed 2 years ago

SrPeterr commented 2 years ago

Question: Hi! I'm not sure if this is possible, but my plan is that when they buy a package on tebex they are granted a role, VIP. This role in the server should have the rank vip, normally the command would be /addpermission ID (group)

Information: FiveM artifact #: 5371 Using QBCore?: yes When did you last update QBCore if you are using it?: This week

zfbx commented 2 years ago

There's the AutoAcePermissions where if a role is set in discord the user on login will be given an ace permission on the server. that what you mean? or do you mean actually givinging them a permissions like mod, admin or god?

SrPeterr commented 2 years ago

It would be something like giving them mod, admin or god. Currently in QB there is, user, admin or god I think but I want to create a new rank, like VIP. user, vip, admin and god

zfbx commented 2 years ago

I'd suggest using FiveM's acePerms system rather than qb's permission system which is planned to be phased out in favor of ace perms:

Info: https://cookbook.fivem.net/2021/07/17/quick-note-on-using-built-in-acl-security/ https://forum.cfx.re/t/basic-aces-principals-overview-guide/90917

SrPeterr commented 2 years ago

Hmmm, the thing is right now I think It would be easier for some scripts to use QB, for example I cant restrict some command for only the "vip" rank or accessing a shop

zfbx commented 2 years ago

Yeah you can, fairly simply too. chat commands support ace perms by default and checking if a source has permission is a simple one liner without any dependency on imports like qbcore. a simple

if IsPlayerAceAllowed(src, 'viprank') then
    -- Special code
end

and as a chat command

RegisterCommand('special', function(source, args, rawCommand)
    -- Special command code to run
end, 'viprank')

Those are FiveM natives

ItzDabbzz commented 2 years ago

FiveM's acePerms the way to go man, screw qb's perms system.

SrPeterr commented 2 years ago

Ohh, will do this, thank you!!

SrPeterr commented 2 years ago

And in the config.js file should be:

const EnableAutoAcePermissions = true;
const AutoAcePermissions = {
    "eclub": "ROLE_ID",
};

And the I have a command like:

RegisterCommand('vip', function(src)
    if IsPlayerAceAllowed(src, 'eclub') then
        TriggerClientEvent('QBCore:Notify', src, "VIP", "success")
    else
        TriggerClientEvent('QBCore:Notify', src, "Not VIP", "error")
    end
end, 'eclub')

With this config, it is showing me that I have not VIP, but I do have that role :/

zfbx commented 2 years ago

The resources I linked go over ace perms in better detail. one thing that trips people up (even me) is permissions vs groups (add_ace vs add_principal)