SA-MP Forums

SA-MP Forums (https://forum.sa-mp.com/index.php)
-   Help Archive (https://forum.sa-mp.com/forumdisplay.php?f=89)
-   -   commands (https://forum.sa-mp.com/showthread.php?t=278845)

Speed 24/08/2011 07:50 AM

commands
 
How i can make it, if player have "CMD" = 1

that he can type no one command expect /help....

i can put this in each command, but can i do easier?:

pawn Code:
CMD:aaa(playerid, params[])
{
    if(GetPVarInt(playerid, "CMD") == 1)
    {
        SendClientMessage(playerid, -1, "You can only type /help!");
    }
    else
    {
    //my code goes here
    return 1;
}

and i must put that in each command, can it be some how easier?

Horrible 24/08/2011 07:52 AM

Re: commands
 
i think this is the easiest way because this easier than make
new CMD[MAX_PLAYER]

=WoR=Varth 24/08/2011 07:52 AM

Re: commands
 
pawn Code:
public OnPlayerCommandReceived(playerid,cmdtext[])
{
    if(GetPVarInt(playerid, "CMD") == 1)
    {
        SendClientMessage(playerid, -1, "You can only type /help!");
        return 0;
    }
    return 1;
}

[HiC]TheKiller 24/08/2011 07:59 AM

Re: commands
 
Just use the function OnPlayerCommandReceived which is included in ZCMD.

pawn Code:
new helped[MAX_PLAYERS];
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(strcmp("/help", cmdtext, true) != 0 && !helped[playerid])
    {
        SendClientMessage(playerid, -1, "You must type /help first!");
        return 0;
    }
    return 1;
}
CMD:help(playerid, params[])
{
    if(!helped[playerid]) helped[playerid] = 1;
    //.....
    return 1;
}
public OnPlayerConnect(playerid)
{
    helped[playerid] = 0;
    return 1;
}

Give that a go.

=WoR=Varth 24/08/2011 08:11 AM

Re: commands
 
Quote:

Originally Posted by [HiC]TheKiller (Post 1365042)
Just use the function OnPlayerCommandReceived which is included in ZCMD.

pawn Code:
new helped[MAX_PLAYERS];
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(strcmp("/help", cmdtext, true) != 0 && !helped[playerid])
    {
        SendClientMessage(playerid, -1, "You must type /help first!");
        return 0;
    }
    return 1;
}
CMD:help(playerid, params[])
{
    if(!helped[playerid]) helped[playerid] = 1;
    //.....
    return 1;
}
public OnPlayerConnect(playerid)
{
    helped[playerid] = 0;
    return 1;
}

Give that a go.

I don't think that will work as he wish.
pawn Code:
new bool:CMD[MAX_PLAYERS];

public OnPlayerCommandReceived(playerid,cmdtext[])
{
    if(CMD[playerid] == false)
    {
        if(!strcmp("/help",cmdtext)) return 1;
        SendClientMessage(playerid,0,"Error");
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    CMD[playerid] = true;
    return 1;
}

[HiC]TheKiller 24/08/2011 08:21 AM

Re: commands
 
Quote:

Originally Posted by varthshenon (Post 1365053)
I don't think that will work as he wish.
pawn Code:
new bool:CMD[MAX_PLAYERS];

public OnPlayerCommandReceived(playerid,cmdtext[])
{
    if(CMD[playerid] == false)
    {
        if(!strcmp("/help",cmdtext)) return 1;
        SendClientMessage(playerid,0,"Error");
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    CMD[playerid] = true;
    return 1;
}

I don't see any difference to what you did except the variable name and it was changed to a bool.

=WoR=Varth 24/08/2011 08:32 AM

Re: commands
 
pawn Code:
new helped[MAX_PLAYERS];
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(strcmp("/help", cmdtext, true) != 0 && !helped[playerid])//Chek if the command is /help and helped value is 0
    {
        SendClientMessage(playerid, -1, "You must type /help first!");
        return 0;
    }
    return 1;
}
CMD:help(playerid, params[])
{
    if(!helped[playerid]) helped[playerid] = 1;//If player's helped value is 0, change it to 1
    //.....
    return 1;
}
public OnPlayerConnect(playerid)
{
    helped[playerid] = 0;
    return 1;
}

//=====================================================

new bool:CMD[MAX_PLAYERS];

public OnPlayerCommandReceived(playerid,cmdtext[])
{
    if(CMD[playerid] == false)//If CMD is false
    {
        if(!strcmp("/help",cmdtext)) return 1;//If player do /help command, the command still called
        SendClientMessage(playerid,0,"Error");//Send error message
        return 0;//Forgot this
        }
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    CMD[playerid] = true;
    return 1;
}

See the difference?

doreto 24/08/2011 08:37 AM

Re: commands
 
PHP Code:

public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    if(!
success) return SendClientMessage(playeridCOLOR_RED,"Wrong commands try /cmds to full list of commands");
    return 
1;


i thing thats more easy becose if commands is wrong or dont exit will say wrong cmd... but if commands true it will not say

[HiC]TheKiller 24/08/2011 08:41 AM

Re: commands
 
Remember that

pawn Code:
if(strcmp("/help", cmdtext, true) != 0)

Is actually checking if the command isn't correct. Your way wouldn't even work, because you are setting CMD[playerid] to true when the player connects. This makes it so regardless if the player had typed /help yet, the player wouldn't get asked to type /help. You also have absolutely no way of setting the command typed to true when the player typed the command.

=WoR=Varth 24/08/2011 08:41 AM

Re: commands
 
Quote:

Originally Posted by doreto (Post 1365088)
PHP Code:

public OnPlayerCommandPerformed(playeridcmdtext[], success)
{
    if(!
success) return SendClientMessage(playeridCOLOR_RED,"Wrong commands try /cmds to full list of commands");
    return 
1;


i thing thats more easy becose if commands is wrong or dont exit will say wrong cmd... but if commands true it will not say

You missundsertood him.
OnPlayerCommandPerformaed called if the command already called.


All times are GMT. The time now is 03:36 PM.

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