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

Solved [ H3LP ] Bits random num


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 10-01-2018 , 20:20   [ H3LP ] Bits random num
Reply With Quote #1

Hello, how I can return random num from a bits var?

Code:
new bitsRandom = (1 | 2 | 3); return bitsRandom (1, 2 or 3)
__________________









Last edited by CrazY.; 10-05-2018 at 15:24.
CrazY. is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-01-2018 , 22:14   Re: [ H3LP ] Bits random num
Reply With Quote #2

Code:
bitsRandom = 1<<random(3)
__________________

Last edited by fysiks; 10-01-2018 at 22:14.
fysiks is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-02-2018 , 02:33   Re: [ H3LP ] Bits random num
Reply With Quote #3

Or bitsRand = random_num(1,3)*2.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 10-02-2018 at 07:21.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-03-2018 , 06:20   Re: [ H3LP ] Bits random num
Reply With Quote #4

Explain what you're trying to do
__________________
Bugsy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 10-03-2018 , 07:43   Re: [ H3LP ] Bits random num
Reply With Quote #5

I'm trying to auto-detect fire animations of weapon models and then store it in a bits var to return a random sequence.
__________________









Last edited by CrazY.; 10-03-2018 at 07:55.
CrazY. is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-03-2018 , 07:56   Re: [ H3LP ] Bits random num
Reply With Quote #6

So there will be random bits set in a cell and you want to randomly get one of the set bits?

So for 0100 0101

You would want to return a random of 1<<0, 1<<2, or 1<<6 ?
__________________
Bugsy is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 10-03-2018 , 08:07   Re: [ H3LP ] Bits random num
Reply With Quote #7

Yes but not as an bit, as an cell instead, the same number I've stored. Example:

Code:
GetRandomPistol() {     const CSW_ALL_PISTOLS = (CSW_P228 | CSW_ELITE | CSW_FIVESEVEN | CSW_USP | CSW_GLOCK18 | CSW_DEAGLE);     // Return a random CSW_. Then, it can be CSW_P228, CSW_ELITE, CSW_FIVESEVEN, etc.     return RandomBitsCell(CSW_ALL_PISTOLS); }

Of course, in that example I can simply return random_num(CSW_P228, CSW_DEAGLE), but is not this I'm trying to achieve.
__________________









Last edited by CrazY.; 10-03-2018 at 08:07.
CrazY. is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 10-03-2018 , 08:29   Re: [ H3LP ] Bits random num
Reply With Quote #8

This is not a bitsum value CSW_P228 you need to shift it. 1<<CSW_P228
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-03-2018 , 08:45   Re: [ H3LP ] Bits random num
Reply With Quote #9

Thats basically what I was asking.

PHP Code:
new iWeapons = ( ( << CSW_AK47 ) | ( << CSW_M4A1 ) ); 
The resulting value will be a combination of all of the bits, so a number like 16332234, for example. Is this the value you are looking for, or the resulting value with only a random one of the 2 bits set?
__________________

Last edited by Bugsy; 10-03-2018 at 08:45.
Bugsy is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 10-03-2018 , 09:20   Re: [ H3LP ] Bits random num
Reply With Quote #10

Code:
AmILuckyBit(int Chance)
{
       return random_num(1, 100) <= Value;
}

for (new Index = 31; Index >= 0; Index--)
{
       if (Variable & (1 << Index) && AmILuckyBit(max(25, (Index * (32 - Index)) / 100)));
              return Index;
}
Min chance is 25
Max is 100
But better and faster would be just using arrays
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 10-03-2018 at 09:27.
Ghosted is offline
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 14:09.


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