SA-MP Forums Archive
SetTimerEx - 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: SetTimerEx (/showthread.php?tid=465576)



SetTimerEx - CesarLT - 22.09.2013

Hello everyone, how can I make a timer that will make players wait like 4 or 5 seconds before entering another pickup?

Thanks in advance.


Re: SetTimerEx - DanishHaq - 22.09.2013

Make a global variable, once a player uses a pickup set the variable to 1 and use SetTimerEx which will stop after however many seconds, and then when the timer ends set the variable to 0. Under where you're picking up the pickup, make sure that you are checking if the player's variable is set to 1 or 0, if it's 1 then don't let them do whatever the pickup does. Ps: make sure the global variable is arrayed with MAX_PLAYERS.


Re: SetTimerEx - CesarLT - 22.09.2013

Quote:
Originally Posted by DanishHaq
Посмотреть сообщение
Make a global variable, once a player uses a pickup set the variable to 1 and use SetTimerEx which will stop after however many seconds, and then when the timer ends set the variable to 0. Under where you're picking up the pickup, make sure that you are checking if the player's variable is set to 1 or 0, if it's 1 then don't let them do whatever the pickup does. Ps: make sure the global variable is arrayed with MAX_PLAYERS.
Well, I am a newbie scripter and started scripting before a few days only, could you show me an example please?
And how to use that if I am having a quiet big amount of pickups?

Thanks in advance again.


Re: SetTimerEx - jakejohnsonusa - 23.09.2013

Add this to the top of your script:

pawn Код:
forward PickedUpPickupReset(playerid);//Timer prepertaion or the "forward"
PickedUpPickup[MAX_PLAYERS] = 0;//Variable to hold if the player has picked somthing up. 0 = No, 1 = Yes
Add this to the OnPlayerPickUpPickupin your script (Obviously don't copy the public OnPlayerPickUpPickup part if you already have it):
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
      if(PickedUpPickup[playerid] != 0)//If they have picked up a pickup...
      {
            SendClientMessage(playerid, -1, "* You need to wait at least 5 seconds before picking up another pickup!");
            return 1;//Ends the code, not allowing the pickup.
      }
      PickedUpPickup[playerid] = 1;//Sets the 'PickedUpPickup' variable to has picked somthing up.
      SetTimerEx("PickedUpPickupReset", 4500, false, "i", playerid);//Sets a timer to reset the 'PickedUpPickup' variable to 0... 4.5 seconds.
}

Then add this to the end of your script:
pawn Код:
public PickedUpPickupReset (playerid)//The timer that resets the variable 'PickedUpPickup' to 0 (Nothing picked up within 4.5 seconds).
{
      PickedUpPickup[playerid] = 0;
      return 1;
}
Hope that helps!


Re: SetTimerEx - CesarLT - 23.09.2013

Quote:
Originally Posted by jakejohnsonusa
Посмотреть сообщение
Add this to the top of your script:

pawn Код:
forward PickedUpPickupReset(playerid);//Timer prepertaion or the "forward"
PickedUpPickup[MAX_PLAYERS] = 0;//Variable to hold if the player has picked somthing up. 0 = No, 1 = Yes
Add this to the OnPlayerPickUpPickupin your script (Obviously don't copy the public OnPlayerPickUpPickup part if you already have it):
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
      if(PickedUpPickup[playerid] != 0)//If they have picked up a pickup...
      {
            SendClientMessage(playerid, -1, "* You need to wait at least 5 seconds before picking up another pickup!");
            return 1;//Ends the code, not allowing the pickup.
      }
      PickedUpPickup[playerid] = 1;//Sets the 'PickedUpPickup' variable to has picked somthing up.
      SetTimerEx("PickedUpPickupReset", 4500, false, "i", playerid);//Sets a timer to reset the 'PickedUpPickup' variable to 0... 4.5 seconds.
}

Then add this to the end of your script:
pawn Код:
public PickedUpPickupReset (playerid)//The timer that resets the variable 'PickedUpPickup' to 0 (Nothing picked up within 4.5 seconds).
{
      PickedUpPickup[playerid] = 0;
      return 1;
}
Hope that helps!
This is what I am getting :/

pawn Код:
C:\Users\xxx\Desktop\xxx\gamemodes\xxx.pwn(24) : error 010: invalid function or declaration
C:\Users\xxx\Desktop\xxx\gamemodes\xxx.pwn(925) : error 017: undefined symbol "PickedUpPickup"
C:\Users\xxx\Desktop\xxx\gamemodes\xxx.pwn(925) : warning 215: expression has no effect
C:\Users\xxx\Desktop\xxx\gamemodes\xxx.pwn(925) : error 001: expected token: ";", but found "]"
C:\Users\xxx\Desktop\xxx\gamemodes\xxx.pwn(925) : error 029: invalid expression, assumed zero
C:\Users\xxx\Desktop\xxx\gamemodes\xxx.pwn(925) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


5 Errors.



Re: SetTimerEx - jakejohnsonusa - 23.09.2013

Oh, whoops!

I forgot to add the "new"... Now here this should work:

Add this to the top of your script:

pawn Код:
forward PickedUpPickupReset(playerid);//Timer prepertaion or the "forward"
new PickedUpPickup[MAX_PLAYERS] = 0;//Variable to hold if the player has picked somthing up. 0 = No, 1 = Yes
Add this to the OnPlayerPickUpPickupin your script (Obviously don't copy the public OnPlayerPickUpPickup part if you already have it):
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
      if(PickedUpPickup[playerid] != 0)//If they have picked up a pickup...
      {
            SendClientMessage(playerid, -1, "* You need to wait at least 5 seconds before picking up another pickup!");
            return 1;//Ends the code, not allowing the pickup.
      }
      PickedUpPickup[playerid] = 1;//Sets the 'PickedUpPickup' variable to has picked somthing up.
      SetTimerEx("PickedUpPickupReset", 4500, false, "i", playerid);//Sets a timer to reset the 'PickedUpPickup' variable to 0... 4.5 seconds.
}

Then add this to the end of your script:
pawn Код:
public PickedUpPickupReset (playerid)//The timer that resets the variable 'PickedUpPickup' to 0 (Nothing picked up within 4.5 seconds).
{
      PickedUpPickup[playerid] = 0;
      return 1;
}
Now I hope it helps you! And +1 as soon as I am allowed to give the next reputation point, again good job for trying to learn!


AW: SetTimerEx - BigETI - 23.09.2013

You can actually use GetTickCount() to calculate the remaining time without using any timers at all.

Example:
pawn Код:
// When you've triggered some event, for example picking up a pickup
my_time = GetTickCount();

// Check, if something has expired, for example the player is allowed to pick a pickup again (5000 means 5000 milliseconds, also 5 seconds)
if(GetTickCount() >= my_time+5000)
{
}

// Calculate the remaining time in milliseconds
remaining_time = (my_time+5000)-GetTickCount();
Also you should check, if your time variable has been ever set, before checking it for being expired or calculating the remaining time.


Re: SetTimerEx - CesarLT - 23.09.2013

Quote:
Originally Posted by jakejohnsonusa
Посмотреть сообщение
Oh, whoops!

I forgot to add the "new"... Now here this should work:

Add this to the top of your script:

pawn Код:
forward PickedUpPickupReset(playerid);//Timer prepertaion or the "forward"
new PickedUpPickup[MAX_PLAYERS] = 0;//Variable to hold if the player has picked somthing up. 0 = No, 1 = Yes
Add this to the OnPlayerPickUpPickupin your script (Obviously don't copy the public OnPlayerPickUpPickup part if you already have it):
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
      if(PickedUpPickup[playerid] != 0)//If they have picked up a pickup...
      {
            SendClientMessage(playerid, -1, "* You need to wait at least 5 seconds before picking up another pickup!");
            return 1;//Ends the code, not allowing the pickup.
      }
      PickedUpPickup[playerid] = 1;//Sets the 'PickedUpPickup' variable to has picked somthing up.
      SetTimerEx("PickedUpPickupReset", 4500, false, "i", playerid);//Sets a timer to reset the 'PickedUpPickup' variable to 0... 4.5 seconds.
}

Then add this to the end of your script:
pawn Код:
public PickedUpPickupReset (playerid)//The timer that resets the variable 'PickedUpPickup' to 0 (Nothing picked up within 4.5 seconds).
{
      PickedUpPickup[playerid] = 0;
      return 1;
}
Now I hope it helps you! And +1 as soon as I am allowed to give the next reputation point, again good job for trying to learn!
Same here, +1 for again helping me. Thank you!