Timer on command
#1

Hello, I'm trying to set a timer on a command, it should only be useable each minute. I'm quite sure I should use SetTimer, but I don't know how. Maybe this already have been explained before but I can't find any similar topic to this. This is how my command look like:
pawn Код:
if (strcmp("/usecanon", cmdtext, true, 9) == 0)
    {
    if(IsPlayerInRangeOfPoint(playerid, 1, -1367.8082,-2327.3691,43.6029))
    {
            GivePlayerWeapon(playerid, 35, 1);
    }
    return 1;
}
If you got any idea how to set a timer so it's only useable each minute or so please reply here.

Thanks.
Reply
#2

http://forum.sa-mp.com/index.php?topic=122711.0
________
Ifa forums
Reply
#3

Top of the script
Код:
new timertest[MAX_PLAYERS];
forward Timer1();
OnPlayerCommandText (or smth like that - your cmd)
Код:
if (strcmp("/usecanon", cmdtext, true, 9) == 0)
	{
    if (timertest[playerid] == 0) 
    {
  	if (IsPlayerInRangeOfPoint(playerid, 1, -1367.8082,-2327.3691,43.6029))
  	{
			GivePlayerWeapon(playerid, 35, 1);
            timertest[playerid] = 1;
            SetTimer("Timer1", 60000, false); 
  	}
    }
  	return 1;
}
Botom of scipt - its already callback
Код:
public Timer1()
{
    if (timertest[playerid] == 1)
    {
    timertest[playerid = 0;
    }
    return 1; // return 1 - or mybe not.. dnt know :D 
}
Reply
#4

Thanks, but.. it gives be these errors:

pawn Код:
error 017: undefined symbol "playerid"
error 017: undefined symbol "playerid"
warning 215: expression has no effect
The errors are pointed out on these lines:
pawn Код:
if (timertest[playerid] == 1)
    timertest[playerid = 0;
I appreciate any further post which can help me.
Reply
#5

Quote:
Originally Posted by Galcio
Thanks, but.. it gives be these errors:

pawn Код:
error 017: undefined symbol "playerid"
error 017: undefined symbol "playerid"
warning 215: expression has no effect
The errors are pointed out on these lines:
pawn Код:
if (timertest[playerid] == 1)
    timertest[playerid = 0;
I appreciate any further post which can help me.
pawn Код:
if (timertest[playerid] == 1)
    timertest[playerid] = 0;
omfg
Reply
#6

No need to omfg, please. :P I figured that out right after I posted, but the same problem remains:
pawn Код:
error 017: undefined symbol "playerid"
error 017: undefined symbol "playerid"
Reply
#7

Just a few improvements on your script, Gagletz,

Код:
new timertest[MAX_PLAYERS]; // on top
forward Timer1(playerid); // on top


// at the onplayercommandtext callback:
if (strcmp("/usecanon", cmdtext, true, 9) == 0)
	{
    if (timertest[playerid] == 0)
    {
	  	if (IsPlayerInRangeOfPoint(playerid, 1, -1367.8082,-2327.3691,43.6029))
	  	{
				GivePlayerWeapon(playerid, 35, 1);
	      timertest[playerid] = 1;
	 			SetTimer("Timer1", 60000, false);
	  	}
    }
  	return 1;
	}

//The timer, new callback:

public Timer1(playerid)
{
    if (timertest[playerid] == 1)
    {
    timertest[playerid] = 0;
    }
    return 1; // return 1 - or mybe not.. dnt know :D
}
Reply
#8

Quote:
Originally Posted by GaGlets®
Top of the script
Код:
new timertest[MAX_PLAYERS];
forward Timer1();
OnPlayerCommandText (or smth like that - your cmd)
Код:
if (strcmp("/usecanon", cmdtext, true, 9) == 0)
	{
    if (timertest[playerid] == 0) 
    {
  	if (IsPlayerInRangeOfPoint(playerid, 1, -1367.8082,-2327.3691,43.6029))
  	{
			GivePlayerWeapon(playerid, 35, 1);
            timertest[playerid] = 1;
            SetTimer("Timer1", 60000, false); 
  	}
    }
  	return 1;
}
Botom of scipt - its already callback
Код:
public Timer1()
{
    if (timertest[playerid] == 1)
    {
    timertest[playerid = 0;
    }
    return 1; // return 1 - or mybe not.. dnt know :D 
}
Wrong, stop confusing players!
Reply
#9

What about mine, Menace?
You called my script the most stupid script you ever saw yesterday, so I want to know if there are improvements :P
Reply
#10

Quote:
Originally Posted by VonLeeuwen
Just a few improvements on your script, Gagletz,

Код:
new timertest[MAX_PLAYERS]; // on top
forward Timer1(playerid); // on top


// at the onplayercommandtext callback:
if (strcmp("/usecanon", cmdtext, true, 9) == 0)
	{
    if (timertest[playerid] == 0)
    {
	  	if (IsPlayerInRangeOfPoint(playerid, 1, -1367.8082,-2327.3691,43.6029))
	  	{
				GivePlayerWeapon(playerid, 35, 1);
	      timertest[playerid] = 1;
	 			SetTimer("Timer1", 60000, false);
	  	}
    }
  	return 1;
	}

//The timer, new callback:

public Timer1(playerid)
{
    if (timertest[playerid] == 1)
    {
    timertest[playerid] = 0;
    }
    return 1; // return 1 - or mybe not.. dnt know :D
}
You rock! Just gotta make it a bit better, then it's perfect! Thanks man.
Reply
#11

Have fun and no problem
Reply
#12

WTF you all rly don't know how to set a timer and pass the id ? WTF..

SetTimerEx("public",time,loop,"i",playerid);.. owned

i call all those script I saw here.. junk ..
Reply
#13

LOL


Sorry, dudes stop ticking my script, I just missed with
Код:
[]
- i was writing all not copying :P

==================
It works at the best :P LOL
SettimerEx - L.O.L - my version is esier :P
Reply
#14

pawn Код:
new timertest[MAX_PLAYERS];
forward Timer1();

public OnFilterScriptInit(){
    SetTimer("Timer1",59302,1);
    return 1;
}
onplayercommandtext:
pawn Код:
if (strcmp("/usecanon", cmdtext, true, 9) == 0)
    {
    if (timertest[playerid] == 0)
    {
    if (IsPlayerInRangeOfPoint(playerid, 1, -1367.8082,-2327.3691,43.6029))
    {
            GivePlayerWeapon(playerid, 35, 1);
            timertest[playerid] = 1;
    }
    }
    return 1;
}
public:
pawn Код:
public Timer1()
{
    for(new playerid; playerid < MAX_PLAYERS;playerid++)
    {
        if (timertest[playerid] == 1)
        {
            timertest[playerid] = 0;
        }
    }
        return 1;
}
would also be good... just another way so you don't have to set 500 timers..
Reply
#15

But you dont have to create 500 timers, right? As it's only called for the player (playerid) who types /usecanon ?
Reply
#16

Hello, I tested this with my friend and it only seem to be working for ID 0. Any solution to that?
Reply
#17

Sorry, but this is like the final thing and then I'm done. Can't say how grateful I would be if someone came with the solution. Here's the pieces of code:

pawn Код:
if (strcmp("/bayonet", cmdtext, true, 8) == 0)
    {
    if (timercrifle[playerid] == 0)
        {
          SendClientMessage(playerid, 0xFFFFFFFF, "You have successfully reloaded your bayonet");
          SendClientMessage(playerid, 0xAAAAAAAA, "(( You may only use the bayonet each every six seconds (takes 6sec to reload). ))");
      ResetPlayerWeapons(playerid);
            GivePlayerWeapon(playerid, 33, 1);
        timercrifle[playerid] = 1;
            SetTimer("Timer2", 6000, false);
    }
        return 1;
    }
pawn Код:
if (strcmp("/usecanon", cmdtext, true, 9) == 0)
    {
    if (timertest[playerid] == 0)
    {
        if (IsPlayerInRangeOfPoint(playerid, 2, -1367.7334,-2329.4153,43.6167) || IsPlayerInRangeOfPoint(playerid, 2,
            -1367.6199,-2325.1145,43.6338) || IsPlayerInRangeOfPoint(playerid, 2, -1367.5388,-2320.6838,43.6629) || IsPlayerInRangeOfPoint(playerid, 2, -1367.0610,-2311.0056,43.6313) || IsPlayerInRangeOfPoint(playerid, 2, -1366.9612,-2306.8826,43.5795) || IsPlayerInRangeOfPoint(playerid, 2, -1366.8689,-2302.5981,43.5999) || IsPlayerInRangeOfPoint(playerid, 2, -1360.4092,-2302.2817,43.7645) || IsPlayerInRangeOfPoint(playerid, 2, -1350.3254,-2302.6692,43.8080) ||
            IsPlayerInRangeOfPoint(playerid, 2, -1340.1608,-2303.2659,43.5959) || IsPlayerInRangeOfPoint(playerid, 2, -1335.8135,-2308.0623,43.5575) || IsPlayerInRangeOfPoint(playerid, 2, -1336.5748,-2318.2117,43.5575) || IsPlayerInRangeOfPoint(playerid, 2, -1336.9384,-2328.4756,43.5575) || IsPlayerInRangeOfPoint(playerid, 2, -1341.9918,-2333.4768,43.6067) || IsPlayerInRangeOfPoint(playerid, 2, -1362.5692,-2332.3665,43.5644))
        {
          SendClientMessage(playerid, 0xFFFFFFFF, "This canon is ready to use.");
          SendClientMessage(playerid, 0xAAAAAAAA, "(( Please, stand at a canon when you use this weapon. ))");
                GivePlayerWeapon(playerid, 35, 1);
          timertest[playerid] = 1;
                SetTimer("Timer1", 60000, false);
        }
        else
        {
          SendClientMessage(playerid, 0xFFFFFFFF, "You are not near a canon or you have just used a canon, please let it reload.");
          SendClientMessage(playerid, 0xAAAAAAAA, "(( It takes sixty seconds for a canon to reload. ))");
        }
    }
    return 1;
    }
Reply
#18

Ohh.. then use SettimerEx and remove yeah. .
Reply
#19

Could you please explain that somewhat deeper and how to do it?
Reply
#20

You don't have to make ANY timers.

pawn Код:
new CmdDelay[MAX_PLAYERS];

//OnPlayerCommandText
if (strcmp("/bayonet", cmdtext, true, 8) == 0)
{
  if (CmdDelay[playerid]<GetTickCount())
  {
    SendClientMessage(playerid, 0xFFFFFFFF, "You have successfully reloaded your bayonet");
    SendClientMessage(playerid, 0xAAAAAAAA, "(( You may only use the bayonet each every six seconds (takes 6sec to reload). ))");
    ResetPlayerWeapons(playerid);
    GivePlayerWeapon(playerid, 33, 1);
    CmdDelay[playerid] = GetTickCount()+6000; //6000 = 6 seconds
  }
  return 1;
}

and FYI, a 'bayonet' is a knife that goes onto the end of a rifle for stabbing people.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)