[Tutorial] How to create Simple Random Messages.
#14

I know this is your tutorial, and I don't mean to hijack your topic, but I just felt the need to show you how I personally would do it.

pawn Code:
//At the top of your script, near your other definitions -
#define     RANDOM_MESSAGE1     "This is random message numero uno!"
    #define     RANDOM_MESSAGE2     "This is random message numero dos!"
        #define     RANDOM_MESSAGE3     "This is random message numero tres!"
            #define     RANDOM_MESSAGETIMEINMINUTES     3 //Every three minutes a random message will be shown.

//OnGameModeInit / OnFilterScriptInit -

SetTimer("ShowARandomMessage", RANDOM_MESSAGETIMEINMINUTES*60000, true); //3 * 60000 = 180,000 milliseconds which translates to 3 minutes.

//Somewhere else in your script (OUTSIDE of a callback) -

forward ShowARandomMessage();
public ShowARandomMessage()
{
    new
        RandomSelection = random(3); //Randoms start from 0 and work their way up -- THEY DO NOT START AT 1.

    switch(RandomSelection) {
        case 0: {
            return SendClientMessageToAll(0xE8B210FF, RANDOM_MESSAGE1);
        }
        case 1: {
            return SendClientMessageToAll(0xE8B210FF, RANDOM_MESSAGE2);
        }
        case 2: {
            return SendClientMessageToAll(0xE8B210FF, RANDOM_MESSAGE3);
        }
    }
    return 1;
}
Like I said above, I don't mean to hijack your thread, I just felt the need to share how I personally do it.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)