[Include] Function by Sequence Time (Loop Timer) - Dynamic?
#1

Well, my first pay I believe Include ... Worked perfectly for me, it creates Include Timer's sequence, you define the amount of times this timer will repeat (loop), removing the need to create a variable for each time and use the "true".

He has three commands for macros:


LoopTimerCreate ("funcname", {Float, _}: ...)
- Used to create a function that will be used in the Sequence LoopTimerStart

Example:
pawn Код:
LoopTimerCreate("Perseguir", playerid, giveid)
{
    new Float:Pos[3];
    GetPlayerPos(giveid, Pos[0], Pos[1], Pos[2]);
    SetPlayerCheckpoint(playerid, Pos[0], Pos[1], Pos[2], 3.0);
    return 1;
}

LoopTimerEnd ("funcname", {Float, _}: ...)
- Called when the "funcname" is ended (when the sequence ends, the loop)

Example:
pawn Код:
LoopTimerEnd("Perseguir", playerid, giveid)
{
    DisablePlayerCheckpoint(playerid);
    printf("Loop Timer Finished");
    return 1;
}

LoopTimerStart ("funcname", time, replications, "Const Format", {Float, _}: ...);
- Start Sequence according to the Time and Reps, etc.

Example:
pawn Код:
LoopTimerStart("Perseguir", 1000, time, "ii", playerid, giveid);


Example Finale:
pawn Код:
#include a_samp
#include zcmd
#include sscanf
#include looptimer

LoopTimerCreate("Perseguir", playerid, giveid)
{
    new Float:Pos[3];
    GetPlayerPos(giveid, Pos[0], Pos[1], Pos[2]);
    SetPlayerCheckpoint(playerid, Pos[0], Pos[1], Pos[2], 3.0);
    return 1;
}

LoopTimerEnd("Perseguir", playerid, giveid)
{
    DisablePlayerCheckpoint(playerid);
    printf("Loop Timer Finished");
    return 1;
}

CMD:falow(playerid, params[])
{
    new giveid, time;
    if(sscanf(params, "dd", giveid, time)) return SendClientMessage(playerid, -1, "USAGE: /falow[ID] [TIME IN SG]");
    LoopTimerStart("Perseguir", 1000, time, "ii", playerid, giveid);
    return 1;
}


INCLUDE:
pawn Код:
#include a_samp

#if defined tabsize
#undef tabsize
#endif
#pragma tabsize 0

#define LoopTimerCreate("%0",%1) \
forward Func_%0(%1); \
forward End_%0(%1); \
public Func_%0(%1)

#define LoopTimerStart(%0,%1,%2,%3,%4) \
for(new c, f[36]; c < %2; c++) \
{ \
    format(f, sizeof(f), "%s", %0); \
    if(c == %2 - 1) \
    { \
        strins(f, "End_", 0); \
        SetTimerEx(f, %1*c, false, "%3", %4); \
    } \
    else \
    { \
        strins(f, "Func_", 0); \
        SetTimerEx(f, %1*c, false, "%3", %4); \
    } \
} \
FuncNone()

#define LoopTimerEnd("%0",%1) \
public End_%0(%1)

stock FuncNone()
{
}


Sorry my bad Inglish.
Hope you like, comment!
Credits 100% for me.

Original Topic: http://forum.sa-mp.com/showthread.ph...16#post1912516


UPDATED FOR FINAL
SPEED - 0.2x SLOWER (DID IT)
OPTIMIZATION - 0.5 A MORE ENHANCED SIZE COMPARED. AMX
SIMPLICITY - 2/3x SIMPLER


DOWNLOAD OF TESTS / TEST CODES / INCLUDE:
Reply
#2

Nice work, seems quite useful!
Reply
#3

thanks very much! Its quite useful!
Reply
#4

pretty much Useful
Reply
#5

Thanks ;*
Reply
#6

how I understood, if I set timer to repeat 3 times it will repeat 3 times, not anymore?
Reply
#7

Quote:
Originally Posted by System64
Посмотреть сообщение
how I understood, if I set timer to repeat 3 times it will repeat 3 times, not anymore?
Yes, see exemple:
pawn Код:
LoopTimerStart("FuncName", 1000, 60, "i", playerid);
As you can see, will repeat 60 times a timer of 1 second, totaling 60 seconds and the function "funcname" updated on a second one :P

#EDIT
Small att in the Include, see .
Reply
#8

48 hours past.
The include has been att.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)