Raised This Month: $ Target: $400
 0% 

[SNIPPET] Get Workshop Map Name


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 10-13-2014 , 13:10   [SNIPPET] Get Workshop Map Name
Reply With Quote #1

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.
Attached Files
File Type: sp Get Plugin or Get Source (map_workshop_functions_test.sp - 317 views - 3.8 KB)
File Type: inc map_workshop_functions.inc (5.5 KB, 579 views)
File Type: smx map_workshop_functions_test.smx (4.9 KB, 429 views)
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 10-21-2015 at 11:59.
Powerlord is offline
 



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 18:30.


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