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

random_num uncertainties


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 03-17-2020 , 06:47   random_num uncertainties
Reply With Quote #1

Hello,
I have some uncertainties about this piece of code:
PHP Code:
points_amount register_cvar("points_amount","5, 10");

new 
rand random_num(get_pcvar_num(points_amount)) 
I want to know if this code will return that integers(or if it need to be a float variable) and if I can use get_pcvar_num instead get_cvar_pointer.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 03-17-2020 at 06:48.
Shadows Adi is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 03-17-2020 , 07:25   Re: random_num uncertainties
Reply With Quote #2

That won't work, i've quickly written something else, it's untested though, but i think u should be doing it something like this

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new points_amount;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
points_amount register_cvar("point_amount""^"5^"^"10^"");
}

new 
szAmounts[32], iAmountsiRand
get_pcvar_string
(points_amountszAmountscharsmax(szAmounts));

remove_quotes(szAmounts);
iAmounts str_to_num(szAmounts);

iRand random(iAmounts); 
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 03-17-2020 , 07:37   Re: random_num uncertainties
Reply With Quote #3

Quote:
Originally Posted by Napoleon_be View Post
That won't work, i've quickly written something else, it's untested though, but i think u should be doing it something like this

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new points_amount;

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
points_amount register_cvar("point_amount""^"5^"^"10^"");
}

new 
szAmounts[32], iAmountsiRand
get_pcvar_string
(points_amountszAmountscharsmax(szAmounts));

remove_quotes(szAmounts);
iAmounts str_to_num(szAmounts);

iRand random(iAmounts); 
Thanks for help, buy I want an explaination too.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]
Shadows Adi is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 03-17-2020 , 07:40   Re: random_num uncertainties
Reply With Quote #4

What you're trying to do, is getting a random number between 5 and 10, in this case you're doing it wrong by doing follow things:

1) random_num() needs 2 arguments, and not just one.
2) Also your pcvar contains a "," which isn't a number, this will most likely throw an error.

If u want a random number to be picked from a cvar, you should be adding the numbers in the cvar without a "," but with quotes instead ("") like i'm doing it. Read the pcvar string, remove the quotes, convert it to an integer and get a random() integer out of it.

At least this is my theory, not sure if the code i provided will work though.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Natsheh
Veteran Member
Join Date: Sep 2012
Old 03-17-2020 , 10:16   Re: random_num uncertainties
Reply With Quote #5

It won't work
__________________
@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
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 03-17-2020 , 16:52   Re: random_num uncertainties
Reply With Quote #6

Why don't you just use two pcvars instead of writing harder codes in just one? I'll not make your PC explode. But whatever:

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

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

new pcvarRandomValues

public plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("print""printRandomValues")
    
pcvarRandomValues register_cvar("random_values""5 10")
}

public 
printRandomValues(id)
{
    new 
szPcvarRandomValues[10]
    
get_pcvar_string(pcvarRandomValuesszPcvarRandomValuescharsmax(szPcvarRandomValues))
    
    
console_print(id"---------- DEBUG INITIATION ----------")
    
console_print(id"- szPcvarRandomValues (value of the cvar): %s"szPcvarRandomValues)
    
    new 
szValues[2][10]
    
parse(szPcvarRandomValuesszValues[0], charsmax(szValues[]), szValues[1], charsmax(szValues[]))
    
    
// debug only
    
console_print(id"- szValues[0]: %s | szValues[1] (values parsed): %s"szValues[0], szValues[1])
     
    new 
iValues[2]
    
iValues[0] = str_to_num(szValues[0])
    
iValues[1] = str_to_num(szValues[1])
     
    
// debug only
    
console_print(id"- iValues[0]: %d | iValues[1]: %d"iValues[0], iValues[1])
    
console_print(id"- Random value between iValues[0] and iValues[1] (%d and %d): %d"iValues[0], iValues[1], random_num(iValues[0], iValues[1]))
    
console_print(id"---------- DEBUG ENDS ----------")

First of, we just registered the pcvar as usual, then, we got it's value with get_pcvar_string (since it's more than just one value). After, we just parsed it and then, changed it from string to interger. After it, just used random_num with both intergers.
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
Xalus
Veteran Member
Join Date: Dec 2009
Location: Belgium
Old 03-18-2020 , 11:49   Re: random_num uncertainties
Reply With Quote #7

PHP Code:
g_point_cvar register_cvar("points_amount","5 10")

new 
Float:points_random_float get_randomcvar_float(g_point_cvar)
new 
points_random floatroundget_randomcvar_float(g_point_cvar) )

get_randomcvar_float(cvar_id)
{
  static 
cvar_string[21]
  
get_pcvar_string(cvar_idcvar_stringcharsmax(cvar_string))

  if(
cvar_string[0])
  {
    new 
string_value1[10], string_value2[10]
    
strbreak(cvar_stringstring_value1charsmax(string_value1), string_value2charsmax(string_value2))

    return 
random_floatstr_to_float(string_value1), str_to_float(string_value2) )
  }
  return 
0.0

__________________
Retired.

Last edited by Xalus; 03-18-2020 at 11:57.
Xalus is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 03-23-2020 , 08:38   Re: random_num uncertainties
Reply With Quote #8

Quote:
Originally Posted by EFFx View Post
Why don't you just use two pcvars instead of writing harder codes in just one? I'll not make your PC explode. But whatever:

PHP Code:
    register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("print""printRandomValues")
    
pcvarRandomValues register_cvar("random_values""5 10") <<-- 
First of, we just registered the pcvar as usual, then, we got it's value with get_pcvar_string (since it's more than just one value). After, we just parsed it and then, changed it from string to interger. After it, just used random_num with both intergers.
That's what I wanted to know. Thanks all.
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 03-23-2020 at 08:38.
Shadows Adi 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 21:16.


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