Advertisement
HR_Shaft

Super Melee v1.1 for stock PC/CE maps for SAPP

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