Raised This Month: $32 Target: $400
 8% 

variable


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
amxxn00b
Junior Member
Join Date: Nov 2006
Old 02-13-2007 , 10:21   variable
Reply With Quote #1

Hi all...

How to set value for variable from other *.amxx ?

For ex. I have:

1.sma:

PHP Code:
#include <amxmodx>
 
new test[32]
 
public 
plugin_init () {
  
register_clcmd("set test","SetTest")
}
 
public 
SetTest(id) {
  new 
arg[8]; read_args(arg,7)
  
format(test,31,arg)
  return 
1

2.sma:

PHP Code:
#include <amxmodx>
 
public plugin_init(){
  
register_clcmd("say test?","CurTest")
}
 
public 
CurTest(id) {
  
client_print (id,print_chat,"Current value for 'test' is: %s",test)
  return 
1

How to make it?
amxxn00b is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 02-13-2007 , 10:33   Re: variable
Reply With Quote #2

cvars.

EDIT:
Code:
#include <amxmodx> public plugin_init () {     register_clcmd("set test", "SetTest")     register_cvar("variable_test", "", FCVAR_SPONLY) } public SetTest(id) {     new arg[8]; read_args(arg,7)     set_cvar_string("variable_test", arg)     return 1 }
Code:
#include <amxmodx> public plugin_init() {     register_clcmd("say test?", "CurTest") } public CurTest(id) {     new test[32]     get_cvar_string("variable_test", test, 31)     client_print (id,print_chat,"Current value for 'test' is: %s", test)     return 1 }

Last edited by [ --<-@ ] Black Rose; 02-13-2007 at 10:52.
[ --<-@ ] Black Rose is offline
amxxn00b
Junior Member
Join Date: Nov 2006
Old 02-13-2007 , 12:08   Re: variable
Reply With Quote #3

Very big thank you man!

But if I have array
new test[5]
test[0] = 1
test[1] = 2 etc
client_print(id,print_chat,test[0]); client_print(id,print_chat,test[1]) etc
...how this make?

it will many args:'i' test[i]...

Last edited by amxxn00b; 02-13-2007 at 12:12.
amxxn00b is offline
[ --<-@ ] Black Rose
ANNIHILATED
Join Date: Sep 2005
Location: Stockholm, Sweden.
Old 02-13-2007 , 14:50   Re: variable
Reply With Quote #4

you could make some kinda break char and break the string to 5 arrays or something.

string[] = "lol|w/e|and so on|forever"
And break them at that '|' to separate them.



EDIT:
For example you have this string
Code:
new string[] = "lol|lol2k|wazza"
you want to separate them using | as a separator. then you do this.
Code:
#include <amxmodx> public func() {         new output[5][10] // 5 strings with len 9.         new string[] = "lol|lol2k|wazza"         explode(string, output, 9, '|')     } /* The last arg is to detect how big the output array is. AFAIK this is the only way to do that ( automaticly ). Of course you can still change it if you for some reason just want the first four or five inputs. */ stock explode(const input[], output[][], const len, const delim, const arraysize=sizeof output) {         new pos, cur, len2, maxlen = strlen(input)         while ( pos < maxlen && cur < arraysize && len2 < len ) {                 if ( input[pos] != delim ) {             output[cur][len2] = input[pos]             len2++         }         else if ( strlen(output[cur]) ) {             cur++             len2 = 0         }         pos++     }         return cur }
Output would be:
Code:
output[0] = "lol" output[1] = "lol2k" output[2] = "wazza"
And the function returns the number of strings separated.

Last edited by [ --<-@ ] Black Rose; 02-13-2007 at 17:36.
[ --<-@ ] Black Rose is offline
amxxn00b
Junior Member
Join Date: Nov 2006
Old 03-15-2007 , 02:15   Re: variable
Reply With Quote #5

I Have file with text:
195.58.237.246
62.221.39.111

plug read this and function explode():
PHP Code:
new banned_ip[100][32]
new 
banned_ip_num 0
new ipFile[64] = "addons/amxmodx/configs/bannedips/ips.dat"
public plugin_init () { AddIP (); register_srvcmd("aa","aa");}
 
public 
aa() {
for (new 
1;<=banned_ip_numi++) {
new 
ips[4][32]
explode(banned_ip[i],ips,31,'.')
server_print ("%s:%s:%s:%s",ips[0],ips[1],ips[2],ips[3])
}
}
 
AddIP () {
new 
text[32], line 0unk
while (read_file(ipFile,line++,text,31,unk)) {
banned_ip_num++
format (banned_ip[banned_ip_num],31,text)
}

server printed:
195:58:237:246
625:22197:111

Last edited by amxxn00b; 03-15-2007 at 05:57.
amxxn00b is offline
amxxn00b
Junior Member
Join Date: Nov 2006
Old 03-15-2007 , 09:08   Re: variable
Reply With Quote #6

I dont know why it work os, but I fix it

Code:
 
stock explode(const input[], output[][], const len, const delim, const arraysize=sizeof output) {
 
new pos, cur, len2, maxlen = strlen(input)
while ( pos < maxlen && cur < arraysize && len2 < len ) {
 
if ( input[pos] != delim ) {
new temp[2] = ""
output[cur][len2] = input[pos]
output[cur][len2+1] = temp[1]
len2++
}
else if ( input[pos] == delim ) {
cur++
len2 = 0
}
pos++
}
 
return cur
}
amxxn00b is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 03-16-2007 , 06:09   Re: variable
Reply With Quote #7

Quote:
cvars
Not really a good solution for a plugin<->plugin communitaction. CVars is for configuring not for storing a data. So i'd say "dynamic natives", also an obsolete way is "xvars".
VEN 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 01:16.


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