AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how to set one id (https://forums.alliedmods.net/showthread.php?t=243560)

Porta0123 07-06-2014 10:19

how to set one id
 
hi, i have one problem...

i have this:
Code:
new Cname[33] //class name new Cdesc[33] //class description new Cexpe[33] //class xp new Cvida[33] //clas live new Cchal[33] //class armour
and i every one need have one id, the id of this class

in =
Code:
public native_register_class(const class_name[],const class_desc[],const xp,const live,const armour) {  //here set the id of the class and save in a new "Cid"(class id) and the Cname[Cid] (Cname of the class id) etc... }

and i have the problem of the ID of the class and the problem in Cname[Cid] = class_name

i want to do this =
Cname[Cid][] = "here the text of class_name in the native"

Black Rose 07-06-2014 10:47

Re: how to set one id
 
Either you hardcode it.
Code:
#define MAX_CLASSES 5 new Cname[MAX_CLASSES][33] //class name copy(Cname[Cid], sizeof Cname[] - 1, class_name);

Or you look into dynamic arrays.

Bos93 07-06-2014 15:58

Re: how to set one id
 
For strings, use param_convert

PHP Code:

public native_register_class(const class_name[],const class_desc[],const xp,const live,const armour)
{
    
param_convert);    
    
param_convert);    
    
param_convert);    
    
    
Cname class_name;
    
etc..



Porta0123 07-06-2014 16:47

Re: how to set one id
 
eh...

Code:
#define MAX_CLASSES 50 new Cid new Cname[MAX_CLASSES][33] new Cdesc[MAX_CLASSES][33] new Cexpe[33] new Cvida[33] new Cchal[33] public native_neo_register_class(const clase_name[], const clase_descripcion[],clase_experiencia,clase_vida, clase_chaleco) {     copy(Cname[Cid],sizeof Cname[] - 1,clase_name)     copy(Cdesc[Cid],sizeof Cdesc[] - 1,clase_descripcion)     Cexpe[Cid] = clase_experiencia     Cvida[Cid] = clase_vida     Cchal[Cid] = clase_chaleco }
this? ...

and the last i dont understend xD

Black Rose 07-06-2014 22:15

Re: how to set one id
 
When using register_native() with style set to 1, you have to use param_convert() to be able to read the strings.
I don't know the technical reason of it.
You need to index all of the variables. Cexpe, Cvida, Cchal as well assuming they are unique to each class. However you don't have to create a second dimension of 33 since they're not arrays.

Porta0123 07-07-2014 08:24

Re: how to set one id
 
Code:
new Cname[MAX_CLASSES] new Cdesc[MAX_CLASSES] new Cexpe[MAX_CLASSES] new Cvida[MAX_CLASSES] new Cchal[MAX_CLASSES] public native_neo_register_class(const clase_name[], const clase_descripcion[],clase_experiencia,clase_vida, clase_chaleco) {     param_convert(1);     param_convert(2);     copy(Cname,sizeof Cname[] - 1,clase_name)     copy(Cdesc,sizeof Cdesc[] - 1,clase_descripcion)     Cexpe[MAX_CLASSES-1]= clase_experiencia     Cvida[MAX_CLASSES-1] = clase_vida     Cchal[MAX_CLASSES-1] = clase_chaleco }

like this?

Black Rose 07-07-2014 16:32

Re: how to set one id
 
Re-add the [33] to Cname and Cdec since those are strings.

You have to define which class index of Cname and Cdesc that has to be written to.

MAX_CLASSES-1 will always remain the same meaning you will overwrite every time you use this native. I'm guessing you don't want that. You need global/static variable that is increasing at the end of this native.

Porta0123 07-08-2014 08:53

Re: how to set one id
 
yes... i want do the same than Cod-Mod and ZP...

1) get all .amxx in "classes.ini"
2) with one menu open the .amxx
etc...

but i donw know how...

maybe... this?

Code:
new Cname[MAX_CLASSES][33] new Cdesc[MAX_CLASSES][33] new Cexpe[MAX_CLASSES] new Cvida[MAX_CLASSES] new Cchal[MAX_CLASSES] new theid public native_neo_register_class(const clase_name[], const clase_descripcion[],clase_experiencia,clase_vida, clase_chaleco) {     param_convert(1);     param_convert(2);     copy(Cname[theid],sizeof Cname[] - 1,clase_name)     copy(Cdesc[theid],sizeof Cdesc[] - 1,clase_descripcion)     Cexpe[theid]= clase_experiencia     Cvida[theid] = clase_vida     Cchal[theid] = clase_chaleco     theid++ }

Black Rose 07-08-2014 12:23

Re: how to set one id
 
That code looks good. Didn't understand 1 & 2.

Porta0123 07-08-2014 14:39

Re: how to set one id
 
i want do the same than Cod-Mod ...

its register the plugin whitout add it in plugins.ini
this will works?
Code:
public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR)     //registrar clases     new Path[256];     get_configsdir(Path, charsmax(Path));     formatex(Path, charsmax(Path),"%s/%s", Path, gFileName);         if(!file_exists(Path))     {         client_print(0, print_chat, "[NeoDeathMatch] El archivo %s no existe", gFileName);         return PLUGIN_HANDLED;     }             new f = fopen(Path, "rt");             new iName[ITEMSLEN+1];       new Item;           while(!feof(f))     {         fgets(f, iName, charsmax(iName));                 if(!iName[0] || iName[0] == ';'         || iName[0] == '/' && iName[1] == '/' ) continue;                   copy(gItems[Item], charsmax(gItems), iName);           Item++;                                                         if(Item >= Cid) break;                 new plugin_id = find_plugin_byfile(iName) // Tira -1 si no lo encuentra.         new forwards_id, null_id;         if( plugin_id == INVALID_PLUGIN_ID )         {                         return log_error(AMX_ERR_NOTFOUND, "Plugin no encontrado")         }         else         {             forwards_id = CreateOneForward(plugin_id, "plugin_init", FP_CELL, FP_STRING)                         if( forwards_id < 0 )             {                 return log_error(AMX_ERR_NATIVE, "Error Creando Forward")             }             else             {             if( !ExecuteForward(forwards_id, null_id) )             {                 return log_error(AMX_ERR_NATIVE, "Error executando Forward")             }             else             {                 DestroyForward(forwards_id);             }             }         }         return 1                 }     fclose(f);     return 1 }


All times are GMT -4. The time now is 21:07.

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