Advertisement
Guest User

damage_in_vehicle.lua

a guest
May 3rd, 2017
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. -- Config
  2.  
  3. -- 0.00 = 0%, 0.50 = 50%, 1.00 = 100%, 2.00 = 200%, etc.
  4. RIDER_DAMAGE = 0.20
  5.  
  6. -- Any damage less than this threshold will have its value changed to RIDER_DAMAGE
  7. RIDER_DAMAGE_THRESHOLD = 0.04
  8.  
  9. -- Usual values are between 0 and 1 (where 0 blocks no damage and 1 blocks all damage)
  10. -- If value is nil, no changes will be made
  11. VEHICLE_PASSTHROUGH_PENALTY = {
  12.     ["none"] = nil,
  13.     ["falling"] = nil,
  14.     ["bullet"] = 0,
  15.     ["grenade"] = nil,
  16.     ["high_explosive"] = nil,
  17.     ["sniper"] = 0,
  18.     ["melee"] = nil,
  19.     ["flame"] = 0,
  20.     ["mounted_weapon"] = nil,
  21.     ["vehicle"] = nil,
  22.     ["plasma"] = 0,
  23.     ["needle"] = 0,
  24.     ["shotgun"] = 0,
  25. }
  26.  
  27. -- End of Config
  28.  
  29. api_version = "1.9.0.0"
  30.  
  31. categories = {
  32.     [0] = "none",
  33.     [1] = "falling",
  34.     [2] = "bullet",
  35.     [3] = "grenade",
  36.     [4] = "high_explosive",
  37.     [5] = "sniper",
  38.     [6] = "melee",
  39.     [7] = "flame",
  40.     [8] = "mounted_weapon",
  41.     [9] = "vehicle",
  42.     [10] = "plasma",
  43.     [11] = "needle",
  44.     [12] = "shotgun"
  45. }
  46.  
  47. function OnScriptLoad()
  48.     register_callback(cb['EVENT_GAME_START'], "OnGameStart")
  49. end
  50.  
  51. function OnGameStart()
  52.     local tags_count = read_dword(0x4044000C)
  53.     local tags_array = read_dword(0x40440000)
  54.     for i=0,tags_count-1 do
  55.         local tag_class = read_dword(tags_array + i*32 + 0x0)
  56.         if(tag_class == 0x6A707421) then -- checks if tag is damage_effect
  57.             local damage_data = read_dword(tags_array + i*32 + 0x14)
  58.             local damage_category = read_word(damage_data + 0x1C6)
  59.             local damage_penalty = VEHICLE_PASSTHROUGH_PENALTY[categories[damage_category]]
  60.             if(damage_penalty ~= nil) then
  61.                 write_float(damage_data + 0x1DC, damage_penalty)
  62.             end
  63.         elseif(tag_class == 0x76656869) then -- checks if tag is vehicle
  64.             local vehicle_data = read_dword(tags_array + i*32 + 0x14)
  65.             local rider_damage_fraction = round(read_float(vehicle_data + 0x184))
  66.             if(rider_damage_fraction < RIDER_DAMAGE_THRESHOLD) then
  67.                 write_float(vehicle_data + 0x184, RIDER_DAMAGE)
  68.             end
  69.         end
  70.     end
  71. end
  72.  
  73. function round(float)
  74.     local multiple = 10^6
  75.     return math.floor(float * multiple + 0.5) / multiple
  76. end
  77.  
  78. function OnScriptUnload() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement