SA-MP Forums Archive
commands - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: commands (/showthread.php?tid=278845)



commands - Speed - 24.08.2011

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?


Re: commands - Horrible - 24.08.2011

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


Re: commands - =WoR=Varth - 24.08.2011

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



Re: commands - [HiC]TheKiller - 24.08.2011

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.


Re: commands - =WoR=Varth - 24.08.2011

Quote:
Originally Posted by [HiC]TheKiller
View Post
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;
}



Re: commands - [HiC]TheKiller - 24.08.2011

Quote:
Originally Posted by varthshenon
View Post
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.


Re: commands - =WoR=Varth - 24.08.2011

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?


Re: commands - doreto - 24.08.2011

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


Re: commands - [HiC]TheKiller - 24.08.2011

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.


Re: commands - =WoR=Varth - 24.08.2011

Quote:
Originally Posted by doreto
View Post
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.


Re: commands - Lorenc_ - 24.08.2011

Quote:
Originally Posted by varthshenon
View Post
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?
I noticed one thing, that you failed to write the code inside 'OnPlayerCommandReceived' properly and stop trying to compete against people in scripting. They have their own style intro coding, and you should respect that. TheKiller posted code that should work fine.


Re: commands - =WoR=Varth - 24.08.2011

Quote:
Originally Posted by [HiC]TheKiller
View Post
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.
I guess I miess read that part.
Also, I just know that he asked that player can't type any command execpt /help if CMD is false.
It can be use for mute command or anything.

Quote:
Originally Posted by Lorenc_
View Post
I noticed one thing, that you failed to write the code inside 'OnPlayerCommandReceived' properly and stop trying to compete against people in scripting. They have their own style intro coding, and you should respect that. TheKiller posted code that should work fine.
It's just the bracket. I forgot to remove that.
Why you said I'm trying to compete against people? I just trying to fix the code.
And also there's nothing tell us that I disrespect TheKiller .


Re: commands - Speed - 24.08.2011

Quote:
Originally Posted by doreto
View Post
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
that dosent help me with my Q, but thanks anyway

@varthshenon i gonna test it now, TY


Re: commands - Speed - 24.08.2011

sorry for DB, but, it dosent work, i teleport to /maze, then i have CMD = false

and i type /ls and i got teleport, but i dont want to teleport me...., if is CMD = false i want, that if i type anything the result is always 0... i mean that nothing happnes ....


Re: commands - [HiC]TheKiller - 24.08.2011

Quote:
Originally Posted by Speed
View Post
sorry for DB, but, it dosent work, i teleport to /maze, then i have CMD = false

and i type /ls and i got teleport, but i dont want to teleport me...., if is CMD = false i want, that if i type anything the result is always 0... i mean that nothing happnes ....
http://forum.sa-mp.com/showpost.php?...42&postcount=4

Try that maybe?