SA-MP Forums Archive
Usage of Random - 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)
+--- Thread: Usage of Random (/showthread.php?tid=357677)



Usage of Random - Dubya - 08.07.2012

Hello. I was wondering what the Usage of "Random" is, because I want it to send random message's to the players, as like a tool-tip?


Re: Usage of Random - Kirollos - 08.07.2012

i didnt understand what you need exactly, if you want what's the parameters of the function random is random(maximum number);


Re: Usage of Random - coole210 - 08.07.2012

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

Random just randomizes between 0 and whatever number you input minus one (read post below).

The example on that wiki shows you how you could do random messages. If you don't understand how to make random messages from that wiki, read this one:

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


Re: Usage of Random - MP2 - 08.07.2012

Quote:
Originally Posted by coole210
Посмотреть сообщение
Random just randomizes between 0 and whatever number you input.
Wrong. If you put 1 it will only ever return 0, ONE value. If you put TWO it has the possibility to return TWO values - 0/1.


Re: Usage of Random - coole210 - 08.07.2012

Quote:
Originally Posted by MP2
Посмотреть сообщение
Wrong. If you put 1 it will only ever return 0, ONE value. If you put TWO it has the possibility to return TWO values - 0/1.
I know, I was simplifying it. I'll edit the post.


Re: Usage of Random - SnG.Scot_MisCuDI - 08.07.2012

pawn Код:
forward RandomMessage();

new RandomMessages[8][156] =
{
    "message1",
    "message2",
    "message3",
    "message4",
    "message5",
    "message6",
    "message7",
    "message8"
};


public OnGameModeInit()
{
    SetTimer("RandomMessage",60000,1); //every minute the message is sent
        return 1;
}


public RandomMessage()
{
    SendClientMessageToAll(COLOR, RandomMessages);
    return 1;
}



Re: Usage of Random - ReneG - 08.07.2012

You need to learn to do arrays if you want random messages.
pawn Код:
new
    szRandMessages[][] = {
    {"Message one"},    // 0
    {"Message two"},    // 1
    {"Message three"}// 2
    {"Message four"},   // 3
    {"Message five"},   // 4
    {"Message six"}};   // 5

public OnGameModeInit()
{
    SetTimer("RandomMessages", 30000, 1);
    return 1;
}

forward RandomMessages();
public RandomMessages()
{
    SendClientMessageToAll(-1, szRandMessages[random(sizeof(szRandMessages))]);
    print("30 secs");
    return 1;
}