AlliedModders

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

amxxn00b 02-13-2007 10:21

variable
 
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?

[ --<-@ ] Black Rose 02-13-2007 10:33

Re: variable
 
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 }

amxxn00b 02-13-2007 12:08

Re: variable
 
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]...

[ --<-@ ] Black Rose 02-13-2007 14:50

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

amxxn00b 03-15-2007 02:15

Re: variable
 
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:221:397:111

amxxn00b 03-15-2007 09:08

Re: variable
 
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
}


VEN 03-16-2007 06:09

Re: variable
 
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".


All times are GMT -4. The time now is 20:16.

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