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

[HELP] Random num saving for another function


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-20-2014 , 10:07   [HELP] Random num saving for another function
Reply With Quote #1

Hey guys! I want to ask, because I didn't find the solution, about saving the random num from random_num native. My question: is there a way you get random_num via the native once, and then get the same random num, as the native got before, but using it in another function. Like to save the got random num from this function, then use it in the other function, and the forget it and start from beging with the first function and another random num?
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 05-20-2014 , 10:14   Re: [HELP] Random num saving for another function
Reply With Quote #2

Save it in a global var when you generate it. After you use it reset the var to a value out of the range of random_num range (?)
NikKOo31 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-20-2014 , 10:19   Re: [HELP] Random num saving for another function
Reply With Quote #3

Oh, right, global vars. I'm so dumb for not trying this. Will test and post if something goes wrong. But for now, the case is closed
EDIT: Nope, even in a global var the random num is again random in every use of this var... Or I didn't get you right, or this metod doesn't work at all Any suggestions?
__________________

Last edited by Flick3rR; 05-20-2014 at 10:49.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 05-20-2014 , 11:03   Re: [HELP] Random num saving for another function
Reply With Quote #4

okay, looks like a bad case of someone who doesn't know basic coding or scripting
here's the deal, you can save your value in a global variable and it will stay the same as long as the function that generated the random number and saved it is not called again

if something keeps calling the random number generation of course it will keep overwriting your global value
aron9forever is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-20-2014 , 11:15   Re: [HELP] Random num saving for another function
Reply With Quote #5

Do you think I didn't get it earlier? Would I make a thread if I didn't try the simplest thing at all. Hating all the time, anyways, right?
Here is an example, which doesn't work for me:
PHP Code:
//That's global
new NumP

//Later in a function
    
for( new 0sizeofprimary_weapons ); i++ )
    {
        
NumP random_num(0i)
        
        
        
AmmoNum primary_weapons[NumP][_Ammo]
        
        
give_item(idprimary_weapons[NumP][_WeaponName])
        
        
cs_set_user_bpammo(idprimary_weapons[NumP][_CSW], AmmoNum)

        
client_print(idprint_chat"You got %s"primary_weapons[NumP][_WeaponNameForChat])
    } 
And the weapon it gives me and that, which appears in chat are different...

EDIT: Yea, all of us make mistakes. I agree with the upper posts, just didn't get the idea and meaning of global var. Just an index and it saves, clear. Thank you, mostly nikko.
__________________

Last edited by Flick3rR; 05-20-2014 at 13:15.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 05-20-2014 , 17:37   Re: [HELP] Random num saving for another function
Reply With Quote #6

Quote:
Originally Posted by Flick3rR View Post
Do you think I didn't get it earlier? Would I make a thread if I didn't try the simplest thing at all. Hating all the time, anyways, right?
Here is an example, which doesn't work for me:
PHP Code:
//That's global
new NumP

//Later in a function
    
for( new 0sizeofprimary_weapons ); i++ )
    {
        
NumP random_num(0i)
        
        
        
AmmoNum primary_weapons[NumP][_Ammo]
        
        
give_item(idprimary_weapons[NumP][_WeaponName])
        
        
cs_set_user_bpammo(idprimary_weapons[NumP][_CSW], AmmoNum)

        
client_print(idprint_chat"You got %s"primary_weapons[NumP][_WeaponNameForChat])
    } 
And the weapon it gives me and that, which appears in chat are different...

EDIT: Yea, all of us make mistakes. I agree with the upper posts, just didn't get the idea and meaning of global var. Just an index and it saves, clear. Thank you, mostly nikko.
That will generate a random number every loop.
Don't need global for that.
__________________

Last edited by Black Rose; 05-20-2014 at 17:38.
Black Rose is offline
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 05-20-2014 , 19:35   Re: [HELP] Random num saving for another function
Reply With Quote #7

This is what I mean

PHP Code:
//That's global
new NumP


//When you decide to change random num
    
NumP = -//some random value not in 0 - i range (if you change it here, random num will be generated again, else will keep previous value)

//Later in a function
    
for( new 0sizeofprimary_weapons ); i++ )
    {
        if(!(
<= NumP <= i)) //if the value is out of the range
            
NumP random_num(0i//generate another random
        //else keep previous value :)
        
AmmoNum primary_weapons[NumP][_Ammo]
        
        
give_item(idprimary_weapons[NumP][_WeaponName])
        
        
cs_set_user_bpammo(idprimary_weapons[NumP][_CSW], AmmoNum)

        
client_print(idprint_chat"You got %s"primary_weapons[NumP][_WeaponNameForChat])
    } 
If I'm right, you are doing a loop with players, will be easier to put that loop inside this one so every one will get same item, unless you are using the random num in other function, then this code will help you
NikKOo31 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 05-21-2014 , 01:18   Re: [HELP] Random num saving for another function
Reply With Quote #8

Problem solved. Excuse that stupid question, wasn't me that night.... My brother is trying to write, making stupid threads all the forums, spamming the people's inboxes... Problem solved anyways, thanks! And now to change that password
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
Reply



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 19:37.


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