Advertisement
Guest User

xr_effects.script

a guest
Nov 9th, 2012
1,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 94.29 KB | None | 0 0
  1. -- ----------------------------------------------------------------------------------------------------
  2. -- Îáùèå ôóíêöèè
  3. -- ----------------------------------------------------------------------------------------------------
  4.  
  5. -- Ïðèíóäèòåëüíî àïäåéòèò ëîãèêó ó îáúåêòîâ, ïåðåäàííûõ ïàðàìåòðîì. Ïîêà ðàáîòàåò òîëüêî ñ ÍÏÑ
  6. function update_npc_logic(actor, object, p)
  7.     --printf("UPDATE NPC LOGIC %s", device():time_global())
  8.     for k,v in pairs(p) do
  9.         local npc = get_story_object(v)
  10.         if npc ~= nil then
  11.             xr_motivator.update_logic(npc)
  12.  
  13.             local planner = npc:motivation_action_manager()
  14.             planner:update()
  15.             planner:update()
  16.             planner:update()
  17.  
  18.             db.storage[npc:id()].state_mgr:update()
  19.             db.storage[npc:id()].state_mgr:update()
  20.             db.storage[npc:id()].state_mgr:update()
  21.             db.storage[npc:id()].state_mgr:update()
  22.             db.storage[npc:id()].state_mgr:update()
  23.             db.storage[npc:id()].state_mgr:update()
  24.             db.storage[npc:id()].state_mgr:update()
  25.         end
  26.     end
  27. end
  28.  
  29. function update_obj_logic(actor, object, p)
  30.     --printf("UPDATE OBJ LOGIC %s", device():time_global())
  31.     for k,v in pairs(p) do
  32.         local obj = get_story_object(v)
  33.         if obj ~= nil then
  34.  
  35.             local st = db.storage[obj:id()]
  36.             xr_logic.try_switch_to_another_section(obj, st[st.active_scheme], actor)
  37.  
  38. --          if st.active_scheme == "sr_cutscene" then
  39. --              st[st.active_scheme].cutscene_action
  40. --          end
  41.  
  42.         end
  43.     end
  44. end
  45.  
  46. local ui_active_slot = 0
  47.  
  48. function disable_ui(actor, npc, p)
  49.     if db.actor:is_talking() then
  50.         db.actor:stop_talk()
  51.     end
  52.     level.show_weapon(false)
  53.  
  54.     if not p or (p and p[1] ~= "true") then
  55.         local slot = db.actor:active_slot()
  56.         if(slot~=0) then
  57.             ui_active_slot = slot
  58.             db.actor:activate_slot(0)
  59.         end
  60.     end
  61.  
  62.     level.disable_input()
  63.     level.hide_indicators_safe()
  64.     local hud = get_hud()
  65.     hud:HideActorMenu()
  66.     hud:HidePdaMenu()
  67.     disable_actor_nightvision(nil,nil)
  68.     disable_actor_torch(nil,nil)
  69. end
  70.  
  71. function disable_ui_only(actor, npc)
  72.     if db.actor:is_talking() then
  73.         db.actor:stop_talk()
  74.     end
  75.     level.show_weapon(false)
  76.  
  77.     if not p or (p and p[1] ~= "true") then
  78.         local slot = db.actor:active_slot()
  79.         if(slot~=0) then
  80.             ui_active_slot = slot
  81.             db.actor:activate_slot(0)
  82.         end
  83.     end
  84.  
  85.     level.disable_input()
  86.     level.hide_indicators_safe()
  87.     local hud = get_hud()
  88.     hud:HideActorMenu()
  89.     hud:HidePdaMenu()
  90. end
  91.  
  92. function enable_ui(actor, npc, p)
  93.     --db.actor:restore_weapon()
  94.  
  95.     if not p or (p and p[1] ~= "true") then
  96.         if ui_active_slot ~= 0 and db.actor:item_in_slot(ui_active_slot) ~= nil then
  97.             db.actor:activate_slot(ui_active_slot)
  98.         end
  99.     end
  100.  
  101.     ui_active_slot = 0
  102.     level.show_weapon(true)
  103.     level.enable_input()
  104.     level.show_indicators()
  105.     enable_actor_nightvision(nil,nil)
  106.     enable_actor_torch(nil,nil)
  107. end
  108.  
  109. local cam_effector_playing_object_id = nil
  110.  
  111. function run_cam_effector(actor, npc, p)
  112.     if p[1] then
  113.         local loop, num = false, (1000 + math.random(100))
  114.         if p[2] and type(p[2]) == "number" and p[2] > 0 then
  115.             num = p[2]
  116.         end
  117.         if p[3] and p[3] == "true" then
  118.             loop = true
  119.         end
  120.         --level.add_pp_effector(p[1] .. ".ppe", num, loop)
  121.         level.add_cam_effector("camera_effects\\" .. p[1] .. ".anm", num, loop, "xr_effects.cam_effector_callback")
  122.         cam_effector_playing_object_id = npc:id()
  123.     end
  124. end
  125.  
  126. function stop_cam_effector(actor, npc, p)
  127.     if p[1] and type(p[1]) == "number" and p[1] > 0 then
  128.         level.remove_cam_effector(p[1])
  129.     end
  130. end
  131.  
  132. function run_cam_effector_global(actor, npc, p)
  133.     local num = 1000 + math.random(100)
  134.     if p[2] and type(p[2]) == "number" and p[2] > 0 then
  135.          num = p[2]
  136.     end
  137.     local fov = device().fov
  138.     if p[3] ~= nil and type(p[3]) == "number" then
  139.         fov = p[3]
  140.     end
  141.     level.add_cam_effector2("camera_effects\\" .. p[1] .. ".anm", num, false, "xr_effects.cam_effector_callback", fov)
  142.     cam_effector_playing_object_id = npc:id()
  143. end
  144.  
  145. function cam_effector_callback()
  146.     if cam_effector_playing_object_id == nil then
  147.         printf("cam_eff:callback1!")
  148.         return
  149.     end
  150.     local st   = db.storage[cam_effector_playing_object_id]
  151.     if st == nil or st.active_scheme == nil then
  152.         printf("cam_eff:callback2!")
  153.         return
  154.     end
  155.  
  156.     if st[st.active_scheme].signals == nil then
  157.         printf("cam_eff:callback3!")
  158.         return
  159.     end
  160.     st[st.active_scheme].signals["cameff_end"] = true
  161. end
  162.  
  163. function run_postprocess(actor, npc, p)
  164.     if (p[1]) then
  165.         if(system_ini():section_exist(p[1])) then
  166.             local num = 2000 + math.random(100)
  167.             if(p[2] and type(p[2]) == "number" and p[2]>0) then
  168.                 num = p[2]
  169.             end
  170.             printf("adding complex effector [%s], id [%s], from [%s]", p[1], tostring(p[2]), tostring(npc:name()))
  171.             level.add_complex_effector(p[1], num)
  172.         else
  173.             abort("Complex effector section is no set! [%s]", tostring(p[1]))
  174.         end
  175.     end
  176. end
  177.  
  178. function stop_postprocess(actor, npc, p)
  179.     if(p[1] and type(p[1]) == "number" and p[1]>0) then
  180.         printf("removing complex effector id [%s] from [%s]", tostring(p[1]), tostring(npc:name()))
  181.         level.remove_complex_effector(p[1])
  182.     end
  183. end
  184.  
  185. function run_tutorial(actor, npc, p)
  186.     printf("run tutorial called")
  187.     game.start_tutorial(p[1])
  188. end
  189.  
  190. --[[
  191. function run_tutorial_if_newbie(actor, npc, p)
  192.     if has_alife_info("esc_trader_newbie") then
  193.         game.start_tutorial(p[1])
  194.     end
  195. end
  196. ]]--
  197.  
  198. function jup_b32_place_scanner(actor, npc)
  199.     for i = 1, 5 do
  200.         if xr_conditions.actor_in_zone(actor, npc, {"jup_b32_sr_scanner_place_"..i})
  201.             and not has_alife_info("jup_b32_scanner_"..i.."_placed") then
  202.             db.actor:give_info_portion("jup_b32_scanner_"..i.."_placed")
  203.             db.actor:give_info_portion("jup_b32_tutorial_done")
  204.             remove_item(actor, npc, {"jup_b32_scanner_device"})
  205.             spawn_object(actor, nil, {"jup_b32_ph_scanner","jup_b32_scanner_place_"..i})
  206.         end
  207.     end
  208. end
  209.  
  210. function jup_b32_pda_check(actor, npc)
  211.     pda.change_anomalies_names()
  212. end
  213.  
  214. function pri_b306_generator_start(actor, npc)
  215.     if xr_conditions.actor_in_zone(actor, npc, {"pri_b306_sr_generator"}) then
  216.         give_info("pri_b306_lift_generator_used")
  217.     end
  218. end
  219.  
  220. function jup_b206_get_plant(actor, npc)
  221.     if xr_conditions.actor_in_zone(actor, npc, {"jup_b206_sr_quest_line"}) then
  222.         give_info("jup_b206_anomalous_grove_has_plant")
  223.         give_actor(actor, npc, {"jup_b206_plant"})
  224.         destroy_object(actor, npc, {"story", "jup_b206_plant_ph"})
  225.     end
  226. end
  227.  
  228. function pas_b400_switcher(actor, npc)
  229.     if xr_conditions.actor_in_zone(actor, npc, {"pas_b400_sr_switcher"}) then
  230.         give_info("pas_b400_switcher_use")
  231.     end
  232. end
  233.  
  234.  
  235. function jup_b209_place_scanner(actor, npc)
  236.     if xr_conditions.actor_in_zone(actor, npc, {"jup_b209_hypotheses"}) then
  237.         scenario_autosave(db.actor, nil, {"st_save_jup_b209_placed_mutant_scanner"})
  238.         db.actor:give_info_portion("jup_b209_scanner_placed")
  239.         remove_item(actor, npc, {"jup_b209_monster_scanner"})
  240.         spawn_object(actor, nil, {"jup_b209_ph_scanner","jup_b209_scanner_place_point"})
  241.     end
  242. end
  243.  
  244. function jup_b9_heli_1_searching(actor, npc)
  245.     if xr_conditions.actor_in_zone(actor, npc, {"jup_b9_heli_1"})
  246.         then
  247.         db.actor:give_info_portion("jup_b9_heli_1_searching")
  248.     end
  249. end
  250.  
  251. function pri_a18_use_idol(actor, npc)
  252.     if xr_conditions.actor_in_zone(actor, npc, {"pri_a18_use_idol_restrictor"})
  253.         then
  254.         db.actor:give_info_portion("pri_a18_run_cam")
  255.     end
  256. end
  257.  
  258. function jup_b8_heli_4_searching(actor, npc)
  259.     if xr_conditions.actor_in_zone(actor, npc, {"jup_b8_heli_4"})
  260.         then
  261.         db.actor:give_info_portion("jup_b8_heli_4_searching")
  262.     end
  263. end
  264.  
  265. function jup_b10_ufo_searching(actor, npc)
  266.     if xr_conditions.actor_in_zone(actor, npc, {"jup_b10_ufo_restrictor"})
  267.         then
  268.         db.actor:give_info_portion("jup_b10_ufo_memory_started")
  269.         give_actor(db.actor,nil,{"jup_b10_ufo_memory"})
  270.     end
  271. end
  272.  
  273.  
  274. function zat_b101_heli_5_searching(actor, npc)
  275.     if xr_conditions.actor_in_zone(actor, npc, {"zat_b101_heli_5"})
  276.         then
  277.         db.actor:give_info_portion("zat_b101_heli_5_searching")
  278.     end
  279. end
  280.  
  281. function zat_b28_heli_3_searching(actor, npc)
  282.     if xr_conditions.actor_in_zone(actor, npc, {"zat_b28_heli_3"})
  283.         then
  284.         db.actor:give_info_portion("zat_b28_heli_3_searching")
  285.     end
  286. end
  287.  
  288. function zat_b100_heli_2_searching(actor, npc)
  289.     if xr_conditions.actor_in_zone(actor, npc, {"zat_b100_heli_2"}) then
  290.         db.actor:give_info_portion("zat_b100_heli_2_searching")
  291.     end
  292. end
  293.  
  294. function teleport_actor(actor, npc, p)
  295.     local point = patrol(p[1])
  296.     local dir
  297.     if p[2] ~= nil then
  298.         local look = patrol(p[2])
  299.         dir = -look:point(0):sub(point:point(0)):getH()
  300.         db.actor:set_actor_direction(dir)
  301.     end
  302.  
  303.     for k,v in pairs(db.no_weap_zones) do
  304.         local zone = db.zone_by_name[k]
  305.         if utils.npc_in_zone(db.actor, zone) then
  306.             db.no_weap_zones[k] = true
  307.         end
  308.     end
  309.  
  310.     if npc and npc:name() ~= nil then
  311.         printf("teleporting actor from [%s]", tostring(npc:name()))
  312.     end
  313.  
  314.     db.actor:set_actor_position(point:point(0))
  315. end
  316.  
  317.  
  318. local function reset_animation(npc)
  319.     local state_mgr = db.storage[npc:id()].state_mgr
  320.     if state_mgr == nil then
  321.         return
  322.     end
  323.     local planner = npc:motivation_action_manager()
  324.  
  325.     state_mgr.animation:set_state(nil, true)
  326.     state_mgr.animation:set_control()
  327.     state_mgr.animstate:set_state(nil, true)
  328.     state_mgr.animstate:set_control()
  329.  
  330.     state_mgr:set_state("idle", nil, nil, nil, {fast_set = true})
  331.  
  332. --  planner:update()
  333. --  planner:update()
  334. --  planner:update()
  335.  
  336.     state_mgr:update()
  337.     state_mgr:update()
  338.     state_mgr:update()
  339.     state_mgr:update()
  340.     state_mgr:update()
  341.     state_mgr:update()
  342.     state_mgr:update()
  343.  
  344.     npc:set_body_state(move.standing)
  345.     npc:set_mental_state(anim.free)
  346.  
  347. end
  348.  
  349.  
  350. function teleport_npc(actor, npc, p)
  351.     local patrol_point = p[1]
  352.     local patrol_point_index = p[2] or 0
  353.     if patrol_point == nil then
  354.         abort("Wrong parameters in 'teleport_npc' function!!!")
  355.     end
  356.     local position = patrol(patrol_point):point(patrol_point_index)
  357.     reset_animation(npc)
  358.  
  359.     npc:set_npc_position(position)
  360. end
  361.  
  362. function teleport_npc_by_story_id(actor, npc, p)
  363.     local story_id = p[1]
  364.     local patrol_point = p[2]
  365.     local patrol_point_index = p[3] or 0
  366.     if story_id == nil or patrol_point == nil then
  367.         abort("Wrong parameters in 'teleport_npc_by_story_id' function!!!")
  368.     end
  369.     local position = patrol(tostring(patrol_point)):point(patrol_point_index)
  370.     local npc_id = get_story_object_id(story_id)
  371.     if npc_id == nil then
  372.         abort("There is no story object with id [%s]", story_id)
  373.     end
  374.     local cl_object = level.object_by_id(npc_id)
  375.     if cl_object then
  376.         reset_animation(cl_object)
  377.         cl_object:set_npc_position(position)
  378.     else
  379.         alife():object(npc_id).position = position
  380.     end
  381. end
  382.  
  383. function teleport_squad(actor, npc, p)
  384.     local squad_story_id = p[1]
  385.     local patrol_point = p[2]
  386.     local patrol_point_index = p[3] or 0
  387.     if squad_story_id == nil or patrol_point == nil then
  388.         abort("Wrong parameters in 'teleport_squad' function!!!")
  389.     end
  390.     local position = patrol(patrol_point):point(patrol_point_index)
  391.     local squad = get_story_squad(squad_story_id)
  392.     if squad == nil then
  393.         abort("There is no squad with story id [%s]", squad_story_id)
  394.     end
  395.     squad:set_squad_position(position)
  396. end
  397.  
  398. function jup_teleport_actor(actor, npc)
  399.     local point_in = patrol("jup_b16_teleport_in"):point(0)
  400.     local point_out = patrol("jup_b16_teleport_out"):point(0)
  401.     local actor_position = actor:position()
  402.     local out_position = vector():set(actor_position.x - point_in.x + point_out.x, actor_position.y - point_in.y + point_out.y , actor_position.z - point_in.z + point_out.z)
  403.     db.actor:set_actor_position(out_position)
  404. end
  405. -----------------------------------------------------------------------------
  406. --[[
  407. local drop_point, drop_object = 0, 0
  408. local function drop_object_item(item)
  409.     drop_object:drop_item_and_teleport(item, drop_point)
  410. end
  411.  
  412. function drop_actor_inventory(actor, npc, p)
  413.     if p[1] then
  414.         drop_point  = patrol(p[1]):point(0)
  415.         drop_object = actor
  416.         actor:inventory_for_each(drop_object_item)
  417.     end
  418. end
  419.  
  420.  
  421. -- FIXME: drop_npc_inventory doesn't work
  422. function drop_npc_inventory(actor, npc, p)
  423.     if p[1] then
  424.         drop_point  = patrol(p[1]):point(0)
  425.         drop_object = npc
  426.         npc:inventory_for_each(drop_object_item)
  427.     end
  428. end
  429.  
  430. function drop_npc_item(actor, npc, p)
  431.     if p[1] then
  432.         local item = npc:object(p[1])
  433.         if item then
  434.             npc:drop_item(item)
  435.         end
  436.     end
  437. end
  438.  
  439. function drop_npc_items(actor, npc, p)
  440.     local item = 0
  441.     for i, v in pairs(p) do
  442.         item = npc:object(v)
  443.         if item then
  444.             npc:drop_item(item)
  445.         end
  446.     end
  447. end
  448. ]]--
  449.  
  450. function give_items(actor, npc, p)
  451.     local pos, lv_id, gv_id, npc_id = npc:position(), npc:level_vertex_id(), npc:game_vertex_id(), npc:id()
  452.     for i, v in pairs(p) do
  453.         alife():create(v, pos, lv_id, gv_id, npc_id)
  454.     end
  455. end
  456.  
  457. function give_item(actor, npc, p)
  458.     if p[2] ~= nil then
  459.         npc_id = get_story_object_id(p[2])
  460.     else
  461.         npc_id = npc:id()
  462.     end
  463.     npc = alife():object(npc_id)
  464.     local pos, lv_id, gv_id, npc_id = npc.position, npc.m_level_vertex_id, npc.m_game_vertex_id, npc.id
  465.     alife():create(p[1], pos, lv_id, gv_id, npc_id)
  466. end
  467.  
  468. function play_particle_on_path(actor, npc, p)
  469.     local name = p[1]
  470.     local path = p[2]
  471.     local point_prob = p[3]
  472.     if name == nil or path == nil then
  473.         return
  474.     end
  475.     if point_prob == nil then
  476.         point_prob = 100
  477.     end
  478.  
  479.     local path = patrol(path)
  480.     local count = path:count()
  481.     for a = 0,count-1,1 do
  482.         local particle = particles_object(name)
  483.         if math.random(100) <= point_prob then
  484.             particle:play_at_pos(path:point(a))
  485.         end
  486.     end
  487. end
  488.  
  489.  
  490. -----------------------------------------------------------------------------
  491. --[[
  492. send_tip(news_id:sender:sender_id)
  493.         1. news_id
  494.         2. sender*
  495.         3. sender_id*
  496.         * - not necessary
  497. --]]
  498. function send_tip(actor, npc, p)
  499.     news_manager.send_tip(actor, p[1], nil, p[2], nil, p[3])
  500. end
  501.  
  502. --[[
  503. Äàòü ñòàëêåðó íåáîëüøîé ïèíîê. Íàïðèìåð ÷òîá ñêèíóòü åãî ñ âîçâûøåíèÿ.
  504. ïàðàìåòðû: actor, npc, p[direction,bone,power,impulse,reverse=false]
  505.         1. direction - åñëè ñòðîêà, òî ñ÷èòàåòñÿ, ÷òî ýòî èìÿ ïóòè è â ñòîðîíó
  506.                 ïåðâîé òî÷êè ïðîèçâîäèòñÿ òîë÷åê. Åñëè æå ýòî ÷èñëî, òî îíî
  507.                 ðàññìàòðèâàåòñÿ êàê story_id ïåðñîíàæà îò êîòîðîãî äîëæåí ïîñòóïèòü õèò.
  508.         2. bone - ñòðîêà. Èìÿ êîñòè, ïî êîòîðîé íàíîñèòñÿ óäàð.
  509.         3. power - ñèëà óäàðà
  510.         4. impulse - èìïóëüñ
  511.         5. reverse (true/false) - èçìåíåíèå íàïðàâëåíèÿ óäàðà. ïî óìîë÷àíèþ false
  512. --]]
  513. function hit_npc(actor, npc, p)
  514.     local h = hit()
  515.     local rev = p[6] and p[6] == 'true'
  516.     h.draftsman = npc
  517.     h.type = hit.wound
  518.     if p[1] ~= "self" then
  519.         local hitter = get_story_object(p[1])
  520.         if not hitter then return end
  521.         if rev then
  522.             h.draftsman = hitter
  523.             h.direction = hitter:position():sub(npc:position())
  524.         else
  525.             h.direction = npc:position():sub(hitter:position())
  526.         end
  527.     else
  528.         if rev then
  529.             h.draftsman = nil
  530.             h.direction = npc:position():sub(patrol(p[2]):point(0))
  531.         else
  532.             h.direction = patrol(p[2]):point(0):sub(npc:position())
  533.         end
  534.     end
  535.     h:bone(p[3])
  536.     h.power = p[4]
  537.     h.impulse = p[5]
  538.     printf("HIT EFFECT: (%s, %s,%d,%d) health(%s)", npc:name(), p[2], h.power, h.impulse, npc.health)
  539.     npc:hit(h)
  540. end
  541.  
  542. --[[
  543. Äàòü îáüåêòó, çàäàííîìó story_id, õèò.
  544. ïàðàìåòðû: actor, npc, p[sid,bone,power,impulse,hit_src=npc:position()]
  545.         1. sid - story_id îáüåêòà, ïî êîòîðîìó íàíîñèòñÿ õèò.
  546.         2. bone - ñòðîêà. Èìÿ êîñòè, ïî êîòîðîé íàíîñèòñÿ óäàð.
  547.         3. power - ñèëà óäàðà
  548.         4. impulse - èìïóëüñ
  549.         5. hit_src - åñëè ÷èñëî, òî ðàññìàòðèâàåòñÿ êàê story_id îáüåêòà, ñî ñòîðîíû
  550.                 êîòîðîãî íàíîñèòñÿ õèò (îí æå ÿâëÿåòñÿ è èíèöèàòîðîì õèòà), èíà÷å ýòî
  551.                 òî÷êà (waypoint), èç êîòîðîé ïî îáúåêòó íàíîñèòñÿ õèò.
  552.                 Åñëè íå çàäàíî, òî áåðåòñÿ ïîçèöèÿ îáüåêòà, èç êîòîðîãî áûëà âûçâàíà
  553.                 äàííàÿ ôóíêöèÿ.
  554. --]]
  555. function hit_obj(actor, npc, p)
  556.     local h = hit()
  557.     local obj = get_story_object(p[1])
  558.     local sid = nil
  559.  
  560.     if not obj then
  561. --    abort("HIT_OBJ [%s]. Target object does not exist", npc:name())
  562.         return
  563.     end
  564.  
  565.     h:bone(p[2])
  566.     h.power = p[3]
  567.     h.impulse = p[4]
  568.  
  569.     if p[5] then
  570.         sid = get_story_object(sid)
  571.         if sid then
  572.             h.direction = vector():sub(sid:position(), obj:position())
  573.         end
  574.         if not sid then
  575.             h.direction = vector():sub(patrol(p[5]):point(0), obj:position())
  576.         end
  577.     else
  578.         h.direction = vector():sub(npc:position(), obj:position())
  579.     end
  580.     h.draftsman = sid or npc
  581.     h.type = hit.wound
  582.     obj:hit(h)
  583. end
  584.  
  585. --[[
  586. function hit_obj_chemical(actor, npc, p)
  587.     local h = hit()
  588.     local obj = get_story_object(p[1])
  589.     local sid = nil
  590.  
  591.     if not obj then
  592. --    abort("HIT_OBJ [%s]. Target object does not exist", npc:name())
  593.         return
  594.     end
  595.  
  596.     h:bone(p[2])
  597.     h.power = p[3]
  598.     h.impulse = p[4]
  599.  
  600.     if p[5] then
  601.         sid = get_story_object(sid)
  602.         if sid then
  603.             h.direction = vector():sub(sid:position(), obj:position())
  604.         end
  605.         if not sid then
  606.             h.direction = vector():sub(patrol(p[5]):point(0), obj:position())
  607.         end
  608.     else
  609.         h.direction = vector():sub(npc:position(), obj:position())
  610.     end
  611.  
  612.     h.draftsman = sid or npc
  613.     h.type = hit.chemical_burn
  614.     obj:hit(h)
  615. end
  616.  
  617. function hit_obj_fire_wound(actor, npc, p)
  618.     local h = hit()
  619.     local obj = get_story_object(p[1])
  620.     local sid = nil
  621.  
  622.     if not obj then
  623. --    abort("HIT_OBJ [%s]. Target object does not exist", npc:name())
  624.         return
  625.     end
  626.  
  627.     h:bone(p[2])
  628.     h.power = p[3]
  629.     h.impulse = p[4]
  630.  
  631.     if p[5] then
  632.         sid = get_story_object(sid)
  633.         if sid then
  634.             h.direction = vector():sub(sid:position(), obj:position())
  635.         end
  636.         if not sid then
  637.             h.direction = vector():sub(patrol(p[5]):point(0), obj:position())
  638.         end
  639.     else
  640.         h.direction = vector():sub(npc:position(), obj:position())
  641.     end
  642.  
  643.     h.draftsman = sid or npc
  644.     h.type = hit.fire_wound
  645.     obj:hit(h)
  646. end
  647. ]]--
  648. --[[
  649. Äàòü ñòàëêåðó íåáîëüøîé ïèíîê ïîñëå ñìåðòè. Àíàëîãè÷íî ïðåäûäóùåìó, òîëüêî íàïðàâëåíèå õèòà òåïåðü
  650. âû÷èñëÿåòñÿ ÷åðåç óáèéöó. Ïîýòîìó ïàðàìåòðà direction íåò.
  651. ïàðàìåòðû: actor, npc, p[bone,power,impulse]
  652. FIXME: killer:position() isn't working
  653. --]]
  654. function hit_by_killer(actor, npc, p)
  655.     if not npc then return end
  656.     local t = db.storage[npc:id()].death
  657.     if t == nil or t.killer == -1 then return end
  658.     local killer = db.storage[t.killer]
  659.     if killer == nil then return end
  660.     local p1, p2
  661.     p1 = npc:position()
  662.     p2 = killer:position()
  663.     local h = hit()
  664.     h.draftsman = npc
  665.     h.type = hit.wound
  666.     h.direction = utils.vector_copy_by_val(p1):sub(p2)
  667.     h.bone = p[1]
  668.     h.power = p[2]
  669.     h.impulse = p[3]
  670.     npc:hit(h)
  671. end
  672.  
  673.  
  674. function hit_npc_from_actor(actor, npc, p)
  675.     local h = hit()
  676.     local sid = nil
  677.     h.draftsman = actor
  678.     h.type = hit.wound
  679.  
  680.     if p and p[1] then
  681.         sid = get_story_object(p[1])
  682.         if sid then
  683.             h.direction = actor:position():sub(sid:position())
  684.         end
  685.         if not sid then
  686.             h.direction = actor:position():sub(npc:position())
  687.         end
  688.     else
  689.         h.direction = actor:position():sub(npc:position())
  690.         sid = npc
  691.     end
  692.  
  693.     h:bone("bip01_spine")
  694.     h.power = 0.001
  695.     h.impulse = 0.001
  696.     sid:hit(h)
  697. end
  698.  
  699. --[[
  700. -- Õèòóåò íïñ îò íïñ, åñëè çàäàí îäèí ïàðàìåòð (ñòîðè àéäè), òî íïñ ñ òàêèì ñòîðè àéäè õèòíåò íïñ ó êîòîðîãî âûçâàëè ýòó ôóíêöèþ.
  701. -- åñëè çàäàíî 2 ñòîðè àéäè , òî íïñ ñ 1-ûì ñòîðè àéäè õèòíåò íïñ ñî 2-ûì ñòîðè àéäè.
  702. function hit_npc_from_npc(actor, npc, p)
  703.     if p == nil then abort("Invalid parameter in function 'hit_npc_from_npc'!!!!") end
  704.     local h = hit()
  705.     local hitted_npc = npc
  706.     h.draftsman = get_story_object(p[1])
  707.     if p[2] ~= nil then
  708.         hitted_npc = get_story_object(p[2])
  709.     end
  710.     h.type = hit.wound
  711.     h.direction = h.draftsman:position():sub(hitted_npc:position())
  712.     h:bone("bip01_spine")
  713.     h.power = 0.03
  714.     h.impulse = 0.03
  715.     hitted_npc:hit(h)
  716. end
  717.  
  718. function hit_actor(actor, npc, p)
  719.     local h = hit()
  720.     h.direction = vector():set(0,0,0)
  721.     h.draftsman = actor
  722.     h.type = hit.shock
  723.     h:bone("bip01_spine")
  724.     h.power = (p and p[1] and tonumber(p[1])) or 0.001
  725.     h.impulse = 0.001
  726.     actor:hit(h)
  727. end
  728. ]]--
  729.  
  730. function restore_health(actor, npc)
  731.     --printf("HEALTH RESTORE")
  732.     npc.health = 1
  733. end
  734.  
  735. function make_enemy(actor, npc, p)
  736.     if p == nil then abort("Invalid parameter in function 'hit_npc_from_npc'!!!!") end
  737.     local h = hit()
  738.     local hitted_npc = npc
  739.     h.draftsman = get_story_object(p[1])
  740.     if p[2] ~= nil then
  741.         hitted_npc = get_story_object(p[2])
  742.     end
  743.     h.type = hit.wound
  744.     h.direction = h.draftsman:position():sub(hitted_npc:position())
  745.     h:bone("bip01_spine")
  746.     h.power = 0.03
  747.     h.impulse = 0.03
  748.     hitted_npc:hit(h)
  749. end
  750.  
  751. function sniper_fire_mode(actor, npc, p)
  752.     if p[1] == "true" then
  753.         --printf("SNIPER FIRE MODE ON")
  754.         npc:sniper_fire_mode(true)
  755.     else
  756.         --printf("SNIPER FIRE MODE OFF")
  757.         npc:sniper_fire_mode(false)
  758.     end
  759. end
  760.  
  761. function kill_npc(actor, npc, p)
  762.     if p and p[1] then
  763.         npc = get_story_object(p[1])
  764.     end
  765.     if npc ~= nil and npc:alive() then
  766.         npc:kill(npc)
  767.     end
  768. end
  769.  
  770. function remove_npc(actor, npc, p)
  771.     if p and p[1] then
  772.         npc_id = get_story_object_id(p[1])
  773.     end
  774.     if npc_id ~= nil then
  775.         alife():release(alife():object(npc_id), true)
  776.     end
  777. end
  778.  
  779. -- ïðèáàâèòü ê óêàçàííîìó ñ÷¸ò÷èêó àêò¸ðà 1
  780. function inc_counter(actor, npc, p)
  781.     if p and p[1] then
  782.         local inc_value = p[2] or 1
  783.         local new_value = xr_logic.pstor_retrieve(actor, p[1], 0) + inc_value
  784.         if npc and npc:name() then
  785.             printf("inc_counter '%s'  to value [%s], by [%s]", p[1], tostring(new_value), tostring(npc:name()))
  786.         end
  787.         xr_logic.pstor_store(actor, p[1], new_value)
  788.     end
  789. end
  790.  
  791. function dec_counter(actor, npc, p)
  792.     if p and p[1] then
  793.         local dec_value = p[2] or 1
  794.         local new_value = xr_logic.pstor_retrieve(actor, p[1], 0) - dec_value
  795.         if new_value < 0 then
  796.             new_value = 0
  797.         end
  798.         xr_logic.pstor_store(actor, p[1], new_value)
  799.         if npc and npc:name() then
  800.             printf( "dec_counter [%s] value [%s] by [%s]", p[1], xr_logic.pstor_retrieve(actor, p[1], 0), tostring(npc:name()))
  801.         end
  802.     end
  803. end
  804.  
  805. function set_counter(actor, npc, p)
  806.     if p and p[1] then
  807.         local count = p[2] or 0
  808. --      printf( "set_counter '%s' %s", p[1], count)
  809.         xr_logic.pstor_store(actor, p[1], count)
  810. --      printf("counter [%s] value [%s]", p[1], xr_logic.pstor_retrieve(actor, p[1], 0))
  811.     end
  812. end
  813.  
  814.  
  815. ------------------------------------------------------------------------------------------------------------------------
  816. -- ïîñòïðîöåññ è âëèÿíèå óäàðà â ìîðäó
  817. function actor_punch(npc)
  818.     if db.actor:position():distance_to_sqr(npc:position()) > 4 then
  819.         return
  820.     end
  821.  
  822.     set_inactivate_input_time(30)
  823.     level.add_cam_effector("camera_effects\\fusker.anm", 999, false, "")
  824.  
  825.     local active_slot = db.actor:active_slot()
  826.     if active_slot ~= 2 and
  827.          active_slot ~= 3
  828.     then
  829.         return
  830.     end
  831.  
  832.     local active_item = db.actor:active_item()
  833.     if active_item then
  834.         db.actor:drop_item(active_item)
  835.     end
  836. end
  837.  
  838. -- çàáûâàíèå îáèäû
  839. function clearAbuse(npc)
  840.     printf("CLEAR_ABUSE")
  841.     xr_abuse.clear_abuse(npc)
  842. end
  843.  
  844. function turn_off_underpass_lamps(actor, npc)
  845.     local lamps_table = {
  846.                             ["pas_b400_lamp_start_flash"] = true,
  847.                             ["pas_b400_lamp_start_red"] = true,
  848.                             ["pas_b400_lamp_elevator_green"] = true,
  849.                             ["pas_b400_lamp_elevator_flash"] = true,
  850.                             ["pas_b400_lamp_elevator_green_1"] = true,
  851.                             ["pas_b400_lamp_elevator_flash_1"] = true,
  852.                             ["pas_b400_lamp_track_green"] = true,
  853.                             ["pas_b400_lamp_track_flash"] = true,
  854.                             ["pas_b400_lamp_downstairs_green"] = true,
  855.                             ["pas_b400_lamp_downstairs_flash"] = true,
  856.                             ["pas_b400_lamp_tunnel_green"] = true,
  857.                             ["pas_b400_lamp_tunnel_flash"] = true,
  858.                             ["pas_b400_lamp_tunnel_green_1"] = true,
  859.                             ["pas_b400_lamp_tunnel_flash_1"] = true,
  860.                             ["pas_b400_lamp_control_down_green"] = true,
  861.                             ["pas_b400_lamp_control_down_flash"] = true,
  862.                             ["pas_b400_lamp_control_up_green"] = true,
  863.                             ["pas_b400_lamp_control_up_flash"] = true,
  864.                             ["pas_b400_lamp_hall_green"] = true,
  865.                             ["pas_b400_lamp_hall_flash"] = true,
  866.                             ["pas_b400_lamp_way_green"] = true,
  867.                             ["pas_b400_lamp_way_flash"] = true,
  868.                         }
  869.     local obj
  870.     for k,v in pairs(lamps_table) do
  871.         obj = get_story_object(k)
  872.  
  873.         if obj then
  874.             obj:get_hanging_lamp():turn_off()
  875.         else
  876.             printf("function 'turn_off_underpass_lamps' lamp [%s] does not exist", tostring(k))
  877.             --abort("function 'turn_off_underpass_lamps' lamp [%s] does not exist", tostring(k))
  878.         end
  879.     end
  880. end
  881.  
  882. ---Âûêëþ÷åíèå äèíàìè÷åñêîé ëàìïî÷êè (hanging_lamp)
  883. function turn_off(actor, npc, p)
  884.     local obj
  885.     for k,v in pairs(p) do
  886.         obj = get_story_object(v)
  887.  
  888.         if not obj then
  889.             abort("TURN_OFF. Target object with story_id [%s] does not exist", v)
  890.             return
  891.         end
  892.         obj:get_hanging_lamp():turn_off()
  893.         --printf("TURN_OFF. Target object with story_id [%s] turned off.", v)
  894.     end
  895. end
  896.  
  897. function turn_off_object(actor, npc)
  898.     npc:get_hanging_lamp():turn_off()
  899. end
  900.  
  901. ---Âêëþ÷åíèå äèíàìè÷åñêîé ëàìïî÷êè (hanging_lamp)
  902. function turn_on(actor, npc, p)
  903.     local obj
  904.     for k,v in pairs(p) do
  905.         obj = get_story_object(v)
  906.  
  907.         if not obj then
  908.             abort("TURN_ON [%s]. Target object does not exist", npc:name())
  909.             return
  910.         end
  911.         obj:get_hanging_lamp():turn_on()
  912.     end
  913. end
  914.  
  915. ---Âêëþ÷åíèå è çàïóñê äèíàìè÷åñêîé ëàìïî÷êè (hanging_lamp)
  916. function turn_on_and_force(actor, npc, p)
  917.     local obj = get_story_object(p[1])
  918.     if not obj then
  919.         abort("TURN_ON_AND_FORCE. Target object does not exist")
  920.         return
  921.     end
  922.     if p[2] == nil then p[2] = 55 end
  923.     if p[3] == nil then p[3] = 14000 end
  924.     obj:set_const_force(vector():set(0,1,0), p[2], p[3])
  925.     obj:start_particles("weapons\\light_signal", "link")
  926.     obj:get_hanging_lamp():turn_on()
  927. end
  928.  
  929. ---Âûêëþ÷åíèå äèíàìè÷åñêîé ëàìïî÷êè è ïàðòèêëîâ (hanging_lamp)
  930. function turn_off_and_force(actor, npc, p)
  931.     local obj = get_story_object(p[1])
  932.     if not obj then
  933.         abort("TURN_OFF [%s]. Target object does not exist", npc:name())
  934.         return
  935.     end
  936.     obj:stop_particles("weapons\\light_signal", "link")
  937.     obj:get_hanging_lamp():turn_off()
  938. end
  939.  
  940.  
  941. function turn_on_object(actor, npc)
  942.     npc:get_hanging_lamp():turn_on()
  943. end
  944.  
  945. function turn_off_object(actor, npc)
  946.     npc:get_hanging_lamp():turn_off()
  947. end
  948.  
  949.  
  950. -- Âûçîâ ýòîé ôóíêöèè îòêëþ÷èò îáðàáîò÷èê [combat] áîÿ äëÿ ïåðñîíàæà.
  951. -- Èñïîëüçóåòñÿ â ñëó÷àÿõ, êîãäà âñå íåîáõîäèìûå äåéñòâèÿ, òàêèå êàê ïåðåêëþ÷åíèå íà äðóãóþ ñåêöèþ,
  952. -- óæå âûïîëíåíû, è ïîâòîðíî âûïîëíÿòü èõ âî âðåìÿ áîÿ íåëüçÿ (à óñëîâèÿ ñåêöèè [combat] ïðîâåðÿþòñÿ íà êàæäîì
  953. -- àïäåéòå, êîãäà ïåðñîíàæ â áîþ, åñëè, êîíå÷íî, íå îòêëþ÷åíû âûçîâîì ýòîé ôóíêöèè).
  954. function disable_combat_handler(actor, npc)
  955.     if db.storage[npc:id()].combat then
  956.         db.storage[npc:id()].combat.enabled = false
  957.     end
  958.  
  959.     if db.storage[npc:id()].mob_combat then
  960.         db.storage[npc:id()].mob_combat.enabled = false
  961.     end
  962. end
  963.  
  964. -- Âûçîâ ýòîé ôóíêöèè îòêëþ÷èò îáðàáîò÷èê [combat_ignore] ïåðåõâàòà áîÿ äëÿ ïåðñîíàæà.
  965. function disable_combat_ignore_handler(actor, npc)
  966.     if db.storage[npc:id()].combat_ignore then
  967.         db.storage[npc:id()].combat_ignore.enabled = false
  968.     end
  969. end
  970.  
  971. -------------------------------------------------------------------------------------
  972. -- Ôóíêöèè äëÿ ðàáîòû ñ âåðòîë¸òàìè
  973. -------------------------------------------------------------------------------------
  974. --[[
  975. function heli_set_enemy_actor(actor, npc)
  976.     local st = db.storage[npc:id()]
  977.     if not st.combat.enemy_id and actor:alive() then
  978.         st.combat.enemy_id = actor:id()
  979.         heli_snd.play_snd( st, heli_snd.snd_see_enemy, 1 )
  980.     end
  981. end
  982.  
  983. function heli_set_enemy(actor, npc, p)
  984.     local st  = db.storage[npc:id()]
  985.     local obj = get_story_object( p[1] )
  986.     if not st.combat.enemy_id and obj:alive() then
  987.         st.combat.enemy_id = obj:id()
  988.         heli_snd.play_snd( st, heli_snd.snd_see_enemy, 1 )
  989.     end
  990. end
  991.  
  992. function heli_clear_enemy(actor, npc)
  993.     db.storage[npc:id()].combat:forget_enemy()
  994. end
  995. ]]--
  996.  
  997. function heli_start_flame(actor, npc)
  998.     bind_heli.heli_start_flame( npc )
  999. end
  1000.  
  1001. function heli_die(actor, npc)
  1002.     bind_heli.heli_die( npc )
  1003. end
  1004.  
  1005.  
  1006. --'-----------------------------------------------------------------------------------
  1007. --' Ôóíêöèè äëÿ ðàáîòû ñ ïîãîäíûìè ýôôåêòàìè
  1008. --'-----------------------------------------------------------------------------------
  1009.  
  1010. -- Ïðèíóäèòåëüíàÿ óñòàíîâêà ïîãîäíûõ óñëîâèé
  1011. -- =set_weather(<ñåêöèÿ ïîãîäû>:true) - óñòàíîâêà ïîãîäû ñðàçó, false - ÷åðåç íåêîòîðîå âðåìÿ
  1012. -- Áóäåò èñïîëüçîâàòüñÿ íà ñòàðòå èãðû Çîâ Ïðèïÿòè è â ñöåíå jup_b15 - óòðî ïîñëå ïüÿíêè ñ Çóëóñîì
  1013. function set_weather(actor, npc, p)
  1014.     if(p[1]) then
  1015.         if(p[2]=="true") then
  1016.             level.set_weather(p[1],true)
  1017.         else
  1018.             level.set_weather(p[1],false)
  1019.         end
  1020.     end
  1021. end
  1022. --[[
  1023. function update_weather(actor, npc, p)
  1024.     if p and p[1] then
  1025.         if p[1] == "true" then
  1026.             level_weathers.get_weather_manager():select_weather(true)
  1027.         elseif p[1] == "false" then
  1028.             level_weathers.get_weather_manager():select_weather(false)
  1029.         end
  1030.     end
  1031. end
  1032.  
  1033. function start_small_reject(actor, npc)
  1034.     level.set_weather_fx("fx_surge_day_3")
  1035.     level.add_pp_effector("vibros_p.ppe", 1974, false)
  1036.     this.aes_earthshake(npc)
  1037. end
  1038.  
  1039. function start_full_reject(actor, npc)
  1040.     level.set_weather_fx("fx_surge_day_3")
  1041.     level.remove_pp_effector(1974)
  1042.     level.remove_cam_effector(1975)
  1043.     level.add_cam_effector("camera_effects\\earthquake.anm", 1975, true, "")
  1044. end
  1045.  
  1046. function stop_full_reject(actor, npc)
  1047.     level.remove_pp_effector(1974)
  1048.     level.remove_cam_effector(1975)
  1049. end
  1050.  
  1051. function run_weather_pp(actor,npc, p)
  1052.     local weather_fx = p[1]
  1053.     if weather_fx == nil then
  1054.         weather_fx = "fx_surge_day_3"
  1055.     end
  1056.     level.set_weather_fx(weather_fx)
  1057. end
  1058. ]]--
  1059.  
  1060. function game_disconnect(actor, npc)
  1061.     local c = get_console()
  1062.     c:execute("disconnect")
  1063. --  c:execute_deferred("main_menu off")
  1064. --  c:execute_deferred("hide")
  1065. end
  1066.  
  1067. function game_credits(actor, npc)
  1068.     db.gameover_credits_started = true
  1069.     game.start_tutorial("credits_seq")
  1070. end
  1071.  
  1072. function game_over(actor, npc)
  1073.     if db.gameover_credits_started ~= true then
  1074.         return
  1075.     end
  1076.     local c = get_console()
  1077.     printf("main_menu on console command is executed")
  1078.     c:execute("main_menu on")
  1079. end
  1080.  
  1081. function after_credits(actor, npc)
  1082.     get_console():execute   ("main_menu on")
  1083. end
  1084.  
  1085. function before_credits(actor, npc)
  1086.     get_console():execute   ("main_menu off")
  1087. end
  1088.  
  1089. function on_tutor_gameover_stop()
  1090.     local c = get_console()
  1091.     printf("main_menu on console command is executed")
  1092.     c:execute("main_menu on")
  1093. end
  1094.  
  1095. function on_tutor_gameover_quickload()
  1096.     local c = get_console()
  1097.     c:execute("load_last_save")
  1098. end
  1099.  
  1100.  
  1101. -- äëÿ ñìåíû ðàáîòû
  1102. function get_stalker_for_new_job(actor, npc, p)
  1103.     xr_gulag.find_stalker_for_job(npc,p[1])
  1104. end
  1105. function switch_to_desired_job(actor, npc, p)
  1106.     xr_gulag.switch_to_desired_job(npc)
  1107. end
  1108.  
  1109. --[[
  1110. function death_hit(actor, npc, p)
  1111.      local draftsman = get_story_object (p[1])
  1112.      local hitted_obj = (p[2] ~= nil and get_story_object (p[2])) or npc
  1113.      if draftsman == nil or hitted_obj == nil then
  1114.         return
  1115.      end
  1116.      local h = hit()
  1117.      h.power = 1000
  1118.      h.direction = hitted_obj:direction()
  1119.      h.draftsman = draftsman
  1120.      h.impulse = 1
  1121.      h.type = hit.wound
  1122.      hitted_obj:hit(h)
  1123. end
  1124. ]]--
  1125.  
  1126. --'-----------------------------------------------------------------------------------
  1127. --' Ôóíêöèè äëÿ ðàáîòû ñ ïîäñïàóíîì
  1128. --'-----------------------------------------------------------------------------------
  1129. function spawn_object(actor, obj, p)
  1130.         --' p[1] - ñåêöèÿ êîãî ñïàóíèòü
  1131.         --' p[2] - èìÿ ïàòðóëüíîãî ïóòè ãäå ñïà óíèòü.
  1132.     local spawn_sect = p[1]
  1133.     if spawn_sect == nil then
  1134.         abort("Wrong spawn section for 'spawn_object' function %s. For object %s", tostring(spawn_sect), obj:name())
  1135.     end
  1136.  
  1137.     local path_name = p[2]
  1138.     if path_name == nil then
  1139.         abort("Wrong path_name for 'spawn_object' function %s. For object %s", tostring(path_name), obj:name())
  1140.     end
  1141.  
  1142.     if not level.patrol_path_exists(path_name) then
  1143.         abort("Path %s doesnt exist. Function 'spawn_object' for object %s ", tostring(path_name), obj:name())
  1144.     end
  1145.     local ptr = patrol(path_name)
  1146.     local index = p[3] or 0
  1147.     local yaw = p[4] or 0
  1148.  
  1149.     --' printf("Spawning %s at %s, %s", tostring(p[1]), tostring(p[2]), tostring(p[3]))
  1150.     local se_obj = alife():create(spawn_sect,
  1151.                                 ptr:point(index),
  1152.                                 ptr:level_vertex_id(0),
  1153.                                 ptr:game_vertex_id(0))
  1154.     if IsStalker( nil, se_obj:clsid()) then
  1155.         se_obj:o_torso().yaw = yaw * math.pi / 180
  1156.     elseif se_obj:clsid() == clsid.script_phys then
  1157.         se_obj:set_yaw(yaw * math.pi / 180)
  1158.     end
  1159. end
  1160.  
  1161. local jup_b219_position
  1162. local jup_b219_lvid
  1163. local jup_b219_gvid
  1164.  
  1165. function jup_b219_save_pos()
  1166.     local obj = get_story_object("jup_b219_gate_id")
  1167.     if obj and obj:position() then
  1168.         jup_b219_position = obj:position()
  1169.         jup_b219_lvid = obj:level_vertex_id()
  1170.         jup_b219_gvid = obj:game_vertex_id()
  1171.     else
  1172.         return
  1173.     end
  1174.     sobj = alife():object(obj:id())
  1175.     if sobj then
  1176.         alife():release(sobj, true)
  1177.     end
  1178. end
  1179.  
  1180. function jup_b219_restore_gate()
  1181.     local yaw = 0
  1182.     local spawn_sect = "jup_b219_gate"
  1183.     if jup_b219_position then
  1184.         local se_obj = alife():create(spawn_sect,
  1185.                                     vector():set(jup_b219_position),
  1186.                                     jup_b219_lvid,
  1187.                                     jup_b219_gvid)
  1188.         se_obj:set_yaw(yaw * math.pi / 180)
  1189.     end
  1190. end
  1191.  
  1192. function spawn_corpse(actor, obj, p)
  1193.         --' p[1] - ñåêöèÿ êîãî ñïàóíèòü
  1194.         --' p[2] - èìÿ ïàòðóëüíîãî ïóòè ãäå ñïàóíèòü.
  1195.     local spawn_sect = p[1]
  1196.     if spawn_sect == nil then
  1197.         abort("Wrong spawn section for 'spawn_corpse' function %s. For object %s", tostring(spawn_sect), obj:name())
  1198.     end
  1199.  
  1200.     local path_name = p[2]
  1201.     if path_name == nil then
  1202.         abort("Wrong path_name for 'spawn_corpse' function %s. For object %s", tostring(path_name), obj:name())
  1203.     end
  1204.  
  1205.     if not level.patrol_path_exists(path_name) then
  1206.         abort("Path %s doesnt exist. Function 'spawn_corpse' for object %s ", tostring(path_name), obj:name())
  1207.     end
  1208.     local ptr = patrol(path_name)
  1209.     local index = p[3] or 0
  1210.  
  1211.     local se_obj = alife():create(spawn_sect,
  1212.                                     ptr:point(index),
  1213.                                     ptr:level_vertex_id(0),
  1214.                                     ptr:game_vertex_id(0))
  1215.     se_obj:kill()
  1216. end
  1217.  
  1218.  
  1219. function spawn_object_in(actor, obj, p)
  1220.     --' p[1] - ñåêöèÿ êîãî ñïàóíèòü
  1221.     --' p[2] - ñòîðè àéäè îáüåêòà â êîòîðûé ñïàâíèòü
  1222.     local spawn_sect = p[1]
  1223.     if spawn_sect == nil then
  1224.         abort("Wrong spawn section for 'spawn_object' function %s. For object %s", tostring(spawn_sect), obj:name())
  1225.     end
  1226.     if p[2] == nil then
  1227.         abort("Wrong target_name for 'spawn_object_in' function %s. For object %s", tostring(target_name), obj:name())
  1228.     end
  1229. --  local box = alife():object(target_name)
  1230. --  if(box==nil) then
  1231.  
  1232.     printf("trying to find object %s", tostring(p[2]))
  1233.  
  1234.     local target_obj_id = get_story_object_id(p[2])
  1235.     if target_obj_id ~= nil then
  1236.         box = alife():object(target_obj_id)
  1237.         if box == nil then
  1238.             abort("There is no such object %s", p[2])
  1239.         end
  1240.         alife():create(spawn_sect,vector(),0,0,target_obj_id)
  1241.     else
  1242.         abort("object is nil %s", tostring(p[2]))
  1243.     end
  1244. end
  1245.  
  1246.  
  1247. function spawn_npc_in_zone(actor, obj, p)
  1248.     --' p[1] - ñåêöèÿ êîãî ñïàóíèòü
  1249.     --' p[2] - èìÿ çîíû â êîòîðîé ñïàóíèòü.
  1250.     local spawn_sect = p[1]
  1251.     if spawn_sect == nil then
  1252.         abort("Wrong spawn section for 'spawn_object' function %s. For object %s", tostring(spawn_sect), obj:name())
  1253.     end
  1254.     local zone_name = p[2]
  1255.     if zone_name == nil then
  1256.         abort("Wrong zone_name for 'spawn_object' function %s. For object %s", tostring(zone_name), obj:name())
  1257.     end
  1258.     if db.zone_by_name[zone_name] == nil then
  1259.         abort("Zone %s doesnt exist. Function 'spawn_object' for object %s ", tostring(zone_name), obj:name())
  1260.     end
  1261.     local zone = db.zone_by_name[zone_name]
  1262. --  printf("spawn_npc_in_zone: spawning %s at zone %s, squad %s", tostring(p[1]), tostring(p[2]), tostring(p[3]))
  1263.     local spawned_obj = alife():create( spawn_sect,
  1264.                                         zone:position(),
  1265.                                         zone:level_vertex_id(),
  1266.                                         zone:game_vertex_id())
  1267.     spawned_obj.sim_forced_online = true
  1268.     spawned_obj.squad = 1 or p[3]
  1269.     db.script_ids[spawned_obj.id] = zone_name
  1270. end
  1271.  
  1272. function destroy_object(actor, obj, p)
  1273.     local sobj
  1274.     if p == nil then
  1275.         sobj = alife():object(obj:id())
  1276.     else
  1277.         if p[1] == nil or p[2] == nil then
  1278.             abort("Wrong parameters in destroy_object function!!!")
  1279.         end
  1280.         local target_str = nil
  1281.         if p[3] ~= nil then
  1282.             target_str = p[1].."|"..p[2]..","..p[3]
  1283.         else
  1284.             target_str = p[1].."|"..p[2]
  1285.         end
  1286.         local target_position, target_id, target_init = xr_remark.init_target(obj, target_str)
  1287.         if target_id == nil then
  1288.             printf("You are trying to set non-existant target [%s] for object [%s] in section [%s]", tostring(target_str), tostring(obj:name()), tostring(db.storage[obj:id()].active_section))
  1289.         end
  1290.         sobj = alife():object(target_id)
  1291.     end
  1292.     if sobj == nil then
  1293.         return
  1294.     end
  1295.     printf("releasing object ["..sobj:name().."]")
  1296.     alife():release(sobj, true)
  1297. end
  1298.  
  1299. function give_actor(actor, npc, p)
  1300.     for k,v in pairs(p) do
  1301.         alife():create(v,
  1302.                 db.actor:position(),
  1303.                 db.actor:level_vertex_id(),
  1304.                 db.actor:game_vertex_id(),
  1305.                 db.actor:id())
  1306.         news_manager.relocate_item(db.actor, "in", v)
  1307.     end
  1308. end
  1309.  
  1310. function activate_weapon_slot(actor, npc, p)
  1311.     db.actor:activate_slot(p[1])
  1312. end
  1313.  
  1314. function anim_obj_forward(actor, npc, p)
  1315.     for k,v in pairs(p) do
  1316.         if v ~= nil then
  1317.             db.anim_obj_by_name[v]:anim_forward()
  1318.         end
  1319.     end
  1320. end
  1321. function anim_obj_backward(actor, npc, p)
  1322.     if p[1] ~= nil then
  1323.         db.anim_obj_by_name[p[1]]:anim_backward()
  1324.     end
  1325. end
  1326. function anim_obj_stop(actor, npc, p)
  1327.     if p[1] ~= nil then
  1328.         db.anim_obj_by_name[p[1]]:anim_stop()
  1329.     end
  1330. end
  1331.  
  1332. -- Ôóíêöèè äëÿ ðàáîòû ñ îãíåííûìè çîíàìè.
  1333. --[[
  1334. function turn_on_fire_zone(actor, npc, p)
  1335.     bind_campfire.fire_zones_table[ p[1] ]:turn_on()
  1336. end
  1337.  
  1338. function turn_off_fire_zone(actor, npc, p)
  1339.     bind_campfire.fire_zones_table[ p[1] ]:turn_off()
  1340. end
  1341. ]]--
  1342. --'-----------------------------------------------------------------------------------
  1343. --' Ôóíêöèè äëÿ îòûãðûâàíèÿ çâóêà
  1344. --'-----------------------------------------------------------------------------------
  1345. function play_sound(actor, obj, p)
  1346.     local theme = p[1]
  1347.     local faction = p[2]
  1348.     local point = sim_board.get_sim_board().smarts_by_names[p[3]]
  1349.     if point ~= nil then
  1350.         point = point.id
  1351.     elseif p[3]~=nil then
  1352.         point = p[3]
  1353.     end
  1354.  
  1355.     if obj and IsStalker(obj) then
  1356.         if not obj:alive() then
  1357.             abort("Stalker [%s][%s] is dead, but you wants to say something for you: [%s]!", tostring(obj:id()), tostring(obj:name()), p[1])
  1358.         end
  1359.     end
  1360.  
  1361.     xr_sound.set_sound_play(obj:id(), theme, faction, point)
  1362. end
  1363.  
  1364. function play_sound_by_story(actor, obj, p)
  1365.     local story_obj = get_story_object_id(p[1])
  1366.     local theme = p[2]
  1367.     local faction = p[3]
  1368.     local point = sim_board.get_sim_board().smarts_by_names[p[4]]
  1369.     if point ~= nil then
  1370.         point = point.id
  1371.     elseif p[4]~=nil then
  1372.         point = p[4]
  1373.     end
  1374.     xr_sound.set_sound_play(story_obj, theme, faction, point)
  1375. end
  1376.  
  1377. function stop_sound(actor, npc)
  1378.     xr_sound.stop_sounds_by_id(npc:id())
  1379. end
  1380.  
  1381. function play_sound_looped(actor, obj, p)
  1382.     local theme = p[1]
  1383.     xr_sound.play_sound_looped(obj:id(), theme)
  1384. end
  1385.  
  1386. function stop_sound_looped(actor, obj)
  1387.     xr_sound.stop_sound_looped(obj:id())
  1388. end
  1389.  
  1390. function barrel_explode (actor , npc , p)
  1391.     local expl_obj = get_story_object (p[1])
  1392.     if expl_obj ~= nil then
  1393.         expl_obj:explode(0)
  1394.     end
  1395. end
  1396.  
  1397. --'-----------------------------------------------------------------------------------
  1398. --' Alife support
  1399. --'-----------------------------------------------------------------------------------
  1400. --[[
  1401. function start_sim(actor, obj)
  1402.     sim_board.get_sim_board():start_sim()
  1403. end
  1404.  
  1405. function stop_sim(actor, obj)
  1406.     sim_board.get_sim_board():stop_sim()
  1407. end
  1408.  
  1409. function update_faction_brain(actor, obj, p)
  1410.     if p[1] == nil then
  1411.         abort("Wrong parameters update_faction_brain")
  1412.     end
  1413.     local board = sim_board.get_sim_board()
  1414.     local player = board.players[ p[1] ]
  1415.     if player == nil then
  1416.         abort("Can't find player %s", tostring(p[1]))
  1417.     end
  1418.     player:faction_brain_update()
  1419. end
  1420. ]]--
  1421.  
  1422. function create_squad(actor, obj, p)
  1423.     if obj ~= nil then
  1424.         printf("pl:creating_squad from obj [%s] in section [%s]", tostring(obj:name()), tostring(db.storage[obj:id()].active_section))
  1425.     end
  1426.     local squad_id = p[1]
  1427.     if squad_id == nil then
  1428.         abort("Wrong squad identificator [NIL] in create_squad function")
  1429.     end
  1430.     local smart_name = p[2]
  1431.     if smart_name == nil then
  1432.         abort("Wrong smart name [NIL] in create_squad function")
  1433.     end
  1434.  
  1435.     local ltx = sim_board.squad_ltx
  1436.  
  1437.     if not ltx:section_exist(squad_id) then
  1438.         abort("Wrong squad identificator [%s]. Squad descr doesnt exist.", tostring(squad_id))
  1439.     end
  1440.  
  1441.     local board = sim_board.get_sim_board()
  1442.     local smart = board.smarts_by_names[smart_name]
  1443.     if smart == nil then
  1444.         abort("Wrong smart_name [%s] for [%s] faction in create_squad function", tostring(smart_name), tostring(player_name))
  1445.     end
  1446.  
  1447.     local squad = board:create_squad(smart, squad_id)
  1448.  
  1449.  
  1450.     board:enter_smart(squad, smart.id)
  1451.  
  1452.     for k in squad:squad_members() do
  1453.         board:setup_squad_and_group(k.object)
  1454.     end
  1455.  
  1456.     squad:update()
  1457. end
  1458.  
  1459. function create_squad_member(actor, obj, p)
  1460.     local squad_member_sect = p[1]
  1461.     local story_id          = p[2]
  1462.     local position          = nil
  1463.     local level_vertex_id   = nil
  1464.     local game_vertex_id    = nil
  1465.     if story_id == nil then
  1466.         abort("Wrong squad identificator [NIL] in 'create_squad_member' function")
  1467.         return
  1468.     end
  1469.     local board = sim_board.get_sim_board()
  1470.     local squad = get_story_squad(story_id)
  1471.     if not (squad) then
  1472.         if (alun_utils) then
  1473.             alun_utils.printf("Squad is nil for Section %s for squad story id %s",squad_member_sect,story_id)
  1474.         else
  1475.             abort("Squad is nil for Section %s for squad story id %s",squad_member_sect,story_id)
  1476.         end
  1477.         return
  1478.     end
  1479.     local squad_smart = board.smarts[squad.smart_id].smrt
  1480.     if p[3] ~= nil then
  1481.         local spawn_point
  1482.         if p[3] == "simulation_point" then
  1483.             spawn_point = utils.cfg_get_string(sim_board.squad_ltx, squad:section_name(), "spawn_point", obj, false, "")
  1484.             if spawn_point == "" or spawn_point == nil then
  1485.                 spawn_point = xr_logic.parse_condlist(obj, "spawn_point", "spawn_point", squad_smart.spawn_point)
  1486.             else
  1487.                 spawn_point = xr_logic.parse_condlist(obj, "spawn_point", "spawn_point", spawn_point)
  1488.             end
  1489.             spawn_point = xr_logic.pick_section_from_condlist(db.actor, obj, spawn_point)
  1490.         else
  1491.             spawn_point = p[3]
  1492.         end
  1493.         position        = patrol(spawn_point):point(0)
  1494.         level_vertex_id = patrol(spawn_point):level_vertex_id(0)
  1495.         game_vertex_id  = patrol(spawn_point):game_vertex_id(0)
  1496.     else
  1497.         local commander = alife():object(squad:commander_id())
  1498.         position        = commander.position
  1499.         level_vertex_id = commander.m_level_vertex_id
  1500.         game_vertex_id  = commander.m_game_vertex_id
  1501.     end
  1502.     local new_member_id = squad:add_squad_member(squad_member_sect, position,  level_vertex_id, game_vertex_id)
  1503.     squad:assign_squad_member_to_smart(new_member_id, squad_smart)
  1504.     board:setup_squad_and_group(alife():object(new_member_id))
  1505.     --squad_smart:refresh()
  1506.     squad:update()
  1507. end
  1508.  
  1509. function remove_squad(actor, obj, p)
  1510.     local story_id = p[1]
  1511.     if story_id == nil then
  1512.         abort("Wrong squad identificator [NIL] in remove_squad function")
  1513.     end
  1514.     local squad = get_story_squad(story_id)
  1515.     if squad == nil then
  1516.         assert("Wrong squad identificator [%s]. squad doesnt exist", tostring(story_id))
  1517.         return
  1518.     end
  1519.     local board = sim_board.get_sim_board()
  1520.     board:remove_squad(squad)
  1521. end
  1522.  
  1523. function kill_squad(actor, obj, p)
  1524.     local story_id = p[1]
  1525.     if story_id == nil then
  1526.         abort("Wrong squad identificator [NIL] in kill_squad function")
  1527.     end
  1528.     local squad = get_story_squad(story_id)
  1529.     if squad == nil then
  1530.         return
  1531.     end
  1532.     local squad_npcs = {}
  1533.     for k in squad:squad_members() do
  1534.         squad_npcs[k.id] = true
  1535.     end
  1536.  
  1537.     for k,v in pairs(squad_npcs) do
  1538.         local cl_obj = db.storage[k] and db.storage[k].object
  1539.         if cl_obj == nil then
  1540.             alife():object(tonumber(k)):kill()
  1541.         else
  1542.             cl_obj:kill(cl_obj)
  1543.         end
  1544.     end
  1545. end
  1546.  
  1547. function heal_squad(actor, obj, p)
  1548.     local story_id = p[1]
  1549.     local health_mod = 1
  1550.     if p[2] and p[2] ~= nil then
  1551.         health_mod = math.ceil(p[2]/100)
  1552.     end
  1553.     if story_id == nil then
  1554.         abort("Wrong squad identificator [NIL] in heal_squad function")
  1555.     end
  1556.     local squad = get_story_squad(story_id)
  1557.     if squad == nil then
  1558.         return
  1559.     end
  1560.     for k in squad:squad_members() do
  1561.         local cl_obj = db.storage[k.id] and db.storage[k.id].object
  1562.         if cl_obj ~= nil then
  1563.             cl_obj.health = health_mod
  1564.         end
  1565.     end
  1566. end
  1567.  
  1568. --[[
  1569. function update_squad(actor, obj, p)
  1570.     local squad_id = p[1]
  1571.     if squad_id == nil then
  1572.         abort("Wrong squad identificator [NIL] in remove_squad function")
  1573.     end
  1574.     local board = sim_board.get_sim_board()
  1575.     local squad = board.squads[squad_id]
  1576.     if squad == nil then
  1577.         assert("Wrong squad identificator [%s]. squad doesnt exist", tostring(squad_id))
  1578.         return
  1579.     end
  1580.     squad:update()
  1581. end
  1582. ]]--
  1583.  
  1584. function clear_smart_terrain(actor, obj, p)
  1585.     local smart_name = p[1]
  1586.     if smart_name == nil then
  1587.         abort("Wrong squad identificator [NIL] in clear_smart_terrain function")
  1588.     end
  1589.  
  1590.     local board = sim_board.get_sim_board()
  1591.     local smart = board.smarts_by_names[smart_name]
  1592.     local smart_id = smart.id
  1593.     for k,v in pairs(board.smarts[smart_id].squads) do
  1594.         if p[2] and p[2] == "false" then
  1595.             if not get_object_story_id(v.id) then
  1596.                 board:exit_smart(v, smart_id)
  1597.                 board:remove_squad(v)
  1598.             end
  1599.         else
  1600.             board:exit_smart(v, smart_id)
  1601.             board:remove_squad(v)
  1602.         end
  1603.     end
  1604. end
  1605.  
  1606. --[[
  1607. function set_actor_faction(actor, obj, p)
  1608.     if p[1] == nil then
  1609.         abort("Wrong parameters")
  1610.     end
  1611.     sim_board.get_sim_board():set_actor_community(p[1])
  1612. end
  1613. ]]--
  1614. --'-----------------------------------------------------------------------------------
  1615. --' Quest support
  1616. --'-----------------------------------------------------------------------------------
  1617. function give_task(actor, obj, p)
  1618.     if p[1] == nil then
  1619.         abort("No parameter in give_task function.")
  1620.     end
  1621.     task_manager.get_task_manager():give_task(p[1])
  1622. end
  1623.  
  1624. function set_active_task(actor, npc, p)
  1625.     if(p[1]) then
  1626.         local t = db.actor:get_task(tostring(p[1]), true)
  1627.         if(t) then
  1628.             db.actor:set_active_task(t)
  1629.         end
  1630.     end
  1631. end
  1632.  
  1633. -- Ôóíêöèè äëÿ ðàáîòû ñ îòíîøåíèÿìè
  1634.  
  1635. function actor_friend(actor, npc)
  1636.     printf("_bp: xr_effects: actor_friend(): npc='%s': time=%d", npc:name(), time_global())
  1637.     npc:force_set_goodwill( 1000, actor)
  1638. end
  1639.  
  1640. function actor_neutral(actor, npc)
  1641.     npc:force_set_goodwill( 0, actor)
  1642. end
  1643.  
  1644. function actor_enemy(actor, npc)
  1645.     npc:force_set_goodwill( -1000, actor)
  1646. end
  1647.  
  1648. function set_squad_neutral_to_actor(actor, npc, p)
  1649.     local story_id = p[1]
  1650.     local squad = get_story_squad(story_id)
  1651.     if squad == nil then
  1652.         printf("There is no squad with id[%s]", tostring(story_id))
  1653.         return
  1654.     end
  1655.     squad:set_squad_relation("neutral")
  1656. end
  1657.  
  1658. function set_squad_friend_to_actor(actor, npc, p)
  1659.     local story_id = p[1]
  1660.     local squad = get_story_squad(story_id)
  1661.     if squad == nil then
  1662.         printf("There is no squad with id[%s]", tostring(story_id))
  1663.         return
  1664.     end
  1665.     squad:set_squad_relation("friend")
  1666. end
  1667.  
  1668. --Ñäåëàòü àêòåðà âðàãîì ê îòðÿäó, ïåðåäàåòñÿ èìÿ îòðÿäà
  1669. function set_squad_enemy_to_actor( actor, npc, p)
  1670.     local story_id = p[1]
  1671.     local squad = get_story_squad(story_id)
  1672.     if squad == nil then
  1673.         printf("There is no squad with id[%s]", tostring(story_id))
  1674.         return
  1675.     end
  1676.     squad:set_squad_relation("enemy")
  1677. end
  1678.  
  1679. --[[
  1680. function set_friends(actor, npc, p)
  1681.     local npc1
  1682.     for i, v in pairs(p) do
  1683.         npc1 = get_story_object(v)
  1684.         if npc1 and npc1:alive() then
  1685.             --printf("_bp: %d:set_friends(%d)", npc:id(), npc1:id())
  1686.             npc:set_relation(game_object.friend, npc1)
  1687.             npc1:set_relation(game_object.friend, npc)
  1688.         end
  1689.     end
  1690. end
  1691.  
  1692. function set_enemies(actor, npc, p)
  1693.     local npc1
  1694.     for i, v in pairs(p) do
  1695.         --printf("_bp: set_enemies(%d)", v)
  1696.         npc1 = get_story_object(v)
  1697.         if npc1 and npc1:alive() then
  1698.             npc:set_relation(game_object.enemy, npc1)
  1699.             npc1:set_relation(game_object.enemy, npc)
  1700.         end
  1701.     end
  1702. end
  1703.  
  1704. function set_gulag_relation_actor(actor, npc, p)
  1705.     if(p[1]) and (p[2]) then
  1706.         game_relations.set_gulag_relation_actor(p[1], p[2])
  1707.     end
  1708. end
  1709.  
  1710. function set_factions_community(actor, npc, p)
  1711.     if(p[1]~=nil) and (p[2]~=nil) and (p[3]~=nil) then
  1712.         game_relations.set_factions_community(p[1], p[2], p[3])
  1713.     end
  1714. end
  1715.  
  1716. function set_squad_community_goodwill(actor, npc, p)
  1717.     if(p[1]~=nil) and (p[2]~=nil) and (p[3]~=nil) then
  1718.         game_relations.set_squad_community_goodwill(p[1], p[2], p[3])
  1719.     end
  1720. end
  1721. ]]--
  1722.  
  1723. --sets NPC relation to actor
  1724. --set_npc_sympathy(number)
  1725. --call only from npc`s logic
  1726. function set_npc_sympathy(actor, npc, p)
  1727.     if(p[1]~=nil) then
  1728.         game_relations.set_npc_sympathy(npc, p[1])
  1729.     end
  1730. end
  1731.  
  1732. --sets SQUAD relation to actor
  1733. --set_squad_goodwill(faction:number)
  1734. function set_squad_goodwill(actor, npc, p)
  1735.     if(p[1]~=nil) and (p[2]~=nil) then
  1736.         game_relations.set_squad_goodwill(p[1], p[2])
  1737.     end
  1738. end
  1739.  
  1740. function set_squad_goodwill_to_npc(actor, npc, p)
  1741.     if(p[1]~=nil) and (p[2]~=nil) then
  1742.         game_relations.set_squad_goodwill_to_npc(npc, p[1], p[2])
  1743.     end
  1744. end
  1745.  
  1746. function inc_faction_goodwill_to_actor(actor, npc, p)
  1747.     local community = p[1]
  1748.     local delta     = p[2]
  1749.     if delta and community then
  1750.         game_relations.change_factions_community_num(community,actor:id(), tonumber(delta))
  1751.     else
  1752.         abort("Wrong parameters in function 'inc_faction_goodwill_to_actor'")
  1753.     end
  1754. end
  1755.  
  1756. function dec_faction_goodwill_to_actor(actor, npc, p)
  1757.     local community = p[1]
  1758.     local delta     = p[2]
  1759.     if delta and community then
  1760.         game_relations.change_factions_community_num(community,actor:id(), -tonumber(delta))
  1761.     else
  1762.         abort("Wrong parameters in function 'dec_faction_goodwill_to_actor'")
  1763.     end
  1764. end
  1765.  
  1766.  
  1767. --[[
  1768. function add_custom_static(actor, npc, p)
  1769.     if p[1] ~= nil and p[2] ~= nil then
  1770.         get_hud():AddCustomStatic(p[1], true)
  1771.         get_hud():GetCustomStatic(p[1]):wnd():SetTextST(p[2])
  1772.     else
  1773.         abort("Invalid parameters in function add_custom_static!!!")
  1774.     end
  1775. end
  1776.  
  1777. function remove_custom_static(actor, npc, p)
  1778.     if p[1] ~= nil then
  1779.         get_hud():RemoveCustomStatic(p[1])
  1780.     else
  1781.         abort("Invalid parameters in function remove_custom_static!!!")
  1782.     end
  1783. end
  1784. ]]--
  1785.  
  1786. function kill_actor(actor, npc)
  1787.     db.actor:kill(db.actor)
  1788. end
  1789.  
  1790. -----------------------------------------------------------------------
  1791. --  Treasures support
  1792. -----------------------------------------------------------------------
  1793. function give_treasure (actor, npc, p)
  1794.     if p == nil then
  1795.         abort("Required parameter is [NIL]")
  1796.     end
  1797.     for k,v in pairs(p) do
  1798.         treasure_manager.get_treasure_manager():give_treasure(v)
  1799.     end
  1800. end
  1801.  
  1802. --[[
  1803. function change_tsg(actor, npc, p)
  1804.     npc:change_team(p[1], p[2], p[3])
  1805. end
  1806.  
  1807. function exit_game(actor, npc)
  1808.     get_console():execute("quit")
  1809. end
  1810. ]]--
  1811.  
  1812. function start_surge(actor, npc, p)
  1813.     surge_manager.start_surge(p)
  1814. end
  1815.  
  1816. function stop_surge(actor, npc, p)
  1817.     surge_manager.stop_surge()
  1818. end
  1819.  
  1820. function set_surge_mess_and_task(actor, npc, p)
  1821.     if(p) then
  1822.         surge_manager.set_surge_message(p[1])
  1823.         if(p[2]) then
  1824.             surge_manager.set_surge_task(p[2])
  1825.         end
  1826.     end
  1827. end
  1828.  
  1829. --[[
  1830. function enable_level_changer(actor, npc, p)
  1831.     if(p[1]~=nil) then
  1832.         local obj = get_story_object(p[1])
  1833.         if(obj) then
  1834.             if db.storage[obj:id()] and db.storage[obj:id()].s_obj then
  1835.                 db.storage[obj:id()].s_obj.enabled = true
  1836.                 db.storage[obj:id()].s_obj.hint = "level_changer_invitation"
  1837.             else
  1838.                 return
  1839.             end
  1840.             obj:enable_level_changer(true)
  1841.             level_tasks.add_lchanger_location()
  1842.             obj:set_level_changer_invitation("level_changer_invitation")
  1843.         end
  1844.     end
  1845. end
  1846.  
  1847. function disable_level_changer(actor, npc, p)
  1848.     if(p[1]~=nil) then
  1849.         local obj = get_story_object(p[1])
  1850.         if(obj) then
  1851.             if not(db.storage[obj:id()] and db.storage[obj:id()].s_obj) then
  1852.                 return
  1853.             end
  1854.             obj:enable_level_changer(false)
  1855.             level_tasks.del_lchanger_mapspot(tonumber(p[1]))
  1856.             db.storage[obj:id()].s_obj.enabled = false
  1857.             if(p[2]==nil) then
  1858.                 obj:set_level_changer_invitation("level_changer_disabled")
  1859.                 db.storage[obj:id()].s_obj.hint = "level_changer_disabled"
  1860.             else
  1861.                 obj:set_level_changer_invitation(p[2])
  1862.                 db.storage[obj:id()].s_obj.hint = p[2]
  1863.             end
  1864.         end
  1865.     end
  1866. end
  1867.  
  1868. function change_actor_community(actor, npc, p)
  1869.     if(p[1]~=nil) then
  1870.         db.actor:set_character_community(p[1], 0, 0)
  1871.     end
  1872. end
  1873.  
  1874. function set_faction_community_to_actor(actor, npc, p)
  1875. -- run_string xr_effects.change_actor_community(nil,nil,{"actor_dolg"})
  1876.     if(p[1]~=nil) and (p[2]~=nil) then
  1877.         local rel = 0
  1878.         if(p[2]=="enemy") then
  1879.             rel = -3000
  1880.         elseif(p[2]=="friend") then
  1881.             rel = 1000
  1882.         end
  1883.         db.actor:set_community_goodwill(p[1], rel)
  1884.     end
  1885. end
  1886.  
  1887. function disable_collision(actor, npc)
  1888.     npc:wounded(true)
  1889. end
  1890. function enable_collision(actor, npc)
  1891.     npc:wounded(false)
  1892. end
  1893.  
  1894. function disable_actor_collision(actor, npc)
  1895.     actor:wounded(true)
  1896. end
  1897. function enable_actor_collision(actor, npc)
  1898.     actor:wounded(false)
  1899. end
  1900.  
  1901. function relocate_actor_inventory_to_box(actor, npc, p)
  1902.     local function transfer_object_item(item)
  1903.         if item:section() ~= "wpn_binoc" and item:section() ~= "wpn_knife" and item:section() ~= "device_torch" then
  1904.             db.actor:transfer_item(item, inv_box_1)
  1905.         end
  1906.     end
  1907.     inv_box_1 = get_story_object (p[1])
  1908.     actor:inventory_for_each(transfer_object_item)
  1909. end
  1910. ]]--
  1911.  
  1912. function set_level_faction_community(actor, npc, p)
  1913.     if(p[1]~=nil) and (p[2]~= nil) and (p[3]~= nil) then
  1914.         local faction = sim_board.get_sim_board().players[p[1]]
  1915.         local goodwill = 0
  1916.         if(p[3]=="enemy") then
  1917.             goodwill = -3000
  1918.         elseif(p[3]=="friend") then
  1919.             goodwill = 1000
  1920.         end
  1921.         for k,v in pairs(faction.squads) do
  1922.             local squad_level = alife():level_name(game_graph():vertex(alife():object(v:commander_id()).m_game_vertex_id):level_id())
  1923.             if(squad_level==p[2]) then
  1924.                 for kk in v:squad_members() do
  1925.                     local npc = kk.object
  1926.                     local tbl = game_relations.temp_goodwill_table
  1927.                     if(tbl.communities==nil) then
  1928.                         tbl.communities = {}
  1929.                     end
  1930.                     if(tbl.communities[p[1]]==nil) then
  1931.                         tbl.communities[p[1]] = {}
  1932.                     end
  1933.                     tbl.communities[p[1]][npc.id] = goodwill
  1934.                     if(db.storage[npc.id]~=nil) then
  1935.                         game_relations.set_level_faction_community(db.storage[npc.id].object)
  1936.                     end
  1937.                 end
  1938.             end
  1939.         end
  1940.     end
  1941. end
  1942.  
  1943. --[[
  1944. function make_actor_visible_to_npc(actor,npc,p)
  1945.     npc:make_object_visible_somewhen(db.actor)
  1946. end
  1947. ]]--
  1948.  
  1949. function make_actor_visible_to_squad(actor,npc,p)
  1950.     local story_id = p and p[1]
  1951.     local squad = get_story_squad(story_id)
  1952.     if squad == nil then abort("There is no squad with id[%s]", story_id) end
  1953.     for k in squad:squad_members() do
  1954.         local obj = level.object_by_id(k.id)
  1955.         if obj ~= nil then
  1956.             obj:make_object_visible_somewhen( db.actor )
  1957.         end
  1958.     end
  1959. end
  1960.  
  1961. function stop_sr_cutscene(actor,npc,p)
  1962.     local obj = db.storage[npc:id()]
  1963.     if(obj.active_scheme~=nil) then
  1964.         obj[obj.active_scheme].signals["cam_effector_stop"] = true
  1965.     end
  1966. end
  1967.  
  1968. --[[
  1969. function reset_dialog_end_signal(actor, npc, p)
  1970.     local st = db.storage[npc:id()]
  1971.     if(st.active_scheme==nil) then
  1972.         return
  1973.     end
  1974.     if(st[st.active_scheme].signals==nil) then
  1975.         return
  1976.     end
  1977.     st[st.active_scheme].signals["dialog_end"] = nil
  1978. end
  1979.  
  1980. function add_map_spot(actor, npc, p)
  1981.     if(p[1]==nil) then
  1982.         abort("Story id for add map spot function is not set")
  1983.     else
  1984.         local story_id = tonumber(p[1])
  1985.         local id = id_by_sid(story_id)
  1986.         if(id==nil) then
  1987.             local obj = alife():object(p[1])
  1988.             id = obj and obj.id
  1989.         end
  1990.         if(id~=nil) then
  1991.             if(p[2]==nil) then
  1992.                 p[2] = "primary_task_location"
  1993.             end
  1994.             if(p[3]==nil) then
  1995.                 p[3] = "default"
  1996.             end
  1997.             if level.map_has_object_spot(id, p[2]) == 0 then
  1998.                 level.map_add_object_spot_ser(id, p[2], p[3])
  1999.             end
  2000.         else
  2001.             abort("Wrong story id or name [%s] for map spot function", tostring(story_id))
  2002.         end
  2003.     end
  2004. end
  2005.  
  2006. function remove_map_spot(actor, npc, p)
  2007.     if(p[1]==nil) then
  2008.         abort("Story id for add map spot function is not set")
  2009.     else
  2010.         local story_id = tonumber(p[1])
  2011.         local id = id_by_sid(story_id)
  2012.         if(id==nil) then
  2013.             local obj = alife():object(p[1])
  2014.             id = obj and obj.id
  2015.         end
  2016.         if(id~=nil) then
  2017.             if(p[2]==nil) then
  2018.                 p[2] = "primary_task_location"
  2019.             end
  2020.             if level.map_has_object_spot(id, p[2]) ~= 0 then
  2021.                 level.map_remove_object_spot(id, p[2])
  2022.             end
  2023.         else
  2024.             abort("Wrong story id or name [%s] for map spot function", tostring(story_id))
  2025.         end
  2026.     end
  2027. end
  2028. ]]--
  2029.  
  2030. -- Anomal fields support
  2031. function enable_anomaly(actor, npc, p)
  2032.     if p[1] == nil then
  2033.         abort("Story id for enable_anomaly function is not set")
  2034.     end
  2035.  
  2036.     local obj = get_story_object(p[1])
  2037.     if not obj then
  2038.         abort("There is no object with story_id %s for enable_anomaly function", tostring(p[1]))
  2039.     end
  2040.     obj:enable_anomaly()
  2041. end
  2042.  
  2043. function disable_anomaly(actor, npc, p)
  2044.     if p[1] == nil then
  2045.         abort("Story id for disable_anomaly function is not set")
  2046.     end
  2047.  
  2048.     local obj = get_story_object(p[1])
  2049.     if not obj then
  2050.         abort("There is no object with story_id %s for disable_anomaly function", tostring(p[1]))
  2051.     end
  2052.     obj:disable_anomaly()
  2053. end
  2054.  
  2055. function launch_signal_rocket(actor, obj, p)
  2056.     if p==nil then
  2057.         abort("Signal rocket name is not set!")
  2058.     end
  2059.     if db.signal_light[p[1]] then
  2060.         db.signal_light[p[1]]:launch()
  2061.     else
  2062.         abort("No such signal rocket: [%s] on level", tostring(p[1]))
  2063.     end
  2064. end
  2065.  
  2066. --[[
  2067. function reset_faction_goodwill(actor, obj, p)
  2068.     if db.actor and p[1] then
  2069.         local board = sim_board.get_sim_board()
  2070.         local faction = board.players[ p[1] ]
  2071.         if faction then
  2072.             db.actor:set_community_goodwill(p[1], 0)
  2073.         end
  2074.     end
  2075. end
  2076. ]]--
  2077.  
  2078. function add_cs_text(actor, npc, p)
  2079.     if p[1] then
  2080.         local hud = get_hud()
  2081.         local cs_text = hud:GetCustomStatic("text_on_screen_center")
  2082.         if cs_text then
  2083.             hud:RemoveCustomStatic("text_on_screen_center")
  2084.         end
  2085.         hud:AddCustomStatic("text_on_screen_center", true)
  2086.         cs_text = hud:GetCustomStatic("text_on_screen_center")
  2087.         cs_text:wnd():TextControl():SetText(game.translate_string(p[1]))
  2088.     end
  2089. end
  2090.  
  2091. function del_cs_text(actor, npc, p)
  2092.     local hud = get_hud()
  2093.     cs_text = hud:GetCustomStatic("text_on_screen_center")
  2094.     if cs_text then
  2095.         hud:RemoveCustomStatic("text_on_screen_center")
  2096.     end
  2097. end
  2098.  
  2099. function spawn_item_to_npc(actor, npc, p)
  2100.     local new_item = p[1]
  2101.     if p[1] then
  2102.         alife():create(new_item,
  2103.         npc:position(),
  2104.         npc:level_vertex_id(),
  2105.         npc:game_vertex_id(),
  2106.         npc:id())
  2107.     end
  2108. end
  2109.  
  2110. function give_money_to_npc(actor, npc, p)
  2111.     local money = p[1]
  2112.     if p[1] then
  2113.         npc:give_money(money)
  2114.     end
  2115. end
  2116.  
  2117. function seize_money_to_npc(actor, npc, p)
  2118.     local money = p[1]
  2119.     if p[1] then
  2120.         npc:give_money(-money)
  2121.     end
  2122. end
  2123.  
  2124. -- Ïåðåäà÷à ïðåäìåòà îò íåïèñÿ ê íåïèñþ
  2125. -- relocate_item(item_name:story_id_from:story_id_to)
  2126. function relocate_item(actor, npc, p)
  2127.     local item = p and p[1]
  2128.     local from_obj = p and get_story_object(p[2])
  2129.     local to_obj = p and get_story_object(p[3])
  2130.     if to_obj ~= nil then
  2131.         if from_obj ~= nil and from_obj:object(item) ~= nil then
  2132.             from_obj:transfer_item(from_obj:object(item), to_obj)
  2133.         else
  2134.             alife():create(item,
  2135.                 to_obj:position(),
  2136.                 to_obj:level_vertex_id(),
  2137.                 to_obj:game_vertex_id(),
  2138.                 to_obj:id())
  2139.         end
  2140.     else
  2141.         abort("Couldn't relocate item to NULL")
  2142.     end
  2143. end
  2144.  
  2145. -- Ñäåëàòü ñêâàäû âðàãàìè, ïåðåäàþòñÿ äâà ñêâàäà set_squads_enemies(squad_name_1:squad_name_2)
  2146. function set_squads_enemies(actor, npc, p)
  2147.     if (p[1] == nil or p[2] == nil) then
  2148.         abort("Wrong parameters in function set_squad_enemies")
  2149.         return
  2150.     end
  2151.  
  2152.     local squad_1 = get_story_squad(p[1])
  2153.     local squad_2 = get_story_squad(p[2])
  2154.  
  2155.     if squad_1 == nil then
  2156.         assert("There is no squad with id[%s]", tostring(p[1]))
  2157.         return
  2158.     end
  2159.     if squad_2 == nil then
  2160.         assert("There is no squad with id[%s]", tostring(p[2]))
  2161.         return
  2162.     end
  2163.  
  2164.     for k in squad_1:squad_members() do
  2165.         local npc_obj_1 = db.storage[k.id] and db.storage[k.id].object
  2166.         if npc_obj_1 ~= nil then
  2167.             for kk in squad_2:squad_members() do
  2168.                 local npc_obj_2 = db.storage[kk.id] and db.storage[kk.id].object
  2169.                 if npc_obj_2 ~= nil then
  2170.                     npc_obj_1:set_relation(game_object.enemy, npc_obj_2)
  2171.                     npc_obj_2:set_relation(game_object.enemy, npc_obj_1)
  2172.                     printf("set_squads_enemies: %d:set_enemy(%d)", npc_obj_1:id(), npc_obj_2:id())
  2173.                 end
  2174.             end
  2175.         end
  2176.     end
  2177. end
  2178.  
  2179. local particles_table = {
  2180. [1] = {particle = particles_object("anomaly2\\teleport_out_00"), sound = sound_object("anomaly\\teleport_incoming")},
  2181. [2] = {particle = particles_object("anomaly2\\teleport_out_00"), sound = sound_object("anomaly\\teleport_incoming")},
  2182. [3] = {particle = particles_object("anomaly2\\teleport_out_00"), sound = sound_object("anomaly\\teleport_incoming")},
  2183. [4] = {particle = particles_object("anomaly2\\teleport_out_00"), sound = sound_object("anomaly\\teleport_incoming")},
  2184. }
  2185.  
  2186. function jup_b16_play_particle_and_sound(actor, npc, p)
  2187.     particles_table[p[1]].particle :play_at_pos(patrol(npc:name().."_particle"):point(0))
  2188.     --particles_table[p[1]].sound    :play_at_pos(actor, patrol(npc:name().."_particle"):point(0), 0, sound_object.s3d)
  2189. end
  2190. --Ôóíêöèÿ óñòàíîâêè ñîñòîÿíèÿ âèäèìîñòè êðîâîñîñà.
  2191. -- Âîçìîæíûé íàáîð ïàðàìåòðîâ --> story_id:visibility_state(ìîæíî âûçûâàòü îòêóäà óãîäíî) èëè visibility_state(åñëè âûçûâàåòñÿ èç êàñòîìäàòû êðîâîñîñà)
  2192. --  visibility_state -->
  2193. --                      0 - íåâèäèìûé
  2194. --                      1 - ïîëóâèäèìûé
  2195. --                      2 - ïîëíîñòüþ âèäèìûé
  2196. function set_bloodsucker_state(actor, npc, p)
  2197.     if (p and p[1]) == nil then abort("Wrong parameters in function 'set_bloodsucker_state'!!!") end
  2198.     local state = p[1]
  2199.     if p[2] ~= nil then
  2200.         state = p[2]
  2201.         npc = get_story_object(p[1])
  2202.     end
  2203.     if npc ~= nil then
  2204.         if state == "default" then
  2205.             npc:force_visibility_state(-1)
  2206.         else
  2207.             npc:force_visibility_state(tonumber(state))
  2208.         end
  2209.     end
  2210. end
  2211.  
  2212. --Ôóíêöèÿ âñòàâêè ïðåäìåòà â îïðåäåëåííóþ òî÷êó, ñäåëàë äëÿ ñöåíû á57
  2213. function drop_object_item_on_point(actor, npc, p)
  2214.     local drop_object = db.actor:object(p[1])
  2215.     local drop_point  = patrol(p[2]):point(0)
  2216.     db.actor:drop_item_and_teleport(drop_object, drop_point)
  2217. end
  2218.  
  2219. --Ôóíêöèÿ îòíÿòèÿ ïðåäìåòà ó èãðîêà
  2220. function remove_item(actor, npc, p)
  2221.     if (p and p[1]) == nil then abort("Wrong parameters in function 'remove_item'!!!") end
  2222.     local item = p[1]
  2223.  
  2224.     local obj = db.actor:object(item)
  2225.     if obj ~= nil then
  2226.         alife():release(alife():object(obj:id()), true)
  2227.     else
  2228.         abort("Actor has no such item!")
  2229.     end
  2230.     news_manager.relocate_item(db.actor, "out", item)
  2231. end
  2232.  
  2233. -- Ñþæåòíîå ñîõðàíåíèå â âàæíûõ ìåñòàõ
  2234. function scenario_autosave(actor, npc, p)
  2235.     local save_name = p[1]
  2236.     if save_name == nil then
  2237.         abort("You are trying to use scenario_autosave without save name")
  2238.     end
  2239.  
  2240.     if IsImportantSave() then
  2241.         local save_param = user_name().." - "..game.translate_string(save_name)
  2242.  
  2243.         get_console():execute("save "..save_param)
  2244.     end
  2245. end
  2246.  
  2247.  
  2248.  
  2249.  
  2250.  
  2251.  
  2252.  
  2253.  
  2254.  
  2255.  
  2256.  
  2257.  
  2258.  
  2259.  
  2260.  
  2261.  
  2262.  
  2263.  
  2264.  
  2265.  
  2266.  
  2267.  
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273.  
  2274.  
  2275.  
  2276.  
  2277.  
  2278.  
  2279.  
  2280.  
  2281. function zat_b29_create_random_infop(actor, npc, p)
  2282.     if p[2] == nil then
  2283.         abort("Not enough parameters for zat_b29_create_random_infop!")
  2284.     end
  2285.  
  2286.     local amount_needed = p[1]
  2287.     local current_infop = 0
  2288.     local total_infop = 0
  2289.  
  2290.     if (not amount_needed or amount_needed == nil) then
  2291.         amount_needed = 1
  2292.     end
  2293.  
  2294.     for k,v in pairs(p) do
  2295.         if k > 1 then
  2296.             total_infop = total_infop + 1
  2297.             disable_info(v)
  2298.         end
  2299.     end
  2300.  
  2301.     if amount_needed > total_infop then
  2302.         amount_needed = total_infop
  2303.     end
  2304.  
  2305.     for i = 1, amount_needed do
  2306.         current_infop = math.random(1, total_infop)
  2307.         for k,v in pairs(p) do
  2308.             if k > 1 then
  2309.                 if (k == current_infop + 1 and (not has_alife_info(v))) then
  2310.                     db.actor:give_info_portion(v)
  2311.                     break
  2312.                 end
  2313.             end
  2314.         end
  2315.     end
  2316. end
  2317.  
  2318. function give_item_b29(actor, npc, p)
  2319. --  local story_object = p and get_story_object(p[1])
  2320.     local az_name
  2321.     local az_table = {
  2322.                         "zat_b55_anomal_zone",
  2323.                         "zat_b54_anomal_zone",
  2324.                         "zat_b53_anomal_zone",
  2325.                         "zat_b39_anomal_zone",
  2326.                         "zaton_b56_anomal_zone",
  2327.                         }
  2328.  
  2329.     for i = 16, 23 do
  2330.         if has_alife_info(dialogs_zaton.zat_b29_infop_bring_table[i]) then
  2331.             for k,v in pairs(az_table) do
  2332.                 if has_alife_info(v) then
  2333.                     az_name = v
  2334.                     disable_info(az_name)
  2335.                     break
  2336.                 end
  2337.             end
  2338.             pick_artefact_from_anomaly(nil, nil, {p[1], az_name, dialogs_zaton.zat_b29_af_table[i]})
  2339.             break
  2340.         end
  2341.     end
  2342. end
  2343.  
  2344. function relocate_item_b29(actor, npc, p)
  2345.     local item
  2346.     for i = 16, 23 do
  2347.         if has_alife_info(dialogs_zaton.zat_b29_infop_bring_table[i]) then
  2348.             item = dialogs_zaton.zat_b29_af_table[i]
  2349.             break
  2350.         end
  2351.     end
  2352.     local from_obj = p and get_story_object(p[1])
  2353.     local to_obj = p and get_story_object(p[2])
  2354.     if to_obj ~= nil then
  2355.         if from_obj ~= nil and from_obj:object(item) ~= nil then
  2356.             from_obj:transfer_item(from_obj:object(item), to_obj)
  2357.         else
  2358.             alife():create(item,
  2359.                 to_obj:position(),
  2360.                 to_obj:level_vertex_id(),
  2361.                 to_obj:game_vertex_id(),
  2362.                 to_obj:id())
  2363.         end
  2364.     else
  2365.         abort("Couldn't relocate item to NULL")
  2366.     end
  2367. end
  2368.  
  2369. -- Ôóíêöèÿ ðåñåòèò ñåêâåíñíóþ çâóêîêóþ òåìó ó íåïèñÿ. by peacemaker, hein, redstain
  2370. function reset_sound_npc(actor, npc, p)
  2371.     local obj_id = npc:id()
  2372.     if obj_id and xr_sound.sound_table and xr_sound.sound_table[obj_id] then
  2373.         xr_sound.sound_table[obj_id]:reset(obj_id)
  2374.     end
  2375. end
  2376.  
  2377. function jup_b202_inventory_box_relocate(actor, npc)
  2378.     local inv_box_out = get_story_object("jup_b202_actor_treasure")
  2379.     local inv_box_in = get_story_object("jup_b202_snag_treasure")
  2380.     local items_to_relocate = {}
  2381.     local function relocate(inv_box_out, item)
  2382.         table.insert(items_to_relocate, item)
  2383.     end
  2384.     inv_box_out:iterate_inventory_box   (relocate, inv_box_out)
  2385.     for k,v in pairs(items_to_relocate) do
  2386.         inv_box_out:transfer_item(v, inv_box_in)
  2387.     end
  2388. end
  2389.  
  2390. function clear_box(actor, npc, p)
  2391.     if (p and p[1]) == nil then abort("Wrong parameters in function 'clear_box'!!!") end
  2392.  
  2393.     local inv_box = get_story_object(p[1])
  2394.  
  2395.     if inv_box == nil then
  2396.         abort("There is no object with story_id [%s]", tostring(p[1]))
  2397.     end
  2398.  
  2399.     local items_table = {}
  2400.  
  2401.     local function add_items(inv_box, item)
  2402.         table.insert(items_table, item)
  2403.     end
  2404.  
  2405.     inv_box:iterate_inventory_box(add_items, inv_box)
  2406.  
  2407.     for k,v in pairs(items_table) do
  2408.         alife():release(alife():object(v:id()), true)
  2409.     end
  2410. end
  2411.  
  2412. function activate_weapon(actor, npc, p)
  2413.     local object = actor:object(p[1])
  2414.     if object == nil then
  2415.         assert("Actor has no such weapon! [%s]", p[1])
  2416.     end
  2417.     if object ~= nil then
  2418.         actor:make_item_active(object)
  2419.     end
  2420. end
  2421.  
  2422. function set_game_time(actor, npc, p)
  2423.     local real_hours = level.get_time_hours()
  2424.     local real_minutes = level.get_time_minutes()
  2425.     local hours = tonumber(p[1])
  2426.     local minutes = tonumber(p[2])
  2427.     if p[2] == nil then
  2428.         minutes = 0
  2429.     end
  2430.     local hours_to_change = hours - real_hours
  2431.     if hours_to_change <= 0 then
  2432.         hours_to_change = hours_to_change + 24
  2433.     end
  2434.     local minutes_to_change = minutes - real_minutes
  2435.     if minutes_to_change <= 0 then
  2436.         minutes_to_change = minutes_to_change + 60
  2437.         hours_to_change = hours_to_change - 1
  2438.     elseif hours == real_hours then
  2439.         hours_to_change = hours_to_change - 24
  2440.     end
  2441.     level.change_game_time(0,hours_to_change,minutes_to_change)
  2442.     level_weathers.get_weather_manager():forced_weather_change()
  2443.     surge_manager.get_surge_manager().time_forwarded = true
  2444.     printf("set_game_time: time changed to [%d][%d]", hours_to_change, minutes_to_change)
  2445. end
  2446.  
  2447. function forward_game_time(actor, npc, p)
  2448.     if not p then
  2449.         abort("Insufficient or invalid parameters in function 'forward_game_time'!")
  2450.     end
  2451.  
  2452.     local hours = tonumber(p[1])
  2453.     local minutes = tonumber(p[2])
  2454.  
  2455.     if p[2] == nil then
  2456.         minutes = 0
  2457.     end
  2458.     level.change_game_time(0,hours,minutes)
  2459.     level_weathers.get_weather_manager():forced_weather_change()
  2460.     surge_manager.get_surge_manager().time_forwarded = true
  2461.     printf("forward_game_time: time forwarded on [%d][%d]", hours, minutes)
  2462. end
  2463.  
  2464. function stop_tutorial()
  2465.     printf("stop tutorial called")
  2466.     game.stop_tutorial()
  2467. end
  2468.  
  2469. function jup_b10_spawn_drunk_dead_items(actor, npc, p)
  2470.     local items_all = {
  2471.                     ["wpn_ak74"] = 1,
  2472.                     ["ammo_5.45x39_fmj"] = 5,
  2473.                     ["ammo_5.45x39_ap"] = 3,
  2474.                     ["wpn_fort"] = 1,
  2475.                     ["ammo_9x18_fmj"] = 3,
  2476.                     ["ammo_12x70_buck"] = 5,
  2477.                     ["ammo_11.43x23_hydro"] = 2,
  2478.                     ["grenade_rgd5"] = 3,
  2479.                     ["grenade_f1"] = 2,
  2480.                     ["medkit_army"] = 2,
  2481.                     ["medkit"] = 4,
  2482.                     ["bandage"] = 4,
  2483.                     ["antirad"] = 2,
  2484.                     ["vodka"] = 3,
  2485.                     ["energy_drink"] = 2,
  2486.                     ["conserva"] = 1,
  2487.                     ["jup_b10_ufo_memory_2"] = 1,
  2488.                     }
  2489.  
  2490.     local items = {
  2491.                     [2] =   {
  2492.                             ["wpn_sig550_luckygun"] = 1,
  2493.                             },
  2494.                     [1] =   {
  2495.                             ["ammo_5.45x39_fmj"] = 5,
  2496.                             ["ammo_5.45x39_ap"] = 3,
  2497.                             ["wpn_fort"] = 1,
  2498.                             ["ammo_9x18_fmj"] = 3,
  2499.                             ["ammo_12x70_buck"] = 5,
  2500.                             ["ammo_11.43x23_hydro"] = 2,
  2501.                             ["grenade_rgd5"] = 3,
  2502.                             ["grenade_f1"] = 2,
  2503.                             },
  2504.                     [0] =   {
  2505.                             ["medkit_army"] = 2,
  2506.                             ["medkit"] = 4,
  2507.                             ["bandage"] = 4,
  2508.                             ["antirad"] = 2,
  2509.                             ["vodka"] = 3,
  2510.                             ["energy_drink"] = 2,
  2511.                             ["conserva"] = 1,
  2512.                             },
  2513.                     }
  2514.  
  2515.     if p and p[1] ~= nil then
  2516.         local cnt = xr_logic.pstor_retrieve(actor, "jup_b10_ufo_counter", 0)
  2517.         if cnt > 2 then return end
  2518.         for k,v in pairs(items[cnt]) do
  2519.             local target_obj_id = get_story_object_id(p[1])
  2520.             if target_obj_id ~= nil then
  2521.                 box = alife():object(target_obj_id)
  2522.                 if box == nil then
  2523.                     abort("There is no such object %s", p[1])
  2524.                 end
  2525.                 for i = 1,v do
  2526.                     alife():create(k,vector(),0,0,target_obj_id)
  2527.                 end
  2528.             else
  2529.                 abort("object is nil %s", tostring(p[1]))
  2530.             end
  2531.         end
  2532.     else
  2533.         for k,v in pairs(items_all) do
  2534.             for i = 1,v do
  2535.                 alife():create(k,
  2536.                     npc:position(),
  2537.                     npc:level_vertex_id(),
  2538.                     npc:game_vertex_id(),
  2539.                     npc:id())
  2540.             end
  2541.         end
  2542.     end
  2543.  
  2544. end
  2545.  
  2546. function pick_artefact_from_anomaly(actor, npc, p)
  2547.     local npc
  2548.     local az_name = p and p[2]
  2549.     local af_name = p and p[3]
  2550.     local af_id
  2551.     local af_obj
  2552.     local anomal_zone = db.anomaly_by_name[az_name]
  2553.  
  2554.     if p and p[1] then
  2555. --      if p[1] == "actor" then
  2556. --          npc = db.actor
  2557. --      else
  2558. --          npc = get_story_object(p[1])
  2559. --      end
  2560.  
  2561.         local npc_id = get_story_object_id(p[1])
  2562.         if npc_id == nil then
  2563.             abort("Couldn't relocate item to NULL in function 'pick_artefact_from_anomaly!'")
  2564.         end
  2565.         npc = alife():object(npc_id)
  2566.         if npc and (not IsStalker(npc) or not npc:alive()) then
  2567.             abort("Couldn't relocate item to NULL (dead or not stalker) in function 'pick_artefact_from_anomaly!'")
  2568.         end
  2569.     end
  2570.  
  2571.     if anomal_zone == nil then
  2572.         abort("No such anomal zone in function 'pick_artefact_from_anomaly!'")
  2573.     end
  2574.  
  2575.     if anomal_zone.spawned_count < 1 then
  2576.         printf("No artefacts in anomal zone [%s]", az_name)
  2577.         return
  2578.     end
  2579.  
  2580.     for k,v in pairs(anomal_zone.artefact_ways_by_id) do
  2581.         if alife():object(tonumber(k)) and af_name == alife():object(tonumber(k)):section_name() then
  2582.             af_id = tonumber(k)
  2583.             af_obj = alife():object(tonumber(k))
  2584.             break
  2585.         end
  2586.         if af_name == nil then
  2587.             af_id = tonumber(k)
  2588.             af_obj = alife():object(tonumber(k))
  2589.             af_name = af_obj:section_name()
  2590.             break
  2591.         end
  2592.     end
  2593.  
  2594.     if af_id == nil then
  2595.         printf("No such artefact [%s] found in anomal zone [%s]", tostring(af_name), az_name)
  2596.         return
  2597.     end
  2598.  
  2599.     anomal_zone:on_artefact_take(af_obj)
  2600.  
  2601.     alife():release(af_obj, true)
  2602.     give_item(db.actor, npc, {af_name, p[1]})
  2603. --  alife():create(af_name,
  2604. --      npc.position,
  2605. --      npc.level_vertex_id,
  2606. --      npc.game_vertex_id,
  2607. --      npc.id)
  2608. end
  2609.  
  2610. function anomaly_turn_off (actor, npc, p)
  2611.     local anomal_zone = db.anomaly_by_name[p[1]]
  2612.     if anomal_zone == nil then
  2613.         abort("No such anomal zone in function 'anomaly_turn_off!'")
  2614.     end
  2615.     anomal_zone:turn_off()
  2616. end
  2617.  
  2618. function anomaly_turn_on (actor, npc, p)
  2619.     local anomal_zone = db.anomaly_by_name[p[1]]
  2620.     if anomal_zone == nil then
  2621.         abort("No such anomal zone in function 'anomaly_turn_on!'")
  2622.     end
  2623.     if p[2] then
  2624.         anomal_zone:turn_on(true)
  2625.     else
  2626.         anomal_zone:turn_on(false)
  2627.     end
  2628. end
  2629.  
  2630. function zat_b202_spawn_random_loot(actor, npc, p)
  2631.     local si_table = {}
  2632.     si_table[1] = {
  2633.         [1] = {item = {"bandage","bandage","bandage","bandage","bandage","medkit","medkit","medkit","conserva","conserva"}},
  2634.         [2] = {item = {"medkit","medkit","medkit","medkit","medkit","vodka","vodka","vodka","kolbasa","kolbasa"}},
  2635.         [3] = {item = {"antirad","antirad","antirad","medkit","medkit","bandage","kolbasa","kolbasa","conserva"}},
  2636.     }
  2637.     si_table[2] = {
  2638.         [1] = {item = {"grenade_f1","grenade_f1","grenade_f1"}},
  2639.         [2] = {item = {"grenade_rgd5","grenade_rgd5","grenade_rgd5","grenade_rgd5","grenade_rgd5"}}
  2640.     }
  2641.     si_table[3] = {
  2642.         [1] = {item = {"detector_elite"}},
  2643.         [2] = {item = {"detector_advanced"}}
  2644.     }
  2645.     si_table[4] = {
  2646.         [1] = {item = {"helm_hardhat"}},
  2647.         [2] = {item = {"helm_respirator"}}
  2648.     }
  2649.     si_table[5] = {
  2650.         [1] = {item = {"wpn_val","ammo_9x39_ap","ammo_9x39_ap","ammo_9x39_ap"}},
  2651.         [2] = {item = {"wpn_spas12","ammo_12x70_buck","ammo_12x70_buck","ammo_12x70_buck","ammo_12x70_buck"}},
  2652.         [3] = {item = {"wpn_desert_eagle","ammo_11.43x23_fmj","ammo_11.43x23_fmj","ammo_11.43x23_hydro","ammo_11.43x23_hydro"}},
  2653.         [4] = {item = {"wpn_abakan","ammo_5.45x39_ap","ammo_5.45x39_ap"}},
  2654.         [5] = {item = {"wpn_sig550","ammo_5.56x45_ap","ammo_5.56x45_ap"}},
  2655.         [6] = {item = {"wpn_ak74","ammo_5.45x39_fmj","ammo_5.45x39_fmj"}},
  2656.         [7] = {item = {"wpn_l85","ammo_5.56x45_ss190","ammo_5.56x45_ss190"}}
  2657.     }
  2658.     si_table[6] = {
  2659.         [1] = {item = {"specops_outfit"}},
  2660.         [2] = {item = {"stalker_outfit"}}
  2661.     }
  2662.     weight_table = {}
  2663.     weight_table[1] = 2
  2664.     weight_table[2] = 2
  2665.     weight_table[3] = 2
  2666.     weight_table[4] = 2
  2667.     weight_table[5] = 4
  2668.     weight_table[6] = 4
  2669.     local spawned_item = {}
  2670.     local max_weight = 12
  2671.     repeat
  2672.         local n = 0
  2673.         repeat
  2674.             n = math.random(1, #weight_table)
  2675.             local prap = true
  2676.             for k,v in pairs(spawned_item) do
  2677.                 if v == n then
  2678.                     prap = false
  2679.                     break
  2680.                 end
  2681.             end
  2682.         until (prap) and ((max_weight - weight_table[n]) >= 0)
  2683.         max_weight = max_weight - weight_table[n]
  2684.         table.insert(spawned_item,n)
  2685.         local item = math.random(1, #si_table[n])
  2686.         for k,v in pairs(si_table[n][item].item) do
  2687.             spawn_object_in(actor, npc, {tostring(v),"jup_b202_snag_treasure"})
  2688.         end
  2689.     until max_weight <= 0
  2690. end
  2691.  
  2692. function zat_a1_tutorial_end_give(actor, npc)
  2693. --  level.add_pp_effector("black.ppe", 1313, true) ---do not stop on r1 !
  2694.     db.actor:give_info_portion("zat_a1_tutorial_end")
  2695. end
  2696.  
  2697. function oasis_heal()
  2698.     local d_health = 0.005
  2699.     local d_power = 0.01
  2700.     local d_bleeding = 0.05
  2701.     local d_radiation = -0.05
  2702.     if(db.actor.health<1) then
  2703.         db.actor.health = d_health
  2704.     end
  2705.     if(db.actor.power<1) then
  2706.         db.actor.power = d_power
  2707.     end
  2708.     if(db.actor.radiation>0) then
  2709.         db.actor.radiation = d_radiation
  2710.     end
  2711.     if(db.actor.bleeding>0) then
  2712.         db.actor.bleeding = d_bleeding
  2713.     end
  2714.         db.actor.satiety = 0.01
  2715. end
  2716.  
  2717. --Ôóíêöèÿ ïðèíèìàåò òîëüêî îäíî çíà÷åíèå, îïðåäåëÿþùåå äëÿ êàêîé ãðóïèðîâêè çàïóñêàåòñÿ. äîñòóïíûå çíà÷åíèÿ [duty, freedom]
  2718. function jup_b221_play_main(actor, npc, p)
  2719.     local info_table = {}
  2720.     local main_theme
  2721.     local reply_theme
  2722.     local info_need_reply
  2723.     local reachable_theme = {}
  2724.     local theme_to_play = 0
  2725.  
  2726.     if (p and p[1]) == nil then
  2727.         abort("No such parameters in function 'jup_b221_play_main'")
  2728.     end
  2729. --Ñîñòàâëÿåì òàáëèöó èíôîïîðøèíîâ îïðåäåëÿþùèõ äîñòóïíîñòü òîé èëè èíîé òåìû, îïðåäåëÿåì ïðåôèêñû òåìû, îòâåòà è ðåàêöèè, ñîîòâåòñòâåííî äëÿ äîëãà èëè äëÿ ñâîáîäû.
  2730.     if tostring(p[1]) == "duty" then
  2731.         info_table = {
  2732.             [1] = "jup_b25_freedom_flint_gone",
  2733.             [2] = "jup_b25_flint_blame_done_to_duty",
  2734.             [3] = "jup_b4_monolith_squad_in_duty",
  2735.             [4] = "jup_a6_duty_leader_bunker_guards_work",
  2736.             [5] = "jup_a6_duty_leader_employ_work",
  2737.             [6] = "jup_b207_duty_wins"
  2738.         }
  2739.         main_theme = "jup_b221_duty_main_"
  2740.         reply_theme = "jup_b221_duty_reply_"
  2741.         info_need_reply = "jup_b221_duty_reply"
  2742.     elseif tostring(p[1]) == "freedom" then
  2743.         info_table = {
  2744.             [1] = "jup_b207_freedom_know_about_depot",
  2745.             [2] = "jup_b46_duty_founder_pda_to_freedom",
  2746.             [3] = "jup_b4_monolith_squad_in_freedom",
  2747.             [4] = "jup_a6_freedom_leader_bunker_guards_work",
  2748.             [5] = "jup_a6_freedom_leader_employ_work",
  2749.             [6] = "jup_b207_freedom_wins"
  2750.         }
  2751.         main_theme = "jup_b221_freedom_main_"
  2752.         reply_theme = "jup_b221_freedom_reply_"
  2753.         info_need_reply = "jup_b221_freedom_reply"
  2754.     else
  2755.         abort("Wrong parameters in function 'jup_b221_play_main'")
  2756.     end
  2757. --Ñîñòàâëÿåì òàáëèöó äîñòûïíûõ òåì(òëüêî íîìåðà òåì).
  2758.     for k,v in pairs(info_table) do
  2759.         if (has_alife_info(v)) and (not has_alife_info(main_theme .. tostring(k) .. "_played")) then
  2760.             table.insert(reachable_theme,k)
  2761. --          printf("jup_b221_play_main: table reachable_theme ------------------------------> [%s]", tostring(k))
  2762.         end
  2763.     end
  2764. --Åñëè òàáëèöà äîñòóïíûõ òåì ïóñòà èãðàåì îòâåò. Åñëè æå îíà íå ïóñòà èãðàåì îñíîâíóþ òåìó. Åñëè èãðàåì îñíîâíóþ òåìó çàíîñèì çíà÷åíèå ñ÷åò÷èêà äëÿ ïîâòîðíîãî âûïîëíåíèÿ ôóíêöèè. Òåìó âûáèðàåì ïî ðàíäîìó.
  2765.     if #reachable_theme ~= 0 then
  2766.         disable_info(info_need_reply)
  2767.         theme_to_play = reachable_theme[math.random(1, #reachable_theme)]
  2768. --      printf("jup_b221_play_main: variable theme_to_play ------------------------------> [%s]", tostring(theme_to_play))
  2769.         xr_logic.pstor_store(actor,"jup_b221_played_main_theme",tostring(theme_to_play))
  2770.         db.actor:give_info_portion(main_theme .. tostring(theme_to_play) .."_played")
  2771.         if theme_to_play ~= 0 then
  2772.             play_sound(actor, npc, {main_theme .. tostring(theme_to_play)})
  2773.         else
  2774.             abort("No such theme_to_play in function 'jup_b221_play_main'")
  2775.         end
  2776.     else
  2777.         db.actor:give_info_portion(info_need_reply)
  2778.         theme_to_play = tonumber(xr_logic.pstor_retrieve(actor,"jup_b221_played_main_theme",0))
  2779.         if theme_to_play ~= 0 then
  2780.             play_sound(actor, npc, {reply_theme..tostring(theme_to_play)})
  2781.         else
  2782.             abort("No such theme_to_play in function 'jup_b221_play_main'")
  2783.         end
  2784.         xr_logic.pstor_store(actor,"jup_b221_played_main_theme","0")
  2785.     end
  2786. end
  2787.  
  2788. function pas_b400_play_particle(actor, npc, p)
  2789.     db.actor:start_particles("zones\\zone_acidic_idle","bip01_head")
  2790. end
  2791.  
  2792. function pas_b400_stop_particle(actor, npc, p)
  2793.     db.actor:stop_particles("zones\\zone_acidic_idle","bip01_head")
  2794. end
  2795.  
  2796. function damage_actor_items_on_start(actor, npc)
  2797.     local actor = db.actor
  2798.  
  2799.     local obj = actor:object("helm_respirator")
  2800.     if obj ~= nil then
  2801.         obj:set_condition(0.8)
  2802.     end
  2803.  
  2804.     obj = actor:object("stalker_outfit")
  2805.     if obj ~= nil then
  2806.         obj:set_condition(0.76)
  2807.     end
  2808.  
  2809.     obj = actor:object("wpn_pm_actor")
  2810.     if obj ~= nil then
  2811.         obj:set_condition(0.9)
  2812.     end
  2813.  
  2814.     obj = actor:object("wpn_ak74u")
  2815.     if obj ~= nil then
  2816.         obj:set_condition(0.7)
  2817.     end
  2818.  
  2819. end
  2820.  
  2821. function damage_pri_a17_gauss()
  2822.     local obj = get_story_object("pri_a17_gauss_rifle")
  2823.     --local obj = npc:object("pri_a17_gauss_rifle")
  2824.     if obj ~= nil then
  2825.         obj:set_condition(0.0)
  2826.     end
  2827. end
  2828.  
  2829. function pri_a17_hard_animation_reset(actor, npc, p)
  2830.     --db.storage[npc:id()].state_mgr:set_state("pri_a17_fall_down", nil, nil, nil, {fast_set = true})
  2831.     db.storage[npc:id()].state_mgr:set_state("pri_a17_fall_down")
  2832.  
  2833.     local state_mgr = db.storage[npc:id()].state_mgr
  2834.     if state_mgr ~= nil then
  2835.         state_mgr.animation:set_state(nil, true)
  2836.         state_mgr.animation:set_state("pri_a17_fall_down")
  2837.         state_mgr.animation:set_control()
  2838.     end
  2839. end
  2840.  
  2841. function jup_b217_hard_animation_reset(actor, npc, p)
  2842.     db.storage[npc:id()].state_mgr:set_state("jup_b217_nitro_straight")
  2843.  
  2844.     local state_mgr = db.storage[npc:id()].state_mgr
  2845.     if state_mgr ~= nil then
  2846.         state_mgr.animation:set_state(nil, true)
  2847.         state_mgr.animation:set_state("jup_b217_nitro_straight")
  2848.         state_mgr.animation:set_control()
  2849.     end
  2850. end
  2851.  
  2852.  
  2853.  
  2854.  
  2855. function sleep(actor, npc)
  2856.     local sleep_zones = {
  2857.                         "zat_a2_sr_sleep",
  2858.                         "jup_a6_sr_sleep",
  2859.                         "pri_a16_sr_sleep",
  2860.                         "actor_surge_hide_2"
  2861.                         }
  2862.  
  2863.     for k,v in pairs(sleep_zones) do
  2864.         if utils.npc_in_zone(db.actor, db.zone_by_name[v]) then
  2865.             ui_sleep_dialog.sleep()
  2866.             give_info("sleep_active")
  2867.         end
  2868.     end
  2869.  
  2870. end
  2871.  
  2872.  
  2873.  
  2874. --[[
  2875. function set_tip_to_story(actor, npc, p)
  2876.     if p == nil or p[2] == nil then
  2877.         abort("Not enough parameters in 'set_tip_to_story' function!")
  2878.     end
  2879.  
  2880.     local obj = get_story_object(p[1])
  2881.  
  2882.     if not obj then
  2883.         return
  2884.     end
  2885.  
  2886.     local tip = p[2]
  2887.  
  2888.     obj:set_tip_text(tip)
  2889. end
  2890.  
  2891. function clear_tip_from_story(actor, npc, p)
  2892.     if p == nil or p[1] == nil then
  2893.         abort("Not enough parameters in 'clear_tip_from_story' function!")
  2894.     end
  2895.  
  2896.     local obj = get_story_object(p[1])
  2897.  
  2898.     if not obj then
  2899.         return
  2900.     end
  2901.  
  2902.     obj:set_tip_text("")
  2903. end
  2904. ]]--
  2905.  
  2906. function mech_discount(actor, npc, p)
  2907.     if(p[1]) then
  2908.                 inventory_upgrades.mech_discount(tonumber(p[1]))
  2909.     end
  2910. end
  2911.  
  2912. function polter_actor_ignore(actor, npc, p)
  2913.     if p[1] and p[1] == "true" then
  2914.                 npc:poltergeist_set_actor_ignore(true)
  2915.     elseif p[1] and p[1] == "false" then
  2916.                 npc:poltergeist_set_actor_ignore(false)
  2917.     end
  2918. end
  2919.  
  2920. function burer_force_gravi_attack(actor, npc)
  2921.     npc:burer_set_force_gravi_attack(true)
  2922. end
  2923.  
  2924. function burer_force_anti_aim(actor, npc)
  2925.     npc:set_force_anti_aim(true)
  2926. end
  2927.  
  2928. function show_freeplay_dialog(actor, npc, p)
  2929.     if p[1] and p[2] and p[2] == "true" then
  2930.         ui_freeplay_dialog.show("message_box_yes_no", p[1])
  2931.     elseif p[1] then
  2932.         ui_freeplay_dialog.show("message_box_ok", p[1])
  2933.     end
  2934. end
  2935.  
  2936.  
  2937.  
  2938. local detectors = { "detector_simple", "detector_advanced", "detector_elite", "detector_scientific" }
  2939.  
  2940. -- Òîëüêî äëÿ state_mgr
  2941. function get_best_detector(npc)
  2942.     for k,v in pairs(detectors) do
  2943.         local obj = npc:object(v)
  2944.         if obj ~= nil then
  2945.             obj:enable_attachable_item(true)
  2946.             return
  2947.         end
  2948.     end
  2949. end
  2950.  
  2951. function hide_best_detector(npc)
  2952.     for k,v in pairs(detectors) do
  2953.         local obj = npc:object(v)
  2954.         if obj ~= nil then
  2955.             obj:enable_attachable_item(false)
  2956.             return
  2957.         end
  2958.     end
  2959. end
  2960.  
  2961. -- Èíôîïîðøíû äëÿ ñèíõðîíèçàöèè àíèìàöèè íïñ ñ ïðî÷èìè äåéñòâèÿìè, è äëÿ äðóãèõ öåëåé
  2962. function pri_a18_radio_start(actor, npc)
  2963.     db.actor:give_info_portion("pri_a18_radio_start")
  2964. end
  2965.  
  2966. function pri_a17_ice_climb_end(actor, npc)
  2967.     db.actor:give_info_portion("pri_a17_ice_climb_end")
  2968. end
  2969.  
  2970. function jup_b219_opening(actor, npc)
  2971.     db.actor:give_info_portion("jup_b219_opening")
  2972. end
  2973.  
  2974. function jup_b219_entering_underpass(actor, npc)
  2975.     db.actor:give_info_portion("jup_b219_entering_underpass")
  2976. end
  2977.  
  2978. function pri_a17_pray_start(actor, npc)
  2979.     db.actor:give_info_portion("pri_a17_pray_start")
  2980. end
  2981.  
  2982. function zat_b38_open_info(actor, npc)
  2983.     db.actor:give_info_portion("zat_b38_open_info")
  2984. end
  2985.  
  2986. function zat_b38_switch_info(actor, npc)
  2987.     db.actor:give_info_portion("zat_b38_switch_info")
  2988. end
  2989. function zat_b38_cop_dead(actor, npc)
  2990.     db.actor:give_info_portion("zat_b38_cop_dead")
  2991. end
  2992.  
  2993. function jup_b15_zulus_drink_anim_info(actor, npc)
  2994.     db.actor:give_info_portion("jup_b15_zulus_drink_anim_info")
  2995. end
  2996.  
  2997. function pri_a17_preacher_death(actor, npc)
  2998.     db.actor:give_info_portion("pri_a17_preacher_death")
  2999. end
  3000.  
  3001. function zat_b3_tech_surprise_anim_end(actor, npc)
  3002.     db.actor:give_info_portion("zat_b3_tech_surprise_anim_end")
  3003. end
  3004.  
  3005. function zat_b3_tech_waked_up(actor, npc)
  3006.     db.actor:give_info_portion("zat_b3_tech_waked_up")
  3007. end
  3008.  
  3009. function zat_b3_tech_drinked_out(actor, npc)
  3010.     db.actor:give_info_portion("zat_b3_tech_drinked_out")
  3011. end
  3012.  
  3013. function pri_a28_kirillov_hq_online(actor, npc)
  3014.     db.actor:give_info_portion("pri_a28_kirillov_hq_online")
  3015. end
  3016.  
  3017. function pri_a20_radio_start(actor, npc)
  3018.     db.actor:give_info_portion("pri_a20_radio_start")
  3019. end
  3020.  
  3021. function pri_a22_kovalski_speak(actor, npc)
  3022.     db.actor:give_info_portion("pri_a22_kovalski_speak")
  3023. end
  3024.  
  3025. function zat_b38_underground_door_open(actor, npc)
  3026.     db.actor:give_info_portion("zat_b38_underground_door_open")
  3027. end
  3028.  
  3029. function zat_b38_jump_tonnel_info(actor, npc)
  3030.     db.actor:give_info_portion("zat_b38_jump_tonnel_info")
  3031. end
  3032.  
  3033. function jup_a9_cam1_actor_anim_end(actor, npc)
  3034.     db.actor:give_info_portion("jup_a9_cam1_actor_anim_end")
  3035. end
  3036.  
  3037. function pri_a28_talk_ssu_video_end(actor, npc)
  3038.     db.actor:give_info_portion("pri_a28_talk_ssu_video_end")
  3039. end
  3040.  
  3041. function set_torch_state(actor, npc, p)
  3042.     if p == nil or p[2] == nil then
  3043.         abort("Not enough parameters in 'set_torch_state' function!")
  3044.     end
  3045.  
  3046.     local obj = get_story_object(p[1])
  3047.  
  3048.     if not obj then
  3049.         return
  3050.     end
  3051.     local torch = obj:object("device_torch")
  3052.     if torch then
  3053.         if p[2] == "on" then
  3054.             torch:enable_attachable_item(true)
  3055.         elseif p[2] == "off" then
  3056.             torch:enable_attachable_item(false)
  3057.         end
  3058.     end
  3059. end
  3060.  
  3061.  
  3062. local actor_nightvision = false
  3063. local actor_torch       = false
  3064.  
  3065. function disable_actor_nightvision(actor, npc)
  3066.     local nightvision = db.actor:object("device_torch")
  3067.     if nightvision ~= nil and nightvision:night_vision_enabled() then
  3068.         nightvision:enable_night_vision(false)
  3069.         actor_nightvision = true
  3070.     end
  3071. end
  3072.  
  3073. function enable_actor_nightvision(actor, npc)
  3074.     local nightvision = db.actor:object("device_torch")
  3075.     if nightvision ~= nil and not nightvision:night_vision_enabled() and actor_nightvision then
  3076.         nightvision:enable_night_vision(true)
  3077.         actor_nightvision = false
  3078.     end
  3079. end
  3080.  
  3081. function disable_actor_torch(actor, npc)
  3082.     local torch = db.actor:object("device_torch")
  3083.     if torch ~= nil and torch:torch_enabled() then
  3084.         torch:enable_torch(false)
  3085.         actor_torch = true
  3086.     end
  3087. end
  3088.  
  3089. function enable_actor_torch(actor, npc)
  3090.     local torch = db.actor:object("device_torch")
  3091.     if torch ~= nil and not torch:torch_enabled() and actor_torch then
  3092.         torch:enable_torch(true)
  3093.         actor_torch = false
  3094.     end
  3095. end
  3096.  
  3097.  
  3098. function create_cutscene_actor_with_weapon(actor, npc, p)
  3099.     --' p[1] - ñåêöèÿ êîãî ñïàóíèòü
  3100.     --' p[2] - èìÿ ïàòðóëüíîãî ïóòè ãäå ñïàóíèòü.
  3101.     --' p[3] - òî÷êà ïàòðóëüíîãî ïóòè
  3102.     --' p[4] - ïîâîðîò ïî îñè Y
  3103.     --' p[5] - ïðèíóäèòåëüíûé ñëîò - áóäåò ðàáîòàòü äàæå ïðè disable_ui
  3104.     local spawn_sect = p[1]
  3105.     if spawn_sect == nil then
  3106.         abort("Wrong spawn section for 'spawn_object' function %s. For object %s", tostring(spawn_sect), obj:name())
  3107.     end
  3108.  
  3109.     local path_name = p[2]
  3110.     if path_name == nil then
  3111.         abort("Wrong path_name for 'spawn_object' function %s. For object %s", tostring(path_name), obj:name())
  3112.     end
  3113.  
  3114.     if not level.patrol_path_exists(path_name) then
  3115.         abort("Path %s doesnt exist. Function 'spawn_object' for object %s ", tostring(path_name), obj:name())
  3116.     end
  3117.     local ptr = patrol(path_name)
  3118.     local index = p[3] or 0
  3119.     local yaw = p[4] or 0
  3120.  
  3121.     local npc = alife():create(spawn_sect, ptr:point(index), ptr:level_vertex_id(0), ptr:game_vertex_id(0))
  3122.     if IsStalker( nil, npc:clsid()) then
  3123.         npc:o_torso().yaw = yaw * math.pi / 180
  3124.     else
  3125.         npc.angle.y = yaw * math.pi / 180
  3126.     end
  3127.  
  3128.     local slot_override = p[5] or 0
  3129.  
  3130.     local slot
  3131.     local active_item
  3132.  
  3133.     if slot_override == 0 then
  3134.         slot = db.actor:active_slot()
  3135.         if(slot~=2 and slot~=3) then
  3136.             return
  3137.         end
  3138.         active_item = db.actor:active_item()
  3139.     else
  3140.         if db.actor:item_in_slot(slot_override) ~= nil then
  3141.             active_item = db.actor:item_in_slot(slot_override)
  3142.         else
  3143.             if db.actor:item_in_slot(3) ~= nil then
  3144.                 active_item = db.actor:item_in_slot(3)
  3145.             elseif db.actor:item_in_slot(2) ~= nil then
  3146.                 active_item = db.actor:item_in_slot(2)
  3147.             else
  3148.                 return
  3149.             end
  3150.         end
  3151.     end
  3152.  
  3153.     local actor_weapon = alife():object(active_item:id())
  3154.     local section_name = actor_weapon:section_name()
  3155.     if section_name == "pri_a17_gauss_rifle" then
  3156.         section_name = "wpn_gauss"
  3157.     end
  3158.  
  3159.     if (active_item) then
  3160.         local new_weapon = alife():create(section_name,
  3161.                                                     ptr:point(index),
  3162.                                                     ptr:level_vertex_id(0),
  3163.                                                     ptr:game_vertex_id(0),
  3164.                                                     npc.id)
  3165.         if section_name ~= "wpn_gauss" then
  3166.             new_weapon:clone_addons(actor_weapon)
  3167.         end
  3168.     end
  3169. end
  3170.  
  3171. -- Çàñòàâèòü èãðàòü óíèêàëüíûå àíèìàöèè ñíà(ó êðîâîñîñà)
  3172. function set_force_sleep_animation(actor, npc, p)
  3173.     local num = p[1]
  3174.     npc:force_stand_sleep_animation(tonumber(num))
  3175. end
  3176. -- Óáðàòü óíèêàëüíûå àíèìàöèè ñíà(ó êðîâîñîñà)
  3177. function release_force_sleep_animation(actor, npc)
  3178.     npc:release_stand_sleep_animation()
  3179. end
  3180.  
  3181. function zat_b33_pic_snag_container(actor, npc)
  3182.     if xr_conditions.actor_in_zone(actor, npc, {"zat_b33_tutor"}) then
  3183.         give_actor(actor, npc, {"zat_b33_safe_container"})
  3184.         db.actor:give_info_portion("zat_b33_find_package")
  3185.         if not has_alife_info("zat_b33_safe_container") then
  3186.             local zone = db.zone_by_name["zat_b33_tutor"]
  3187.             play_sound(actor, zone, {"pda_news"})
  3188.         end
  3189.     end
  3190. end
  3191.  
  3192. --Îòêëþ÷åíèå âîçäåéñòâèÿ âðàæåñêîãî íïñ íà èíäèêàòîð âèäèìîñòè âðàãà íà õàäå èãðîêà.
  3193. --Èñï. òîëüêî èç ëîãèêè íïñ.
  3194. function set_visual_memory_enabled(actor, npc, p)
  3195.     if (p and p[1]) and (tonumber(p[1]) >= 0) and (tonumber(p[1]) <= 1) then
  3196.         local boolval = false
  3197.         if (tonumber(p[1]) == 1) then
  3198.             boolval = true
  3199.         end
  3200.         npc:set_visual_memory_enabled(boolval)
  3201.     end
  3202. end
  3203.  
  3204. function disable_memory_object (actor, npc)
  3205.     local best_enemy = npc:best_enemy()
  3206.     if best_enemy then
  3207.         npc:enable_memory_object(best_enemy, false)
  3208.     end
  3209. end
  3210.  
  3211. function zat_b202_spawn_b33_loot(actor, npc, p)
  3212.     local info_table = {
  3213.         "zat_b33_first_item_gived",
  3214.         "zat_b33_second_item_gived",
  3215.         "zat_b33_third_item_gived",
  3216.         "zat_b33_fourth_item_gived",
  3217.         "zat_b33_fifth_item_gived"
  3218.     }
  3219.     local item_table = {}
  3220.     item_table[1] = {
  3221.         "wpn_fort_snag"
  3222.     }
  3223.     item_table[2] = {
  3224.         "medkit_scientic",
  3225.         "medkit_scientic",
  3226.         "medkit_scientic",
  3227.         "antirad",
  3228.         "antirad",
  3229.         "antirad",
  3230.         "bandage",
  3231.         "bandage",
  3232.         "bandage",
  3233.         "bandage",
  3234.         "bandage"
  3235.     }
  3236.     item_table[3] = {
  3237.         "wpn_ak74u_snag"
  3238.     }
  3239.     item_table[4] = {
  3240.         "af_soul"
  3241.     }
  3242.     item_table[5] = {
  3243.         "helm_hardhat_snag"
  3244.     }
  3245.     for k,v in pairs(info_table) do
  3246.         local obj_id
  3247.         if (k == 1) or (k == 3) then
  3248.             obj_id = "jup_b202_stalker_snag"
  3249.         else
  3250.             obj_id = "jup_b202_snag_treasure"
  3251.         end
  3252.         if not has_alife_info(tostring(v)) then
  3253.             for l,m in pairs(item_table[k]) do
  3254. --              printf("zat_b202_spawn_b33_loot: number [%s] item [%s] to [%s]", tostring(k), tostring(m), tostring(obj_id))
  3255.                 spawn_object_in(actor, npc, {tostring(m),tostring(obj_id)})
  3256.             end
  3257.         end
  3258.     end
  3259. end
  3260.  
  3261. function set_monster_animation (actor, npc, p)
  3262.     if not (p and p[1]) then
  3263.         abort("Wrong parameters in function 'set_monster_animation'!!!")
  3264.     end
  3265.     npc:set_override_animation (p[1])
  3266. end
  3267.  
  3268. function clear_monster_animation (actor, npc)
  3269.     npc:clear_override_animation ()
  3270. end
  3271.  
  3272. local actor_position_for_restore
  3273. local actor_direction_for_restore
  3274.  
  3275. function save_actor_position()
  3276.     actor_position_for_restore = get_story_object("actor"):position()
  3277.     --actor_direction_for_restore = get_story_object("actor"):direction()
  3278. end
  3279.  
  3280. function restore_actor_position()
  3281.     --db.actor:set_actor_direction(actor_direction_for_restore)
  3282.     db.actor:set_actor_position(actor_position_for_restore)
  3283. end
  3284.  
  3285. function upgrade_hint(actor, npc, p)
  3286.     if(p) then
  3287.         inventory_upgrades.cur_hint = p
  3288.     end
  3289. end
  3290.  
  3291. function force_obj(actor, npc, p)
  3292.     local obj = get_story_object(p[1])
  3293.     if not obj then
  3294.         abort("'force_obj' Target object does not exist")
  3295.         return
  3296.     end
  3297.     if p[2] == nil then p[2] = 20 end
  3298.     if p[3] == nil then p[3] = 100 end
  3299.     obj:set_const_force(vector():set(0,1,0), p[2], p[3])
  3300. end
  3301.  
  3302. function pri_a28_check_zones()
  3303.     local story_obj_id
  3304.     local dist
  3305.     local index = 0
  3306.  
  3307.     local zones_tbl = {
  3308.                         [1] = "pri_a28_sr_mono_add_1",
  3309.                         [2] = "pri_a28_sr_mono_add_2",
  3310.                         [3] = "pri_a28_sr_mono_add_3",
  3311.                         }
  3312.  
  3313.     local info_tbl = {
  3314.                         [1] = "pri_a28_wave_1_spawned",
  3315.                         [2] = "pri_a28_wave_2_spawned",
  3316.                         [3] = "pri_a28_wave_3_spawned",
  3317.                         }
  3318.  
  3319.     local squad_tbl = {
  3320.                         [1] = "pri_a28_heli_mono_add_1",
  3321.                         [2] = "pri_a28_heli_mono_add_2",
  3322.                         [3] = "pri_a28_heli_mono_add_3",
  3323.                         }
  3324.  
  3325.     for k,v in pairs(zones_tbl) do
  3326.         story_obj_id = get_story_object_id(v)
  3327.         if story_obj_id then
  3328.             local se_obj = alife():object(story_obj_id)
  3329.             local curr_dist = se_obj.position:distance_to(db.actor:position())
  3330.             if index == 0 then
  3331.                 dist = curr_dist
  3332.                 index = k
  3333.             elseif dist < curr_dist then
  3334.                 dist = curr_dist
  3335.                 index = k
  3336.             end
  3337.         end
  3338.     end
  3339.  
  3340.     if index == 0 then
  3341.         abort("Found no distance or zones in func 'pri_a28_check_zones'")
  3342.     end
  3343.  
  3344.     if has_alife_info(info_tbl[index]) then
  3345.         for k,v in pairs(info_tbl) do
  3346.             if not has_alife_info(info_tbl[k]) then
  3347.                 db.actor:give_info_portion(info_tbl[k])
  3348.             end
  3349.         end
  3350.     else
  3351.         db.actor:give_info_portion(info_tbl[index])
  3352.     end
  3353.  
  3354.     create_squad(db.actor,nil,{squad_tbl[index],"pri_a28_heli"})
  3355. end
  3356.  
  3357. function eat_vodka_script()
  3358.     if db.actor:object("vodka_script") ~= nil then
  3359.         db.actor:eat(db.actor:object("vodka_script"))
  3360.     end
  3361. end
  3362.  
  3363. local mat_table = {
  3364.                     "jup_b200_material_1",
  3365.                     "jup_b200_material_2",
  3366.                     "jup_b200_material_3",
  3367.                     "jup_b200_material_4",
  3368.                     "jup_b200_material_5",
  3369.                     "jup_b200_material_6",
  3370.                     "jup_b200_material_7",
  3371.                     "jup_b200_material_8",
  3372.                     "jup_b200_material_9",
  3373.                     }
  3374.  
  3375. function jup_b200_count_found(actor)
  3376.     local cnt = 0
  3377.  
  3378.     for k,v in pairs(mat_table) do
  3379.         local material_obj = get_story_object(v)
  3380.         if material_obj then
  3381.             local parent = material_obj:parent()
  3382.             if parent then
  3383.                 local parent_id = parent:id()
  3384.                 if parent_id ~= 65535 and parent_id == actor:id() then
  3385.                     cnt = cnt + 1
  3386.                 end
  3387.             end
  3388.         end
  3389.     end
  3390.  
  3391.     cnt = cnt + xr_logic.pstor_retrieve(actor, "jup_b200_tech_materials_brought_counter", 0)
  3392.     xr_logic.pstor_store(actor, "jup_b200_tech_materials_found_counter", cnt)
  3393. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement