timer between pickups? -
Stroker - 12.06.2014
Hey everyone, is it possible to place a timer between pickups? So it won't be rapidately spammed?
Re: timer between pickups? -
DavidBilla - 12.06.2014
if you are talking about same pickup reappearing after each time you pick it up,yes there is a way.
when you create a pickup,assign a name to it.
example
pawn Код:
//under ongamemodeinit
new weaponpickup;
weaponpickup = CreatePickup(..........);
pawn Код:
//under OnPlayerPickupPickup
if(pickupid == weaponpickup)
{
GivePlayerWeapon(playerid,24,100);
DestroyPickup(weaponpickup);
SetTimerEx(......)
}
pawn Код:
//under the timer's function
weaponpickup = CreatePickup(..........);
This will kinda cycle it,it'll keep reoccuring according to the time you set in the timer.
Re: timer between pickups? -
Stroker - 12.06.2014
Quote:
Originally Posted by DavidBilla
if you are talking about same pickup reappearing after each time you pick it up,yes there is a way.
when you create a pickup,assign a name to it.
example
pawn Код:
//under ongamemodeinit new weaponpickup; weaponpickup = CreatePickup(..........);
pawn Код:
//under OnPlayerPickupPickup if(pickupid == weaponpickup) { GivePlayerWeapon(playerid,24,100); DestroyPickup(weaponpickup); SetTimerEx(......) }
pawn Код:
//under the timer's function weaponpickup = CreatePickup(..........);
This will kinda cycle it,it'll keep reoccuring according to the time you set in the timer.
|
Well thanks, but it's not what I am asking for, I meant like..you have to wait around 5 seconds between entering pickups, which will prevent spam aswell
Re: timer between pickups? -
Stroker - 13.06.2014
bump
Re: timer between pickups? -
Manyula - 13.06.2014
Start a non-repeating Timer as soon as a player picks up a certain pickup.
Set a variable on 1, when the player has picked up the pickup and reset the variable in the timer function.
Under OnPlayerPickUpPickup, ask for the pickupid and whether the variable is 0 or 1.
Re: timer between pickups? -
Stroker - 14.06.2014
Quote:
Originally Posted by Manyula
Start a non-repeating Timer as soon as a player picks up a certain pickup.
Set a variable on 1, when the player has picked up the pickup and reset the variable in the timer function.
Under OnPlayerPickUpPickup, ask for the pickupid and whether the variable is 0 or 1.
|
i am kinda a newbie scripter, can you please give me an example of a code?
Re: timer between pickups? -
Threshold - 15.06.2014
pawn Код:
#define PICKUP_DELAY 5
//This means you want 5 second delays between pickups. You can change this to whatever you want.
new LastPickup[MAX_PLAYERS];
public OnPlayerConnect(playerid)
{
LastPickup[playerid] = 0; //Reset the LastPickup for the player.
return 1;
}
public OnPlayerPickUpPickup(playerid, pickupid)
{
if((gettime() - LastPickup[playerid]) < PICKUP_DELAY) return 1;
if(pickupid == 1) //Example
{
//Your code
}
LastPickup[playerid] = gettime();
return 1;
}
The #define and new LastPickup would have to be at the top of your script.
pawn Код:
if((gettime() - LastPickup[playerid]) < PICKUP_DELAY) return 1;
This line prevents the code from continuing if it hasn't been 5 seconds since their last pickup.
Sources:
https://sampwiki.blast.hk/wiki/Gettime
https://sampwiki.blast.hk/wiki/OnPlayerPickUpPickup