Intercept actor_on_info_callback function for battery drain

kcs123
Scavenger
Posts: 10
Joined: 11 Oct 2015, 12:41

Intercept actor_on_info_callback function for battery drain

Postby kcs123 » 16 Oct 2015, 11:57

I get battery drain feature working, all but battery drain when PDA UI is open and checks if can be opened at all if actor does not have UPD with enough condition (battery charge).

Might be wrong in following, but this is how much I was able to figure out by looking into scripts used in Misery.
There is comment in axr_battery.script:
-- add this function to bind_stalker info_callback function
-- battery.process_pda_infoportion(info_id)


However, it was not done in that way. Instead, in bind_stalker.script is this:

Code: Select all

function actor_binder:info_callback(npc, info_id)
   -- Alundaio
   if (axr_main) then axr_main.actor_on_info_callback(npc,info_id) end
   -- Alundaio
end


And in axr_main.script is this part of code:

Code: Select all

-------------------
-- actor_on_info_callback(npc,info_id)
-------------------
function actor_on_info_callback(npc,info_id)
   for i=1, #intercepts.actor_on_info_callback do
      intercepts.actor_on_info_callback[i](npc,info_id)
   end
end


So, my best guess on this is that following part of code in axr_battery.script register interception and then it is triggered with rest of interceptions in code above.

Code: Select all

RegisterScriptCallback("actor_on_info_callback",process_pda_infoportion)


However, in CoC, that function "process_pda_infoportion" is not processed at all. It is never executed. I probably missing something, like additional data in intercepts table in axr_main.script or something. CoC handles all this stuff in probably better way, but I was not able to figure out all new changes.

So, my question is, how to properly register interceptions in CoC ?

User avatar
Alundaio
S.T.A.L.K.E.R.
Posts: 1368
Joined: 26 May 2012, 22:26

Re: Intercept actor_on_info_callback function for battery drain

Postby Alundaio » 16 Oct 2015, 13:43

Code: Select all

function actor_on_info_callback(binder,obj,info_id)
   SendScriptCallback("actor_on_info_callback",obj,info_id)
end

Add the above to bind_stalker_ext.script, it was missing maybe intentionally, because I thought there was no use for it. bind_stalker should already register this function for the callback, but since it is nil, it isn't triggered.

Registering For Script Callbacks:
axr_main is pretty much automated now. For the new system, you need to create a on_game_start function for your script. Then call what script callbacks you want to register for. To register a script for on_game_start callback you simply add the script name to script_modules table in axr_main.script. Technically you can use RegisterScriptCallback anywhere, you don't have to do it on_game_start. SendScriptCallback will iterate the intercept table and execute all the registered functions.

axr_main.script:
local script_modules = {
"modules",
"alife_storage_manager",
"atmosfear",
"axr_battery"
"surge_manager",
"psi_storm_manager",
"phantom_manager",
"xrs_dyn_music",
"coc_treasure_manager",
"ui_mm_faction_select",
"axr_keybind",
--"xrs_rnd_npc_loadout",
--"axr_dynamic_spawn",
"itms_manager",
"xr_statistic",
"m_mines",
"axr_task_manager",
"axr_companions",
"xr_eat_medkit",
"axr_trade_manager",
"inventory_upgrades",
"axr_task_manager"
}


axr_battery.script:

Code: Select all

function on_game_start()
     RegisterScriptCallback("actor_on_info_callback",process_pda_infoportion)
end

function process_pda_infoportion(npc,info_id)
     -- do stuff
end


Creating New Script Callbacks:
If you want to create new script callbacks for your own uses, add the callback name to the intercepts table in axr_main.script. Then when you want the callback to be triggered, just call CreateScriptCallback.


Now hopefully you can see why this new system is better. No need to create dozens of functions in axr_main itself or to manually write out code every time.
"I have a dream that one day this community will rise up and live out the true meaning of its creed: "We hold these truths to be self-evident; that all mods are created equal."

kcs123
Scavenger
Posts: 10
Joined: 11 Oct 2015, 12:41

Re: Intercept actor_on_info_callback function for battery drain

Postby kcs123 » 16 Oct 2015, 14:47

Thanks, I already added axr_battery to script_modules table. UPD condition is properly drained when NVG or head flashlight is used. Also battery change function works well, I just added

Code: Select all

axr_battery.use_battery(sec)

nested in actor_on_item_use(binder,item) function.

That missing function in bind_stalker_ext.script was puzzled me around. I couldn't figure out exact syntax what I need to write there. I tried something similar but it was throws error. I gave up after few attempts and done some other things in meantime.

Yep, whole scripts feels a lot more organized, much easier to merge other scripts as plugin. Especialy if other scripts are properly written. Ai_tweaks and inventory radiation(artifact containers) worked almost without additional modifications.

Only problem is that we have to get used to new system, lot of old scripts need to be changed slightly to better fit in new merging system. But once it is figured out it will certainly be much more easier to do further tweaks.

kcs123
Scavenger
Posts: 10
Joined: 11 Oct 2015, 12:41

Re: Intercept actor_on_info_callback function for battery drain

Postby kcs123 » 16 Oct 2015, 15:46

I have added missing function actor_on_info_callback in bind_stalker_ext.script. Interception has start triggering, although I have expected to be more often. in axr_battery.script "process_pda_infoportion" function look like this:

Code: Select all

function process_pda_infoportion(npc,info_id)
   local actor = db.actor
   if actor then
      alun_utils.printf("KCS - axr_battery pda infoportion triggered, info_id = %s",info_id) -- KCS - additional info for debug
      if info_id == "ui_pda" then
         -- PDA opened
         -- set flag to indicate PDA is open
         pda_open = true;
         alun_utils.printf("KCS - axr_battery pda_open flag set to True") -- KCS - additional info for debug
         --news_manager.send_tip(actor, "Opening PDA", nil, nil, 5000)
         actor:disable_info_portion("ui_pda_hide")
      elseif info_id == "ui_pda_hide" then
         -- PDA closed
         -- remove flag to indicate PDA is closed
         pda_open = false;
         alun_utils.printf("KCS - axr_battery pda_open flag set to False") -- KCS - additional info for debug
         --news_manager.send_tip(actor, "Closing PDA", nil, nil, 5000)
         actor:disable_info_portion("ui_pda")
      end
   end
end


In console/log I see only this part:
KCS - axr_battery pda infoportion triggered


That probably mean info_id has never value "ui_pda" or "ui_pda_hide". Probably that was changed from vanilla CoP or it was added on some other script/config file. Can you recall where it is handled ?

From that function only "pda_open" value is used in other function to drain battery or force closing PDA if battery is too low.
Since for some reason info_id have different value or (just poped on my mind) info_id is not passed properly, it have nil value or something like that.

I will try to print value from info_id in log, if it is nil then I'm on dead end again.

EDIT:
I have updated script to catch info_id value in log. I got this in log/console:
! Cannot find saved game ~#debug msg:kcs - axr_battery pda infoportion triggered, info_id = bar_visitors_npc_trade


It seems something is missmatched in scripts. I have expected to see some flooding in log when actor open PDA, but neither have happened. I never have "ui_pda" value in log for some reason.

User avatar
Alundaio
S.T.A.L.K.E.R.
Posts: 1368
Joined: 26 May 2012, 22:26

Re: Intercept actor_on_info_callback function for battery drain

Postby Alundaio » 16 Oct 2015, 16:36

Okay, I just tested this. I saw ui_pda and ui_pda_local_map print out to log when I opened the PDA and then I saw pda_hide when I closed it. But only once. It's not being switched on and off.

These are handled by engine and gamedata\configs\gameplay\info_portions.xml. You can perform dialog or enable/disable info when actor receives info with this. It is set up to toggle like you expect. I'm not sure what the problem is.

Here is engine code that sends the pda info portions:

Code: Select all

void CUIPdaWnd::Show(bool status)
{
   inherited::Show                  (status);
   if(status)
   {
      InventoryUtilities::SendInfoToActor   ("ui_pda");
      
      if ( !m_pActiveDialog )
      {
         SetActiveSubdialog            ("eptTasks");
      }
      m_pActiveDialog->Show            (true);
   }else
   {
      InventoryUtilities::SendInfoToActor   ("ui_pda_hide");
      CurrentGameUI()->UIMainIngameWnd->SetFlashIconState_(CUIMainIngameWnd::efiPdaTask, false);
      m_pActiveDialog->Show            (false);
      g_btnHint->Discard               ();
      g_statHint->Discard               ();
   }
}


So what seems to be the problem is the info not being disabled somewhere. Strangely I cannot find any references to info_portions.xml which could be the problem. Maybe it was removed in 1.6 engine and is obsolete. Your code should technically work if you start a new game and it's the first time the pda is ever opened.

EDIT:

I found it in code and it is indeed commented out in 1.6 source. So this is a problem in vanilla COP too.

system.ltx info_portion section is not loaded which is rather odd.
"I have a dream that one day this community will rise up and live out the true meaning of its creed: "We hold these truths to be self-evident; that all mods are created equal."

kcs123
Scavenger
Posts: 10
Joined: 11 Oct 2015, 12:41

Re: Intercept actor_on_info_callback function for battery drain

Postby kcs123 » 18 Oct 2015, 16:30

Just to confirm, when this missing function is added in bind_stalker_ext.script everything works as intended on new game, even spam in log due to extra comments added for debug purposes.

Code: Select all

function actor_on_info_callback(binder,obj,info_id)
   SendScriptCallback("actor_on_info_callback",obj,info_id)
end


Maybe someone else will need that info, if deceide to add battery drain in their mod.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest