One time command. - 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: One time command. (
/showthread.php?tid=412309)
One time command. -
dorperez - 01.02.2013
Hey guys,
I want to create a command you can only type ones.
How can I do it ?
Tnx
Re: One time command. -
BlackRaven - 01.02.2013
What do you mean by "ones"?
Re: One time command. -
dorperez - 01.02.2013
once********
Re: One time command. -
BlackRaven - 01.02.2013
pawn Код:
command(once, playerid, params[])
{
new pressed = false;
if(pressed == false)
{
pressed = true;
// do your code now!
}
return 1;
}
Re: One time command. -
LarzI - 01.02.2013
@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;
}
Respuesta: Re: One time command. -
OPremium - 01.02.2013
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
Re: One time command. -
dorperez - 01.02.2013
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 ?