Nuor

campfire_manager.script

Jan 10th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. local wait, use_cooking
  2.  
  3. function activate_feature()
  4. wait = true
  5. use_cooking = false
  6. RegisterScriptCallback("actor_on_item_use",item_use)
  7. CreateTimeEvent(0,"save_camp_timer",30,save_camp)
  8. end
  9.  
  10. function deactivate_feature()
  11. wait = nil
  12. use_cooking = nil
  13. UnregisterScriptCallback("actor_on_item_use",item_use)
  14. end
  15.  
  16. local function opt_menu_on_init(menu)
  17. -- matches_used
  18. menu.gameplay_add_options["matches_used"] = {default=false, debug_only=false, typ="check",
  19. on_accept=function(handler,optMgr,ctrl)
  20. if (level.present()) then
  21. if (ctrl:GetCheck()) then
  22. activate_feature()
  23. else
  24. deactivate_feature()
  25. end
  26. end
  27. end
  28. }
  29. end
  30.  
  31. function on_game_start()
  32. RegisterScriptCallback("opt_menu_on_init",opt_menu_on_init)
  33. if (axr_main.config:r_value("mm_options","enable_matches_used",1,false) == false) then return end
  34. activate_feature()
  35. end
  36.  
  37. function item_use(obj)
  38. if (obj:section() == "matches") then
  39. campfire_on(obj)
  40. end
  41. end
  42.  
  43. function iSnearCamp(dist)
  44. for id,binder in pairs(bind_campfire.campfires_all) do
  45. if (db.actor:position():distance_to_sqr(binder.object:position()) <= dist^2) then
  46. return binder.object
  47. end
  48. end
  49. end
  50.  
  51. function iSnearCustom(dist)
  52. for id, se_obj in alife():objects() do
  53. if se_obj:section_name() == "ph_campfire" and se_obj.position:distance_to_sqr(db.actor:position()) < dist^2 then
  54. --news_manager.send_tip(db.actor, "Near Campfire", nil, nil, nil, 1000)
  55. return level.object_by_id(id)
  56. end
  57. end
  58. end
  59.  
  60. function save_camp()
  61. wait = nil
  62. return true
  63. end
  64.  
  65. function campfire_on(matches)
  66. local obj = iSnearCamp(1.5) or iSnearCustom(1.5)
  67. local cf = obj and obj:get_campfire()
  68. if cf then
  69. -- save on match use
  70. if not (wait) then
  71. local flist = getFS():file_list_open_ex("$game_saves$", bit_or(FS.FS_ListFiles,FS.FS_RootOnly),"*".. ui_load_dialog.saved_game_extension)
  72. local f_cnt = flist and flist:Size() or 0
  73.  
  74. local inc = 0
  75. if (f_cnt > 0) then
  76. flist:Sort(FS.FS_sort_by_modif_down)
  77. for it=0, f_cnt-1 do
  78. local file_name = flist:GetAt(it):NameFull():sub(0,-6):lower()
  79. -- grab last modified quicksave increment count
  80. local d = tonumber( file_name:match("campfire_autosave(%d+)") )
  81. if (d) then
  82. inc = d
  83. break
  84. end
  85. end
  86. end
  87. inc = inc >= axr_main.config:r_value("mm_options","quicksave_cnt",2,5) and 1 or inc + 1
  88. get_console():execute("save campfire_autosave"..inc)
  89. wait = true
  90. CreateTimeEvent(0,"save_camp_timer",30,save_camp)
  91. end
  92. -- attempt to light fire
  93. if not (cf:is_on()) then
  94. if actor_effects then actor_effects.use_item("matches") end
  95. if (level.rain_factor() < math.random()) then
  96. xr_sound.set_sound_play(db.actor:id(),"inv_matches")
  97. cf:turn_on()
  98. if bind_picnic then bind_picnic.safe_zone() end
  99. else
  100. local text = game.translate_string("st_fail")
  101. SetHudMsg(text,3)
  102. end
  103. end
  104. else
  105. local text = game.translate_string("st_camp_far")
  106. SetHudMsg(text,3)
  107. end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment