AlliedModders

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

Willmaker 12-29-2005 22:07

Help with arrays
 
2 Attachment(s)
Im trying to create a plugin which can read and write to a file glow.cfg.
Ive managed to get it to read from the file, and everything was working then.

But now I want it to write to the glow.cfg, and I believe Ive made some huge mistakes somewhere, and as I dont have experience in this sort of thing, I really need help..

Code:
#include <amxmodx> #include <amxmisc> #include <engine> #include <fun> // For reference //set_user_rendering(id, Fx, R, G, B, Mode, Amount) //e_render (Mode, Amount, Fx, R, G, B) new szData[10][56], line=0,k=0, szLine[256],szFileName[128] public plugin_init(){     register_plugin("Glow Plugin", "0.3", "Willmaker")     register_cvar("amx_glow", "1" )     register_clcmd("say","renderglow") } public renderglow(id){     if (!get_cvar_num("amx_glow")){         client_print(id, print_chat, "[AMXX] Sorry, glow is disabled")         return PLUGIN_HANDLED     }     new args[64], arg[6], arg1[11], arg2[11], arg3[5], arg4[5], arg5[5], arg6[5], arg7[2], arg8[4], arg9[34], arg10[55], arg11[2]     read_args(args, 63)     remove_quotes(args)     trim(args)     parse(args, arg, 5, arg1, 10, arg2, 10, arg3, 4, arg4, 4, arg5, 4, arg6, 4, arg7, 1, arg8, 4, arg9, 33, arg10, 54, arg11, 1)         if (equali(arg, "/glow", 5)){ // Check first argument after the /say command         if (equali(arg1, "help")){             show_motd(id,"glowhelp.txt","Glow Help.")             return PLUGIN_HANDLED         }         if (equali(arg1, "off")){             set_user_rendering(id, 0, 0, 0, 0, 0, 0)             client_print(id,print_chat,"[AMXX] You have turned off glowing")             return PLUGIN_HANDLED         }         if (equali(arg1, "add")){             addglow(id)             return PLUGIN_HANDLED         }         get_configsdir(szFileName,127)         format(szFileName,127,"%s/glows.cfg",szFileName)         while( read_file(szFileName,line++,szLine,255,k)){             if((szLine[0] == ';') || !k) continue             if(!file_exists(szFileName)){                 log_amx("[AMXX] %s file not found, custom glows could not be loaded.",szFileName)                 return PLUGIN_CONTINUE             }             parse(szLine,szData[0],9,szData[1],3,szData[2],4,szData[3],4,szData[4],4,szData[5],2,szData[6],4,szData[7],36,szData[8],36,szData[9],2)             //szData[0] Shortname eg will .. (/glow will)             //szData[1] Fx             //szData[2] R             //szData[3] G             //szData[4] B             //szData[5] Mode             //szData[6] Amount             //szData[7] Steamid             //szData[8] Full name             //szData[9] Private = 1 Public = 0             new Fx1 = str_to_num(szData[1])             new R1 = str_to_num(szData[2])             new G1 = str_to_num(szData[3])             new B1 = str_to_num(szData[4])             new Mode1 = str_to_num(szData[5])             new Amount1 = str_to_num(szData[6])             log_amx("[AMXX Glows] If your reading this, its working so far")             if (equali(arg1, szData[0])){ // Find shortname                 if (str_to_num(szData[9]) == 1){ //Check if private                     new authid[32]                     get_user_authid(id,authid,31)                     if (equali(authid, szData[7])){ //Check if they have correct steamid                         client_print(id,print_chat,"[AMXX] Glow info for %s: %i, %i, %i, %i, %i, %i",szData[0],Fx1,R1,G1,B1,Mode1,Amount1)                         set_user_rendering(id, Fx1, R1, G1, B1, Mode1, Amount1)                         client_print(id,print_chat,"[AMXX] You are now glowing %s's private glow",szData[8])                         return PLUGIN_HANDLED                     }else{                         client_print(id,print_chat,"[AMXX] You are not allowed to use %s's private glow",szData[8])                         return PLUGIN_HANDLED                     }                 }else if(str_to_num(szData[9]) == 0){ // Glow is public, allow user                     client_print(id,print_chat,"[AMXX] Glow info for %s: %i, %i, %i, %i, %i, %i",szData[0],Fx1,R1,G1,B1,Mode1,Amount1)                     set_user_rendering(id, Fx1, R1, G1, B1, Mode1, Amount1)                     client_print(id,print_chat,"[AMXX] You are now glowing %s's public glow",szData[8])                     return PLUGIN_HANDLED                 }             }         }         new Fx = str_to_num(arg1)         new R = str_to_num(arg2)         new G = str_to_num(arg3)         new B = str_to_num(arg4)         new Mode = str_to_num(arg5)         new Amount = str_to_num(arg6)         if (Fx > 19 || Fx < 0){             client_print(id,print_chat,"[AMXX] Fx value is invalid")             return PLUGIN_HANDLED         }         if (R > 255 || R < 0){             client_print(id,print_chat,"[AMXX] Red value is invalid")             return PLUGIN_HANDLED         }         if (G > 255 || G < 0){             client_print(id,print_chat,"[AMXX] Green value is invalid")             return PLUGIN_HANDLED         }         if (B > 255 || B < 0){             client_print(id,print_chat,"[AMXX] Blue value is invalid")             return PLUGIN_HANDLED         }         if (Amount > 255 || Amount < 0){             client_print(id,print_chat,"[AMXX] Amount value is invalid")             return PLUGIN_HANDLED         }         if (Mode > 5 || Mode < 0 || Mode == 3){             client_print(id,print_chat,"[AMXX] Mode value is invalid")             return PLUGIN_HANDLED         }         set_user_rendering(id, Fx, R, G, B, Mode, Amount)         client_print(id,print_chat,"[AMXX] Your new glow info: Fx = %i, R = %i, G = %i, B = %i, Mode = %i, Amount = %i",Fx,R,G,B,Mode,Amount)     }     return PLUGIN_CONTINUE } public addglow(id){     new args[64], arg[6], arg1[11], arg2[11], arg3[5], arg4[5], arg5[5], arg6[5], arg7[2], arg8[4], arg9[34], arg10[55], arg11[2]     read_args(args, 63)     remove_quotes(args)     trim(args)     parse(args, arg, 5, arg1, 10, arg2, 10, arg3, 4, arg4, 4, arg5, 4, arg6, 4, arg7, 1, arg8, 4, arg9, 33, arg10, 54, arg11, 1)         new Fx2 = str_to_num(arg3)     new R2 = str_to_num(arg4)     new G2 = str_to_num(arg5)     new B2 = str_to_num(arg6)     new Mode2 = str_to_num(arg7)     new Amount2 = str_to_num(arg8)     new Private2 = str_to_num(arg11)         get_configsdir(szFileName,127)     format(szFileName,127,"%s/glows.cfg",szFileName)     while( read_file(szFileName,line++,szLine,255,k)){         if((szLine[0] == ';') || !k) continue         if(!file_exists(szFileName)){             log_amx("[AMXX] %s file not found, custom glows could not be loaded.",szFileName)             return PLUGIN_CONTINUE         }         parse(szLine,szData[0],9,szData[1],3,szData[2],4,szData[3],4,szData[4],4,szData[5],2,szData[6],4,szData[7],36,szData[8],36,szData[9],2)     }     if (equali(arg2, szData[0])){         log_amx("[AMXX] A glow with that name already exists - %s",szData[0])         return PLUGIN_HANDLED     }     write_file(szFileName, arg2, Fx2, R2, G2, B2, Mode2, Amount2, arg9, arg10, Private2)     log_amx("[AMXX] Glow '%s' has been successfully added", shortname2)     return PLUGIN_CONTINUE }

VEN 12-30-2005 04:01

Code:
public addglow(id){     new args[64], arg[6], arg1[11], arg2[11], arg3[5], arg4[5], arg5[5], arg6[5], arg7[2], arg8[4], arg9[34], arg10[55], arg11[2]
This function can't give you args of renderglow function.

You can make args global or send it as argument: addglow(id, args)

Then your
Code:
public addglow(id){
would looks as
Code:
public addglow(id, args[]){

Also i think you should increease args array size.

Fire-Wired 01-02-2006 00:57

This seems like my unreleased plugin that im working on still.
http://forums.alliedmods.net/showthread.php?t=14600

I didn't mind you rewritting the other snarkcafe plugins, but this is something that bothers me now.

Willmaker 01-02-2006 19:45

Both might do similar functions, but the coding is completely different. :wink:


All times are GMT -4. The time now is 15:56.

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