Raised This Month: $ Target: $400
 0% 

Hostname changer.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
.OM NOM NOM NOM
BANNED
Join Date: Dec 2009
Old 12-31-2009 , 05:36   Hostname changer.
Reply With Quote #1

Evening, would any of you kind gentelmen add a shuffle mode to this code?
I'll give you 's in return.


Code:
#include <amxmodx>
#include <amxmisc>
#define Plugin "Server Name Changer"
#define Version "1.0"
#define Author "Doombringer"
new time_to_change
new const name_file[] = "server_names.ini"
new server_names[100][180], num_of_names, current_name
public plugin_init()
{
register_plugin(Plugin, Version, Author)
time_to_change = register_cvar("NC_change_time", "120")

read_names()
set_task(get_pcvar_float(time_to_change), "change_name",_,_,_, "b")
}
public read_names()
{
new configsdir[64], dir[132]
get_configsdir(configsdir, 63)

format(dir, 131, "%s/%s", configsdir, name_file)
new file = fopen(dir, "rt")

if(!file)
{
server_print("Could not find the %s file", name_file)
return PLUGIN_CONTINUE
}

new text[180]

while(!feof(file))
{
fgets(file, text, 179)

if( (strlen(text) < 2) || (equal(text, "//", 2)) )
continue;

num_of_names++
server_names[num_of_names] = text

server_print("%s", server_names[num_of_names])
}

fclose(file)
server_print("Successfully added %d server names", num_of_names)

return PLUGIN_CONTINUE
}
public change_name()
{
if(current_name + 1 > num_of_names)
current_name = 0

current_name++
server_cmd("hostname ^"%s^"", server_names[current_name])
}
.OM NOM NOM NOM is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-31-2009 , 19:41   Re: Hostname changer.
Reply With Quote #2

Names should be random. (same name can be used twice in a row) Fixed a flaw in the usage of num_of_names. Also, fixed the incorrect of assigning a string.

PHP Code:
#include <amxmodx>
#include <amxmisc>

#define Plugin "Server Name Changer"
#define Version "1.0"
#define Author "Doombringer"

new time_to_change
new const name_file[] = "server_names.ini"
new server_names[100][180], num_of_namescurrent_name

public plugin_init()
{
    
register_plugin(PluginVersionAuthor)
    
time_to_change register_cvar("NC_change_time""120")

    
read_names()
    
set_task(get_pcvar_float(time_to_change), "change_name",_,_,_"b")
}

public 
read_names()
{
    new 
configsdir[64], dir[132]
    
get_configsdir(configsdir63)

    
format(dir131"%s/%s"configsdirname_file)
    new 
file fopen(dir"rt")

    if(!
file)
    {
        
server_print("Could not find the %s file"name_file)
        return 
PLUGIN_CONTINUE
    
}
    new 
text[180]
    
num_of_names 0
    
    
while(!feof(file))
    {
        
fgets(filetext179)

        if( (
strlen(text) < 2) || (equal(text"//"2)) )
            continue;

        
copy(server_names[num_of_names], charsmax(server_names[]), text)

        
server_print("%s"server_names[num_of_names])
        
num_of_names++
    }

    
fclose(file)
    
server_print("Successfully added %d server names"num_of_names)

    return 
PLUGIN_CONTINUE
}

public 
change_name()
{
    
// if(current_name + 1 > num_of_names)
        // current_name = 0

    // current_name++
    // server_cmd("hostname ^"%s^"", server_names[current_name])
    
server_cmd("hostname ^"%s^""server_names[random(num_of_names)])

__________________

Last edited by fysiks; 12-31-2009 at 19:48.
fysiks is offline
.OM NOM NOM NOM
BANNED
Join Date: Dec 2009
Old 12-31-2009 , 19:47   Re: Hostname changer.
Reply With Quote #3

Going to test it right away.
's, as promised.
.OM NOM NOM NOM is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-31-2009 , 19:48   Re: Hostname changer.
Reply With Quote #4

I updated once more to correct an incorrect string assignment.
__________________
fysiks is offline
.OM NOM NOM NOM
BANNED
Join Date: Dec 2009
Old 12-31-2009 , 19:53   Re: Hostname changer.
Reply With Quote #5

/groups/amxmodx/tmp3/text43X6eZ.sma(65) : warning 203: symbol is never used: "current_name"

This one?

-EDIT-
Everything seems to work lovely. Big thanks.

Last edited by .OM NOM NOM NOM; 12-31-2009 at 19:56.
.OM NOM NOM NOM is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-31-2009 , 19:55   Re: Hostname changer.
Reply With Quote #6

Nope. That warning is OK.
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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 04:15.


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