Random with case (Variables) - 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: Random with case (Variables) (
/showthread.php?tid=630795)
Random with case (Variables) -
Groc - 18.03.2017
So i remember when i made random gift from pickups it had one problem that if i put checking with variable, random case will be always the same. I will explain it better
so for example
Код:
if(pInfo[playerid][IsPlayerInfected] == 0)
{
new slot, weap, ammo;
for ( slot = 0; slot < 14; slot++ )
{
GetPlayerWeaponData(playerid,slot,weap,ammo);
if(IsValidWeapon(weap))
{
new randomselect = random(5); // i put random 5 because i want give a chance win nothing.
switch(randomselect)
{
case 0:
{
new randomammo = random(15);
GivePlayerWeapon(playerid,weap,randomammo);
format(string,sizeof(string),"~g~Found~w~: %d ammo",randomammo);
GameTextForPlayer(playerid,string,4000,5);
DestroyPickup(drop[playerid]);
}
case 1:
{
new randomxp = random(7);
format(string,sizeof(string),"~g~Found~w~: %d XP",randomxp);
GameTextForPlayer(playerid,string,4000,5);
pInfo[playerid][pXP] += randomxp;
DestroyPickup(drop[playerid]);
}
So with this code i can get ammo, exp, and nothing. So if i do something like this
Код:
new slot, weap, ammo;
for ( slot = 0; slot < 14; slot++ )
{
GetPlayerWeaponData(playerid,slot,weap,ammo);
if(IsValidWeapon(weap))
{
new randomselect = random(5); // i put random 5 because i want give a chance win nothing.
switch(randomselect)
{
case 0:
{
new randomammo = random(15);
GivePlayerWeapon(playerid,weap,randomammo);
format(string,sizeof(string),"~g~Found~w~: %d ammo",randomammo);
GameTextForPlayer(playerid,string,4000,5);
DestroyPickup(drop[playerid]);
}
case 1:
{
new randomxp = random(7);
format(string,sizeof(string),"~g~Found~w~: %d XP",randomxp);
GameTextForPlayer(playerid,string,4000,5);
pInfo[playerid][pXP] += randomxp;
DestroyPickup(drop[playerid]);
}
case 2:
{
if(pInfo[playerid][IsPlayerInfected] == 1 || pInfo[playerid][IsPlayerBlind] == 1)
{
GameTextForPlayer(playerid, "Cure", 5000, 2);
CurePlayer(playerid);
DestroyPickup(drop[playerid]);
}
}
}
}
Now if player get "IsPlayerInfected", "IsPlayerBlind" case 2 will be always selected. How can i avoid this and make chance to get case 0, case 1?
Re: Random with case (Variables) -
Groc - 18.03.2017
Up up up
Re: Random with case (Variables) -
Groc - 19.03.2017
Bump
Re: Random with case (Variables) -
Toroi - 19.03.2017
Are you sure your whole function needs to run in a loop?
Код:
for ( slot = 0; slot < 14; slot++ )
It does not make sense for me, can you explain it? Perhaps it is the problem