Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local wait, use_cooking
- function activate_feature()
- wait = true
- use_cooking = false
- RegisterScriptCallback("actor_on_item_use",item_use)
- CreateTimeEvent(0,"save_camp_timer",30,save_camp)
- end
- function deactivate_feature()
- wait = nil
- use_cooking = nil
- UnregisterScriptCallback("actor_on_item_use",item_use)
- end
- local function opt_menu_on_init(menu)
- -- matches_used
- menu.gameplay_add_options["matches_used"] = {default=false, debug_only=false, typ="check",
- on_accept=function(handler,optMgr,ctrl)
- if (level.present()) then
- if (ctrl:GetCheck()) then
- activate_feature()
- else
- deactivate_feature()
- end
- end
- end
- }
- end
- function on_game_start()
- RegisterScriptCallback("opt_menu_on_init",opt_menu_on_init)
- if (axr_main.config:r_value("mm_options","enable_matches_used",1,false) == false) then return end
- activate_feature()
- end
- function item_use(obj)
- if (obj:section() == "matches") then
- campfire_on(obj)
- end
- end
- function iSnearCamp(dist)
- for id,binder in pairs(bind_campfire.campfires_all) do
- if (db.actor:position():distance_to_sqr(binder.object:position()) <= dist^2) then
- return binder.object
- end
- end
- end
- function iSnearCustom(dist)
- for id, se_obj in alife():objects() do
- if se_obj:section_name() == "ph_campfire" and se_obj.position:distance_to_sqr(db.actor:position()) < dist^2 then
- --news_manager.send_tip(db.actor, "Near Campfire", nil, nil, nil, 1000)
- return level.object_by_id(id)
- end
- end
- end
- function save_camp()
- wait = nil
- return true
- end
- function campfire_on(matches)
- local obj = iSnearCamp(1.5) or iSnearCustom(1.5)
- local cf = obj and obj:get_campfire()
- if cf then
- -- save on match use
- if not (wait) then
- local flist = getFS():file_list_open_ex("$game_saves$", bit_or(FS.FS_ListFiles,FS.FS_RootOnly),"*".. ui_load_dialog.saved_game_extension)
- local f_cnt = flist and flist:Size() or 0
- local inc = 0
- if (f_cnt > 0) then
- flist:Sort(FS.FS_sort_by_modif_down)
- for it=0, f_cnt-1 do
- local file_name = flist:GetAt(it):NameFull():sub(0,-6):lower()
- -- grab last modified quicksave increment count
- local d = tonumber( file_name:match("campfire_autosave(%d+)") )
- if (d) then
- inc = d
- break
- end
- end
- end
- inc = inc >= axr_main.config:r_value("mm_options","quicksave_cnt",2,5) and 1 or inc + 1
- get_console():execute("save campfire_autosave"..inc)
- wait = true
- CreateTimeEvent(0,"save_camp_timer",30,save_camp)
- end
- -- attempt to light fire
- if not (cf:is_on()) then
- if actor_effects then actor_effects.use_item("matches") end
- if (level.rain_factor() < math.random()) then
- xr_sound.set_sound_play(db.actor:id(),"inv_matches")
- cf:turn_on()
- if bind_picnic then bind_picnic.safe_zone() end
- else
- local text = game.translate_string("st_fail")
- SetHudMsg(text,3)
- end
- end
- else
- local text = game.translate_string("st_camp_far")
- SetHudMsg(text,3)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment