Advertisement
Guest User

Untitled

a guest
May 3rd, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. --[[ ----------------------------------------------------------------------------------------------
  2. File : xr_combat_ignore.script
  3. Description: Ignoring enemies
  4. Copyright : 2004 © GSC Game World
  5. Author : Chugai Alexander
  6. Editors : gr1ph00n
  7. Last edit : 06.05.2013 [...]
  8. --]] ----------------------------------------------------------------------------------------------
  9. -- TODO: Problem: slow reacting on combat_ignore_cond = {+info}, slow reacting on actor at all before any combat starts, very serious problem!!!
  10. -- TODO: add proper condition always, from new broken script xr_combat_ignore.script_ or use it and fix it!
  11. --/ -----------------------------------------------------------------
  12. --/ VARIABLEs
  13. --/ -----------------------------------------------------------------
  14. local sModule = script_name()
  15. --/ ------------------------------------------------------------------
  16. local log = function(fmt,...) _G.log(sModule..":"..tostring(fmt),...) end
  17. --/ ------------------------------------------------------------------
  18.  
  19. --/ ---------------------------------------------
  20. --/ CONSTRUCTION SCHEME
  21. --/ -----------------------------------------------------------------------------------------------
  22. class "action_process_enemy"
  23. --/ -----------------------------------------------------------------------------------------------
  24. function action_process_enemy:__init( oNPC, st )
  25. self.object = oNPC
  26. self.st = st
  27. self.log = st.log
  28. end
  29. --/------------------------------------------------------------------
  30. --/ CALLBACKs
  31. --/------------------------------------------------------------------
  32. function action_process_enemy:hit_callback(oObj, iAmount, vLocalDirection, oWho, iBoneIndex)
  33. -- if self.log then log("ac:hit_callback:NPC=[%s],Enemy=[%s]", oObj and oObj:name(), oWho and oWho:name(), "") end --/#~#
  34. if iAmount > 0 and oWho and oWho:id() == idActor then --/ otherwise: somebody shoot in air
  35. local tOverrides = self.st.overrides --xr_logic.generic_scheme_overrides(oObj)
  36. if not (tOverrides and tOverrides.combat_ignore_keep_when_attacked) then
  37. self.st.enabled = false
  38. end
  39. end
  40. end
  41.  
  42. function action_process_enemy:enemy_callback(oNPC, oEnemy)
  43. if oNPC and oEnemy then
  44. if self.log then log("ac:enemy_callback:NPC=[%s],Enemy=[%s]", self.object:name(), oEnemy and oEnemy:name(), "") end --/#~#
  45. return this.is_enemy(oNPC, oEnemy, self.st) --/>
  46. end
  47. return false --/>
  48. end
  49. --/ -----------------------------------------------------------------------------------------------
  50. --/ Binder
  51. --/ -----------------------------------------------------------------------------------------------
  52. function add_to_binder(oNPC, ini, sScheme, sSection, st)
  53. -- log("add_to_binder:NPC=[%s],scheme=[%s],section=[%s]:[%s]", oNPC:name(), sScheme, sSection, ">") --/#~#
  54. st.action = this.action_process_enemy(oNPC, st)
  55. --/ fot debug!
  56. if st.log then log("add_to_binder:NPC=[%s],scheme=[%s],section=[%s]:[%s]", oNPC:name(), sScheme, sSection, "+") end --/#~#
  57. end
  58. --/ -----------------------------------------------------------------
  59. --/ SET SCHEME - enabling scheme
  60. --/ -----------------------------------------------------------------
  61. function set_scheme(oNPC, ini, sScheme, sSection)
  62. -- log("set_scheme:NPC=[%s],scheme=[%s],section=[%s]", oNPC:name(), sScheme, sSection, "") --/#~#
  63. local st = xr_logic.assign_storage_and_bind(oNPC, ini, sScheme, sSection)
  64. --[[
  65. oNPC:set_enemy_callback( st.action.enemy_callback, st.action ) --/#?#
  66. --/ registration of 'action', for call of 'callback' when changing settings of scheme:
  67. xr_logic.subscribe_action_for_events(oNPC, st, st.action)
  68. --st.logic = xr_logic.cfg_get_switch_conditions(ini, sSection, oNPC)
  69. st.enabled = true
  70. --]]
  71. --/ for debug
  72. if st.log then log("set_scheme:NPC=[%s],scheme=[%s],section=[%s]", oNPC:name(), sScheme, sSection, "") end --/#~#
  73. end
  74. --/ -----------------------------------------------------------------
  75. --/ RESET SCHEME - switching scheme
  76. --/ -----------------------------------------------------------------
  77. function reset_scheme(oNPC, sScheme, tStor, sSection) --/#+#
  78. local st = tStor.combat_ignore
  79. if st then
  80. if st.action then
  81. --/ setting enemy-callback
  82. if IsStalker(oNPC) then
  83. oNPC:set_enemy_callback( st.action.enemy_callback, st.action ) --/#?#
  84. else
  85. log("reset_scheme:NPC=[%s],clsid=[%s],scheme=[%s],section=[%s] ~ not set_enemy_callback", oNPC:name(), oNPC:clsid(), sScheme, sSection, "") --/#~#
  86. end
  87. --/ subscribe on hit callback:
  88. xr_logic.subscribe_action_for_events( oNPC, st, st.action )
  89. st.overrides = xr_logic.generic_scheme_overrides(oNPC)
  90. st.enabled = true
  91. --/ for debug
  92. if st.log then log("reset_scheme:NPC=[%s],scheme=[%s],section=[%s]", oNPC:name(), sScheme, sSection, "") end --/#~#
  93. else
  94. log("reset_scheme:NPC=[%s],scheme=[%s],section=[%s], action~%s", oNPC:name(), sScheme, "???") --/#~#
  95. end
  96. end
  97. end
  98. --/------------------------------------------------------------------
  99. --/ DISABLE SCHEME - disabling scheme
  100. --/------------------------------------------------------------------
  101. function disable_scheme(oNPC, sScheme)
  102. if IsStalker(oNPC) then --/ CCustomMonster : cannot access class member set_enemy_callback!
  103. oNPC:set_enemy_callback() --/< disable 'enemy_callback'
  104. elseif not IsTrader(oNPC) then
  105. log("disable_scheme: NPC=[%s], clsid=[%s] ~ cannot access class member set_enemy_callback!", oNPC and oNPC:name(), oNPC and oNPC:clsid(), "") --/#~#
  106. end
  107. local st = db.storage[oNPC:id()][sScheme]
  108. if st then
  109. st.enabled = false
  110. if st.action then
  111. --/ unsubscribe from hit callback:
  112. --/ This is necessary cause otherwise when switching on other set of schemes, in which there is no interception of combat,
  113. --/ on old subscribed action continue call of callback.
  114. xr_logic.unsubscribe_action_from_events(oNPC, st, st.action)
  115. end
  116. if st.log then log("disable_scheme:NPC=[%s],scheme=[%s]", oNPC:name(), sScheme, "") end --/#~#
  117. end
  118. end
  119. --/ -----------------------------------------------------------------------------------------------
  120. --/ HELPERs
  121. --/ -----------------------------------------------------------------------------------------------
  122. function is_enemy(oNPC, oEnemy, st)
  123. if not oNPC:alive() then
  124. return false --/>
  125. elseif oNPC:critically_wounded() then
  126. return true --/>
  127. end
  128. local tStor = db.storage[oNPC:id()]
  129. if not st then
  130. if tStor then
  131. st = tStor.combat_ignore
  132. end
  133. end
  134. if not (st and st.enabled) then
  135. return true --/>
  136. end
  137.  
  138. tStor.enemy = oEnemy
  139. tStor.enemy_id = oEnemy and oEnemy:id() --/#?#
  140.  
  141. local tO = st.overrides --xr_logic.generic_scheme_overrides(oNPC)
  142. if tO and tO.combat_ignore and xr_logic.pick_section_from_condlist(db.actor, oNPC, tO.combat_ignore.condlist) ~= nil then
  143. oNPC:enable_memory_object(oEnemy, false)
  144. return false --/>
  145. end
  146. return true --/>
  147. end
  148. --/ -----------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement