max. Random -
Justsmile - 17.05.2009
Hi,
i have got a problem. I will explain and I hope you can help me. Ok, i want to make my own Weather Change. How can I define mind. Random and max random?
like this?:
new weatherChange = random(<12 && >4);
or how? pls explain me.
Re: max. Random -
Weirdosport - 17.05.2009
#define MAX 50
#define MIN 10
random(MAX-MIN) + MIN
For greater efficiency you might want to add:
#define RANDOMNUMBERTHING MAX-MIN so your computer doesn't constantly have to do MAX - MIN, but this is trivial..
Re: max. Random -
Justsmile - 17.05.2009
I hvae it like this.
if(hour == 9 || hour == 10 || hour == 11)
{
new wea2 = random(MAX_WEA2-MIN_WEA2) + MIN_WEA2;
SetWeather(wea2);
}
Re: max. Random -
Justsmile - 17.05.2009
Sorry for Doublepost. How can i do like this.
I want the change of 3 ids they are 12 & 17 & 3. How can i do this?
Re: max. Random -
Weirdosport - 17.05.2009
Put them in an array:
new WeatherIDs[3] = { 3, 12, 17 };
Then use something like:
WeatherIDs[random(sizeof(WeatherIDs))];
Re: max. Random -
Justsmile - 17.05.2009
Erros:
K:\The Godfather - Neu\gamemode\gf.pwn(31445) : error 012: invalid function call, not a valid address
K:\The Godfather - Neu\gamemode\gf.pwn(31445) : error 001: expected token: ",", but found "sizeof"
K:\The Godfather - Neu\gamemode\gf.pwn(31445) : warning 215: expression has no effect
K:\The Godfather - Neu\gamemode\gf.pwn(31445) : error 001: expected token: ";", but found ")"
K:\The Godfather - Neu\gamemode\gf.pwn(31445) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
if(hour == 6)
{
new WeatherIDs[3] = { 3, 12, 17 };
new irandom = random(sizeof(WeatherIDs));
SetWeather(irandom(sizeof(WeatherIDs)));//31445
}
Re: max. Random -
Weirdosport - 17.05.2009
Outside everything, at top of script:
pawn Код:
new WeatherIDs[3] = { 3, 12, 17 };
In the command/function
pawn Код:
if(hour == 6)
{
SetWeather(WeatherIDs[random(sizeof(WeatherIDs))]);
}
EDIT: I modified the code above a couple of times because I noticed a couple of mistakes, if it doesn't work check you have the latest version..
Re: max. Random -
Justsmile - 17.05.2009
Thanks for good explaining. I understand and i think its works
Re: max. Random -
Weirdosport - 17.05.2009
Unless you hadn't already guessed the line I gave you was quite a few functions rolled into one!
Explanation:
SetWeather(WeatherIDs[random(sizeof(WeatherIDs))]);
WeatherIDs is an array, so sizeof(WeatherIDs) returns how many spaces it has (3)
random(3) gives you a random number, either 0, 1, or 2.
WeatherIDs[1] is the second cell in the array, which in this case is 12.
The only downside is that you may get the same WeatherID twice in a row.
Re: max. Random -
Justsmile - 17.05.2009
ok, woah i understand it perfectly. Thanks a lot

Maybe you can say whats wroing with this:
It always says, tht more cops must be online.
if(Cops_On < 0)
{
GameTextForPlayer(playerid,"More Cops must be Online.",5000,3);
return 1;
}
new Cops[MAX_PLAYERS];
new Cops_On;
forward GetCops();
public GetCops()
{
Cops_On = 0;
for(new i=0;i<MAX_PLAYERS;i++)
{
if(IsPlayerConnected(i))
{
if(IsACop(i))
{
Cops[i] = 1;
Cops_On++;
}
else
{
Cops[i] = 0;
}
}
}
}