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
#2

Up up up
Reply
#3

Bump
Reply
#4

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)