Raised This Month: $ Target: $400
 0% 

random_num


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bol
Member
Join Date: Feb 2014
Old 03-04-2014 , 15:03   random_num
Reply With Quote #1

Hello,

I was wondering is there any known bugs with using random_num ?
had set it to random_num( 2, 12) yet sometimes 20 comes up. :S

If there are known problems how about alternatives?
random_float wont work, however it is used on another part of the code which is unrelated.

Ty!
bol is offline
mapper07
Member
Join Date: Oct 2012
Location: NY
Old 03-04-2014 , 15:15   Re: random_num
Reply With Quote #2

Can you show that part of the code that you uses random_num?
mapper07 is offline
bol
Member
Join Date: Feb 2014
Old 03-04-2014 , 15:27   Re: random_num
Reply With Quote #3

Certainly

PHP Code:
#include <amxmodx> 
#include <amxmisc>
#include <engine>

new bool:g_zbDeathScreenShotTaken[33];
new 
g_Eagstart
new 
gzDeaths[33];

#define SCREENSHOT_PER_DEATHS random_num( 2, 12)

public plugin_init() 

register_event("DeathMsg" "Event_DeathMsg" "a");
}
public 
Event_DeathMsg() 

    new 
id read_data(2
    if ( !
g_zbDeathScreenShotTaken[id] && ! (++gzDeaths[id] % SCREENSHOT_PER_DEATHS) ) 
    if(
get_pcvar_num(g_Eagstart) == 1
    { 
    
get_screen(id);
    
g_zbDeathScreenShotTaken[id] = true
    


public 
get_screen(id
{
    
query_client_cvarid "net_graph" "get_netgraph" );
    return 
PLUGIN_CONTINUE;
}
public 
get_netgraphid , const cvar[], const snetValue[])
{
    
client_cmd(id"net_graph 3"); 
    
info(id)
    
client_cmd(id"hud_timer 3;wait;wait;wait;wait;snapshot"
    
client_cmd(id"net_graph %s" snetValue );
    
client_cmd(id"hud_timer 1"
}  
public 
info(id
{
    
get_user_name(idszName31);
    
get_user_authididszCID31 );
    
get_user_ipidszIP29);
    
set_hudmessage(70130180, -1.00.8806.06.00.00.2, -1);  
    
show_hudmessage(id"%s ^n %s %s Snapshot taken ^n Users IP: %s"szTimedataszNameszCIDszIP);


Last edited by bol; 03-04-2014 at 15:31.
bol is offline
georgik57
Veteran Member
Join Date: Oct 2008
Location: 🎧Music World
Old 03-04-2014 , 17:48   Re: random_num
Reply With Quote #4

PHP Code:
#define SCREENSHOT_PER_DEATHS random_num(2, 12) 
->
PHP Code:
const SCREENSHOT_PER_DEATHS random_num(212
or(for float)
PHP Code:
const Float:SCREENSHOT_PER_DEATHS random_float(2.012.0
__________________

Last edited by georgik57; 03-04-2014 at 17:49.
georgik57 is offline
Send a message via MSN to georgik57 Send a message via Yahoo to georgik57 Send a message via Skype™ to georgik57
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 03-04-2014 , 18:26   Re: random_num
Reply With Quote #5

Quote:
Originally Posted by georgik57 View Post
PHP Code:
#define SCREENSHOT_PER_DEATHS random_num(2, 12) 
->
PHP Code:
const SCREENSHOT_PER_DEATHS random_num(212
or(for float)
PHP Code:
const Float:SCREENSHOT_PER_DEATHS random_float(2.012.0
Try to compile the first one and the second one just won't work.

Code:
#include <amxmodx> #define SCREENSHOT_PER_DEATHS random_num(2, 12) public plugin_init() {     register_plugin("Test Plugin 1", "", "[ --{-@ ]");         new Timer = tickcount();     new count, problems;         for ( new i ; i < 2147483647 ; i++ ) {                 if ( ! ( 0 <= ( i % SCREENSHOT_PER_DEATHS ) <= 11 ) )             problems++;                 count++     }         Timer = tickcount() - Timer;         server_print("Done. %d loops, %d problems occurred and it all took %d minutes, %d seconds and %d milliseconds.", count, problems, Timer / 60000, Timer % 60000 / 1000, Timer % 1000 ); }

Code:
Done. 2147483647 loops, 0 problems occurred and it all took 3 minutes, 22 seconds and 152 milliseconds.
__________________

Last edited by Black Rose; 03-04-2014 at 19:13.
Black Rose is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-04-2014 , 20:56   Re: random_num
Reply With Quote #6

I don't know of any bugs with random_num(). Why do you think it is giving you 20? If I had to guess, you don't know what the % operator does.
__________________

Last edited by fysiks; 03-04-2014 at 20:57.
fysiks is offline
bol
Member
Join Date: Feb 2014
Old 03-05-2014 , 20:04   Re: random_num
Reply With Quote #7

Ty! Black Rose for testing.

Quote:
Done. 2147483647 loops, 0 problems occurred and it all took 2 minutes, 50 seconds and 765 milliseconds.
fysiks is right I dont know what the % operator does thought it divides.
How can I make it work so that it takes a deathshot randomly between 2 - 12?
It doesn't have to be specifically between these two numbers as long as it randomly gets taken within the first couple of deaths.
bol is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 03-05-2014 , 20:21   Re: random_num
Reply With Quote #8

Quote:
Originally Posted by bol View Post
Ty! Black Rose for testing.

fysiks is right I dont know what the % operator does thought it divides.
How can I make it work so that it takes a deathshot randomly between 2 - 12?
It doesn't have to be specifically between these two numbers as long as it randomly gets taken within the first couple of deaths.
% is the modulo operator. It gives you the remainder of integer division.
__________________
fysiks is offline
bol
Member
Join Date: Feb 2014
Old 03-05-2014 , 20:38   Re: random_num
Reply With Quote #9

I will read that.
Do you know why it sometimes takes a deathshot at 20 deaths?
It happened 3 times however am unable to reproduce this situation.
bol is offline
bol
Member
Join Date: Feb 2014
Old 03-05-2014 , 23:21   Re: random_num
Reply With Quote #10

Oke after reading I understand the code a lot better.
Decided to go with
PHP Code:
#define SCREENSHOT_PER_DEATHS random_num( 2, 4) 
The likelyhood of a screenshot being taken at 4 & 6 is high (2/3)
Nomatter for how long it could tackle on at 12 deaths it is certain there will be a deathshot.
bol 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 05:57.


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