SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Plugin Development

Reply
 
Thread Tools Display Modes
Old 14/10/2018, 10:45 AM   #451
g1venchy
Little Clucker
 
g1venchy's Avatar
 
Join Date: Oct 2018
Posts: 28
Reputation: 0
Default Re: Pawn.CMD

OnPlayerCommandText will be called when player enters text what starts with /
OnPlayerText will be called when player enters text what start with somthing else.

PHP Code:
public OnPlayerText(playerid,text[]){
    new 
len,tempText[128];
    if((
text[0]=='@' || text[0]=='7') && (len=strlen(text)) >= ){
        for(new 
i=1leni++){
            if(!(
'a'<=text[i]<='z') && 4)return 0;
            if(
text[i]==' ')break;
            
tempText[i]=text[i];
        }
        if(
PC_CommandExists(tempText)) text[0]='/',PC_EmulateCommand(playerid,text);
    }
    return 
0;

g1venchy is offline   Reply With Quote
Old 14/10/2018, 12:03 PM   #452
Calisthenics
Huge Clucker
 
Join Date: May 2018
Posts: 404
Reputation: 69
Default Re: Pawn.CMD

Quote:
Originally Posted by YourShadow View Post
PHP Code:
public OnPlayerCommandReceived(playeridcmd[], params[], flags)
{
    if (!(
flags pPermissions[playerid]))
    {
        
printf("player %d doesn’t have access to command '%s'"playeridcmd);

        return 
0;
    }

    return 
1;

A command with no flags set will be blocked for any player.
pawn Code:
if (flags != 0 && !(flags & pPermissions[playerid]))
Calisthenics is offline   Reply With Quote
Old 16/10/2018, 07:05 PM   #453
Crayder
High-roller
 
Crayder's Avatar
 
Join Date: Sep 2013
Location: Flames of Hell
Posts: 3,824
Reputation: 603
Default Re: Pawn.CMD

Quote:
Originally Posted by Calisthenics View Post
A command with no flags set will be blocked for any player.
pawn Code:
if (flags != 0 && !(flags & pPermissions[playerid]))
You didn't fix anything, you're still only accepting things that are not zero... xD

The example is for scripts that have all flags set, which is how it tends to be if you're using flags. You can't have a flag that is nothing so you can't check for a flag that's not set because it is 0 and you can't do bit operations on it. I can't explain things when I first wake up... but I think you get my point?

But, if you prefer to have a way to see if no flags are set, you should be using OR not AND.
__________________
Those who deserve reputation, do not need to beg for it.
Also, don't expect the help you need when offering reputation, you'll just be attracting Rep Hunters.
Join SA-MP Discord!
Crayder is offline   Reply With Quote
Old 17/10/2018, 05:41 PM   #454
Calisthenics
Huge Clucker
 
Join Date: May 2018
Posts: 404
Reputation: 69
Default Re: Pawn.CMD

Quote:
Originally Posted by Crayder View Post
You didn't fix anything, you're still only accepting things that are not zero... xD

The example is for scripts that have all flags set, which is how it tends to be if you're using flags. You can't have a flag that is nothing so you can't check for a flag that's not set because it is 0 and you can't do bit operations on it. I can't explain things when I first wake up... but I think you get my point?

But, if you prefer to have a way to see if no flags are set, you should be using OR not AND.
Or simply when flags is 0 (non set), it means it is a non-admin command.

pawn Code:
#include <a_samp>
#include <Pawn.CMD>

main() {}

enum (<<= 1)
{
    CMD_ADMIN = 1, // 0b00000000000000000000000000000001
    CMD_MODER,     // 0b00000000000000000000000000000010
    CMD_JR_MODER   // 0b00000000000000000000000000000100
};

new pPermissions[MAX_PLAYERS];

flags:ban(CMD_ADMIN);
cmd:ban(playerid, params[])
{
    return 1;
}

cmd:rules(playerid, params[])
{
    return 1;
}

public OnPlayerCommandReceived(playerid, cmd[], params[], flags)
{
    printf("OnPlayerCommandReceived(%d, \"%s\", \"%s\", %d)", playerid, cmd, params, flags);

    if (!(flags & pPermissions[playerid]))
    {
        printf("player %d doesn’t have access to command '%s'", playerid, cmd);

        return 0;
    }
    return 1;
}

public PC_OnInit()
{
    const testAdminPlayerId = 1, testSimplePlayerId = 4;

    pPermissions[testAdminPlayerId] = CMD_ADMIN | CMD_MODER | CMD_JR_MODER;
    pPermissions[testSimplePlayerId] = 0;

    PC_EmulateCommand(testAdminPlayerId, "/ban 4 some reason");
    PC_EmulateCommand(testSimplePlayerId, "/ban 1 some reason");
    PC_EmulateCommand(testAdminPlayerId, "/rules");
    PC_EmulateCommand(testSimplePlayerId, "/rules");
}
Output:
Code:
OnPlayerCommandReceived(1, "ban", "4 some reason", 1)
OnPlayerCommandReceived(4, "ban", "1 some reason", 1)
player 4 doesn’t have access to command 'ban'
OnPlayerCommandReceived(1, "rules", "", 0)
player 1 doesn’t have access to command 'rules'
OnPlayerCommandReceived(4, "rules", "", 0)
player 4 doesn’t have access to command 'rules'
Nobody can use /rules command unless you change that line to:
pawn Code:
if (flags != 0 && !(flags & pPermissions[playerid]))
Output:
pawn Code:
OnPlayerCommandReceived(1, "ban", "4 some reason", 1)
OnPlayerCommandReceived(4, "ban", "1 some reason", 1)
player 4 doesn’t have access to command 'ban'
OnPlayerCommandReceived(1, "rules", "", 0)
OnPlayerCommandReceived(4, "rules", "", 0)
accessible by every player.
Calisthenics is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Plugin] Vectoral Pawn - STL Data containers for pawn Rancho Plugin Development 70 03/05/2017 08:41 PM
Forum bug with [pawn][/pawn] BBCODE Yuripe Everything and Nothing 4 06/10/2012 01:58 PM
[Tool/Web/Other] PAWN Scanner - Scan PAWN files for information. Slice Tools and Files 10 15/07/2012 08:09 PM
[Help With Pawn] Pawn and compiler is not working..... D_Less Client Support 3 09/03/2012 05:49 AM


All times are GMT. The time now is 05:49 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.