AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   CFG and INI files (https://forums.alliedmods.net/showthread.php?t=3309)

[cTs] Strake*ROC* 07-03-2004 00:44

CFG and INI files
 
I am read tons of amx plugins, yet i still cant figgure out how to make a plugin to read a CFG or INI file!

Can anyone help me with the basics for making a plugin read a file?

Thanks,
[cTs] Strake*ROC*

kingpin 07-03-2004 00:55

u want to know how to read and write to one so like a kinda vault file maybe? or just a pre made cfg?

[cTs] Strake*ROC* 07-03-2004 01:00

i wana be able to make a plugin, that read an INI file,
for plugins like one i am working on, that tells clan members if they have been promoted or not to a new rank, so when they log on, it checks the INI file, and if their Steam ID is in the file, then it tells them GRATZ you been Promoted!

kingpin 07-03-2004 01:01

yeah but is it writeable from inside the server? becuase then its a vault type file thats what meant is it writeable from inside server or no?

[cTs] Strake*ROC* 07-03-2004 01:02

as in command like

amx_newpromo "steam ID"

?

No, i want it so i can write a file, and the server uses it...

the
Users.ini
and amx mod X

Dygear 07-03-2004 11:41

I want to read from an INI file, like a list of clan tags (ya know what i mean).

kingpin 07-03-2004 11:54

1 Attachment(s)
well I have been trying to write good examples of how u can use a cfg file but I think best would be if u see an actually example so without further ado here is a small place from Lud's map cvar plugin :
Code:
if(file_exists("addons/amxx/custom/map_cvars.txt") == 1){         new line = 0         new data[128]         new stextsize = 0         new type[4]         new map_or_lock[32]         new map_cvar[64]         new value[32]         log_message("[AMXX][MAPCVARS] Cvar exec / plugin pause-unpause begin")         while((line=read_file("addons/amxx/custom/map_cvars.txt",line,data,128,stextsize))!=0){             parse(data,type,4,map_or_lock,32,map_cvar,64,value,32)             if(equali(type,"M",1)){                 if(map_on == true){                     map_on = false                 }                 if( (equali(map_or_lock,ThisMap)) || (equali(map_or_lock,"*allmaps")) ){                     map_on = true                 }             }             else if(equali(type,"C",1)){                 if(map_on == true){                     copy(locked_cvar[inum_cvars],64,map_cvar)                     copy(locked_value[inum_cvars],32,value)                     if(equal(map_or_lock,"1"))                         locked_yn[inum_cvars] = 1                     if(cvar_exists(map_cvar)){                         server_cmd("%s %s",map_cvar,value)                         log_message("[AMXX][MAPCVARS] Executed:  %s %s",map_cvar,value)                         inum_cvars +=1                         if(inum_cvars >= 25){                             map_on = false                             log_message("[AMXX][MAPCVARS] Warning:   Limit of 25 special cvars reached.")                         }                     }else{                         invalid = 1                         log_message("[AMXX][MAPCVARS] Warning:   Cvar ^"%s^" does not exist.", map_cvar)                     }                 }             }             else if(equali(type,"P",1)){                 if(map_on == true){                     if(equali(map_or_lock,"P",1))                         do_pplugin(0,map_cvar)                     else if(equali(map_or_lock,"U",1))                         do_pplugin(1,map_cvar)                 }             }         }

just gotta let the plugin read specific "words/cvars" in the file and then place a

Dygear 07-03-2004 12:16

Luds huh, will I talk with him on a regular basis, everyday in fact, usefull isent he.

kingpin 07-03-2004 12:22

lol well im certain my views on Mr. lidman are well known. but yeah I generally refrence his plguin library when I need help.

Zor 07-03-2004 15:05

1 Attachment(s)
Ok I just threw this together and compiled it. The compile works but I'm not sure if it does:

Code:

/*
*        All rights reserved BlackWatch Clan
*        Author:                |BW|.Zor
*        Version:        0.1
*        Description:
*                Check an ini file for a user and tell them they are promoted
*/

#include <amxmodx>

//////////////////////////////////////////////
// Version Control
//
new AUTH[] = "|BW|.Zor"
new PLUGIN_NAME[] = "Promotion"
new VERSION[] = "0.1"
new ACCESS = ADMIN_LEVEL_A
//
//////////////////////////////////////////////

//////////////////////////////////////////////
// Globals
//
new fileName[] = "addons/amxx/custom/promotion.ini"
//
//////////////////////////////////////////////

public plugin_init()
{
        // Register the plugin
        register_plugin(PLUGIN_NAME,VERSION,AUTH)

        // Register the console commands
        register_concmd("amx_newpromo", "input", ACCESS, "- adds someone to the promotion list")
}

public client_putinserver(id)
{
        new steam[2][32], promotion[64], lineIn[96], counter = 0, a = 0, placeToRemove = 0
       
        get_user_authid(id, steam[0], 31)
       
        while( read_file(fileName, counter, lineIn, 95, a) != 0 )
        {
                // Parse the line out.  If you manually input a promotion make sure its at the
                //end of the file and looks like the following:
                // "STEAM_0:0:123456" "Killer"
               
                parse(lineIn, steam[1], 31, promotion, 63)
               
                // Are the 2 steam ids equal?
                if(equal(steam[0], steam[1]))
                {
                        client_print( id, print_console, "You have been promoted to %s, congrats, change your name!", promotion)
                        placeToRemove = counter
                }
               
                counter++       
        }
       
        // Remove that entry so It wont tell em again
        if( placeToRemove > 0)
        {
                counter = placeToRemove + 1
                while( read_file(fileName, counter++, lineIn, 95, a) != 0 )
                {
                        write_file(fileName, lineIn, placeToRemove++)
                }
               
                write_file(fileName, "", counter)
        }
       
        return PLUGIN_CONTINUE
}

public input(id)
{
        if(read_argc() < 2)
        {
                client_print(id, print_console, "[AMXX] Usage: amx_newpromo STEAM_0:0:123456 PromotionName")
                return PLUGIN_HANDLED
        }
       
        new fileLength = file_size(fileName, 1)
        new command[2][64], temp[128]
        read_argv(1, command[0], 63)
        read_argv(2, command[1], 63)
       

        format(temp, 127, "^"%s^" ^"%s^"", command[0], command[1])
        write_file(fileName, temp, fileLength)
       
        return PLUGIN_CONTINUE
}

Cheers! And good luck with it!
Zor


All times are GMT -4. The time now is 14:57.

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