Set timer is not working
#1

Hey,
heres my setup.

I have textdraws for a /fixveh function to show up when the car is fixed and then disappear in 4 seconds.

well its disappearing before my eyes can see it, so I dont think the timer is working.

pawn Код:
if (!strcmp("/fixveh", cmdtext, true))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            new VehicleID = GetPlayerVehicleID(playerid);
            RepairVehicle(VehicleID);
           
            /////  SHOW  /////
            TextDrawShowForPlayer(playerid,Text:Textdraw14);
            TextDrawShowForPlayer(playerid,Text:Textdraw15);
           
            SetTimerEx("delay",4000,false,"i",playerid); // delay is just a "dummy" function that returns 1
           
            /////  HIDE  /////
            TextDrawHideForPlayer(playerid,Text:Textdraw14);
            TextDrawHideForPlayer(playerid,Text:Textdraw15);
            return 1;
        }
        else
        {
            return 1;
        }
    }
I have tested it without the textdrawhide lines and I saw the shown textdraws so I know for a fact it is the set timer function not waiting like its supposed to.
Reply
#2

Why don't you use GameTextForPlayer ? It's better and there is a timer in itself. There are styles in the gametext as well.

pawn Код:
GameTextForPlayer(playerid, "Fixed", 3000, 1);
Original Link: https://sampwiki.blast.hk/wiki/GameTextForPlayer
-FalconX
Reply
#3

... A timer is not a delay or sleep function, it calls the function you put ( "delay" ) after the set time ( 4 seconds )
Reply
#4

This is what you are suppose to do:
pawn Код:
forward delay(playerid);
if (!strcmp("/fixveh", cmdtext, true))
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new VehicleID = GetPlayerVehicleID(playerid);
        RepairVehicle(VehicleID);

        /////  SHOW  /////
        TextDrawShowForPlayer(playerid,Text:Textdraw14);
        TextDrawShowForPlayer(playerid,Text:Textdraw15);

        SetTimerEx("delay",4000,false,"i",playerid); // delay is just a "dummy" function that returns 1
        return 1;
    }
    else
    {
        return 1;
    }
    return 1;
}

public delay(playerid)
{
    /////  HIDE  /////
    TextDrawHideForPlayer(playerid,Text:Textdraw14);
    TextDrawHideForPlayer(playerid,Text:Textdraw15);
    return 1;
}
Reply
#5

Quote:
Originally Posted by PrawkC
Посмотреть сообщение
... A timer is not a delay or sleep function, it calls the function you put ( "delay" ) after the set time ( 4 seconds )
Ok tell me if Im right,

once it gets to that timer line, it waits 4 seconds then executes the command in the string?
and then after that command is done, it should return to the line after the timer line.

If thats so, then my code should be working, as it is supposed to execute the delay function (dummy function) after the 4 seconds is up, but it seems its skipping the 4 seconds completely.
Reply
#6

Did you even look at my code? That is what it is suppose to be like, not the way you have it.
Reply
#7

Quote:
Originally Posted by LeetModz
Посмотреть сообщение
Ok tell me if Im right,

once it gets to that timer line, it waits 4 seconds then executes the command in the string?
and then after that command is done, it should return to the line after the timer line.

If thats so, then my code should be working, as it is supposed to execute the delay function (dummy function) after the 4 seconds is up, but it seems its skipping the 4 seconds completely.
How a timer works.. It goes to the part in the code that you set the timer in, and starts a timer, once the timer time is finished (4,000 ms in the example above), it will execute the code in the timers public.

E.G;

pawn Код:
public OnGameModeInit ( )
{
    SetTimer( "ThisisaFunction", 1000, true );
    return true;
}

forward ThisisaFunction ( );
public ThisisaFunction( )
{
    print( "This timer is called once every second!" );
    return true;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)