timer between pickups?
#1

Hey everyone, is it possible to place a timer between pickups? So it won't be rapidately spammed?
Reply
#2

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

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
Reply
#4

bump
Reply
#5

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)