|
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;
}
}
|
CMD:@at(playerid)
{
//yourcodeblabla...
return 1;
}
CMD:/at(playerid)
{
//yourcodeblabla...
return 1;
}
CMD:!at(playerid)
{
//yourcodeblabla...
return 1;
}
CMD:$at(playerid)
{
//yourcodeblabla...
return 1;
}
@at | /at | !at | $at
CMD:pallaringas(playerid)
{
return 1;
}
|
@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;
}
Code:
@at | /at | !at | $at Code:
CMD:pallaringas(playerid)
{
return 1;
}
![]() |
|
@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;
}
Code:
@at | /at | !at | $at Code:
CMD:pallaringas(playerid)
{
return 1;
}
![]() |
|
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.
|
if(text[0] == '!command' && Player[playerid][Spawned] == 1)
{
//function....
return 0;
}
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;
}
|
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;
}
![]() |
|
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. |
|
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;
}
![]() |
CMD:test(playerid, params[])
{
}
|
Exact. Although if you want something like that, you can use "OnPlayerText".
PHP Code:
|
|
You only need to check the first character: http://forum.sa-mp.com/showpost.php?...&postcount=160
|
public OnPlayerText(playerid,text[]){
new len,tempText[128];
if((text[0]=='@' || text[0]=='7') && (len=strlen(text)) >= 2 ){
for(new i=1; i < len; i++){
if(!('a'<=text[i]<='z') && i < 4)return 0;
if(text[i]==' ')break;
tempText[i]=text[i];
}
if(PC_CommandExists(tempText)) text[0]='/',PC_EmulateCommand(playerid,text);
}
return 0;
}
|
PHP Code:
|
if (flags != 0 && !(flags & pPermissions[playerid]))
|
A command with no flags set will be blocked for any player.
pawn Code:
|
|
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. |
#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");
}
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'
if (flags != 0 && !(flags & pPermissions[playerid]))
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)
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;
}
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();
}