HR_Shaft

Chaos Gulch for Phasor v2+ and SAPP

Dec 16th, 2014
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.53 KB | None | 0 0
  1. -- Chaos gulch by 002 v1.1 (not my script)
  2. -- Configuration
  3.  
  4. -- Time in seconds
  5. CHAOS_GULCH_DURATION = 90
  6.  
  7. -- Chance (%age) per game
  8. CHAOS_GULCH_CHANCE = 100
  9.  
  10. -- Chaos gulch (if it happens) happens after this many seconds into the game
  11. CHAOS_GULCH_TIME_MINIMUM = 20
  12.  
  13. -- Chaos gulch (if it happens) happens before this many seconds into the game
  14. CHAOS_GULCH_TIME_MAXIMUM = 120
  15.  
  16. -- Warn this many seconds before carnage begins (0 = don't warn)
  17. WARNING_TIME = 5.0
  18. WARNING_MESSAGE = "Prepare for carnage..."
  19. MESSAGE_BEGINNING = "Begin carnage."
  20. MESSAGE_ENDING = "Carnage has ended. Resume normal gameplay."
  21.  
  22.  
  23. -- Use random projectiles
  24. RANDOM_PROJECTILES = true
  25. -- Don't use projectiles that have a velocity of 0
  26. NO_SLOW_PROJECTILES = true
  27. -- Round-based weapons don't use up ammo
  28. INFINITE_AMMO = true
  29. -- I believe I can fly
  30. FLYING_WARTHOGS = true
  31.  
  32.  
  33.  
  34. -- End of configuration
  35.  
  36. api_version = "1.6.0.0"
  37. game_started_time = nil
  38. warned = false
  39. in_progress = false
  40. chaos_gulch_time = CHAOS_GULCH_TIME_MINIMUM
  41.  
  42.  
  43. -- {Function, Address, Value}
  44. rollback_actions = {}
  45.  
  46. -- Projectiles to choose from
  47. random_projectiles = {}
  48.  
  49. -- Dependencies for weapons
  50. projectile_dependencies = {}
  51.  
  52. function OnScriptLoad()
  53.     if(register_callback ~= nil) then
  54.         register_callback(cb['EVENT_TICK'],"GameTick")
  55.         register_callback(cb['EVENT_GAME_START'],"GameStart")
  56.         register_callback(cb['EVENT_GAME_END'],"GameEnd")
  57.     else
  58.         write_float = writefloat
  59.         read_float = readfloat
  60.         write_dword = writedword
  61.         read_dword = readdword
  62.         write_word = writeword
  63.         read_word = readword
  64.         timer = registertimer
  65.         say_all = say
  66.         rand = getrandomnumber
  67.         SyncAllWeapons = SyncAllWeaponsPhasor
  68.         timer(1/30 * 1000,"GameTick_Phasor")
  69.     end
  70. end
  71.  
  72. function OnScriptUnload()
  73.     RollbackEverything()
  74. end
  75.  
  76. function RollbackEverything()
  77.     for i=1,TableLength(rollback_actions) do
  78.         rollback_actions[i][1](rollback_actions[i][2],rollback_actions[i][3])
  79.     end
  80.     rollback_actions = {}
  81.     projectile_dependencies = {}
  82.     random_projectiles = {}
  83. end
  84.  
  85. function TableLength(TableVariable)
  86.     if(TableVariable == nil or type(TableVariable) ~= "table") then return 0 end
  87.     local table_size = 0
  88.     while TableVariable[table_size + 1] ~= nil do table_size = table_size + 1 end
  89.     return table_size
  90. end
  91.  
  92. function GameStart()
  93.     game_started_time = os.clock()
  94.     warned = false
  95.     in_progress = false
  96.     chaos_gulch_time = rand(CHAOS_GULCH_TIME_MINIMUM,CHAOS_GULCH_TIME_MAXIMUM)
  97. end
  98.  
  99. function GameEnd()
  100.     RollbackEverything()
  101.     game_started_time = nil
  102.     in_progress = false
  103. end
  104.  
  105. function PrepareRollback()
  106.     local tag_array = read_dword(0x40440000)
  107.     local tag_count = read_word(0x4044000C)
  108.     for i=0,tag_count-1 do
  109.         local offset = tag_array + 0x20 * i
  110.         if(RANDOM_PROJECTILES) then
  111.             if(read_dword(offset) == 2003132784) then --weap
  112.                 local data_offset = read_dword(offset + 0x14)
  113.                 local trigger_count = read_dword(data_offset + 0x4FC)
  114.                 if(trigger_count > 0) then
  115.                     local trigger_offset = read_dword(data_offset + 0x4FC + 0x4)
  116.                     for q=0,trigger_count-1 do
  117.                         local trigger_offset = trigger_offset + q * 276
  118.                         local value_offset = trigger_offset + q * 276 + 0x94 + 0xC
  119.                         rollback_actions[TableLength(rollback_actions) + 1] = { write_dword, value_offset, read_dword(value_offset) }
  120.                         projectile_dependencies[TableLength(projectile_dependencies) + 1] = value_offset
  121.                         rollback_actions[TableLength(rollback_actions) + 1] = { write_dword, trigger_offset, read_dword(trigger_offset) }
  122.                         write_dword(trigger_offset, 0)
  123.                         if(INFINITE_AMMO) then
  124.                             rollback_actions[TableLength(rollback_actions) + 1] = { write_word, trigger_offset + 0x22, read_word(trigger_offset + 0x22) }
  125.                             write_word(trigger_offset + 0x22, 0)
  126.                         end
  127.                     end
  128.                 end
  129.             end
  130.             if(read_dword(offset) == 1886547818) then --proj
  131.                 local identity = read_dword(offset + 0xC)
  132.                 local data_offset = read_dword(offset + 0x14)
  133.                 if(NO_SLOW_PROJECTILES == false or (read_float(data_offset + 0x1E4) ~= 0 and read_float(data_offset + 0x1E8) ~= 0)) then
  134.                     random_projectiles[TableLength(random_projectiles) + 1] = identity
  135.                 end
  136.             end
  137.         end
  138.         if(FLYING_WARTHOGS) then
  139.             if(read_dword(offset) == 1986357353) then --vehi
  140.                 local data_offset = read_dword(offset + 0x14)
  141.                 local value = read_word(data_offset + 0x2F4)
  142.                 if(value == 0 or value == 1 or value == 2 or value == 4) then
  143.                     rollback_actions[TableLength(rollback_actions) + 1] = { write_word, data_offset + 0x2F4, read_word(data_offset + 0x2F4) }
  144.                     write_word(data_offset + 0x2F4, 0x3)
  145.                 end
  146.             end
  147.         end
  148.     end
  149. end
  150.  
  151. function RandomProjectile()
  152.     if(TableLength(random_projectiles) == 0) then return 0xFFFFFFFF end
  153.     return random_projectiles[rand(1,TableLength(random_projectiles))]
  154. end
  155.  
  156. function GameTick()
  157.     if(game_started_time ~= nil) then
  158.         local time = os.clock()
  159.         if(time > (game_started_time - WARNING_TIME + chaos_gulch_time) and warned == false and WARNING_TIME ~= 0.0) then
  160.             say_all(WARNING_MESSAGE)
  161.             warned = true
  162.         end
  163.         if(time > (game_started_time + chaos_gulch_time) and in_progress == false) then
  164.             say_all(MESSAGE_BEGINNING)
  165.             in_progress = true
  166.             PrepareRollback()
  167.             if(INFINITE_AMMO) then
  168.                 timer(1000,"SyncAllWeapons")
  169.             end
  170.         end
  171.         if(time > (game_started_time + chaos_gulch_time + CHAOS_GULCH_DURATION)) then
  172.             say_all(MESSAGE_ENDING)
  173.             in_progress = false
  174.             game_started_time = nil
  175.             RollbackEverything()
  176.         end
  177.         if(in_progress and TableLength(projectile_dependencies) > 0) then
  178.             for i=1,TableLength(projectile_dependencies) do
  179.                 write_dword(projectile_dependencies[i],RandomProjectile())
  180.             end
  181.         end
  182.     end
  183. end
  184.  
  185. function SyncAllWeapons()
  186.     for i=1,16 do
  187.         if(player_alive(i) == true) then
  188.             local player_dyn = get_dynamic_player(i)
  189.             for q=0,3 do
  190.                 local object_id = read_dword(player_dyn + 0x2F8 + q * 0x4)
  191.                 if(object_id ~= 0xFFFFFFFF) then sync_ammo(object_id) end
  192.             end
  193.         end
  194.     end
  195.     return in_progress
  196. end
  197.  
  198.  
  199. -- Phasor stuff
  200.  
  201. function GetRequiredVersion()
  202.     return 200
  203. end
  204.  
  205. function SyncAllWeaponsPhasor()
  206.     for i=0,15 do
  207.         if(getplayer(i) ~= nil) then
  208.             local player_objectid = getplayerobjectid(i)
  209.             if(player_objectid ~= nil) then
  210.                 local player_dyn = getobject(player_objectid)
  211.                 for q=0,3 do
  212.                     local object_id = read_dword(player_dyn + 0x2F8 + q * 0x4)
  213.                     if(object_id ~= 0xFFFFFFFF) then updateammo(object_id) end
  214.                 end
  215.             end
  216.         end
  217.     end
  218.     return in_progress
  219. end
  220.  
  221. function GameTick_Phasor()
  222.     GameTick()
  223.     return true
  224. end
  225.  
  226. OnNewGame = GameStart
  227. OnGameEnd = GameEnd
Advertisement
Add Comment
Please, Sign In to add comment