SA-MP Forums Archive
I need help with timers! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: I need help with timers! (/showthread.php?tid=195506)



I need help with timers! - Rokzlive - 02.12.2010

I am very new to pawn and i made this auto message script. It displays the first message over and over, when i want it to go message by message. Plz help!

pawn Код:
#define COLOR_BLUE                  0x1229FAFF
#define FILTERSCRIPT

#include <a_samp>

new Timer0;
new Timer1;
new Timer2;
new Timer3;
new Timer4;
new Timer5;
new Timer6;
new Timer7;
new Timer8;

forward a0(playerid);
forward a1(playerid);
forward a2(playerid);
forward a3(playerid);
forward a4(playerid);
forward a5(playerid);
forward a6(playerid);
forward a7(playerid);
forward a8(playerid);

public OnFilterScriptInit()
{
        print("\n-----------------------------------");
        print("ROKZLIVE AUTOMATIC MESSAGES                   ");
        print("-----------------------------------  ");
        print("by Rokzlive aka Whatcha        ");
        print("-----------------------------------\n");
        return 1;
}

public OnFilterScriptExit()
{
        return 1;
}

public a0(playerid)
{
    Timer0 = SetTimer("a0",150000,false);
    SendClientMessage(playerid, COLOR_BLUE, "Visit our website at www.Rokzlive.com!");
    return 1;
}
public a1(playerid)
{
    KillTimer(Timer0);
    Timer1 = SetTimer("a1",150000,false);
    SendClientMessage(playerid, COLOR_BLUE, "Visit our forum at Forum.Rokzlive.com!");
    return 1;
}
public a2(playerid)
{
    KillTimer(Timer1);
    Timer2 = SetTimer("a2",150000,false);
    SendClientMessage(playerid, COLOR_BLUE, "See a cheater or rule breaker? /report them to an administrator!");
    return 1;
}
public a3(playerid)
{
    KillTimer(Timer2);
    Timer0 = SetTimer("a3",150000,false);
    SendClientMessage(playerid, COLOR_BLUE, "Obey ALL speed limits!");
    return 1;
}
public a4(playerid)
{
    KillTimer(Timer3);
    Timer1 = SetTimer("a4",150000,false);
    SendClientMessage(playerid, COLOR_BLUE, "Dont DM! If you DM you will be warned or banned!");
    return 1;
}
public a5(playerid)
{
    KillTimer(Timer4);
    Timer2 = SetTimer("a5",150000,false);
    SendClientMessage(playerid, COLOR_BLUE, "Follow all rules to assure the best experience for all!");
    return 1;
}
public a6(playerid)
{
    KillTimer(Timer5);
    Timer0 = SetTimer("a6",150000,false);
    SendClientMessage(playerid, COLOR_BLUE, "Drive on the right side of the road!");
    return 1;
}
public a7(playerid)
{
    KillTimer(Timer6);
    Timer1 = SetTimer("a7",150000,false);
    SendClientMessage(playerid, COLOR_BLUE, "Drive and act as you would in real life!!");
    return 1;
}
public a8(playerid)
{
    KillTimer(Timer7);
    Timer2 = SetTimer("a8",150000,false);
    SendClientMessage(playerid, COLOR_BLUE, "Dont ask to be staff! It will make us less willing to hire you!");
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
        if(strcmp(cmdtext, "/auto", true) == 0 && IsPlayerAdmin(playerid))
    {
             Timer0 = SetTimer("a0",150000,false);
             KillTimer(Timer1);
             KillTimer(Timer2);
             KillTimer(Timer3);
             KillTimer(Timer4);
             KillTimer(Timer5);
             KillTimer(Timer6);
             KillTimer(Timer7);
             KillTimer(Timer8);
             SendClientMessage(playerid, COLOR_BLUE, "SYSTEM: Auto Messages Enabled");
             return true;
    }
        if(strcmp(cmdtext, "/unauto", true) == 0 && IsPlayerAdmin(playerid))
         {
             KillTimer(Timer0);
             KillTimer(Timer1);
             KillTimer(Timer2);
             KillTimer(Timer3);
             KillTimer(Timer4);
             KillTimer(Timer5);
             KillTimer(Timer6);
             KillTimer(Timer7);
             KillTimer(Timer8);
             SendClientMessage(playerid, COLOR_BLUE, "SYSTEM: Auto Messages Disabled");
             return true;
    }
        return 0;
}



Re: I need help with timers! - Haydz - 02.12.2010

You could have done this alot easier.

https://sampwiki.blast.hk/wiki/Random_Messages


Re: I need help with timers! - Kitten - 02.12.2010

this is way better than making way to many publics
pawn Код:
forward RandomM(playerid);
    public RandomM(playerid)
    {
        new msg == random(8);
        switch(msg)
        {
            case 0: SendClientMessage(playerid, COLOR_BLUE, "Visit our website at www.Rokzlive.com!");
            case 1: SendClientMessage(playerid, COLOR_BLUE, "Visit our forum at Forum.Rokzlive.com!");
            case 2: SendClientMessage(playerid, COLOR_BLUE, "See a cheater or rule breaker? /report them to an administrator!");
            case 3: SendClientMessage(playerid, COLOR_BLUE, "Obey ALL speed limits!");
            case 4: SendClientMessage(playerid, COLOR_BLUE, "Dont DM! If you DM you will be warned or banned!");
            case 5: SendClientMessage(playerid, COLOR_BLUE, "Follow all rules to assure the best experience for all!");
            case 6: SendClientMessage(playerid, COLOR_BLUE, "Drive on the right side of the road!");
            case 7: SendClientMessage(playerid, COLOR_BLUE, "Drive and act as you would in real life!!");
            case 8: SendClientMessage(playerid, COLOR_BLUE, "Dont ask to be staff! It will make us less willing to hire you!");
        }
        return 1;
    }



Re: I need help with timers! - Rokzlive - 02.12.2010

Omfg how many people do i have to explain this to, i also want to edit the script to do rcon commands and i want to make my own stuff not use others!


Re: I need help with timers! - PowerPC603 - 02.12.2010

This could also work:
Код:
#define COLOR_BLUE                  0x1229FAFF
#define FILTERSCRIPT

#include <a_samp>

// Create an enumeration to hold a reference to the timer and the current timerstep
enum TTimer
{
	MsgTimer,
	TimerStep
}

// Create a variable to hold the data for the timer
new MessageTimer[TTimer];

public OnFilterScriptInit()
{
        print("\n-----------------------------------");
        print("ROKZLIVE AUTOMATIC MESSAGES                   ");
        print("-----------------------------------  ");
        print("by Rokzlive aka Whatcha        ");
        print("-----------------------------------\n");
        return 1;
}

public OnFilterScriptExit()
{
        return 1;
}

forward MyTimer();
public MyTimer()
{
	MessageTimer[TimerStep]++;

	if (MessageTimer[TimerStep] == 9)
	    MessageTimer[TimerStep] = 0;

	switch (MessageTimer[TimerStep])
	{
		case 0: SendClientMessageToAll(COLOR_BLUE, "Visit our website at www.Rokzlive.com!");
		case 1: SendClientMessageToAll(COLOR_BLUE, "Visit our forum at Forum.Rokzlive.com!");
		case 2: SendClientMessageToAll(COLOR_BLUE, "See a cheater or rule breaker? /report them to an administrator!");
		case 3: SendClientMessageToAll(COLOR_BLUE, "Obey ALL speed limits!");
		case 4: SendClientMessageToAll(COLOR_BLUE, "Dont DM! If you DM you will be warned or banned!");
		case 5: SendClientMessageToAll(COLOR_BLUE, "Follow all rules to assure the best experience for all!");
		case 6: SendClientMessageToAll(COLOR_BLUE, "Drive on the right side of the road!");
		case 7: SendClientMessageToAll(COLOR_BLUE, "Drive and act as you would in real life!!");
		case 8: SendClientMessageToAll(COLOR_BLUE, "Dont ask to be staff! It will make us less willing to hire you!");
	}

	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
        if(strcmp(cmdtext, "/auto", true) == 0 && IsPlayerAdmin(playerid))
    {
             MessageTimer[MsgTimer] = SetTimer("MyTimer", 150000, true);
             SendClientMessage(playerid, COLOR_BLUE, "SYSTEM: Auto Messages Enabled");
             return true;
    }
        if(strcmp(cmdtext, "/unauto", true) == 0 && IsPlayerAdmin(playerid))
         {
             KillTimer(MessageTimer[MsgTimer]);
             SendClientMessage(playerid, COLOR_BLUE, "SYSTEM: Auto Messages Disabled");
             return true;
    }
        return 0;
}
This uses one enumeration to hold the timer-reference and the step (messagenumber) of the timer.
It uses one timer and sends a message based on that timerstep value.
Everytime the timer is executed it will select the next message and it will loop automatically.

It's also best in this case to use "SendClientMessageToAll" inside the timer.
It's no use that the rules of the server are sent only to the administrator who executed the command.


Re: I need help with timers! - The_Moddler - 02.12.2010

Quote:
Originally Posted by Rokzlive
Посмотреть сообщение
Omfg how many people do i have to explain this to, i also want to edit the script to do rcon commands and i want to make my own stuff not use others!
Your stuff is useless and inneficient, so use that.