[Plugin] Pawn.CMD

Quote:
Originally Posted by Romero837
Посмотреть сообщение
How could I put restrictions on commands, that is, in an event system, if I enter the event I can not use the command, I already have the variable bool. But if I use / salirevento I'll come out of it. I'm using Pawn.CMD and I really did not find help.

I tried to use this code in OnPlayerCommandReceive but not works, and in OnPlayerCommandText works but the excepcion not works with /salirevento.


Код:
public OnPlayerCommandReceived(playerid, cmd[], params[], flags)  //Not works 
{
    if(CmdBloq5[playerid] == 1)
    {
	    PlayerPlaySound(playerid,1140,0.0,0.0,0.0);
	    GameTextForPlayer(playerid,"~n~~p~Estas en un ~r~Evento ~n~~w~usa /Salirevento",3000,3);
	    return 1;
	}
}

public OnPlayerCommandText(playerid, cmdtext[])  //Not works
{
    if(CmdBloq5[playerid] == 1)
    {
	    PlayerPlaySound(playerid,1140,0.0,0.0,0.0);
	    GameTextForPlayer(playerid,"~n~~p~Estas en un ~r~Evento ~n~~w~usa /Salirevento",3000,3);
	    return 1;
    }
}
You have to return 0.
Reply

Yes, all commands are return 0 and can't use commands but i only need use /exitevent command.
Reply

Help @YourShadow
Reply

@YourShadow


should give possibility that other symbols can be added ( @, !, &, $, %, Ў ) instead of alone " / "



Example:

Код:
CMD:@at(playerid)
{
    //yourcodeblabla...
    return 1;
}

CMD:/at(playerid)
{
    //yourcodeblabla...
    return 1;
}

CMD:!at(playerid)
{
    //yourcodeblabla...
    return 1;
}

CMD:$at(playerid)
{
    //yourcodeblabla...
    return 1;
}
would print:

Код:
@at | /at | !at | $at
if symbolos is not added then by default it will be "/"

Код:
CMD:pallaringas(playerid)
{
    return 1;
}
I hope you have this suggestion in mind for future updating.
Reply

Quote:
Originally Posted by Alteh
View Post
@YourShadow


should give possibility that other symbols can be added ( @, !, &, $, %, Ў ) instead of alone " / "



Example:

Code:
CMD:@at(playerid)
{
    //yourcodeblabla...
    return 1;
}

CMD:/at(playerid)
{
    //yourcodeblabla...
    return 1;
}

CMD:!at(playerid)
{
    //yourcodeblabla...
    return 1;
}

CMD:$at(playerid)
{
    //yourcodeblabla...
    return 1;
}
would print:

Code:
@at | /at | !at | $at
if symbolos is not added then by default it will be "/"

Code:
CMD:pallaringas(playerid)
{
    return 1;
}
I hope you have this suggestion in mind for future updating.
Technically not possible that way since these symbols would be part of the function name. Some of these aren't possible to use in function names in PAWN.
Reply

Quote:
Originally Posted by Alteh
View Post
@YourShadow


should give possibility that other symbols can be added ( @, !, &, $, %, Ў ) instead of alone " / "



Example:

Code:
CMD:@at(playerid)
{
    //yourcodeblabla...
    return 1;
}

CMD:/at(playerid)
{
    //yourcodeblabla...
    return 1;
}

CMD:!at(playerid)
{
    //yourcodeblabla...
    return 1;
}

CMD:$at(playerid)
{
    //yourcodeblabla...
    return 1;
}
would print:

Code:
@at | /at | !at | $at
if symbolos is not added then by default it will be "/"

Code:
CMD:pallaringas(playerid)
{
    return 1;
}
I hope you have this suggestion in mind for future updating.
Quote:
Originally Posted by NaS
View Post
Technically not possible that way since these symbols would be part of the function name. Some of these aren't possible to use in function names in PAWN.
Exact. Although if you want something like that, you can use "OnPlayerText".

PHP Code:
if(text[0] == '!command' && Player[playerid][Spawned] == 1)
    {
          
//function....
        
return 0;
    } 
It is not recommended to fill the "OnPlayerText" callback with pure commands. It's just a suggestion that if you can do something with that callback.
Reply

why not?

look it:

Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "!cmd", true))
{
    SendClientMessage(playerid, -1, "Message 1");
    return 1;
}
if(!strcmp(cmdtext, "&cmd", true))
{
    SendClientMessage(playerid, -1, "Message 2");
    return 1;
}
if(!strcmp(cmdtext, "@cmd", true))
{
    SendClientMessage(playerid, -1, "Message 3");
    return 1;
}
return 0;
}
If that's possible... Why not with the function of Pawn.CMD?
Reply

Quote:
Originally Posted by Alteh
View Post
why not?

look it:

Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "!cmd", true))
{
    SendClientMessage(playerid, -1, "Message 1");
    return 1;
}
if(!strcmp(cmdtext, "&cmd", true))
{
    SendClientMessage(playerid, -1, "Message 2");
    return 1;
}
if(!strcmp(cmdtext, "@cmd", true))
{
    SendClientMessage(playerid, -1, "Message 3");
    return 1;
}
return 0;
}
If that's possible... Why not with the function of Pawn.CMD?
Taken from the SA-MP Wiki:

Quote:

This callback is called when a player enters a command into the client chat window. Commands are anything that start with a forward slash, e.g. /help.

If I'm not mistaken, commands are only registered as commands by OnPlayerCommandText if it detects the forward slash as the first character. Might be possible to make it different through Pawn.CMD but the code you posted wouldn't work.
Reply

Quote:
Originally Posted by Alteh
View Post
why not?

look it:

Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "!cmd", true))
{
    SendClientMessage(playerid, -1, "Message 1");
    return 1;
}
if(!strcmp(cmdtext, "&cmd", true))
{
    SendClientMessage(playerid, -1, "Message 2");
    return 1;
}
if(!strcmp(cmdtext, "@cmd", true))
{
    SendClientMessage(playerid, -1, "Message 3");
    return 1;
}
return 0;
}
If that's possible... Why not with the function of Pawn.CMD?
Because using strcmp is completely different from ZCMD or PawnCMD.

ZCMD and PawnCMD create a public function for your command to call when the player types it. That's why they are so much faster.
The command you type gets directly called instead of compared to hundreds of strings.

So making a command like this:

Code:
CMD:test(playerid, params[])
{
}
will declare a public function called "cmd_test". Since you can call public functions by name from anywhere (with (eg) CallLocalFunction) this can be done from the command processor as well.

Using symbols would make these part of the function name, which isn't possible as such. Not sure if you could use some tricks to get around it.

Of course you could substitute these symbols with something like a prefix.
You could just as well use ZCMD for it and modify it to use OnPlayerText and replace (eg.) '$' with something else before calling your Command.

I'm not sure if many people need this, so I don't know if it would be worth implementing. But that's not up to me anyway :P
Reply

Quote:
Originally Posted by Undef1ned
View Post
Exact. Although if you want something like that, you can use "OnPlayerText".

PHP Code:
if(text[0] == '!command' && Player[playerid][Spawned] == 1)
    {
          
//function....
        
return 0;
    } 
It is not recommended to fill the "OnPlayerText" callback with pure commands. It's just a suggestion that if you can do something with that callback.
You only need to check the first character: http://forum.sa-mp.com/showpost.php?...&postcount=160
Reply

Quote:
Originally Posted by Calisthenics
View Post
You only need to check the first character: http://forum.sa-mp.com/showpost.php?...&postcount=160
Ohh, I did not know.


thanks!
Reply

Is it possible to add more than one custom file as a #include with different commands? I've issues which prevents me from creating a tree fro dynamic gamemode containing a lot of places with differents parts of it. I mean: I can #include only one file.pwn, any other included after is not working.
Reply

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;

Reply

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]))
Reply

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.
Reply

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.
Reply

https://github.com/urShadow/Pawn.CMD/issues/13
Reply

Is there a way to dynamically list all the commands to a player? Here's the equivelant in y_commands format:

pawn Code:
YCMD:commands(playerid, params[], help)
{
    if(help) SendClientMessage(playerid, 0xFF0000AA, "Lists all the commands a player can use.");
    else
    {
        new count = Command_GetPlayerCommandCount(playerid);
        for (new i = 0; i != count; ++i)
        {
            SendClientMessage(playerid, 0xFF0000AA, Command_GetNext(i, playerid));
        }
    }
    return 1;
}
Reply

Code:
PrintAlias(const cmd[]) 
{ 
    new 
        dest[32], 
        CmdArray: PC_alias = PC_GetAliasArray(cmd); 

    for (new i, j = PC_GetArraySize(PC_alias); i < j; i++) 
    { 
        PC_GetCommandName(PC_alias, i, dest); 
        printf("alias: %s", dest); 
    } 

    PC_FreeArray(PC_alias); 
}

PrintCommands() 
{ 
    new 
        dest[32], 
        CmdArray: PC_array = PC_GetCommandArray(); 

    for (new i, j = PC_GetArraySize(PC_array); i < j; i++) 
    { 
        PC_GetCommandName(PC_array, i, dest); 
        printf("cmd: %s", dest);
		PrintAlias(dest);
    } 

    PC_FreeArray(PC_array); 
}  

public PC_OnInit()
{
	PrintCommands();
}
Reply

how much work does it take for converting from zcmd? it seems similar in syntax

also is there really a point with modern hardware in regards to it actually adding any performance?
Reply


Forum Jump:


Users browsing this thread: 13 Guest(s)