ZCMD Command Restriction
#1

i wanna make that if a player is in a dm or jailed "if(PlayerInfo[playerid][pDM] == 1)" he cant use any commands but in dm i wanna make the only command that he can use is /exitdm . Also i wanna make that if he types an invalid command it shows a specific sentence "ClientMessage" i've tried doing them on my own but i found that the only way to make the dm and jail thing is to put this line in every command i make
Code:
if(PlayerInfo[playerid][pDM] == 1)
SendClientMessage(playerid,0xFFFFFF,"You cant use commands in the DM Zone/Jail");
but i have alot of commands so is there a shorter way ??
Reply
#2

You need use OnPlayerCommandReceived callback

pawn Code:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(PlayerInfo[playerid][pDM] == 1) // if is player in DM
    {
        if(!strcmp(cmdtext,"/exitdm",true)) return 1; // he can use only /exitdm
        return !SendClientMessage(playerid,0xFFFFFF,"You cant use commands in the DM Zone/Jail"); // return 0 is blocking all other commands
    }
    return 1;
}
Reply
#3

Quote:
Originally Posted by Jefff
View Post
You need use OnPlayerCommandReceived callback

pawn Code:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(PlayerInfo[playerid][pDM] == 1) // if is player in DM
    {
        if(!strcmp(cmdtext,"/exitdm",true)) return 1; // he can use only /exitdm
        return !SendClientMessage(playerid,0xFFFFFF,"You cant use commands in the DM Zone/Jail"); // return 0 is blocking all other commands
    }
    return 1;
}
Thanks will try , how about when a player types in an invalid command , what can i write to make it send a message like (Invalid Command! Check /CMDS for the commands list) ??
Reply
#4

pawn Code:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
    if(!success)
    {
        // info invalid command
    }
    return 1;
}
Reply
#5

Thank you very much , +REP
EDIT: i will be able to give reputations after 24hrs , i'll reputate u as soon as i can
Reply
#6

If you have nothing else in the function OnPlayerCommandPerformed, you can use the ternary.
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
    return (
success SendClientMessage(playerid, -1"Invalid Command! Check /CMDS for the commands list")); 
Reply
#7

Quote:
Originally Posted by Dutheil
View Post
If you have nothing else in the function OnPlayerCommandPerformed, you can use the ternary.
PHP Code:
public OnPlayerCommandPerformed(playeridcmdtext[], success)
    return (
success SendClientMessage(playerid, -1"Invalid Command! Check /CMDS for the commands list")); 
i have something else , this
Code:
       format(szString, sizeof(szString), "[CMD]: %s[%d] Has Used Command: %s", PlayerName(playerid), playerid, cmdtext);
	for (new a = 0; a < MAX_PLAYERS; a++) if (IsPlayerAdmin(a))
 	SendClientMessage(a, 0xF6BB0AA, szString);
it sends me the cmds players use when im logged in as Rcon admin , what can i do to solve it ?
Reply
#8

Your code is correct. Maybe not indented in my way, but you make what you want.
Reply
#9

Quote:
Originally Posted by Dutheil
View Post
Your code is correct. Maybe not indented in my way, but you make what you want.

here's the whole code
Code:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
	if(!success)
	{
	    SendClientMessage(playerid,COL_GREEN,"ERROR: Invalid command! Check /CMDS for the commands list");
	}
	format(szString, sizeof(szString), "[CMD]: %s[%d] Has Used Command: %s", PlayerName(playerid), playerid, cmdtext);
	for (new a = 0; a < MAX_PLAYERS; a++) if (IsPlayerAdmin(a))
 	SendClientMessage(a, 0xF6BB0AA, szString);
	return 1;
}
didnt edit anything , it all works but the problem is that the Invalid Command msg shows up whenever i do any cmd

how can i fix it ? i tried to return 0 but when i did it showed the Invalid command and that white "Unkown Command" thing
Reply
#10

Quote:
Originally Posted by YoussefHammad
View Post
here's the whole code
Code:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
	if(!success)
	{
	    SendClientMessage(playerid,COL_GREEN,"ERROR: Invalid command! Check /CMDS for the commands list");
	}
	format(szString, sizeof(szString), "[CMD]: %s[%d] Has Used Command: %s", PlayerName(playerid), playerid, cmdtext);
	for (new a = 0; a < MAX_PLAYERS; a++) if (IsPlayerAdmin(a))
 	SendClientMessage(a, 0xF6BB0AA, szString);
	return 1;
}
didnt edit anything , it all works but the problem is that the Invalid Command msg shows up whenever i do any cmd

how can i fix it ? i tried to return 0 but when i did it showed the Invalid command and that white "Unkown Command" thing
Find OnPlayerCommandText
return 1 instead of 0
^^
This disables the default unknown command
and the way new YSI works is you should put your unknown command text under OnPlayerCommandReceived
because OnPlayerCommandPerformed is called after a command finishes not before
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)