[Tutorial] Using less timers (1 timer for everything - faster script)
#6

While I do support the writing of tutorials, there are some huge issues that need to be addressed here.

1. Combining all timers into one or having less timers with more code is actually probably more problematic than having more times with less code. The statement I just made is valid in most cases, and the more code and the more timers combined into one there are, the more valid it becomes. Why? Due to the way SA-MP synchronization works. And if you think about it, it'll make sense.
Reading on the subject (more specifically, "Timers are efficient" paragraph)
This is the best topic I can find for this purpose right now.

2. You describe taking advantage of timestamps, yet there's a better way to do it rather than using timers. This comes with a little downside though - you will lose the messages like "You can use command ... now.", so the point I'm making is perhaps not very useful for you.
However what you've done can simply be solved by this:
pawn Code:
COMMAND:heal(playerid, params[])
{
    if((gettime() - heal_reload[playerid]) < 10)
        return SendClientMessage(playerid, 0xFF0000FF, "Please wait before using this command again!"), true;
    heal_reload[playerid] = gettime();

    SetPlayerHealth(playerid,100.0);
    SendClientMessage(playerid,0xFFFFFFFF,"You've healed yourself.");
    return 1;
}
There! No need for a timer, basically speaking.


I seriously hope that you take note of the 1st note that I wrote, because this is a serious misunderstanding by many many scripters. And while it does not make a difference with less code and less timers combined, there will be minor lag if there's a lot of code that takes a long time to execute per iteration or just many timers combined.

Hopefully you'll revise this tutorial. Thank you.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)