AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hostname changer. (https://forums.alliedmods.net/showthread.php?t=113897)

.OM NOM NOM NOM 12-31-2009 05:36

Hostname changer.
 
Evening, would any of you kind gentelmen add a shuffle mode to this code?
I'll give you :crab:'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])
}


fysiks 12-31-2009 19:41

Re: Hostname changer.
 
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)])



.OM NOM NOM NOM 12-31-2009 19:47

Re: Hostname changer.
 
Going to test it right away.
:crab::crab::crab:'s, as promised.

fysiks 12-31-2009 19:48

Re: Hostname changer.
 
I updated once more to correct an incorrect string assignment.

.OM NOM NOM NOM 12-31-2009 19:53

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

This one? :)

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

fysiks 12-31-2009 19:55

Re: Hostname changer.
 
Nope. That warning is OK.


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

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