How to make something that changes randomally! -
Mean - 05.02.2011
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:
An open bracket
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:
Thanks for viewing, comments are welcome!
Re: How to make something that changes randomally! -
jameskmonger - 05.02.2011
Not detailed, and that's not a function.
Re: How to make something that changes randomally! -
admantis - 05.02.2011
Quote:
Originally Posted by jameskmonger
Not detailed, and that's not a function.
|
Random is a function. Just like is goto, break, switch, for, new, continue, switch, their functions
Re: How to make something that changes randomally! -
Tee - 05.02.2011
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;
}
Re: How to make something that changes randomally! -
-•♥♠♦♣-•Arshavin•-♥♠♦♣•- - 05.02.2011
Quote:
Originally Posted by Tee
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!
Re: How to make something that changes randomally! -
Hiddos - 05.02.2011
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.