Raised This Month: $ Target: $400
 0% 

[Request] Reading stuff from a file


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Mythic
Junior Member
Join Date: Apr 2009
Old 04-15-2009 , 01:48   [Request] Reading stuff from a file
Reply With Quote #1

How would I read a file, such as stuff.ini, then assign variables in an array based on section.

kinda like

if the file was:

[Section#1]
Stuff=fef
[Section#2]
Stuff=lol

it would assign variables like
GetStuff[0] = "fef"
GetStuff[1] = "lol"

All my previous attempts have miserably failed, it would randomly cut parts of the variable off and crap.

Last edited by Mythic; 04-15-2009 at 03:44.
Mythic is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-15-2009 , 06:15   Re: [Request] Reading stuff from a file
Reply With Quote #2

See csdm_main.sma ( CSDM ). Though, you can't assign variables like you does since the value is a string.
Arkshine is offline
Mythic
Junior Member
Join Date: Apr 2009
Old 04-15-2009 , 14:22   Re: [Request] Reading stuff from a file
Reply With Quote #3

if your referring to this, https://forums.alliedmods.net/showpo...13&postcount=2 then it isn't what i'm looking for because it doesn't even read from a file, but thanks anyways
Mythic is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-15-2009 , 15:30   Re: [Request] Reading stuff from a file
Reply With Quote #4

I'm talking about CSDM ( see the forum above ), the main plugin is called 'csdm_main.sma' ; the config file of CSDM used a similar syntax, that's why I say you to take a look into the source.
Arkshine is offline
Mythic
Junior Member
Join Date: Apr 2009
Old 04-15-2009 , 16:13   Re: [Request] Reading stuff from a file
Reply With Quote #5

I see what you mean, however I don't think CSDM has its source available anywhere, so I still don't know how I would read the strings and add them to variables >.<
Mythic is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 04-15-2009 , 16:29   Re: [Request] Reading stuff from a file
Reply With Quote #6

-_-

Official forum, just below : http://forums.alliedmods.net/forumdisplay.php?f=87
Official site, http://bailopan.net/csdm/

You are blind. :p
Arkshine is offline
Mythic
Junior Member
Join Date: Apr 2009
Old 04-15-2009 , 16:34   Re: [Request] Reading stuff from a file
Reply With Quote #7

Oh, I really am!

I only saw this the 2nd time I looked over his site.

All Source Code:
Mythic is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 04-15-2009 , 16:39   Re: [Request] Reading stuff from a file
Reply With Quote #8

The source code is available to download.
Just download the regular .zip file for installation and look in the addons/amxmodx/scripting folder.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Mythic
Junior Member
Join Date: Apr 2009
Old 04-15-2009 , 18:30   Re: [Request] Reading stuff from a file
Reply With Quote #9

I don't get this, if you do the new getServerAddress[8] inside of the function, it works, if you don't it overlaps the variables a couple times.... sorry for the really shitty look, I was trying to figure out why it wasn't working so it's all messy and such.

I also wanted to make a new cmd, amx_servermove, it moves a user to a server, like, amx_servermove UID OR NICK, 2 (for server 2), but i haven't gotten this far, cuz i can't even get it to load the servers correctly.

This is the first time i've ever done anything for amx and i only started yesterday, so don't hate too much. :S

Quote:
Originally Posted by ansa_servers_list.ini
[Server#1]
name=1asdfasdf
address=127.0.0.1:27015

[Server#2]
name=2asdfasdf
address=127.0.0.1:27016

[Server#3]
name=3asdfasdf
address=127.0.0.1:27017
Code:
#include <amxmodx>
#include <amxmisc>

// Saves Server Name
new getServerName[8];

// Saves Server IP & Port
new getServerAddress[8];

// Server Counter


public plugin_init() {
    load_servers()
    register_clcmd("say_team /servers","ServerMenu");
    register_clcmd("say /servers","ServerMenu");
    register_clcmd("say_team /server","ServerMenu");
    register_clcmd("say /server","ServerMenu");
}

public ServerMenu(id) {
    new menu = menu_create("Server Menu:", "ServerMenu_handler");
    new MenuCounter = 0;
    while(MenuCounter <= 2) {
        menu_additem(menu, getServerName[MenuCounter], "1", 0);
        MenuCounter++
    }
    //menu_additem(menu, "1: ANSA-Gaming.com | Dust2/Inferno", "1", 0);
    //menu_additem(menu, "2: ANSA-Gaming.com | Assault Addicts", "2", 0);
    //menu_additem(menu, "3: ANSA-Gaming.com | Zombie MADNESS", "3", 0);
    menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
    menu_display(id, menu, 0);
}

public ServerMenu_handler(id, menu, item) {
    if( item == MENU_EXIT ) {
        menu_destroy(menu);
        return PLUGIN_HANDLED;
    }
    
    new data[6], iName[64];
    new access, callback;
    menu_item_getinfo(menu, item, access, data,5, iName, 63, callback);

    new key = str_to_num(data);
    switch(key)
    {
        case 1:
        {
            client_cmd(id, "say .../%s : %s.../%s : %s.../%s : %s.../%s : %s.../%s : %s", getServerName[0], getServerAddress[0], getServerName[1], getServerAddress[1], getServerName[2], getServerAddress[2], getServerName[3], getServerAddress[3], getServerName[4], getServerAddress[4]);
            //client_cmd(id, "connect 125.214.70.100:27015");
        }
        case 2:
        {
            client_cmd(id, "connect 125.214.70.100:27016");
        }
        case 3:
        {
            client_cmd(id, "connect 125.214.70.100:27017");
        }
    }

    menu_destroy(menu);
    return PLUGIN_HANDLED;
}

public bool:load_servers() {
    new szFile[256];
    get_configsdir(szFile,255);
    format(szFile,255,"%s/ansa_servers_list.ini",szFile);

    new nFilePos = 0;
    new sFileLine[256];
    new nReadLen;
    
    new sKey[256];
    new sValue[256];
    
    new nCurrentServer = -1;
    
    while (read_file(szFile, nFilePos++, sFileLine, sizeof(sFileLine), nReadLen)) {
        if ((sFileLine[0] == ';') && (strcmp(sFileLine, "") == 0)) continue;

        if ((sFileLine[0] == '[') && (sFileLine[strlen(sFileLine) - 1] == ']'))    {
            nCurrentServer++
            continue;
        }

        if (nCurrentServer >= 0) {
            strtok(sFileLine, sKey, 255, sValue, 255, '=', 1);
            if (strcmp(sKey, "name") == 0) {
                copy(getServerName[nCurrentServer], strlen(sValue), sValue);
                continue;
            }
            if (strcmp(sKey, "address") == 0) {
                copy(getServerAddress[nCurrentServer], strlen(sValue), sValue);
                continue;
            }
        }
    }
    if (nCurrentServer < 0) {
        return false;
    }
    
    return true;
}

Last edited by Mythic; 04-15-2009 at 18:44.
Mythic 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 19:13.


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