Nuor

ammo_dampness.script

Jul 19th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. --Ammo damp refactored
  2. local tmr
  3. local ini = system_ini()
  4.  
  5. function on_game_start()
  6. RegisterScriptCallback("actor_on_update",actor_on_update)
  7. end
  8.  
  9. function actor_on_update()
  10. if surge_manager.actor_in_cover == true then return end
  11. local diff = tmr and game.get_game_time():diffSec(tmr) or 3600
  12. if (diff < 3600) then
  13. return
  14. end
  15. tmr = game.get_game_time()
  16.  
  17. local dampness_chance = math.ceil(level.rain_factor()*100)
  18. local backpack = db.actor:item_in_slot(13)
  19. backpack = backpack and backpack:section()
  20.  
  21. if backpack then
  22. if (backpack == "backpack_heavy") then
  23. dampness_chance = math.ceil(dampness_chance/10)
  24. elseif (backpack == "backpack_tourist") then
  25. dampness_chance = math.ceil(dampness_chance/3)
  26. elseif ((backpack == "backpack_specops") or (backpack == "backpack_military")) then
  27. dampness_chance = math.ceil(dampness_chance/6)
  28. end
  29. end
  30.  
  31. local function damp_ammo(dummy, item)
  32. local sec = item:section()
  33. if sec and IsAmmo(item) and ini:section_exist(sec.."_bad") then
  34. --printf("inventory item:%s",sec)
  35. local org_cnt = item:ammo_get_count()
  36. local new_cnt = math.floor(org_cnt * (100-dampness_chance) / 100)
  37. if new_cnt > 0 then
  38. item:ammo_set_count(new_cnt)
  39. else
  40. alife():release(alife_object(item:id()),true)
  41. end
  42. create_ammo(sec.."_bad",db.actor:position(),db.actor:level_vertex_id(),db.actor:game_vertex_id(),0,org_cnt - new_cnt)
  43. end
  44. end
  45. --printf("dampness:%s",dampness_chance)
  46. if (dampness_chance >= 2000) then -- 5% chance of failure with no backpack and 100% rain
  47. db.actor:iterate_inventory(damp_ammo)
  48. end
  49. end
Advertisement
Add Comment
Please, Sign In to add comment