AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Approved Plugins (https://forums.alliedmods.net/forumdisplay.php?f=8)
-   -   Random Map for server startup (https://forums.alliedmods.net/showthread.php?t=67650)

NeoMatrix99 02-28-2008 06:32

Random Map for server startup
 
3 Attachment(s)
File Name: Random Map on Start

Author: NeoMatrix99.j2

Category: Misc

Current Version: 1.1

Platform / Test Machine: Windows - Amxx 1.8.0 and Amxx 1.8.1.3679 - NS 3.2

Required Modules: none

CVars: firstmap, used to save the firstmap on server startup if COMMANDLINE is set to 0

Natives: none

Credits: Crab Map Manager by Head crab - Most of the base code - For maximum compatibility
187comat Server run by Scrow - Getting me started on the idea and testing first beta versions
nsmod.org (originally modns.org) - For giving me a chance to release this to the public

Commands: none

Features: Set a random map to start with on server startup.

Description: By default it picks a random map on server startup and changes to it. Otherwise it will pick a new map after each map change and set it in a config to use as the servers first map.
The random map can not be in the history file (if you use Crab Map Manager) and not the current map.

This does work without Crab's Map Manager without needing any modifications to the code. Read below for instructions on how to use with or without Crab's Map Manager.

Changelog:
1.1 - 2/29/2008
- Switched out hardcoded paths for required files.
----- Allows compatability if the location of the amxmodx configs directory changes in the future.
- Added support for servers who either are unable or will not change their server command lines.
----- In this mode this plugin conflicts with vote map after crash.

Conflicts: In it's default mode this plugin will conflict with votemap after crash causing a vote to not launch.

This plugin could theoretically be used with other mods but has yet to be tested with anything other than NS 3.2

Code:

Place randommap.txt in your amxmodx configs folder, put inside a list of the
maps you would like to pick from for your startup map.

Set #define MAP_LIMIT 32 to the max number of maps you want it to find.
I suggest making it a few above how many maps you have.

If you use crab map manager do the following to let this plugin read your
history file:
Set #define CRABMAP 0 to 1
Set #define HISTORY_LIMIT 3 to match what you have in your crab map
manager SMA file.

The map history file default location is inside your amxmodx configs folder
so you can place the file there or let the plugin create it's own. Make sure
this is the same as your crab map manager maphistory.ini location.

Place randommap.cfg in your amxmodx configs folder if you follow the
directions below to edit your server command line. If the map inside is
not a map you have or use change the map name to something you
would use.

If you want to edit your server command line set #define COMMANDLINE
in the SMA file to 1 (defaulted to 0) and follow the step below.

In your server start command remove +map ******* and put in
+exec /path/to/amxmodx/configs/randommap.cfg
ex. +exec addons/amxmodx/configs/randommap.cfg


YamiKaitou 02-28-2008 11:24

Re: Random Map for server startup
 
Okay, some things about your code.

Do not hardcode paths. Use the get_configsdir function to do what you are doing.

Why do you have a map name hardcoded in? co_angst

Where are you changing the map? Instead of changing the command line (some people can't do this), let the command line be and use
server_cmd("changelevel %s", ValidMaps[randommap]);

|PJ| Shorty 02-28-2008 23:12

Re: Random Map for server startup
 
also:
Code:

while (a < MAP_LIMIT) {
  while (pos < HISTORY_LIMIT) {
      read_file(g_MapHistFile,pos,g_MapHistName[pos],31,length)
  }
}

you should read the file once to an array, than compare the arrays.

NeoMatrix99 02-29-2008 00:13

Re: Random Map for server startup
 
Quote:

Originally Posted by YamiKaitou (Post 590869)
Okay, some things about your code.

Do not hardcode paths. Use the get_configsdir function to do what you are doing.

Why do you have a map name hardcoded in? co_angst

Where are you changing the map? Instead of changing the command line (some people can't do this), let the command line be and use
server_cmd("changelevel %s", ValidMaps[randommap]);

I hardcode the paths because I give admins the option of deciding where to put thier files. For instance on 187combat we have the history file in the ns directory.

I don't change the map. When you don't include a "+map mapname" in the command line the server will hang, however with the +exec line in there it execs that file which only contains the one command "map mapname" which is the same as putting "+map mapname" in the command line. This way my method works with programs like serverdoc.

Thus allowing me to set a random map for it to start with instead of starting the server and then immediately change the map which could lead to crash issues on linux boxes seeing as I try to use timers as little as possible in my plugins. This also allows clients to reconnect back as soon as possible.

As for the map co_angst there are two versions of the map out which are co_angst and co_angst8. On 187combat we have both and the maps are nearly identical but have thier little differences but still gets pretty annoying to play them back to back so that line I put in there makes them seem like the same map when reading both the randommap.txt and the maphistory.ini

Quote:

you should read the file once to an array, than compare the arrays.
I don't know how to do arrays but I'll look into it, I'm learning how to make these plugins as I go along.

YamiKaitou 02-29-2008 00:18

Re: Random Map for server startup
 
Make the plugin change the map. Some people do not have the ability to change the command line. Issuing a changelevel will not crash the server and doesn't kick the clients.

Do not hardcode the file paths. It looks bad and is unprofessional. Also, I believe it can not be approved because of this.

FYI, white space is good for readability.

NeoMatrix99 02-29-2008 01:15

Re: Random Map for server startup
 
I guess I can put in a define so if someone doesn't want to or can't change the command line it will issue a changelevel but otherwise will do it this way. I'll have to find a way of detecting whether this is the first map of the server or not but thats easy enough. Will have to wait till I get home for changes to be put in. Atm it simply reads the history file (unless set not to) and the randommap.txt every mapchange and writes the new random map to randommap.cfg

This will have to instead detect if this is the first map, choose a new map, and then change.

My original method was adopted because we have startup crash issues on 187combat which is on a linux box and I didn't want to add to the problem.

Will also make a change to the hardcoded paths.

NeoMatrix99 02-29-2008 08:29

Re: Random Map for server startup
 
Plugin updated.

1.1 - 2/29/2008
- Switched out hardcoded paths for required files.
----- Allows compatability if the location of the amxmodx configs directory changes in the future.
- Added support for servers who either are unable or will not change their server command lines.
----- In this mode this plugin conflicts with vote map after crash.


All times are GMT -4. The time now is 01:33.

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