One time command.
#1

Hey guys,

I want to create a command you can only type ones.

How can I do it ?

Tnx
Reply
#2

What do you mean by "ones"?
Reply
#3

once********
Reply
#4

pawn Код:
command(once, playerid, params[])
{
    new pressed = false;
    if(pressed == false)
    {
        pressed = true;
        // do your code now!
    }
    return 1;
}
Reply
#5

@Blackraven: Not quite. The variable would reset each time you did the command, because you declare the variable inside it. You would have to declare it globally for it to work, like I've done below.
_________

You would need to declare a global boolean, for example:

pawn Код:
new
    bool: g_bCmdUsed[ MAX_PLAYERS ]
;
Then you would need to set it to do a check in the command if g_bCmdUsed is true, and if it's not, go through with the command and set it to true:

pawn Код:
if( !g_bCmdUsed[ playerid ] ) //if it's false
{
    //do command
    g_bCmdUsed[ playerid ] = true;
}
Reply
#6

Quote:
Originally Posted by BlackRaven
Посмотреть сообщение
pawn Код:
command(once, playerid, params[])
{
    new pressed = false;
    if(pressed == false)
    {
        pressed = true;
        // do your code now!
    }
    return 1;
}
That condition will ALWAYS be true, you need to set a GLOBAL variable instead

pawn Код:
new
    typedCommand[MAX_PLAYERS];

CMD:once(playerid, params[])
{
    if(!typedCommand[playerid])
    {
        typedCommand[playerid] = 1;
        // Whatever you want the command to do
    }
    else
    {
        // Error message saying that they already used it
    }
    return 1;
}

public OnPlayerConnect(playerid)
{
    typedCommand[playerid] = 0; // Here we reset the variable so other players who join with same ID can use the command later
    return 1;
}

// You can also save the variable in player's file
EDIT: Too late
Reply
#7

Quote:
Originally Posted by LarzI
Посмотреть сообщение
@Blackraven: Not quite. The variable would reset each time you did the command, because you declare the variable inside it. You would have to declare it globally for it to work, like I've done below.
_________

You would need to declare a global boolean, for example:

pawn Код:
new
    bool: g_bCmdUsed[ MAX_PLAYERS ]
;
Then you would need to set it to do a check in the command if g_bCmdUsed is true, and if it's not, go through with the command and set it to true:

pawn Код:
if( !g_bCmdUsed[ playerid ] ) //if it's false
{
    //do command
    g_bCmdUsed[ playerid ] = true;
}
So "g_bCmdUsed " is the command ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)