Weed timer help
#1

I want to make it to where when you /plant the weed somewhere, you will be able to /pick an hour later and it will destroy the plant, giving you 9 grams of marijuana..

PHP код:
PlayerInfo[playerid][pMarijuana]+=9
I think I have to make some sort of timer, but I'm not sure, so can someone help me out?

PHP код:
CMD:plant(playeridparams[])
{
    if(
PlayerInfo[playerid][pSeeds] > 2)
    {
            new 
Name[MAX_PLAYER_NAME],string[128],Float:x,Float:y,Float:z;
            
GetPlayerName(playerid,Namesizeof(Name));
            
format(string128"* %s plants seeds into his(her) plant pot."Name);
            
SendClientMessageToAll(COL_WHITE,string); // to nearby players
            
GetPlayerPos(playerid,x,y,z);
            
CreateObject(19473,x,y,z-2,0,0,0);
            
PlayerInfo[playerid][pSeeds]-=3;
    }
    else
    
SendClientMessage(playerid,COL_WHITE,"You don't have enough seeds!");
    return 
1;

Reply
#2

Okay, I'm going to save both of us a headache (even though I have one due to this medication I have been on; and I have had a constant headache for over a week now, but that's a different story) and use y_timers.

Remember, timers calculate time in milliseconds. There are 60,000 milliseconds in a minute, so there are 60000*60000=3600000000 milliseconds in an hour. Using y_timers, let's set that timer.

pawn Код:
timer weedWaitingPeriod[3600000000](playerid)
{}
Okay, the timer is set. Now in your code above, we need to call the timer so it will begin the countdown. We can do that by calling the following function:

pawn Код:
defer weedWaitingPeriod(playerid);
In the timer function itself, we need to set a bool variable to tell the server that the waiting period is up and the player can go crop the drugs.

You need to add this somewhere at the top of your script, first!

pawn Код:
new bool:canCropWeed[MAX_PLAYERS] = false;
pawn Код:
timer weedWaitingPeriod[3600000000](playerid)
{
   canCropWeed[playerid] = true;
}
Finally, you need to make a new command that will crop the weed, give the player the drugs, and remove the plant. I'll let you do that, but you DO need to run the following if statement before letting them do anything:

pawn Код:
if(canCropWeed[playerid])
{
Good luck!
Reply
#3

Thanks. Good luck with the headache!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)