Advertisement
HR_Shaft

Automatic Server Messages for SAPP

Jul 19th, 2015
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.92 KB | None | 0 0
  1. --[[ ###  Automatic Server Messages 1.0 ###]]--
  2. --[[ ###      by H® Shaft for SAPP      ###]]--
  3.  
  4. -- Enable server admins to setup automatic server messages: single line messages that will be shown to players based on the delay frequency you set
  5. -- You can determine the order of the messages as sequential or random: default sequential (see random_order below)
  6.  
  7. -- Spam Messages: Messages everyone sees based on the order and frequency you set. Defaults: Sequential order, 1 spam message shown every 60 seconds
  8. -- Join Message: Private messages only shown to the joining player
  9. -- End Messages: Private message shown to each player at games end.
  10. -- Team Switch Message: Message everyone sees when a player switches teams during team games, shows the team they switched to.
  11. -- Team Kill Message: Private message only the betrayer sees on team games.
  12.  
  13. -- spam messages: add your own, ensure the messages are within quotes, and separated by a comma between each message
  14. -- add as many as you want
  15. SPAM_MESSAGES = {
  16.     "Spam message 1",
  17.     "Spam message 2",
  18.     "Spam message 3",
  19. }
  20.  
  21. -- message order: If set to true, spam messages will be in random order (1,4,2,5,3 etc). If false, it will be sequential (1,2,3,4,5 etc)
  22. -- random order only recommended when you have more than 5 spam messages
  23. RANDOM_ORDER = false
  24.  
  25. -- delay in SECONDS between each spam message, if less than 60 seconds, it seems spammy.  Too much spam causes players to ignore all messages.
  26. MESSAGE_DELAY = 30
  27.  
  28. -- private message shown when player joins. Optional player name variable ($PLAYER) Example: Welcome to the best server H® Shaft! 
  29. -- should not be more than 3 entries, ensure the messages are within quotes, and separated by a comma between each message
  30. JOIN_MESSAGES = {
  31.     "Private join message 1: $PLAYER",
  32.     "Private join message 2: $PLAYER",
  33.     "Private join message 3: $PLAYER",
  34. }  
  35.  
  36. -- message shown when game ends. Optional player name variable ($PLAYER) Example: Thanks for playing in the best server H® Shaft!
  37. -- should not be more than 3 entries, ensure the messages are within quotes, and separated by a comma between each message
  38. END_MESSAGES = {
  39.     "Private game end message 1: $PLAYER",
  40.     "Private game end message 2: $PLAYER",
  41.     "Private game end message 3: $PLAYER",
  42. }
  43.  
  44. -- a single private message shown to betrayer when they team kill, Optional player name variable ($PLAYER)
  45. TK_MESSAGE = "$PLAYER !!: DON'T KILL YOUR OWN TEAM!!"  
  46.  
  47. -- sapp api version
  48. api_version = "1.8.0.0"
  49. game_started = false
  50.  
  51. function OnScriptLoad()
  52.     MESSAGE_NO = 1
  53.     register_callback(cb['EVENT_GAME_START'],"OnNewGame")
  54.     register_callback(cb['EVENT_GAME_END'],"OnGameEnd")
  55.     register_callback(cb['EVENT_JOIN'],"OnPlayerJoin")
  56.     register_callback(cb['EVENT_BETRAY'], "OnEventBetray")
  57.     register_callback(cb['EVENT_TEAM_SWITCH'],"OnTeamSwitch")
  58.     timedmessage = timer(MESSAGE_DELAY * 1000, "TimedMessages")
  59. end
  60.  
  61. function OnScriptUnload()
  62.     SPAM_MESSAGES, JOIN_MESSAGES, END_MESSAGES = {}, {}, {}
  63. end
  64.  
  65. function OnPlayerJoin(PlayerIndex)
  66.     if player_present(PlayerIndex) then
  67.         for l,message in pairs(JOIN_MESSAGES) do
  68.             say(PlayerIndex,string.gsub(message,"$PLAYER",get_var(PlayerIndex,"$name")))
  69.         end    
  70.     end
  71. end
  72.  
  73. function OnNewGame()
  74.     game_started = true
  75.     team_play = getteamplay()
  76. end
  77.  
  78. function OnGameEnd()
  79.     game_started = false
  80.     timedmessage = nil
  81.     timedendmessage = timer(8000, "GameEndMessages")
  82. end
  83.  
  84. function TimedMessages(id, count)
  85.     for i = 1,16 do
  86.         if player_present(i) and game_started then
  87.             say(i, SPAM_MESSAGES[MESSAGE_NO])
  88.             if RANDOM_ORDER then
  89.                 if #SPAM_MESSAGES > 1 then
  90.                     MESSAGE_NO = rand(1, #SPAM_MESSAGES+1)
  91.                 end        
  92.                 MESSAGE_NO = MESSAGE_NO + 1
  93.                 if MESSAGE_NO > #SPAM_MESSAGES+1 then
  94.                     MESSAGE_NO = 1
  95.                 end            
  96.             else
  97.                 MESSAGE_NO = MESSAGE_NO + 1
  98.                 if MESSAGE_NO > #SPAM_MESSAGES then
  99.                     MESSAGE_NO = 1
  100.                 end
  101.             end
  102.         end
  103.     end
  104.     return true
  105. end
  106.  
  107. function GameEndMessages(id, count)
  108.     for i = 1,16 do
  109.         if player_present(i) and not game_started then
  110.             for l,message in pairs(END_MESSAGES) do
  111.                 say(i,string.gsub(message,"$PLAYER",get_var(i,"$name")))
  112.             end    
  113.         end
  114.     end
  115.     return false
  116. end
  117.  
  118. function OnEventBetray(PlayerIndex)
  119.     if game_started and team_play then
  120.         if player_present(PlayerIndex) then
  121.             say(PlayerIndex,string.gsub(TK_MESSAGE,"$PLAYER",get_var(PlayerIndex,"$name")))
  122.         end
  123.     end    
  124. end
  125.  
  126. function OnTeamSwitch(PlayerIndex)
  127.     if game_started and team_play then
  128.         local name = get_var(PlayerIndex,"$name")
  129.         local dest = get_var(PlayerIndex,"$team")
  130.         local team
  131.         if dest == "red" then team = "Red Team." elseif dest == "blue" then team = "Blue Team." end
  132.         local str1 = string.format("%s switched-teams to the %s", tostring(name), tostring(team))
  133.         say_all(str1)
  134.     end
  135. end
  136.  
  137. function getteamplay()
  138.     if (get_var(0,"$ffa") == "0") then
  139.         return true
  140.     else
  141.         return false
  142.     end
  143. end
  144.  
  145. -- Created by H® Shaft
  146. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement