AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   random_num (https://forums.alliedmods.net/showthread.php?t=236416)

bol 03-04-2014 15:03

random_num
 
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!

mapper07 03-04-2014 15:15

Re: random_num
 
Can you show that part of the code that you uses random_num?

bol 03-04-2014 15:27

Re: random_num
 
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);



georgik57 03-04-2014 17:48

Re: random_num
 
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


Black Rose 03-04-2014 18:26

Re: random_num
 
Quote:

Originally Posted by georgik57 (Post 2107553)
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.

fysiks 03-04-2014 20:56

Re: random_num
 
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.

bol 03-05-2014 20:04

Re: random_num
 
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.

fysiks 03-05-2014 20:21

Re: random_num
 
Quote:

Originally Posted by bol (Post 2108076)
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.

bol 03-05-2014 20:38

Re: random_num
 
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 03-05-2014 23:21

Re: random_num
 
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.


All times are GMT -4. The time now is 05:57.

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