Textdraw countdown
#1

Well I have this code:
pawn Код:
new Text:Textdraw5;
new Time, TimeM = 20, TimeS = 0;
pawn Код:
Textdraw5 = TextDrawCreate(17.000000, 429.000000, "20:00");
    TextDrawBackgroundColor(Textdraw5, 65535);
    TextDrawFont(Textdraw5, 1);
    TextDrawLetterSize(Textdraw5, 0.500000, 1.000000);
    TextDrawColor(Textdraw5, 16777215);
    TextDrawSetOutline(Textdraw5, 1);
    TextDrawSetProportional(Textdraw5, 1);
    Time = SetTimer("UpdateTime", 1000, true);
pawn Код:
forward UpdateTime();
public UpdateTime()
{
  new Str[34];
  TimeS --;
  if(TimeM == 0 && TimeS == 0)
  {
    KillTimer(Time);
  }
  if(TimeS == -1)
  {
    TimeM--;
    TimeS = 59;
  }
  if(TimeS<10)
  {
    format(Str, sizeof(Str), "%d:0%d", TimeM, TimeS);
  }
  if(TimeS>9)
  {
    format(Str, sizeof(Str), "%d:%d", TimeM, TimeS);
  }
  TextDrawSetString(Textdraw0, Str);
  return 1;
}
But it don't want to countdown, there is textdraw 20:00 but time it's not going down..
Reply
#2

Put this in gamemodeinit

pawn Код:
SetTimer("UpdateTime", 1000,true);
maybe this will fix your problem.
Reply
#3

I have it on Gamemodeinit.., more help please
Reply
#4

pawn Код:
if(ServerSeconds == 0)
{
    ServerMinutes--;
    ServerSeconds = 59;
}
else
{
    ServerSeconds--;
}

if(ServerSeconds < 10)
{
    new string[48];
    format(string, sizeof(string), "%d:0%d", ServerMinutes,ServerSeconds);
    TextDrawSetString(ServerTimeTXT,string);
}
else
{
    new string[48];
    format(string, sizeof(string), "%d:%d", ServerMinutes,ServerSeconds);
    TextDrawSetString(ServerTimeTXT,string);
}
sorry bro. I can't find the mistake in your code. So, i am giving you my code. Please check the above code and try to fix yours.
As it is working for me.
Reply
#5

Fixed.. it was really stupid mistake, I reped you for your help ^^ but I had ShowTextDraw(Textdraw0) insted of Textdraw5 so it was fucked up a bit haha
Reply
#6

Oh lol. I didn't noticed that :P.

Thank You.
Reply
#7

Okay I fixed it somehow as I said but there is one problem, I can start timer mutliple times and everything related to that timer is fucked up I don't know how should I make that this "pepper spray" effect cannot be spammed and it won't trigger timer multi times

here is the code I'm using (everything related to this)
pawn Код:
new Text:Textdraw5;
new Time, TimeS = 20;
pawn Код:
Textdraw5 = TextDrawCreate(17.000000, 429.000000, "20");
    TextDrawBackgroundColor(Textdraw5, 65535);
    TextDrawFont(Textdraw5, 1);
    TextDrawLetterSize(Textdraw5, 0.500000, 1.000000);
    TextDrawColor(Textdraw5, 16777215);
    TextDrawSetOutline(Textdraw5, 1);
    TextDrawSetProportional(Textdraw5, 1);
pawn Код:
forward UpdateTime(playerid);
public UpdateTime(playerid)
{
  new Str[34];
  TimeS --;
  if(TimeS == 0)
  {
    KillTimer(Time);
    TextDrawHideForPlayer(playerid, Textdraw5);
  }
  if(TimeS == -1)
  {
    TimeS--;
    TimeS = 20;
  }
  if(TimeS<10)
  {
    format(Str, sizeof(Str), "0%d",TimeS);
  }
  if(TimeS>9)
  {
    format(Str, sizeof(Str), "%d",TimeS);
  }
  TextDrawSetString(Textdraw5, Str);
  return 1;
}
pawn Код:
if (strcmp("/test", cmdtext, true, 5) == 0)
    {
        Time = SetTimer("UpdateTime", 1000, true);
        TextDrawShowForPlayer(playerid, Textdraw5);
        ApplyAnimation(playerid,"CRACK","null",4.0,0,0,0,0,0,0);
        ApplyAnimation(playerid,"CRACK","crckdeth1",4.0,0,0,0,0,0,0);
        IsSprayed[playerid] = 1;
        TextDrawShowForPlayer(playerid,Textdraw0);
        TextDrawShowForPlayer(playerid,Textdraw1);
        TextDrawShowForPlayer(playerid,Textdraw2);
        TextDrawShowForPlayer(playerid,Textdraw3);
        TextDrawShowForPlayer(playerid,Textdraw4);
        return 1;
    }
I'm using command for this.. but how can I make that timer will trigger only once? because if I spam with /test
it will trigger more timers than only one and it will countdown ALOT faster and that's not cool.

I know I can make veriable that will check if I already used command but I don't need that for command it's only testing command, later I will use this:

pawn Код:
public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid)
{

    if(issuerid != INVALID_PLAYER_ID && weaponid == 41 && IsPlayerCop(playerid))
    {
        ApplyAnimation(playerid,"CRACK","null",4.0,0,0,0,0,0,0);
        ApplyAnimation(playerid,"CRACK","crckdeth1",4.0,0,0,0,0,0,0);
        TextDrawShowForPlayer(playerid,Textdraw0);
        TextDrawShowForPlayer(playerid,Textdraw1);
        TextDrawShowForPlayer(playerid,Textdraw2);
        TextDrawShowForPlayer(playerid,Textdraw3);
        TextDrawShowForPlayer(playerid,Textdraw4);
    }
    return 1;
}
Cuz I'm working on pepper spray effect..
So how can I make that timer will trigger only once (at /test cmd) and at "publuc OnPlayerTakeDamage"
Rep+ for helpers
Reply
#8

Anyone? Is even possible to make timer to trigger only once and it's repeating?
Reply
#9

Can someone help c'mon :/
Reply
#10

Last bump.. how should I make if I write /test timer won't be triggered multiple times, so it won't start countdown faster if I will write /test multiple times... :S please help
Code is above those posts..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)