How to: Detection? - 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: How to: Detection? (
/showthread.php?tid=514315)
How to: Detection? -
lexurs - 20.05.2014
I'm still wondering how I would make a system to detect if a player used a used a
specific command a specific number of times in order for another system to work. Can anyone help me get started or give hints on how to do this?
Re: How to: Detection? -
Lynn - 20.05.2014
pawn Code:
new UsedCmd[MAX_PLAYERS] = 0;
pawn Code:
public OnPlayerConnect(playerid)
{
UsedCmd[playerid] = 0;
return 1;
}
pawn Code:
CMD:cmd(playerid, params[])
{
// Do stuff here
UsedCmd[playerid]++; // This will increase it +1
}
Then from there, it'd be
pawn Code:
if(UsedCmd[playerid] >= 5) { // Change 5 to the number of your choice.
Re: How to: Detection? -
lexurs - 20.05.2014
Quote:
Originally Posted by Lynn
pawn Code:
new UsedCmd[MAX_PLAYERS] = 0;
pawn Code:
public OnPlayerConnect(playerid) { UsedCmd[playerid] = 0; return 1; }
pawn Code:
CMD:cmd(playerid, params[]) { // Do stuff here UsedCmd[playerid]++; // This will increase it +1 }
Then from there, it'd be
pawn Code:
if(UsedCmd[playerid] >= 5) { // Change 5 to the number of your choice.
|
How would I be able to setup the rest of the system functioning only if you used the specific command within a specific time? Perhaps 1 minute.
Re: How to: Detection? -
K9IsGodly - 20.05.2014
Quote:
Originally Posted by lexurs
The command that the player is going to use can be used for other things too (/me and /do). Is it possible to do this another way?
|
What he gave you would work with any command. Just take this:
PHP Code:
CMD:cmd(playerid, params[])
{
// Do stuff here
UsedCmd[playerid]++; // This will increase it +1
}
And adapt it to your command of choice..
PHP Code:
CMD:me(playerid, params[])
{
// The command etc
UsedCmd[playerid]++;
}
But of course you must define the variable of UsedCmd and you of course would want to set it to 0 when they join, as Lynn showed.
"How would I be able to setup the rest of the system functioning only if you used the specific command within a specific time? Perhaps 1 minute."
I would suggest using timers.
Re: How to: Detection? -
lexurs - 20.05.2014
Quote:
Originally Posted by K9IsGodly
What he gave you would work with any command. Just take this:
PHP Code:
CMD:cmd(playerid, params[])
{
// Do stuff here
UsedCmd[playerid]++; // This will increase it +1
}
And adapt it to your command of choice..
PHP Code:
CMD:me(playerid, params[])
{
// The command etc
UsedCmd[playerid]++;
}
But of course you must define the variable of UsedCmd and you of course would want to set it to 0 when they join, as Lynn showed.
|
Thank you, I understood after looking twice.
Re: How to: Detection? -
Lynn - 20.05.2014
Quote:
Originally Posted by lexurs
How would I be able to setup the rest of the system functioning only if you used the specific command within a specific time? Perhaps 1 minute.
|
Create a PVar, looped through a timer.
Once the timer is done, Delete the Pvar.
And in the command simply check if it equals 1, and if it doesn't then allow the command to go through.
Because if it does equal 1, it means the PVar hasn't been deleted yet so it's been less then 1 minute.
Re: How to: Detection? -
arakuta - 20.05.2014
Quote:
Originally Posted by Lynn
Create a PVar, looped through a timer.
Once the timer is done, Delete the Pvar.
And in the command simply check if it equals 1, and if it doesn't then allow the command to go through.
Because if it does equal 1, it means the PVar hasn't been deleted yet so it's been less then 1 minute.
|
Or just use simple math?
pawn Code:
UsedCmd[playerid] = gettime();
// Then check if 1 minute has passed or not
if(gettime() - UsedCmd[playerid] < 60)
{
// 1 Minute didn't pass
}
else
{
// 1 minute passed
}
Re: How to: Detection? -
lexurs - 21.05.2014
Quote:
Originally Posted by arakuta
Or just use simple math?
pawn Code:
UsedCmd[playerid] = gettime();
// Then check if 1 minute has passed or not
if(gettime() - UsedCmd[playerid] < 60) { // 1 Minute didn't pass } else { // 1 minute passed }
|
Where would this go?
Re: How to: Detection? -
Lynn - 21.05.2014
Quote:
Originally Posted by arakuta
Or just use simple math?
pawn Code:
UsedCmd[playerid] = gettime();
// Then check if 1 minute has passed or not
if(gettime() - UsedCmd[playerid] < 60) { // 1 Minute didn't pass } else { // 1 minute passed }
|
I assumed he wouldn't know this method.
SetTimerEx is more of a 'beginner' way, with the way I said.