Thread: [Solved] pass 'enum' as parameter
View Single Post
Author Message
wilian159
Member
Join Date: Dec 2013
Old 07-24-2022 , 16:42   pass 'enum' as parameter
Reply With Quote #1

I have that:

PHP Code:
enum _:xEnumProbItems PROB_ITEM_NAME[32], Float:PROB_ITEM_CHANCE }

new const 
xProbItems[][xEnumProbItems] =
{
    { 
"Chinelo"58.5 },
    { 
"Oculos"61.7 },
    { 
"Bazooka"0.01 },
    { 
"Rifle"0.1 },
    { 
"Pistola"2.5 },

and that

PHP Code:
stock probItems(const array2D[][], array2DSize)
{
    new 
find = -1
    
new Float:totalProbability 0.0

    
for(new 0array2DSizei++)
        
totalProbability += array2D[i][PROB_ITEM_CHANCE]

    new 
Float:stopAt random_float(0.00001totalProbability)
    new 
Float:currentProbability 0.0

    
for(new 0array2DSizei++)
    {
        
currentProbability += array2D[i][PROB_ITEM_CHANCE]

        if(
currentProbability >= stopAt)
            
find i

        
if(find != -1)
            break
    }

    return (
find != -1) ? find : -1

notice in the 'stock' that I use the 'enum: PROB_ITEM_CHANCE', but I don't want to use it this way, I want to pass the column 'chance' as a parameter in the stock, more or less like this

PHP Code:
probItems(const array2D[][], array2DSizeenumToCheck
I tested several ways, but it didn't work, bugged the sum of 'float' and other things
__________________

Last edited by wilian159; 07-24-2022 at 19:18.
wilian159 is offline