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;
}