Raised This Month: $12 Target: $400
 3% 

Solved pass 'enum' as parameter


Post New Thread Reply   
 
Thread Tools Display Modes
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
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 16:51   Re: pass 'enum' as parameter
Reply With Quote #2

My guess is that it will no longer know that it's a floating point value by not using PROB_ITEM_CHANCE strictly. Try applying the Float tag to array2D[][] where you're summing the values.

Also, when you say you tried something that doesn't work, you should provide that version of the code also so we can see what you tried and maybe fix it. It's hard to be sure what you actually tried when you describe it in words.
__________________
fysiks is offline
wilian159
Member
Join Date: Dec 2013
Old 07-24-2022 , 17:00   Re: pass 'enum' as parameter
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
My guess is that it will no longer know that it's a floating point value by not using PROB_ITEM_CHANCE strictly. Try applying the Float tag to array2D[][] where you're summing the values.

Also, when you say you tried something that doesn't work, you should provide that version of the code also so we can see what you tried and maybe fix it. It's hard to be sure what you actually tried when you describe it in words.
well, I want to know if there is a way to pass the 'enum' parameter in the stock,


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

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

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

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

        if(
currentProbability >= stopAt)
            
find i

        
if(find != -1)
            break
    }

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

because I tried some ways and it didn't work, so I want to know if there's a 'right' way
__________________
wilian159 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 17:09   Re: pass 'enum' as parameter
Reply With Quote #4

So, you're not going to read the first paragraph that I wrote? I don't know if that will fix it for sure but it's not hard to try.
__________________
fysiks is offline
wilian159
Member
Join Date: Dec 2013
Old 07-24-2022 , 17:18   Re: pass 'enum' as parameter
Reply With Quote #5

Quote:
Originally Posted by fysiks View Post
So, you're not going to read the first paragraph that I wrote? I don't know if that will fix it for sure but it's not hard to try.
doesn't work, I recommend you test it yourself, before trying to guess
__________________
wilian159 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 17:22   Re: pass 'enum' as parameter
Reply With Quote #6

Quote:
Originally Posted by wilian159 View Post
doesn't work, I recommend you test it yourself, before trying to guess
If I was getting paid to waste my time on some random request on the internet I probably would do that more often.
__________________
fysiks is offline
wilian159
Member
Join Date: Dec 2013
Old 07-24-2022 , 17:27   Re: pass 'enum' as parameter
Reply With Quote #7

Quote:
Originally Posted by fysiks View Post
If I was getting paid to waste my time on some random request on the internet I probably would do that more often.
to disturb the post bro, if you don't have the solution don't comment.
__________________
wilian159 is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 07-24-2022 , 17:53   Re: pass 'enum' as parameter
Reply With Quote #8

try
PHP Code:
stock probItems(const xEnumProbItems:array2D[][], array2DSize
lexzor is offline
wilian159
Member
Join Date: Dec 2013
Old 07-24-2022 , 18:02   Re: pass 'enum' as parameter
Reply With Quote #9

Quote:
Originally Posted by lexzor View Post
try
PHP Code:
stock probItems(const xEnumProbItems:array2D[][], array2DSize
it makes no sense because it would be dependent on 'xEnumProbItems', the idea is to make it dynamic,

what i need is this:

Call
PHP Code:
probItems(xProbItemssizeof(xProbItems), PROB_ITEM_CHANCE

PHP Code:
stock probItems(const array2D[][], array2DSizecolumChanceToCheck)
    for(new 
0array2DSizei++)
        
totalProbability += array2D[i][columChanceToCheck
but when i try the value is not correct
__________________
wilian159 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-24-2022 , 18:47   Re: pass 'enum' as parameter
Reply With Quote #10

My original suggestion works perfectly for me:

PHP Code:
enum myEnum {NAME[32], Float:CHANCE};
new 
myArray[][myEnum] = 
{
    {
"item1"10.1},
    {
"item2"20.1},
    {
"item3"30.1},
    {
"item4"40.1},
}


public 
cmdTest()
{
    
server_print("sum:  %f"myFunction(myArraysizeof myArrayCHANCE))
}

stock Float:myFunction(array[][], size, const index)
{
    new 
Float:fProb 0.0
    
for( new 0sizei++ )
    {
        
fProb += Float:array[i][index]
    }
    return 
fProb

Output is:

Code:
sum:  100.400001
Which is correct. Without the "Float:" where I said to put it, I get

Code:
sum:  4409498112.000000
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:02.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode