daily pastebin goal
80%
SHARE
TWEET

vitality_settings.lua

a guest Feb 13th, 2018 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Config
  2.  
  3. -- tag_type can be vehi or bipd
  4. -- stun_time is the length of time shields do not recharge after taking damage
  5. -- recharge_time is the length of time it would take for shields to recharge after being completely depleted
  6. -- stun_time and recharge_time are both in seconds
  7. VITALITY_SETTINGS = {
  8.     ["bigass_falcon"] = {
  9.         ["tag_path"] = "vehicles\\falcon\\falcon",
  10.         ["tag_type"] = "vehi",
  11.         ["max_health"] = 0,
  12.         ["max_shield"] = 500,
  13.         ["stun_time"] = 40,
  14.         ["recharge_time"] = 30,
  15.     },
  16.     ["default_biped"] = {
  17.         ["tag_path"] = "characters\\cyborg_mp\\cyborg_mp",
  18.         ["tag_type"] = "bipd",
  19.         ["max_health"] = 75,
  20.         ["max_shield"] = 75,
  21.         ["stun_time"] = 6,
  22.         ["recharge_time"] = 4,
  23.     },
  24. }
  25.  
  26. --End of config
  27.  
  28. object_table_pointer = nil
  29. old_collision_geometry_settings = {}
  30. api_version = "1.9.0.0"
  31.  
  32. function OnScriptLoad()
  33.     object_table_pointer = sig_scan("A1????????8B48348B44910881A004020000FFFFFFFDC3") + 0x1
  34.     register_callback(cb['EVENT_GAME_START'], "OnGameStart")
  35.     register_callback(cb['EVENT_GAME_END'], "OnGameEnd")
  36.    
  37.     local ticks = tonumber(get_var(0, "$ticks"))
  38.     if(ticks > 0) then
  39.         OnGameStart()
  40.     end
  41. end
  42.  
  43. function OnGameStart()
  44.     for k,v in pairs(VITALITY_SETTINGS) do
  45.         if(type(v.tag_path) == "string" and type(v.tag_type) == "string") then
  46.             if(v.tag_type == "vehi" or v.tag_type == "bipd") then
  47.                 local unit_tag = lookup_tag(v.tag_type, v.tag_path)
  48.                 if(unit_tag ~= 0) then
  49.                     local unit_meta = read_dword(unit_tag + 0xC)
  50.                     local unit_data = read_dword(unit_tag + 0x14)
  51.                     local collision_meta = read_dword(unit_data + 0x7C)
  52.                     if(collision_meta ~= 0xFFFFFFFF) then
  53.                         local collision_tag = lookup_tag(collision_meta)
  54.                         if(collision_tag ~= 0) then
  55.                             local collision_data = read_dword(collision_tag + 0x14)
  56.                            
  57.                             local old_data = {
  58.                                 ["collision_meta"] = collision_meta,
  59.                                 ["unit_meta"] = unit_meta,
  60.                                 ["max_health"] = read_float(collision_data + 0x8),
  61.                                 ["max_shield"] = read_float(collision_data + 0xCC),
  62.                                 ["stun_time"] = read_float(collision_data + 0x10C),
  63.                                 ["recharge_time"] = read_float(collision_data + 0x110),
  64.                             }
  65.                             table.insert(old_collision_geometry_settings, old_data)
  66.            
  67.                             if(type(v.max_health) == "number") then
  68.                                 write_float(collision_data + 0x8, v.max_health)
  69.                             end
  70.                             if(type(v.max_shield) == "number") then
  71.                                 write_float(collision_data + 0xCC, v.max_shield)
  72.                             end
  73.                             if(type(v.stun_time) == "number") then
  74.                                 write_float(collision_data + 0x10C, v.stun_time)
  75.                             end
  76.                             if(type(v.recharge_time) == "number") then
  77.                                 write_float(collision_data + 0x110, v.recharge_time)
  78.                             end
  79.                            
  80.                             SetVitalityOfObjects(unit_meta, v.max_health, v.max_shield)
  81.                         end
  82.                     end
  83.                 end
  84.             end
  85.         end
  86.     end
  87. end
  88.  
  89. function OnGameEnd()
  90.     old_collision_geometry_settings = {}
  91. end
  92.  
  93. function SetVitalityOfObjects(MetaID, MaxHealth, MaxShield)
  94.     if(type(MetaID) == "number") then
  95.         local object_table = read_dword(read_dword(object_table_pointer))
  96.         local object_count = read_word(object_table + 0x2E)
  97.         local object_data = read_dword(object_table + 0x34)
  98.         for i=0,object_count-1 do
  99.             local object = read_dword(object_data + i*12 + 0x8)
  100.             if(object ~= 0 and object ~= 0xFFFFFFFF) then
  101.                 local object_meta = read_dword(object)
  102.                 if(object_meta == MetaID) then
  103.                     if(type(MaxHealth) == "number") then
  104.                         write_float(object + 0xD8, MaxHealth)
  105.                     end
  106.                     if(type(MaxShield) == "number") then
  107.                         write_float(object + 0xDC, MaxShield)
  108.                     end
  109.                 end
  110.             end
  111.         end
  112.     end
  113. end
  114.  
  115. function OnScriptUnload()
  116.     for k,v in pairs(old_collision_geometry_settings) do
  117.         local collision_tag = lookup_tag(v.collision_meta)
  118.         if(collision_tag ~= 0) then
  119.             local collision_data = read_dword(collision_tag + 0x14)
  120.             write_float(collision_data + 0x8, v.max_health)
  121.             write_float(collision_data + 0xCC, v.max_shield)
  122.             write_float(collision_data + 0x10C, v.stun_time)
  123.             write_float(collision_data + 0x110, v.recharge_time)
  124.            
  125.             SetVitalityOfObjects(v.unit_meta, v.max_health, v.max_shield)
  126.         end
  127.     end
  128. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top