Raised This Month: $ Target: $400
 0% 

random_num error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
timmiesgubbe
Member
Join Date: Oct 2012
Location: Sweden
Old 09-16-2013 , 02:25   random_num error
Reply With Quote #1

How i putt
Code:
new Num = random_num(10, 30)
in global
Code:
/* Plugin generated by AMXX-Studio */ #include <amxmodx> #include <amxmisc> #include <ColorChat> #define PLUGIN "New Plug-In" #define VERSION "1.0" #define AUTHOR "Timmie" Line 11 :new Num = random_num(10, 30) //Error: Must be a constant expression; assumed zero on line 11 public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR) } public Number1(id) {     ColorChat(id, GREY, "Random Num: %i", Num); } public Number2(id) {     ColorChat(id, GREY, "Random Num: %i", Num); } public Number3(id) {     ColorChat(id, GREY, "Random Num: %i", Num); }

Last edited by timmiesgubbe; 09-16-2013 at 02:31.
timmiesgubbe is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 09-16-2013 , 03:34   Re: random_num error
Reply With Quote #2

Because natives must be executed inside a function / forward. eg. Inside plugin_init()
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
timmiesgubbe
Member
Join Date: Oct 2012
Location: Sweden
Old 09-16-2013 , 03:41   Re: random_num error
Reply With Quote #3

Quote:
Originally Posted by hornet View Post
Because natives must be executed inside a function / forward. eg. Inside plugin_init()
ok
timmiesgubbe is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 09-16-2013 , 08:55   Re: random_num error
Reply With Quote #4

Quote:
Originally Posted by timmiesgubbe View Post
ok
public iNum = random_num(X,X);
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Old 09-16-2013, 10:25
LordOfNothing
This message has been deleted by ConnorMcLeod. Reason: troll, or posting random confusing code, or posting for posts count
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 09-16-2013 , 16:40   Re: random_num error
Reply With Quote #5

Quote:
Originally Posted by LordOfNothing View Post
PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <ColorChat> 

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

 
public plugin_init() { 
register_plugin(PLUGINVERSIONAUTHOR)

 }

 public 
Number1(id) {
new 
Num random_num(1030
ColorChat(idGREY"Random Num: %i"Num); 



You can use a native outside of function...
same as public iNum = random_num(X,X);
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-16-2013 , 16:44   Re: random_num error
Reply With Quote #6

Quote:
Originally Posted by ^SmileY View Post
public iNum = random_num(X,X);
Quote:
Originally Posted by LordOfNothing View Post
PHP Code:
#include <amxmodx> 
#include <amxmisc> 
#include <ColorChat> 

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

 
public plugin_init() { 
register_plugin(PLUGINVERSIONAUTHOR)

 }

 public 
Number1(id) {
new 
Num random_num(1030
ColorChat(idGREY"Random Num: %i"Num); 



You can use a native outside of function...
Don't worry guys. You're both wrong.



This example will give a random value to g_num ONE TIME and will not change unless you change it.
Code:
#include <amxmodx> new g_num; public plugin_init() {     register_plugin("Test Plugin 7", "", "");     g_num = random_num(10, 30);         whatever();     whatever2(); } whatever() {     server_print("num first time: %d", g_num); } whatever2() {     server_print("num second time: %d", g_num); }
Code:
num first time: 16
num second time: 16
If you want a random number every time you'll have to do this:
Code:
#include <amxmodx> public plugin_init() {     register_plugin("Test Plugin 7", "", "");         whatever();     whatever2(); } whatever() {     server_print("num first time: %d", random_num(10, 30)); } whatever2() {     server_print("num second time: %d", random_num(10, 30)); }
Code:
num first time: 29
num second time: 12
__________________

Last edited by Black Rose; 09-16-2013 at 16:45.
Black Rose 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 18:53.


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