Advertisement
Guest User

Untitled

a guest
Sep 27th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. ----------------
  2. -- dynamite.lua
  3. -- $Date: 2007-02-10 21:35:12 +0100 (Sat, 10 Feb 2007) $
  4. -- $Id: dynamite.lua 66 2007-02-10 20:35:12Z etpro $
  5. -- $Revision: 66 $
  6. --
  7. -- Config:
  8. -- where to place the timer message, see
  9. -- http://wolfwiki.anime.net/index.php/SendServerCommand#Printing
  10. -- for valid locations
  11. local announce_pos = "b 8"
  12.  
  13. -- print "Dynamite planted at LOCATION"?
  14. local announce_plant = false
  15.  
  16. -- for 20, 10, 5, 3, 2, 1, BOOM use:
  17. local first_step = 20
  18. local steps = { -- [step] = { next step, diff to next step }
  19. [20] = { 10, 10 },
  20. [10] = { 5, 5 },
  21. [5] = { 3, 2 },
  22. [3] = { 2, 1 },
  23. [2] = { 1, 1 },
  24. [1] = { 0, 1 },
  25. [0] = { 0, 0 } -- delete if diff to next == 0
  26. }
  27. -- -- for 25, 15, 5, 3, 2, 1 use:
  28. -- local first_step = 25
  29. -- local steps = {
  30. -- [25]={15,10},
  31. -- [15]={5,10},
  32. -- [5]={3,2},
  33. -- [3]={2,1},
  34. -- [2]={1,1},
  35. -- [1]={0,0} -- no "Dynamite at %s exploding now" message
  36. -- }
  37. -- -- I think you got the idea now ...oh setting first_step = 30 will print
  38. -- -- everything one (server) frame too late ;-)
  39. -- end Config
  40.  
  41. local version = "1.0"
  42.  
  43. local timers = {}
  44. local levelTime
  45.  
  46. local ST_NEXT = 1
  47. local ST_DIFF = 2
  48.  
  49. local T_TIME = 1
  50. local T_STEP = 2
  51. local T_LOCATION = 3
  52.  
  53.  
  54. -- called when game inits
  55. function et_InitGame(levelTime, randomSeed, restart)
  56. et.RegisterModname( "dynamite.lua" .. version .. " " .. et.FindSelf() )
  57. et.G_Print("Vetinari's dynamite.lua version " .. version .. " activated...\n")
  58. end
  59.  
  60. function sayClients(pos, msg)
  61. et.trap_SendServerCommand(-1, string.format("%s \"%s^7\"", pos, msg))
  62. end
  63.  
  64. function et_Print(text)
  65. -- etpro popup: allies planted "the Old City Wall"
  66. -- etpro popup: axis defused "the Old City Wall"
  67. local pattern = "^etpro%s+popup:%s+(%w+)%s+(%w+)%s+\"(.+)\""
  68. local junk1,junk2,team,action,location = string.find(text, pattern)
  69. if team ~= nil and action ~= nil and location ~= nil then
  70. if action == "planted" then
  71. if announce_plant then
  72. sayClients(announce_pos,
  73. string.format("Dynamite planted at ^8%s^7", location))
  74. end
  75. addTimer(location)
  76. end
  77. if action == "defused" then
  78. sayClients(announce_pos,
  79. string.format("Dynamite defused at ^8%s^7", location))
  80. removeTimer(location)
  81. end
  82. end
  83. if text == "Exit: Timelimit hit.\n" or text == "Exit: Wolf EndRound.\n" then
  84. -- stop countdowns on intermission
  85. timers = {}
  86. end
  87. end
  88.  
  89. function printTimer(seconds, loc)
  90. local when = string.format("in ^8%d^7 seconds", seconds)
  91. if seconds == 0 then
  92. when = "^8now^7"
  93. elseif seconds == 1 then
  94. when = "in ^81^7 second"
  95. end
  96. sayClients(announce_pos,
  97. string.format("Dynamite at ^8%s^7 exploding %s", loc, when))
  98. end
  99.  
  100. function addTimer(location)
  101. -- local diff = ((30 - first_step) * 1000) - 25 -- move one frame earlier
  102. local diff = (30 - first_step) * 1000
  103. table.insert(timers, { levelTime + diff, first_step, location })
  104. end
  105.  
  106. function removeTimer(location)
  107. local delete = table.foreach(timers,
  108. function(i, timer)
  109. -- problem with 2 or more planted dynas at one location
  110. -- ... remove the one which was planted first
  111. if timer[T_LOCATION] == location then
  112. return(i)
  113. end
  114. end
  115. )
  116. if delete ~= nil then
  117. table.remove(timers, delete)
  118. end
  119. end
  120.  
  121. function et_RunFrame(lvltime)
  122. levelTime = lvltime
  123. table.foreach(timers,
  124. function(i, timer)
  125. if timer[T_TIME] <= levelTime then
  126. printTimer(timer[T_STEP], timer[T_LOCATION])
  127. local step = steps[timer[T_STEP]]
  128. if step[ST_DIFF] == 0 then
  129. removeTimer(timer[T_LOCATION])
  130. else
  131. timer[T_STEP] = step[ST_NEXT]
  132. timer[T_TIME] = levelTime + (step[ST_DIFF] * 1000)
  133. end
  134. end
  135. end
  136. )
  137. end
  138.  
  139. -- vim: ts=4 sw=4 expandtab syn=lua
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement