Advertisement
HR_Shaft

Super Melee for stock PC/CE maps for SAPP

Sep 27th, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.66 KB | None | 0 0
  1. -- Super Melee for stock PC/CE maps for SAPP
  2. -- by H® Shaft
  3.  
  4. -- Allows players to melee enemy players AND enemy players in vehicles.
  5. -- Melee to enemy players is instant kill, does not harm yourself or team
  6. -- Melee to enemy players in vehicles causes vehicle to spill and causes some damage to riders.
  7. -- WILL work with custom CE maps which have stock weapon sets
  8.  
  9. -- don't edit --
  10. api_version = "1.8.0.0"
  11. melee = {}
  12. game_started = false
  13.  
  14. function OnScriptLoad()
  15.     local tick_counter_sig = sig_scan("8B2D????????807D0000C644240600")
  16.     if (tick_counter_sig ~= 0) then
  17.         tick_counter_address = read_dword(read_dword(tick_counter_sig + 2)) + 0xC
  18.         register_callback(cb['EVENT_TICK'],"OnTick")
  19.     end
  20.     register_callback(cb['EVENT_GAME_START'], "OnNewGame") 
  21.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  22.     register_callback(cb['EVENT_JOIN'], "OnPlayerJoin")
  23.     register_callback(cb['EVENT_LEAVE'], "OnPlayerLeave")
  24.     if get_var(0, "$gt") ~= "n/a" then
  25.         for i=1,16 do
  26.             if player_present(i) then
  27.                 melee[i] = 0
  28.             end    
  29.         end
  30.     end
  31. end
  32.  
  33. function OnScriptUnload() end
  34.  
  35. function OnPlayerJoin(PlayerIndex)
  36.     melee[PlayerIndex] = 0
  37.     rprint(PlayerIndex, "|c Super Melee is active!")
  38. end
  39.  
  40. function OnPlayerLeave(PlayerIndex)
  41.     melee[PlayerIndex] = nil
  42. end
  43.  
  44. function OnNewGame()
  45.     game_started = true
  46. end
  47.  
  48. function OnGameEnd()
  49.     game_started = false
  50.     melee = {}
  51. end
  52.  
  53. function SuperMelee(PlayerIndex, x, y, z)
  54.     if PlayerIndex ~= nil and x ~= nil and y ~= nil and z ~= nil then
  55.         local player_object = get_dynamic_player(PlayerIndex)
  56.         local player_obj_id = read_dword(get_player(PlayerIndex) + 0x34)
  57.         if player_object ~= 0 then
  58.             local grunt = generategrunt(grunt)
  59.             local melee_id = spawn_object("proj", "weapons\\rocket launcher\\rocket", x, y, z+0.7)
  60.             local melee_object = get_object_memory(melee_id)
  61.             if melee_object ~= 0 then
  62.                 write_dword(melee_object + 0xC4, player_obj_id)
  63.                 write_float(melee_object + 0x74, -0.996)
  64.                 write_float(melee_object + 0x70, -5)
  65.             end
  66.             rprint(PlayerIndex, "|c".. grunt)
  67.         end    
  68.     end
  69. end
  70.  
  71. function OnTick()
  72.     if game_started then
  73.         -- damage attributes
  74.         local tick_id = read_dword(tick_counter_address)
  75.         local tag_address = read_dword(0x40440000)
  76.         local tag_count = read_word(0x4044000C)
  77.         for A=0,tag_count-1 do
  78.             local tag_id = tag_address + A * 0x20
  79.             if (read_dword(tag_id) == 1785754657) then
  80.                 local tag_data = read_dword(tag_id + 0x14)
  81.                 if tag_data ~= nil then
  82.                     if (read_word(tag_data + 0x1C6) == 4) then -- rocket/explosion damage: values below are based on this
  83.                         write_bit(tag_data + 0x1C8, 0, 1) -- doesn't hurt self: 1 = true, 0 = false
  84.                         write_bit(tag_data + 0x1C8, 3, 1) -- doesn't hurt team: 1 = true, 0 = false
  85.                         write_float(tag_data + 0x1D8, 0.5) -- damage amount: passed to enemy players
  86.                         write_float(tag_data + 0x1DC, 0.275) -- damage enemy vehicle riders - 0 damages, 1 = no damage
  87.                         write_float(tag_data + 0x1F4, 3) -- force amount: amount of outward force
  88.                     elseif (read_word(tag_data + 0x1C6) == 6) then -- melee damage
  89.                         write_bit(tag_data + 0x1C8, 7, 1) -- flaming death/instant kill melee
  90.                     end                
  91.                 end
  92.             end
  93.         end
  94.         -- melee detection and activation of super melee
  95.         for PlayerIndex=1,16 do
  96.             if player_alive(PlayerIndex) then
  97.                 local player_object = get_dynamic_player(PlayerIndex)
  98.                 local player_obj_id = read_dword(get_player(PlayerIndex) + 0x34)
  99.                 local x,y,z = read_vector3d(player_object + 0x5C)
  100.                 if (player_object ~= 0) then
  101.                     -- melee detection
  102.                     if not isinvehicle(PlayerIndex) then
  103.                         if melee[PlayerIndex] == nil then melee[PlayerIndex] = 0 end
  104.                         if melee[PlayerIndex] > 0 then melee[PlayerIndex] = melee[PlayerIndex] - 1 end
  105.                         if (melee[PlayerIndex] == 0) and (read_bit(player_object + 0x208, 7) == 1) then
  106.                             SuperMelee(PlayerIndex, x, y, z)
  107.                             melee[PlayerIndex] = math.floor(1.7*30)
  108.                         end
  109.                     end
  110.                 end
  111.             end
  112.         end
  113.     end
  114. end
  115.  
  116. function isinvehicle(PlayerIndex)
  117.     local player_object = get_dynamic_player(PlayerIndex)
  118.     local vehicleId = read_dword(player_object + 0x11C)
  119.     if vehicleId == 0xFFFFFFFF then
  120.         return false
  121.     else
  122.         return true
  123.     end
  124. end
  125.  
  126. -- when a player melees, this short message is shown to them
  127. function generategrunt(grunt)
  128.     local grunt = {"Uhn!", "Hiyah!", "Umph!", "Doh!", "Fuuuh!", "Efff!", "Nuh!", "Arrg!", "Ack!", "Smack!", "Thwack!", "Nuh!", "whack!", "Pow!"}
  129.     local gruntcount = #grunt
  130.     local rand_grunt = rand(1, gruntcount+1)
  131.     local grunt_type = string.format("%s",  grunt[rand_grunt])
  132.     if grunt_type then
  133.         return grunt_type
  134.     else
  135.         return "Uhn!"
  136.     end
  137. end
  138.  
  139. -- Created by H® Shaft
  140. -- Visit http://halorace.org/forum/index.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement