OnPlayerCommandReceived Question
#1

I'm trying to make that when play uses command when he is injured he wouldn't be able to actually execute them (return 0), however I want him to be able only to execute the /ems, /me, /do commands.

Can you help me on how build this so I can do it on any command i want to?

Here is what I have made so far (This code wont compile & show error) :
pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(GetPVarInt(playerid, "Injured") != 0 || GetPVarInt(playerid, "Cuffed") != 0)
    {
        if(cmdtext[] != ems)
        {
            SendClientMessage(playerid,COLOR_RED, "[SERVER]: You can't use commands while: injured/recovering/cuffed.");
            return 0;
        }
    }
    return 1;
}
Reply
#2

https://sampwiki.blast.hk/wiki/Strcmp to compare strings.
Reply
#3

You should do it in a command itself, example:
pawn Код:
new bool:pInjured[MAX_PLAYERS] = false;

CMD:test(playerid, params[])
{
    if(pInjured[playerid]) return 0;
    return 1;
}
Reply
#4

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I think i'll go with the compering strings method. Thanks.

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
You should do it in a command itself, example:
pawn Код:
new bool:pInjured[MAX_PLAYERS] = false;

CMD:test(playerid, params[])
{
    if(pInjured[playerid]) return 0;
    return 1;
}
Lets say i have 150 commands, you suggest instead using this on one public, i should do it on all the 150 commands?
Reply
#5

Quote:
Originally Posted by maximthepain
Посмотреть сообщение
I think i'll go with the compering strings method. Thanks.



Lets say i have 150 commands, you suggest instead using this on one public, i should do it on all the 150 commands?
Well, are you going to compare 150 strings everytime a player types a command, and make "zcmd commands into strcmp commands"? And yes, I suggest adding it to the commands, it would be better and somehow more efficient.
Reply
#6

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
Well, are you going to compare 150 strings everytime a player types a command, and make "zcmd commands into strcmp commands"? And yes, I suggest adding it to the commands.
No need to, his way was good. His only mistake was the way he compared the string. He'll be still using ZCMD.

If the player is injured and the command was performed is not equal to "/ems", then do something.
Reply
#7

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
No need to, his way was good. His only mistake was the way he compared the string. He'll be still using ZCMD.

If the player is injured and the command was performed is not equal to "/ems", then do something.
Oh, he doesn't want anyone that's injured to use commands, except /ems? I thought he wanted to compare those 150 commands (and that he had more) on that callback and return 0 afterwards if a match was found (making strcmp type of commands).

Anyway, it should look like this:
pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(GetPVarInt(playerid, "Injured") != 0 || GetPVarInt(playerid, "Cuffed") != 0)
    {
        if(strcmp(cmdtext, "ems", true, 3) == 0)
        {
            SendClientMessage(playerid,COLOR_RED, "[SERVER]: You can't use commands while: injured/recovering/cuffed.");
            return 0;
        }
    }
    return 1;
}
"cmdtext" returns the command and params too.
Reply
#8

No, he wants injured/cuffed players only to be able to use /ems /me and /do commands. Like the way you did it, but in this case you need to check if the strcmp returns a value not equal to 0.
Reply
#9

You added too much parentheses and cmdtext doesn't have "/" before the command.

pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0)
    {
        SendClientMessage(playerid,COLOR_RED, "[SERVER]: You can't use commands if you didn't login.");
        return 0;
    }
    if(GetPVarInt(playerid, "Injured") != 0 || GetPVarInt(playerid, "Dragged") == 1 || GetPVarInt(playerid, "Cuffed") != 0)
    {
        if(strcmp(cmdtext, "ems", true, 3) == 0 || strcmp(cmdtext, "me", true, 2) == 0 || strcmp(cmdtext, "do", true, 2) == 0 || strcmp(cmdtext, "giveup", true, 6) == 0 || strcmp(cmdtext, "revive", true, 6) == 0)
        {
            SendClientMessage(playerid,COLOR_RED, "[SERVER]: You can't use commands while: injured/dragged/cuffed.");
            return 0;
        }
    }
    return 1;
}
Reply
#10

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
You added too much parentheses.

pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0)
    {
        SendClientMessage(playerid,COLOR_RED, "[SERVER]: You can't use commands if you didn't login.");
        return 0;
    }
    if(GetPVarInt(playerid, "Injured") != 0 || GetPVarInt(playerid, "Dragged") == 1 || GetPVarInt(playerid, "Cuffed") != 0)
    {
        if(strcmp(cmdtext, "ems", true, 3) == 0 || strcmp(cmdtext, "me", true, 2) == 0 || strcmp(cmdtext, "do", true, 2) == 0 || strcmp(cmdtext, "giveup", true, 6) == 0 || strcmp(cmdtext, "revive", true, 6) == 0)
        {
            SendClientMessage(playerid,COLOR_RED, "[SERVER]: You can't use commands while: injured/dragged/cuffed.");
            return 0;
        }
    }
    return 1;
}
okay this is working, however, quick fix for anyone who will need this in the future.
this is the right way:
pawn Код:
public OnPlayerCommandReceived(playerid, cmdtext[])
{
    if(GetPVarInt(playerid, "LoggedIn") == 0)
    {
        SendClientMessage(playerid,COLOR_RED, "[SERVER]: You can't use commands if you didn't login.");
        return 0;
    }
    if(GetPVarInt(playerid, "Injured") != 0 || GetPVarInt(playerid, "Dragged") == 1 || GetPVarInt(playerid, "Cuffed") != 0)
    {
        if(strcmp(cmdtext, "/ems", true, 3) == 0 || strcmp(cmdtext, "/me", true, 2) == 0 || strcmp(cmdtext, "/do", true, 2) == 0 || strcmp(cmdtext, "/giveup", true, 6) == 0 || strcmp(cmdtext, "/revive", true, 6) == 0)
        {
            return 1;
        }
        else
        {
            SendClientMessage(playerid,COLOR_RED, "[SERVER]: You can't use commands while: injured/dragged/cuffed.");
            return 0;
        }
    }
    return 1;
}
Thanks for the guys who replied in the thread! honored rep++;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)