[REP+]why this random gives error? and how to fix it? -
niels44 - 04.02.2012
hey guys,
i have mad ethis that when a player does /deal and he reaches his checkpoint the checkpoint gets deleted and he gets a random money... but the random thing isnt working.. it is giving this error:
Код:
D:\Program Files\[0.3d]my own drifting gamemode\gamemodes\TorettoRacing1.pwn(12308) : error 035: argument type mismatch (argument 2)
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
1 Error.
and i know this means that i typed something wrong.. but what? and how to fix it?
this are my pawn codes:
on top of script:
pawn Код:
new RandomMoney[][] =
{
{5000},
{3900},
{8900},
{7600},
{6758},
{4589},
{3000}
};
on onplayerenter checkpoint:
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
GivePlayerMoney(playerid,RandomMoney[random(sizeof(RandomMoney))]);// this line gives the error
DisablePlayerCheckpoint(playerid);
return 1;
}
plsh elp
greets niels
Re: [REP+]why this random gives error? and how to fix it? -
thimo - 04.02.2012
I dont thing the sizeof(RandomMoney))]); is needed try remove the sizeof part and if im wrong im sorry then atleast i tried to help
Re: [REP+]why this random gives error? and how to fix it? -
niels44 - 04.02.2012

not working.. now i got this error:
Код:
D:\Program Files\[0.3d]my own drifting gamemode\gamemodes\TorettoRacing1.pwn(12309) : error 076: syntax error in the expression, or invalid function call
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
1 Error.
and this code:
pawn Код:
public OnPlayerEnterCheckpoint(playerid)
{
GivePlayerMoney(playerid,RandomMoney[random]);
DisablePlayerCheckpoint(playerid);
return 1;
}
pls help
Re: [REP+]why this random gives error? and how to fix it? -
Konstantinos - 04.02.2012
pawn Код:
public OnPlayerEnterCheckpoint( playerid )
{
new
rand = random( sizeof( RandomMoney ) );
GivePlayerMoney( playerid, RandomMoney[ rand ][ 0 ] );// this line gives the error
DisablePlayerCheckpoint( playerid );
return 1;
}
Edit: Try it now, I forgot to add the "[ 0 ]" before.
It should work.
Re: [REP+]why this random gives error? and how to fix it? -
niels44 - 04.02.2012
still gives the same error...

anyone knows how to fix?
Respuesta: [REP+]why this random gives error? and how to fix it? -
OPremium - 04.02.2012
You don't need the extra dimension!
Change the array to this:
pawn Код:
new RandomMoney[] =
{
5000,
3900,
8900,
7600,
6758,
4589,
3000
};
It gives the error because it was returning another array instead of the integer
Re: [REP+]why this random gives error? and how to fix it? -
niels44 - 04.02.2012
yeah that works XD
eehm and how do i make it that when the player enters the cp he gets the money and a msg says how much money he has earned?
Re: [REP+]why this random gives error? and how to fix it? -
Babul - 04.02.2012
you created a 2dimensional array, thats not needed for a linear ordered amount of values:
pawn Код:
new RandomMoney[]={
5000,
3900,
8900,
7600,
6758,
4589,
3000
};
and then, the same as Dwane suggested: (now including the message ^^)
pawn Код:
new rnd=random(sizeof(RandomMoney));
GivePlayerMoney(playerid,RandomMoney[rnd]);
new string[128];
format(string,sizeof(string),"You earned $%d",RandomMoney[rnd]);
SendClientMessage(playerid,0x33aa33ff,string);
edit: lucky you, i posted between. just delete the double shit hehe
Re: [REP+]why this random gives error? and how to fix it? -
niels44 - 04.02.2012
yeah that works XD
eehm and how do i make it that when the player enters the cp he gets the money and a msg says how much money he has earned?
EDIT: this is double post but else someone doesnt sees it XD
Respuesta: [REP+]why this random gives error? and how to fix it? -
OPremium - 04.02.2012
Use format in the code that Dwane provided:
pawn Код:
public OnPlayerEnterCheckpoint( playerid )
{
new
rand = random( sizeof( RandomMoney ) );
GivePlayerMoney( playerid, RandomMoney[ rand ] );
format(string, sizeof(string), "You earned $%d!", RandomMoney[rand]); //Change the message to whatever you like :P
SendClientMessage(playerid, 0xFFFFFFFF, string); //Sends the message
DisablePlayerCheckpoint( playerid );
return 1;
}
EDIT: This time "Babul" was faster XD