18.03.2017, 19:17
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
So with this code i can get ammo, exp, and nothing. So if i do something like this
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?
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]); }
Код:
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]); } } } }