Raised This Month: $12 Target: $400
 3% 

Random Map for server startup


Post New Thread Reply   
 
Thread Tools Display Modes
Plugin Info:     Modification:   Natural Selection        Category:   Server Management        Approver:   Hawk552 (427)
NeoMatrix99
New Member
Join Date: Feb 2008
Old 02-28-2008 , 06:32   Random Map for server startup
Reply With Quote #1

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
Attached Files
File Type: cfg randommap.cfg (15 Bytes, 834 views)
File Type: txt randommap.txt (73 Bytes, 804 views)
File Type: sma Get Plugin or Get Source (randommap.sma - 2027 views - 6.6 KB)

Last edited by NeoMatrix99; 02-29-2008 at 08:55. Reason: Update
NeoMatrix99 is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-28-2008 , 11:24   Re: Random Map for server startup
Reply With Quote #2

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]);
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
NeoMatrix99
New Member
Join Date: Feb 2008
Old 02-29-2008 , 00:13   Re: Random Map for server startup
Reply With Quote #3

Quote:
Originally Posted by YamiKaitou View Post
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.
NeoMatrix99 is offline
|PJ| Shorty
Veteran Member
Join Date: Aug 2005
Location: Bavaria, Germany
Old 02-28-2008 , 23:12   Re: Random Map for server startup
Reply With Quote #4

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.
__________________
There are only 10 types of people in the world:
Those who understand binary, and those who donīt.

Last edited by |PJ| Shorty; 02-28-2008 at 23:17.
|PJ| Shorty is offline
Send a message via ICQ to |PJ| Shorty Send a message via AIM to |PJ| Shorty Send a message via MSN to |PJ| Shorty Send a message via Yahoo to |PJ| Shorty Send a message via Skype™ to |PJ| Shorty
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 02-29-2008 , 00:18   Re: Random Map for server startup
Reply With Quote #5

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.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
NeoMatrix99
New Member
Join Date: Feb 2008
Old 02-29-2008 , 01:15   Re: Random Map for server startup
Reply With Quote #6

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 is offline
NeoMatrix99
New Member
Join Date: Feb 2008
Old 02-29-2008 , 08:29   Re: Random Map for server startup
Reply With Quote #7

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.

Last edited by NeoMatrix99; 02-29-2008 at 08:56.
NeoMatrix99 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 10:11.


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