[Include] Timer Fix (seamlessly makes SetTimer very accurate)
#41

How to use this include? Can you elaborate please? Thanks for sharing this great include. Seems like a good release.
Reply
#42

Quote:
Originally Posted by FIRST POST
Usage
You just have to add one single line of code after you included a_samp:
pawn Code:
#include <timerfix>
That ^
Reply
#43

Quote:
Originally Posted by Slice
View Post
That ^
Whats the correct params to use this?
SetTimerEx("CountDown", 1000, 0, "ii", playerid, seconds);

I am using these type of SetTimerEx's?

But it shows me warnings "Tag Mismatch" It works for SetTimerEx isnt it? or we got some new params to use this function!
Reply
#44

Put "false" instead of 0.
Reply
#45

Quote:
Originally Posted by Slice
View Post
Your function takes a lot of time to execute. Too much! Even without timerfix, this is a bad thing. What does "Global" do?
Ping MySQL every 15 seconds, move camera when a player connect to server (remove "spawn" button OnPlayerRequestClass) and show a dialog.

pawn Code:
task Global[1000]()
{
    if (sqlx15 == 15)
    {
        MySQLVerificarConexion();
        sqlx15 = 1;
    }
    else if (sqlx15 > 15) sqlx15 = 1;
    else sqlx15++;
    foreach(new i: Player)
    {
        if(InicioCam[i] == 1)
        {
            LimpiarChat(i);
            SetPlayerCameraPos(i, 1349.4004, -880.2820, 52.0618);
            SetPlayerCameraLookAt(i, 1350.1967, -879.6675, 52.2867);
            SetPlayerPos(i, 1349.4004, -880.2820, 50.0618);
           
            new query[96], rows;
            mysql_format(mysql, query, "SELECT Nombre FROM Usuarios WHERE Nombre = '%e'", GetName(i));
            mysql_query(query);
            mysql_store_result();
            rows = mysql_num_rows();
            mysql_free_result();
            if(rows == 0)
            {
                DialogoRegistro(i);
            }
            InicioCam[i] = 0;
        }
    }
    return 1;
}
pawn Code:
#define funcion%0(%1) forward%0(%1); public%0(%1)

//...

funcion MySQLVerificarConexion()
{
    if(mysql_ping() == 1) return 1;
    else
    {
        print("MYSQL: La conexiуn parece muerta, reintentando...");
        mysql_reconnect(mysql);
        if(mysql_ping() == 1)
        {
            print("MYSQL: Conexiуn exitosa. Continuamos de forma normal.");
            return 1;
        }
        else
        {
            print("MYSQL: No se puede conectar al servidor, terminando servidor...");
            SendRconCommand("exit");
            return 0;
        }
    }
}
Reply
#46

You should almost never run MySQL queries non-threaded, it's SLOW!
Reply
#47

Quote:
Originally Posted by Slice
View Post
You should almost never run MySQL queries non-threaded, it's SLOW!
thanks! Also I was using strcat (dialog), I removed it and everything seems work perfect
Reply
#48

How exactly did you test this? Wouldn't the test results also be off?
Reply
#49

Time for the SAMP releases to adress this problems.
Reply
#50

I used GetTickCount.

pawn Code:
#include <a_samp>
#include <timerfix>

main() {
    SetTimer("TimerFunc", 500, true);
}

forward TimerFunc();
public TimerFunc() {
    static
        previous_call
    ;
   
    if (previous_call)
        printf("Previous call %dms ago.", GetTickCount() - previous_call);
   
    previous_call = GetTickCount();
}
Try it out for yourself, both with and without timerfix.
Reply
#51

Nice lazyness helps sometimes lol
Reply
#52

It does, but "IsPlayerConnected" still has it's place in loops when you don't use "foreach". In this case you only have a single function inside the loop, so there's no gain, but if you had many functions inside the loop then you might want to wrap them all in a check so they aren't all half executed.
Reply
#53

Ok thanks for the advice and if I switch to foreach will do this check itself ? I have it but I didn't actually used it...
Reply
#54

A timer with 5 ms lol, that's gonna lag. Maybe a plugin would be better than fixing this on Pawn.
Reply
#55

Quote:
Originally Posted by Francis.
Посмотреть сообщение
A timer with 5 ms lol, that's gonna lag. Maybe a plugin would be better than fixing this on Pawn.
A plugin would be better, though this solution works just fine. A 5ms timer is nothing, really.
Reply
#56

Nice Slice
Reply
#57

nice thx
Reply
#58

pawn Код:
if(newstate==PLAYER_STATE_DRIVER)
    {
        speedotimer[playerid] = SetTimerEx("Speedo",200,1,"i",playerid);
    }

pawn Код:
public Speedo(i)
{

            if(IsPlayerInAnyVehicle(i) && GetPlayerState(i) == PLAYER_STATE_DRIVER)
            {
                new iVehicleID = GetPlayerVehicleID(i);
                new model = GetVehicleModel(iVehicleID);
                if(model ==510 || model==509 || model==481) return 1;
               
                PlayerTextDrawShow(i, textdraws[Textdraw2][i]);
                PlayerTextDrawShow(i, textdraws[Textdraw0][i]);
                PlayerTextDrawShow(i, textdraws[Textdraw202][i]);

                GetVehicleVelocity(GetPlayerVehicleID(i), svx[i], svy[i], svz[i]); // This Saves Our Velocitys To Our Varibles
                s10[i] = floatsqroot(((svx[i]*svx[i])+(svy[i]*svy[i]))+(svz[i]*svz[i]))*136.666667; // This Is Our Forumula ( I Don't Know How It Works )
                s2[i] = floatround(s10[i],floatround_round); // This Rounds Our Output To The Nearest Whole Number
                format(s3[i],30,"SPEED: %iKM/H", s2[i]); // This Format Our Text Into What We See
                format(s4[i],30,"FUEL: %iL", VehicleFuel[GetPlayerVehicleID(i)]); // This Format Our Text Into What We See

                static string[16];
                if(GetVehicleSpeed(iVehicleID) > 10)
                {
                    vInfo[iVehicleID][vMetrai] += floatround(floatdiv(GetVehicleSpeed(iVehicleID), 60.0));
                }
                if(vInfo[iVehicleID][vMetrai] > 9)
                {
                    vInfo[iVehicleID][vKilometrai] += 1;
                    vInfo[iVehicleID][vMetrai] = 0;
                }
                if(arrlen(vInfo[iVehicleID][vKilometrai]) == 1)
                {
                    format(string, 16, "0000%d~r~%d", vInfo[iVehicleID][vKilometrai], vInfo[iVehicleID][vMetrai]);
                    PlayerTextDrawSetString(i,textdraws[Textdraw202][i], string);
                }
                else if(arrlen(vInfo[iVehicleID][vKilometrai]) == 2)
                {
                    format(string, 16, "000%d~r~%d", vInfo[iVehicleID][vKilometrai], vInfo[iVehicleID][vMetrai]);
                    PlayerTextDrawSetString(i,textdraws[Textdraw202][i], string);
                }
                else if(arrlen(vInfo[iVehicleID][vKilometrai]) == 3)
                {
                    format(string, 16, "00%d~r~%d", vInfo[iVehicleID][vKilometrai], vInfo[iVehicleID][vMetrai]);
                    PlayerTextDrawSetString(i,textdraws[Textdraw202][i], string);
                }
                else if(arrlen(vInfo[iVehicleID][vKilometrai]) == 4)
                {
                    format(string, 16, "0%d~r~%d", vInfo[iVehicleID][vKilometrai], vInfo[iVehicleID][vMetrai]);
                    PlayerTextDrawSetString(i,textdraws[Textdraw202][i], string);
                }
                else if(arrlen(vInfo[iVehicleID][vKilometrai]) == 5)
                {
                    format(string, 16, "%d~r~%d", vInfo[iVehicleID][vKilometrai], vInfo[iVehicleID][vMetrai]);
                    PlayerTextDrawSetString(i,textdraws[Textdraw202][i], string);
                }

                PlayerTextDrawSetString(i,textdraws[Textdraw0][i], s3[i]); // This Changes The Value Of Our Textdraw To What We Formatted
                PlayerTextDrawSetString(i,textdraws[Textdraw2][i], s4[i]); // This Changes The Value Of Our Textdraw To What We Formatted
                return 1;
            }
            return 1;
}

gives:
Quote:

[15:41:40] (TimerFix) ERROR: The function "Speedo" didn't properly execute, some timers might not have been called.

Reply
#59

Do you have crashdetect? I suspect you're accessing an out of bounds index in an array or something inside that function.
Reply
#60

Having (or more 'had' - not (can't!) use this anymore) problems with this. Timers not executing, causing mySQL queries to produce 'lost connection to server during query' errors and all sorts. This include would be great if it worked properly. Anyone else experiencing this or is it just my shitty 3 year old gamemode?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)