SourceMod 1.8 has a function GetMapDisplayName(const char[] map, char[] displayName, int maxlength) that should be used instead of this functionality.
So, I wrote this just recently and was thinking about submitting it for inclusion in SourceMod.
Note that if this
is included in SourceMod, it likely would end up split into multiple include files instead of just the one (likely string.inc for SubString, mapchooser.inc for the others.)
Changelog- 1.1.1 - Minor optimization to SubString in case you pass a 0 for len.
- 1.1 - RemoveMapPath will now copy the original text to destination when it doesn't remove anything.
- 1.0 - Initial release
Functions in this file:
Code:
/**
* Copy a substring from source to destination
*
* @param source String to copy from
* @param start position to start at, 0 numbered. Negative means to start that many characters from the end.
* @param len number of characters to copy. Negative means to not copy that many characters from the end.
* @param destination String to copy to
* @param maxlen Length of destination string. Must be 1 or greater.
*
* @return True if success, false if number of characters copied would be negative.
* NOTE: There is no mechanism to get the remaining characters of a string.
* Instead, use strcopy with source[start] for that.
*/
bool:SubString(const String:source[], start, len, String:destination[], maxlen)
Code:
/**
* Remove the path from the map name
* This was added to remove workshop paths.
*
* @param map Map name
* @param destination String to copy map name to
* @param maxlen Length of destination string
*
* @return true if path was removed, false if map and destination are the same
*/
bool:RemoveMapPath(const String:map[], String:destination[], maxlen)
Code:
/**
* Check if two maps are the same map.
* Takes workshop paths into account.
*
* @param map First map
* @param map2 Second map
*
* @return true if they're the same map, false if not.
*/
bool:MapEqual(const String:map[], const String:map2[])
Code:
/**
* Returns the index for the first occurrence of the provided map. If the map cannot be located, -1 will be returned.
* Takes workshop maps into account.
*
* @param array Array Handle.
* @param map Map to search for
*
* @return Array index, or -1 on failure
*/
FindMapStringInMapArray(Handle:array, const String:map[])
Note that these were primarily written for use in a MapChooser and were tested using the attached plugin.