How to: Detection?
#1

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?
Reply
#2

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.
Reply
#3

Quote:
Originally Posted by Lynn
View Post
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.
Reply
#4

Quote:
Originally Posted by lexurs
View Post
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(playeridparams[]) 
{
    
// Do stuff here
    
UsedCmd[playerid]++; // This will increase it +1

And adapt it to your command of choice..

PHP Code:
CMD:me(playeridparams[])
{
   
// 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.
Reply
#5

Quote:
Originally Posted by K9IsGodly
View Post
What he gave you would work with any command. Just take this:

PHP Code:
CMD:cmd(playeridparams[]) 
{
    
// Do stuff here
    
UsedCmd[playerid]++; // This will increase it +1

And adapt it to your command of choice..

PHP Code:
CMD:me(playeridparams[])
{
   
// 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.
Reply
#6

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

Quote:
Originally Posted by Lynn
View Post
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
}
Reply
#8

Quote:
Originally Posted by arakuta
View Post
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?
Reply
#9

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


Forum Jump:


Users browsing this thread: 5 Guest(s)