Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

CommonUtils.GetScenarioName

By: mikeyy on Jul 25th, 2011  |  syntax: Lua  |  size: 0.68 KB  |  views: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. local ScenarioName = false
  2.  
  3. --Returns the name of the current scenario in lowercase, minus _scenario suffix and file extension
  4. --e.g. 'map10' for '/maps/map10/map10_scenario.lua'
  5. function GetScenarioName()
  6.     if ScenarioName then
  7.         return ScenarioName
  8.     else
  9.         local scenName, scenFile
  10.         if IsSim() then
  11.             scenFile = ScenarioInfo.file
  12.         elseif IsUser() then
  13.             scenFile = SessionGetScenarioInfo().file
  14.         end
  15.         if scenFile then
  16.             scenName = string.gsub(scenFile, '^.+/([^/_]+)_scenario%.lua$', '%1')
  17.             ScenarioName = scenName
  18.             return ScenarioName
  19.         end
  20.     end
  21.     return false
  22. end