Advertisement
mikeyy

CommonUtils.GetScenarioName

Jul 25th, 2011
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.68 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement