[Tutorial] How to make something that changes randomally!
#1

Hello, today I am going to show you how to make anything random. For example, random spawns or weather system.

So, first we need to make a new function, and tell the script that it will change randomally:
pawn Code:
new spawnpoint = random(4) // 4 = for 4 spawns, change the number to your max random thingies you'll do
Then we need to make a switch/case:
pawn Code:
switch(spawnpoint)
An open bracket
pawn Code:
{
Then we need to make, what it will actually do:
pawn Code:
case 0: SetPlayerPos(playerid, 0.0, 0.0, 0.0);
Then, another case ( we need four of them, since we put four up there^^ )
pawn Code:
case 1: SetPlayerPos(playerid, 2.0, 2.0, 2.0);
Next
pawn Code:
case 2: SetPlayerPos(playerid, 3.0, 3.0, 3.0);
And the final one
pawn Code:
case 3: SetPlayerPos(playerid, 4.0, 4.0, 4.0);
This was just example usage.
This will pick randomally, between 4 spawns
You can use it for anything, and if you want more than a single function in there:
pawn Code:
case 0:
{
    SetPlayerPos(playerid, 0.0, 0.0, 0.0);
    SendClientMessage(playerid, 0xAAAAAA, "Hi");
}
After all, closing the switch bracket:
pawn Code:
}
Thanks for viewing, comments are welcome!
Reply
#2

Not detailed, and that's not a function.
Reply
#3

Quote:
Originally Posted by jameskmonger
View Post
Not detailed, and that's not a function.
Random is a function. Just like is goto, break, switch, for, new, continue, switch, their functions
Reply
#4

Nice tutorial.

Why not:

pawn Code:
new Float:RandomSpawns[][3] =//The 3 here shows that there will be 3 pos. x, y and z
{
    {2756.1196,690.8884,10.8984},// You can edit these for the positions you want.
    {2755.4023,683.8808,10.8984},
    {2756.1243,668.4799,10.8984}
};
pawn Code:
public OnPlayerSpawn(playerid)
{
    new rand = random(sizeof(RandomSpawns));
    SetPlayerPos(playerid, RandomSpawns[rand][0], RandomSpawns[rand][1], RandomSpawns[rand][2]);
    return 1;
}
Reply
#5

Quote:
Originally Posted by Tee
View Post
Nice tutorial.

Why not:

pawn Code:
new Float:RandomSpawns[][3] =
{
    {2756.1196,690.8884,10.8984},
    {2755.4023,683.8808,10.8984},
    {2756.1243,668.4799,10.8984}
};
pawn Code:
public OnPlayerSpawn(playerid)
{
    new rand = random(sizeof(RandomSpawns));
    SetPlayerPos(playerid, RandomSpawns[rand][0], RandomSpawns[rand][1], RandomSpawns[rand][2]);
    return 1;
}
yee nice one!
Reply
#6

This topic could've been way better if you made it about the function itself (random()), not about the example script you're showing. The way I'd do this is making the topic itself about the random() function, and at the post footer add a few example scripts.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)