Random with case (Variables)
#1

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?
Reply


Messages In This Thread
Random with case (Variables) - by Groc - 18.03.2017, 19:17
Re: Random with case (Variables) - by Groc - 18.03.2017, 22:20
Re: Random with case (Variables) - by Groc - 19.03.2017, 09:02
Re: Random with case (Variables) - by Toroi - 19.03.2017, 11:10

Forum Jump:


Users browsing this thread: 1 Guest(s)