Reseting a Timer.Would this work?
#1

So,how can I do this?
I have a timer,made with SetTimerEx.
If a player does a specific command,the timer will reset. With another value.
SetTimerEx("MyTimer", 50000, 0, "d", playerid);

If the player does /command
What should I do next?
Should I just
SetTimerEx("MyTimer", 7400000, 0, "d", playerid);
with the different value?

I just want it to reset for the player with a different value(different time).I am asking if this is possible

Thanks for your time
Regards
Reply
#2

no just kill the timer first then recreate it
https://sampwiki.blast.hk/wiki/KillTimer

youll need to hold the ID of the timer
let us know if you need more help
Reply
#3

Alright,I'll give it a try and then post here if it work.
Thanks for your reply
Reply
#4

I still have the problem,I'll just post de code here.

pawn Код:
public OnPlayerLogin
{
if(PlayerInfo[playerid][pAddicted] == 1)
        {
           drugtime = SetTimerEx("AddictionKickIn", 1800000, 0, "d", playerid);
        }
}
--------------------------------------------------------------------------------------------

public OnPlayerCommandText
{
if(strcmp(cmd,"/usedrugs",true)==0)
    {
        if(IsPlayerConnected(playerid))
        {
           new x_job[256];
           x_job = strtok(cmdtext, idx);
           GetPlayerName(playerid, sendername, sizeof(sendername));
           if(!strlen(x_job))
           {
             SendClientMessage(playerid,COLOR_GREY,"Correct Usage: /usedrugs [drugname]");
             SendClientMessage(playerid,COLOR_WHITE,"|_________ Available Names __________|");
             SendClientMessage(playerid,COLOR_GREY,"Weed(25HP),LSD(50HP),PCP(60HP),Methamphetamine(75HP),Cocaine(100HP)");
             return 1;
           }
           if(strcmp(x_job,"Weed",true) == 0)
           {
             if(PlayerInfo[playerid][pDrugs] >= 1)
             {
                if(High[playerid] == 0)
                {
                GameTextForPlayer(playerid, "~w~You are now~n~~p~High !", 4000, 1);
                new Float:health;
                GetPlayerHealth(playerid, health);
                if(PlayerInfo[playerid][pDrugPerk] > 0)
                {
                  if(health >= 125)
                  {
                    new hp = 2 * PlayerInfo[playerid][pDrugPerk]; hp += 125;
                    SetPlayerHealth(playerid, 150);
                  }
                  else
                  {
                    new hp = 2 * PlayerInfo[playerid][pDrugPerk]; hp += 125;
                    SetPlayerHealth(playerid, health + hp);
                  }
                }
                else
                {
                  if(health >= 125)
                  {
                    SetPlayerHealth(playerid, 150);
                  }
                  else
                  {
                    SetPlayerHealth(playerid, health + 25);
                  }
                }
                GameTextForPlayer(playerid,"~w~ You are now ~p~~h~ High ",3000,1);
                SendClientMessage(playerid, COLOR_GREY, " 1 Drug Grams used !");
                if(AddictTime[playerid] > 0 )
                {
                 SendClientMessage(playerid,COLOR_YELLOW,"You used drugs to calm your drug addiction !");
                 AddictTime[playerid] = 0;
                }
                KillTimer(drugtime);
                drugtime = SetTimerEx("AddictionKickIn", 50000, 0, "d", playerid);
                PlayerInfo[playerid][pAddicted] = 1;
                PlayerInfo[playerid][pPassAddiction] = 5;
                PlayerInfo[playerid][pDrugs] -= 1;
                High[playerid] = 1;
                SetPlayerWeather(playerid,2009);
                SetTimerEx("ResetWeather", 45000, 0, "d", playerid);
                format(string, sizeof(string), "* %s rolls up some weed and starts to smoke it.", sendername);
                ProxDetector(10.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                ApplyAnimation(playerid,"SMOKING","M_smk_out", 4.0, 0, 0, 0, 0, 0);
                return 1;
                }
                else
                {
                   SendClientMessage(playerid,COLOR_GREY,"You can not use drugs right now !");
                }
              }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "   You need 1 gram of drugs for that drug !");
            }
          }
}
--------------------------------------------------------------------------------------------------------
public AddictionKickIn(playerid)
{
 if(PlayerInfo[playerid][pPassAddiction] <= 5 && PlayerInfo[playerid][pPassAddiction] != 0)
 {
  if(AddictTime[playerid] < 10)
  {
   new string[256];
   new HP = random(9)+1;
   SetPlayerHealth(playerid, -HP);
   SendClientMessage(playerid,COLOR_YELLOW,"Your drug addiction has kicked in !");
   format(string, sizeof(string), "* %s are ochii rosii si incepe sa tremure.", sendername);
   ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
   format(string, sizeof(string), "* You lost %d HP because of your drug addiction",HP);
   SendClientMessage(playerid,COLOR_YELLOW,string);
   SendClientMessage(playerid,COLOR_YELLOW," You can /usedrugs or wait for the addiction to go ");
   drugtime = SetTimerEx("AddictionKickIn", 60000, 0, "d", playerid);
   AddictTime[playerid] += 1;
  }
  else if(AddictTime[playerid] == 10)
  {
    SendClientMessage(playerid,COLOR_YELLOW," Your addiction passed and you didn't used drugs ! Good Job !");
    AddictTime[playerid] = 0;
    PlayerInfo[playerid][pPassAddiction] -= 1;
    if(PlayerInfo[playerid][pPassAddiction] == 0)
    {
      SendClientMessage(playerid,COLOR_YELLOW," Congratulations ! You are not addicted to drugs anymore !");
      PlayerInfo[playerid][pAddicted] = 0;
    }
    return 1;
  }
 }
 return 1;
}
What may be the problem? I've tried anything,nothing happens when I do /usedrugs,the AddictionKickIn just doesn't show up.

EDIT: I also tried to replace
Quote:

if(PlayerInfo[playerid][pPassAddiction] <= 5 && PlayerInfo[playerid][pPassAddiction] != 0)

with
Quote:

if(PlayerInfo[playerid][pAddicted] == 1)

Reply
#5

Firstly, Indentation is key to manageable code, secondly use pastebin for large scripts, and thirdly, use [ pawn ] [ /pawn ] tags around the start and end of your code.
Reply
#6

Quote:
Originally Posted by Hoborific
Посмотреть сообщение
Firstly, Indentation is key to manageable code, secondly use pastebin for large scripts, and thirdly, use [ pawn ] [ /pawn ] tags around the start and end of your code.
Done and thanks for the info
Reply
#7

Made it more visible now
Reply
#8

Is there any solutin for my problem?
Maybe the SetTimerEx function? Is there a problem with the special format indicating the types of values the timer will carry ? The "d"? Should I change it to something else?
Reply
#9

http://pastebin.com/cZgvWCUf

the pastebin code
Reply
#10

dont bump...
always edit your last post if your the last one to post in a thread.. okay. now on to this..

Quote:
Originally Posted by FreeSoul
Посмотреть сообщение
Is there any solutin for my problem?
Maybe the SetTimerEx function? Is there a problem with the special format indicating the types of values the timer will carry ? The "d"? Should I change it to something else?
well d and i are for integers
you can try changing it to i

but i dont think thats the problem.
after looking threw this code, id have to implement this in a gamemode
to try to fix it and I just dont have the time right now.

sorry.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)