Advertisement
HR_Shaft

Script Loader/Unloader for SAPP

Aug 16th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. -- Script Loader by H® Shaft
  2.  
  3. -- allows you to specify a script to load for a specific map name and game type combination, and unload that script when game is over
  4. -- Add this script to your sapp init file, when the map and gametype load, the specified script will load as well
  5.  
  6. -- sapp api version
  7. api_version = "1.8.0.0"
  8.  
  9. function OnScriptLoad()
  10.     register_callback(cb['EVENT_GAME_START'], "OnNewGame")
  11.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  12.     if get_var(0, "$gt") ~= "n/a" then
  13.         load_script()
  14.     end    
  15. end
  16.  
  17. function OnScriptUnload() end
  18.  
  19. function OnNewGame()
  20.     load_script()
  21. end
  22.  
  23. function load_script()
  24.     local game_mode = get_var(0, "$mode")
  25.     local map_name = get_var(0, "$map")
  26.    
  27.     if (map_name == "bloodgulch") and (game_mode == "YOUR_GAME_TYPE_HERE") then -- << Enter your MAP NAME ("bloodgulch") and GAME TYPE name ("YOUR_GAME_TYPE_HERE")
  28.         execute_command("lua_load YOUR_SCRIPT_NAME_HERE") -- << Enter your script name to load when game starts. Also, enter this name below to unload it
  29.     end
  30. end
  31.  
  32. function OnGameEnd()
  33.     execute_command("lua_unload YOUR_SCRIPT_NAME") -- << Enter your script name to UNLOAD when game is over
  34. end
  35.  
  36.    
  37. -- Created by H® Shaft
  38. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement