SA-MP Forums Archive
ZCMD Command Restriction - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: ZCMD Command Restriction (/showthread.php?tid=593886)



ZCMD Command Restriction - YoussefHammad - 10.11.2015

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 ??


Re: ZCMD Command Restriction - Jefff - 10.11.2015

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;
}



Re: ZCMD Command Restriction - YoussefHammad - 10.11.2015

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) ??


Re: ZCMD Command Restriction - Jefff - 10.11.2015

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



Re: ZCMD Command Restriction - YoussefHammad - 10.11.2015

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


Re : ZCMD Command Restriction - Dutheil - 11.11.2015

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")); 



Re: Re : ZCMD Command Restriction - YoussefHammad - 11.11.2015

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 ?


Re : ZCMD Command Restriction - Dutheil - 11.11.2015

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


Re: Re : ZCMD Command Restriction - YoussefHammad - 11.11.2015

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


Re: Re : ZCMD Command Restriction - PrO.GameR - 11.11.2015

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