Guest User

_g.script

a guest
Feb 2nd, 2013
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- 071217 - fix negative relation changes in quests
  2. -- 080131 - abort() no longer crashes with "nil arg to format"
  3.  
  4. -- set this true if you want to shut down if abort() called
  5. quit_on_abort = false
  6.  
  7. if (jit == nil) then
  8. profiler.setup_hook ()
  9. end
  10.  
  11. schemes = {} -- ñîîòâåòñòâèå ñõåì ìîäóëÿì
  12. stypes = {} -- òèïû ñõåì
  13.  
  14. -- Çàãðóæàåò ñõåìó èç ôàéëà íà äèñêå è àêòèâèðóåò â ìîòèâàòîðå.
  15. -- Çäåñü:
  16. -- filename - èìÿ ôàéëà, â êîòîðîì ðåàëèçîâàíà ñõåìà, áåç ðàñøèðåíèÿ
  17. -- scheme - èìÿ ñõåìû
  18. function load_scheme(filename, scheme, stype)
  19. schemes[scheme] = filename
  20. stypes[scheme] = stype
  21. end
  22.  
  23. ----------------------------------------------------------------------
  24.  
  25. function printf(fmt,...)
  26. -- local arg={...}
  27. -- if arg==nil or arg[0]==nil then
  28. -- mylog(fmt)
  29. -- else
  30. -- mylog(string.format(fmt,...))
  31. -- end
  32. end
  33.  
  34. local bufferedmessages={}
  35.  
  36. function mylog(msg)
  37. -- if db and db.actor then
  38. -- if bufferedmessages then
  39. -- for k,v in ipairs(bufferedmessages) do
  40. -- db.actor:give_game_news(v, "ui\\ui_iconsTotal", Frect():set(0,0,100,100), 0, 15000)
  41. -- end
  42. -- bufferedmessages=nil
  43. -- end
  44. -- db.actor:give_game_news(msg, "ui\\ui_iconsTotal", Frect():set(0,0,100,100), 0, 15000)
  45. -- else
  46. -- table.insert(bufferedmessages,msg)
  47. -- end
  48. end
  49.  
  50. function dbglog(fmt,...)
  51. local msg = string.format(fmt, ...)
  52. local msg_no_ws = string.gsub(msg, "%s", "_")
  53. get_console():execute("dbg:_" .. msg_no_ws)
  54. end
  55.  
  56. ----------------------------------------------------------------------
  57. if nil == time_global then
  58. time_global = function () return device():time_global() end
  59. end
  60.  
  61. function wait_game(time_to_wait)
  62. verify_if_thread_is_running()
  63. if (time_to_wait == nil) then
  64. coroutine.yield()
  65. else
  66. local time_to_stop = game.time() + time_to_wait
  67. while game.time() <= time_to_stop do
  68. coroutine.yield()
  69. end
  70. end
  71. end
  72.  
  73. function wait(time_to_wait)
  74. verify_if_thread_is_running()
  75. if (time_to_wait == nil) then
  76. coroutine.yield()
  77. else
  78. local time_to_stop = time_global() + time_to_wait
  79. while time_global() <= time_to_stop do
  80. coroutine.yield()
  81. end
  82. end
  83. end
  84.  
  85. function action(obj,...)
  86. local arg = {...}
  87. local act = entity_action()
  88. local i = 1
  89. while true do
  90. if (arg[i] ~= nil) then
  91. act:set_action(arg[i])
  92. else
  93. break
  94. end
  95. i = i + 1
  96. end
  97. if (obj ~= nil) then
  98. obj:command(act,false)
  99. end
  100. return entity_action(act)
  101. end
  102.  
  103. function action_first(obj,...)
  104. local arg = {...}
  105. local act = entity_action()
  106. local i = 1
  107. while true do
  108. if (arg[i] ~= nil) then
  109. act:set_action(arg[i])
  110. else
  111. break
  112. end
  113. i = i + 1
  114. end
  115. if (obj ~= nil) then
  116. obj:command(act,true)
  117. end
  118. return entity_action(act)
  119. end
  120.  
  121. function round (value)
  122. local min = math.floor (value)
  123. local max = min + 1
  124. if value - min > max - value then return max end
  125. return min
  126. end
  127.  
  128. function debug_get_level_object(obj_name)
  129. local res = level.debug_object(obj_name)
  130. while res == nil do
  131.  
  132. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  133. // !!!!! ÍÅ ÇÀÊÎÌÌÅÍÒÀÐÈÂÀÉÒÅ, ÈÍÀ×Å ÍÅ ÁÓÄÅÒ ÂÈÄÍÎ ÎØÈÁÎÊ ÏÐÈ ÐÀÑÑÒÀÍÎÂÊÅ ÎÁÚÅÊÒΠ!!!!!
  134. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  135. printf("get_level_object() is waiting for object \"%s\"", obj_name)
  136.  
  137. res = level.object(obj_name)
  138. wait ()
  139. end
  140. return res
  141. end
  142.  
  143. function debug_get_actor()
  144. local res = level.debug_actor()
  145. while res == nil do
  146. res = level.debug_actor()
  147. wait ()
  148. end
  149. return res
  150. end
  151.  
  152. function distance_between(obj1, obj2)
  153. return obj1:position():distance_to(obj2:position())
  154. end
  155.  
  156. // Åñëè îäèí îáúåêò nil, íàïðèìåð íåò àêòåðà, òî ñ÷èòàåì, ÷òî îí äàëåêî
  157. function distance_between_safe(obj1, obj2)
  158. if(obj1 == nil or obj2 == nil) then return 100000 end
  159. return obj1:position():distance_to(obj2:position())
  160. end
  161.  
  162.  
  163. --' Ïðîâåðêà íà èíôîïîðøíû, äàæå åñëè èãðîêà íå ñóùåñòâóåò
  164. function has_alife_info(info_id)
  165. local aa = alife()
  166. if aa == nil then
  167. return false
  168. end
  169. return aa:has_info(0, info_id)
  170. end
  171.  
  172.  
  173. --------------------------------------------------
  174. -- ³ëàññ LUA ðåàëèçó³ èé Finite State Machine
  175. -- äëÿ óïðàâëåíèÿ ïåðñîíàæàìè
  176. --------------------------------------------------
  177. class 'FSM'
  178.  
  179. -- èíèöèàëèçàöèÿ ïóòåì çàäàíèÿ îáúåêòà Non-Player Character
  180. function FSM:__init(script_name, npc_obj)
  181. -- óêàçàòåëü íà ïîäêîíòðîëüívé NPC
  182. self.npc = npc_obj
  183. -- ñòðîêà - èìÿ ñêðèïòà, êîòîðvé çàïóñêàåò èãðó
  184. self.script_name = script_name
  185. -- ìàòðèöà, çàäà³ àÿ ãðàô ïåðåõîäîâ ñîñòîÿíèé
  186. -- ðåàëèçóåòñÿ êàê äâóìåðíàÿ òàáëèöà
  187. self.transition_matrix = {[0] = {}}
  188. -- íîìåð òåêó åãî ñîñòîÿíèÿ
  189. self.current_state = 0
  190.  
  191. -- ôëàã òîãî, ÷òî ìàøèíà âêë³÷åíà
  192. self.machine_running = true
  193.  
  194. printf("inialization FSM for NPC %s", self.npc:name())
  195. end
  196.  
  197. function FSM:is_running()
  198. return self.machine_running
  199. end
  200.  
  201. function FSM:start()
  202. printf("starting FSM for %s", self.npc:name())
  203. self.machine_running = true
  204. end
  205.  
  206. function FSM:stop()
  207. printf("stoping FSM for %s", self.npc:name())
  208. self.machine_running = false
  209. self:reset_script_control()
  210. end
  211.  
  212.  
  213. -- äîáàâëåíèå óêàçàòåëÿ íà áóëåâó
  214. -- ôóíêöè³ óñëîâèÿ ïåðåõîäà
  215. function FSM:set_transition(from_state_num, to_state_num, cond_func)
  216. printf("in setting transition %d, %d ", from_state_num, to_state_num)
  217.  
  218. if self.transition_matrix[from_state_num] == nil then
  219. self.transition_matrix[from_state_num] = {[to_state_num] = cond_func}
  220. else
  221. self.transition_matrix[from_state_num][to_state_num] = cond_func
  222. end
  223. end
  224.  
  225. -- åäèíè÷íàÿ ïðîâåðêà FSM
  226. function FSM:run()
  227. local transition_vector = self.transition_matrix[self.current_state]
  228. table.foreach(transition_vector,
  229. function(to_state_num, cond_func)
  230. if cond_func(self.npc, self) == true then
  231. printf("transition from %d to %d", self.current_state, to_state_num)
  232.  
  233. if to_state_num == 0 then
  234. self:reset_script_control()
  235. end
  236.  
  237. --if self.current_state == 0 then
  238. -- self:set_script_control()
  239. --end
  240.  
  241. self.current_state = to_state_num
  242. return true
  243. end
  244. return nil
  245. end)
  246. end
  247.  
  248.  
  249. -- çàïóñê áåñêîíå÷íîãî öèêëà FSM
  250. function FSM:run_loop()
  251. printf("running FSM loop for NPC %s", self.npc:name())
  252.  
  253. while self:is_running() do
  254. local transition_vector = self.transition_matrix[self.current_state]
  255. table.foreach(transition_vector,
  256. function(to_state_num, cond_func)
  257. if cond_func(self.npc, self) == true then
  258. printf("transition from %d to %d", self.current_state, to_state_num)
  259.  
  260. if to_state_num == 0 then
  261. self:reset_script_control()
  262. end
  263.  
  264. --if self.current_state == 0 then
  265. -- self:set_script_control()
  266. --end
  267.  
  268. self.current_state = to_state_num
  269. return true
  270. end
  271. return nil
  272. end)
  273. if self.npc:alive () == false then
  274. self.npc:script (false, self.script_name)
  275. return
  276. end
  277. wait()
  278. end
  279. end
  280.  
  281. -- âçÿòèå ïîä êîíòðîëü ñêðèïòà NPC (ïåðåõîä èç íóëåâîãî ñîñòîÿíèÿ)
  282. function FSM:set_script_control()
  283. printf("set script control for FSM of NPC %s", self.npc:name())
  284. self.npc:script(true, self.script_name)
  285. end
  286.  
  287. -- îòïóñêàíèå èç ïîä êîíòðîëÿ ñêðèïòà NPC (ïåðåõîä â íóëåâîå ñîñòîÿíèå)
  288. function FSM:reset_script_control()
  289. printf("reset script control for FSM of NPC %s", self.npc:name())
  290. self.npc:script(false, self.script_name)
  291. end
  292.  
  293. --------------------------------------------------
  294. -- end of class 'FSM'
  295. --------------------------------------------------
  296.  
  297. function reset_action (npc, script_name)
  298. if npc:get_script () then
  299. npc:script (false, script_name)
  300. end
  301. npc:script (true, script_name)
  302. end
  303.  
  304. class "script_object"
  305.  
  306. function script_object.__init(self,name,script,...)
  307. self.action = action(nil,...)
  308. self.object_name = name
  309. self.script_name = script
  310. self.object = nil
  311. end
  312.  
  313. function script_object:update()
  314. local obj = self.object
  315. self.object = level.object(self.object_name)
  316. if ((obj == nil) and (self.object ~= nil)) then
  317. self.object:script (true,self.script_name)
  318. self.object:command (self.action,false)
  319. end
  320. end
  321.  
  322. --
  323. -- ³åðåäà÷à ïåðñîíàæó èíôîðìàöèè
  324. --
  325.  
  326. function GiveInfoViaPda(obj_receiver, obj_sender, info_number)
  327. obj_receiver:give_info_portion_via_pda(info_number, obj_sender)
  328. end
  329.  
  330.  
  331. --------------------------------------------------
  332. -- Functions and variables added by Zmey
  333. --------------------------------------------------
  334.  
  335. -- ³îíñòàíòà, êîòîðó³ èñïîëüçîâàòü â ìåñòàõ, ãäå íóæíî çàäàòü íåîãðàíè÷åííîå âðåìÿ äåéñòâèÿ
  336. time_infinite = 100000000
  337.  
  338. -- =àçâàíèå ñêðèïòà, êîòîðvé â äàíívé ìîìåíò íàõîäèòñÿ â îòëàäêå
  339. -- (â ýòîì ñêðèïòå áóäóò ñðàáàòvâàòü âvçîâv ôóíêöèè debug_log)
  340. debug_script_name = ""
  341.  
  342. -- Tvâîäèò â ëîã ñòðî÷êó, åñëè script_name == debug_script_name
  343. -- Lñïîëüçóåòñÿ äëÿ îòðàäêè ñöåíàðèåâ
  344. function debug_log(script_name, fmt, ...)
  345. if debug_script_name == script_name then
  346. log(string.format(fmt, ...))
  347. end
  348. end
  349.  
  350. -- +ñëè â äàíívé ìîìåíò âvïîëíÿåòñÿ êàêîå-òî äåéñòâèå, ïðåðvâàåò åãî è îòêë³÷àåò ñêðèïòîâvé ðåæèì
  351. function interrupt_action(who, script_name)
  352. if who:get_script() then
  353. who:script(false, script_name)
  354. end
  355. end
  356.  
  357. function random_choice(...)
  358. local arg = {...}
  359. local r = math.random(1, table.getn(arg))
  360. return arg[r]
  361. end
  362.  
  363. function new_action(...)
  364. local arg = {...}
  365. local act = entity_action()
  366. for i = 1, table.getn(arg) do
  367. act:set_action(arg[i])
  368. end
  369. return act;
  370. end
  371.  
  372. obj_last_actions = {};
  373.  
  374. function perform_action(obj, action_name, action)
  375. if (obj ~= nil) then
  376. obj_last_actions[obj] = action_name
  377. obj:command(act, false)
  378. end
  379. end
  380.  
  381. function last_action(obj)
  382. return obj_last_actions[obj]
  383. end
  384.  
  385. function if_then_else(cond, if_true, if_false)
  386. if cond then
  387. return if_true
  388. end
  389. return if_false
  390. end
  391.  
  392. function update_action (npc, script, ...)
  393. local arg = {...}
  394. if npc == nil then return end
  395. local act = npc:action ()
  396. if arg.n == 0 then return end
  397.  
  398. if act == nil then act = entity_action () end
  399.  
  400. for a = 1, arg.n, 1 do
  401. if arg[a] ~= nil then act:set_action (arg[a]) end
  402. end
  403. reset_action (npc, script)
  404. npc:command (act, false)
  405.  
  406. end
  407.  
  408.  
  409. function set_current_time (hour, min, sec)
  410. local current_time_factor = level.get_time_factor ()
  411.  
  412. printf ("Need time : %d:%d:%d", hour, min, sec)
  413.  
  414. local current_time = game.time ()
  415. local c_day = math.floor (current_time / 86400000)
  416. local c_time = current_time - c_day * 86400000
  417. local n_time = (sec + min * 60 + hour * 3600) * 1000
  418.  
  419. if c_time > n_time then c_day = c_day + 1 end
  420. n_time = n_time + c_day * 86400000
  421.  
  422. level.set_time_factor (10000)
  423. while game.time () < n_time do wait () end
  424.  
  425. level.set_time_factor (current_time_factor)
  426. end
  427.  
  428.  
  429.  
  430. if (editor() == false) then
  431. class "pp_effector" (effector)
  432.  
  433. function pp_effector:__init(effector_type,start_time,dest_power,life_time) super(effector_type,start_time)
  434. self.start_time = start_time
  435. self.stop_time = start_time + life_time
  436. self.max_power = dest_power
  437. end
  438.  
  439. function pp_effector:process(pp)
  440. effector.process(self,pp)
  441.  
  442. local curr_time = time_global()
  443. local d = 0.0
  444.  
  445. if curr_time < self.start_time then
  446. d = 0.0
  447. else
  448. if curr_time < self.stop_time then
  449. d = (curr_time - self.start_time) / (self.stop_time - self.start_time)
  450. else
  451. self.info = self.max_power
  452. return true
  453. end
  454. end
  455.  
  456. local dual = duality()
  457. local noise = noise()
  458. local base = color()
  459. local gray = color()
  460. local add = color()
  461.  
  462. dual.h = self.max_power.dual.h * d
  463. dual.v = self.max_power.dual.v * d
  464.  
  465. noise.grain = self.max_power.noise.grain * d
  466. noise.intensity = self.max_power.noise.intensity * d
  467. noise.fps = self.max_power.noise.fps * d
  468.  
  469. base.r = self.max_power.color_base.r * d
  470. base.g = self.max_power.color_base.g * d
  471. base.b = self.max_power.color_base.b * d
  472.  
  473. gray.r = self.max_power.color_gray.r * d
  474. gray.g = self.max_power.color_gray.g * d
  475. gray.b = self.max_power.color_gray.b * d
  476.  
  477. add.r = self.max_power.color_add.r * d
  478. add.g = self.max_power.color_add.g * d
  479. add.b = self.max_power.color_add.b * d
  480.  
  481. pp.gray = self.max_power.gray * d
  482. pp.blur = self.max_power.blur * d
  483.  
  484. pp.dual = dual
  485. pp.noise = noise
  486. pp.color_base = base
  487. pp.color_gray = gray
  488. pp.color_add = add
  489.  
  490. self.info = pp
  491.  
  492. return true
  493. end
  494.  
  495. function pp_effector:finished()
  496. return self.stop_time < time_global()
  497. end
  498.  
  499. --
  500. -- postprocess for rainbow
  501. --
  502. class "pp_linear_lerp" (effector)
  503.  
  504. function pp_linear_lerp:__init(effector_type,start_time,life_time,start_power,dest_power) super(effector_type,start_time)
  505. self.start_time = start_time
  506. self.stop_time = start_time + life_time
  507. self.min_power = start_power
  508. self.max_power = dest_power
  509. end
  510.  
  511. function pp_linear_lerp:process(pp)
  512. effector.process(self,pp)
  513.  
  514. local curr_time = time_global()
  515. local d = 0.0
  516.  
  517. if curr_time < self.start_time then
  518. d = 0.0
  519. else
  520. if curr_time < self.stop_time then
  521. d = (curr_time - self.start_time) / (self.stop_time - self.start_time)
  522. else
  523. self.info = self.max_power
  524. return true
  525. end
  526. end
  527.  
  528. local dual = duality()
  529. local noise = noise()
  530. local base = color()
  531. local gray = color()
  532. local add = color()
  533.  
  534. dual.h = self.min_power.dual.h + (self.max_power.dual.h - self.min_power.dual.h ) * d
  535. dual.v = self.min_power.dual.v + (self.max_power.dual.v - self.min_power.dual.v ) * d
  536.  
  537. noise.grain = self.min_power.noise.grain + (self.max_power.noise.grain - self.min_power.noise.grain ) * d
  538. noise.intensity = self.min_power.noise.intensity + (self.max_power.noise.intensity - self.min_power.noise.intensity) * d
  539. noise.fps = self.min_power.noise.fps + (self.max_power.noise.fps - self.min_power.noise.fps ) * d
  540.  
  541. base.r = self.min_power.color_base.r + (self.max_power.color_base.r - self.min_power.color_base.r ) * d
  542. base.g = self.min_power.color_base.g + (self.max_power.color_base.g - self.min_power.color_base.g ) * d
  543. base.b = self.min_power.color_base.b + (self.max_power.color_base.b - self.min_power.color_base.b ) * d
  544.  
  545. gray.r = self.min_power.color_gray.r + (self.max_power.color_gray.r - self.min_power.color_gray.r ) * d
  546. gray.g = self.min_power.color_gray.g + (self.max_power.color_gray.g - self.min_power.color_gray.g ) * d
  547. gray.b = self.min_power.color_gray.b + (self.max_power.color_gray.b - self.min_power.color_gray.b ) * d
  548.  
  549. add.r = self.min_power.color_add.r + (self.max_power.color_add.r - self.min_power.color_add.r ) * d
  550. add.g = self.min_power.color_add.g + (self.max_power.color_add.g - self.min_power.color_add.g ) * d
  551. add.b = self.min_power.color_add.b + (self.max_power.color_add.b - self.min_power.color_add.b ) * d
  552.  
  553. pp.gray = self.min_power.gray + (self.max_power.gray - self.min_power.gray ) * d
  554. pp.blur = self.min_power.blur + (self.max_power.blur - self.min_power.blur ) * d
  555.  
  556. pp.dual = dual
  557. pp.noise = noise
  558. pp.color_base = base
  559. pp.color_gray = gray
  560. pp.color_add = add
  561.  
  562. self.info = pp
  563.  
  564. return true
  565. end
  566.  
  567. function pp_linear_lerp:finished()
  568. return self.stop_time < time_global()
  569. end
  570. --
  571. -- end of postprocess for rainbow
  572. --
  573.  
  574. ----------------------------------------------------------------------------------------------------------------------
  575. -- Evaluators
  576. ----------------------------------------------------------------------------------------------------------------------
  577. -- çàðåçåðâèðîâàív id ñ íîìåðàìè îò 0 äî 256 äëÿ ñîçäàíèÿ ñòàíäàðòívõ ýâàëóàòîðîâ.
  578.  
  579. --Constant evaluator
  580. class "const_evaluator" (property_evaluator)
  581.  
  582. function const_evaluator:__init (name, value) super (nil, name)
  583. self.value = value
  584. end
  585.  
  586. function const_evaluator:evaluate()
  587. return self.value
  588. end
  589.  
  590. --Wait evaluator
  591. class "wait_evaluator" (property_evaluator)
  592.  
  593. function wait_evaluator:__init (wait_time) super ()
  594. self.wait_time = wait_time
  595. self.first_call = true
  596. self.current_time = 0
  597. end
  598.  
  599. function wait_evaluator:evaluate ()
  600. if self.first_call == true then
  601. self.first_call = false
  602. self.current_time = device ():time_global ()
  603. return false
  604. end
  605.  
  606. local t = device():time_global () - self.current_time;
  607. if t > self.wait_time then return true end
  608. return false
  609. end
  610. --------------------------------------------------------------------------------
  611. class "enabled_evaluator" (property_evaluator)
  612.  
  613. function enabled_evaluator:__init (name, storage) super ()
  614. self.a = storage
  615. end
  616.  
  617. function enabled_evaluator:evaluate()
  618. return self.a.enabled
  619. end
  620.  
  621. end -- end of editor() == false
  622.  
  623.  
  624. function str_split (str)
  625.  
  626. local strlen = string.len (str)
  627.  
  628. local parts = {{}, {}, {}, {}}
  629. local cpart = 1
  630.  
  631. for a = 1, strlen, 1 do
  632. local char = string.byte (str, a)
  633. if char ~= 95 then
  634. table.insert (parts[cpart], char)
  635. else
  636. cpart = cpart + 1
  637. if cpart > 4 then break end
  638. end
  639. end
  640.  
  641. if cpart ~= 4 then return "unknown", "stalker", 0, 0 end
  642.  
  643. local str1 = string.char ()
  644. local str2 = string.char ()
  645. local str3 = string.char ()
  646. local str4 = string.char ()
  647.  
  648. local ref = parts[1]
  649. for a = 1, table.getn (ref), 1 do
  650. str1 = string.format ("%s%c", str1, ref[a])
  651. end
  652.  
  653. ref = parts[2]
  654. for a = 1, table.getn (ref), 1 do
  655. str2 = string.format ("%s%c", str2, ref[a])
  656. end
  657.  
  658. ref = parts[3]
  659. for a = 1, table.getn (ref), 1 do
  660. str3 = string.format ("%s%c", str3, ref[a])
  661. end
  662.  
  663. ref = parts[4]
  664. for a = 1, table.getn (ref), 1 do
  665. str4 = string.format ("%s%c", str4, ref[a])
  666. end
  667.  
  668. printf ("%s %s %d %d", str1, str2, str3, str4)
  669. return str1, str2, (str3 + 1) - 1, (str4 + 1) - 1
  670. end
  671.  
  672. function random_number (min_value, max_value)
  673. math.randomseed (device ():time_global ())
  674. if min_value == nil and max_value == nil then
  675. return math.random ()
  676. else
  677. return math.random (min_value, max_value)
  678. end
  679. end
  680.  
  681. -- ‚६ï áã⮪ ¢ ¬á
  682. -- —㣠©
  683. local ms_per_day = 24 * 60 * 60 * 1000
  684. function day_time()
  685. return math.mod( game.time(), ms_per_day )
  686. end
  687.  
  688. --Time in hours
  689. function local_hours()
  690. return math.floor( math.mod( game.time()/1000, 86400 )/ 3600 )
  691. end
  692.  
  693. -- ¯ àá¨â áâப㠢¨¤  "   , ¡¡¡, ¢¢¢..." ¢ â ¡«¨æã { "   ", "¡¡¡", "¢¢¢", ... }
  694. -- —㣠©
  695. function parse_names( s )
  696. local t = {}
  697. for name in string.gfind( s, "([%w_\\]+)%p*" ) do
  698. --for name in string.gfind( s, "%s*([^%,]+)%s*" ) do
  699. table.insert( t, name )
  700. end
  701.  
  702. return t
  703. end
  704.  
  705.  
  706. function parse_key_value( s )
  707. local t = {}
  708. if s == nil then
  709. return nil
  710. end
  711. local key, nam = nil, nil
  712. -- nv071217 don't match "-" as punctuation
  713. -- for name in string.gfind( s, "([%w_\\]+)%p*" ) do
  714. for name in string.gfind( s, "([%w_\\%-]+)[,%s]*" ) do
  715. if key == nil then
  716. key = name
  717. else
  718. t[key] = name
  719. key = nil
  720. end
  721. end
  722. return t
  723. end
  724.  
  725.  
  726. -- ¯ àá¨â áâப㠢¨¤  "n1, n2, n3..." ¢ â ¡«¨æã { n1, n2, n3, ... } £¤¥ n1, n2, n3... - æ¥«ë¥ ç¨á« 
  727. -- —㣠©
  728. --[[function parse_nums( s )
  729. local t = {}
  730.  
  731. for entry in string.gfind( s, "([%w_\\]+)%p*" ) do
  732. table.insert( t, tonumber( entry ) )
  733. end
  734.  
  735. return t
  736. end]]
  737.  
  738. -- ¯ àá¨â áâப㠢¨¤  "n1, n2, n3..." ¢ â ¡«¨æã { n1, n2, n3, ... } £¤¥ n1, n2, n3... - ¤à®¡­ë¥ ç¨á« 
  739. function parse_nums( s )
  740. local t = {}
  741.  
  742. for entry in string.gfind( s, "([%d%.]+)%,*" ) do
  743. table.insert( t, tonumber( entry ) )
  744. end
  745.  
  746. return t
  747. end
  748.  
  749. -- ¯à®¢¥àï¥â, ¥áâì «¨ ®¡ê¥ªâ ¢ ®­« ©­¥
  750. function is_object_online(obj_id)
  751. return level.object_by_id(obj_id) ~= nil
  752. end
  753.  
  754. function get_clsid(npc)
  755. if npc == nil then return nil end
  756.  
  757. return npc:clsid()
  758.  
  759. -- if is_object_online(npc:id()) then
  760. -- return npc:clsid()
  761. -- else
  762. -- return nil
  763. -- end
  764. end
  765.  
  766. -- ¯à®¢¥àï¥â ®à㦨¥ «¨ íâ® (¯¥à¥¤ ¢ âì game_object)
  767. function isWeapon(object)
  768. local id = get_clsid(object)
  769. if id == nil then return false end
  770.  
  771. if id == clsid.wpn_vintorez_s then return true
  772. elseif id == clsid.wpn_ak74_s then return true
  773. elseif id == clsid.wpn_lr300_s then return true
  774. elseif id == clsid.wpn_hpsa_s then return true
  775. elseif id == clsid.wpn_pm_s then return true
  776. elseif id == clsid.wpn_shotgun_s then return true
  777. elseif id == clsid.wpn_bm16_s then return true
  778. elseif id == clsid.wpn_svd_s then return true
  779. elseif id == clsid.wpn_svu_s then return true
  780. elseif id == clsid.wpn_rpg7_s then return true
  781. elseif id == clsid.wpn_val_s then return true
  782. elseif id == clsid.wpn_walther_s then return true
  783. elseif id == clsid.wpn_usp45_s then return true
  784. elseif id == clsid.wpn_groza_s then return true
  785. elseif id == clsid.wpn_knife_s then return true
  786. elseif id == clsid.wpn_grenade_launcher then return true
  787. elseif id == clsid.wpn_grenade_f1 then return true
  788. elseif id == clsid.wpn_grenade_rpg7 then return true
  789. elseif id == clsid.wpn_grenade_rgd5 then return true
  790. elseif id == clsid.wpn_grenade_fake then return true
  791. else return false end
  792. end
  793.  
  794. --Tv÷èñëÿåò yaw â ðàäèàíàõ
  795. function yaw( v1, v2 )
  796. return math.acos( ( (v1.x*v2.x) + (v1.z*v2.z ) ) / ( math.sqrt(v1.x*v1.x + v1.z*v1.z ) * math.sqrt(v2.x*v2.x + v2.z*v2.z ) ) )
  797. end
  798.  
  799. function yaw_degree( v1, v2 )
  800. return (math.acos( ( (v1.x*v2.x) + (v1.z*v2.z ) ) / ( math.sqrt(v1.x*v1.x + v1.z*v1.z ) * math.sqrt(v2.x*v2.x + v2.z*v2.z ) ) ) * 57.2957)
  801. end
  802. function yaw_degree3d( v1, v2 )
  803. return (math.acos((v1.x*v2.x + v1.y*v2.y + v1.z*v2.z)/(math.sqrt(v1.x*v1.x + v1.y*v1.y + v1.z*v1.z )*math.sqrt(v2.x*v2.x + v2.y*v2.y + v2.z*v2.z)))*57.2957)
  804. end
  805.  
  806. function vector_cross (v1, v2)
  807. return vector ():set (v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x)
  808. end
  809.  
  810. //Âðàùàåò âåêòîð âîêðóã îñè y ïðîòèâ ÷àñîâîé ñòðåëêè
  811.  
  812. function vector_rotate_y (v, angle)
  813. angle = angle * 0.017453292519943295769236907684886
  814. local c = math.cos (angle)
  815. local s = math.sin (angle)
  816. return vector ():set (v.x * c - v.z * s, v.y, v.x * s + v.z * c)
  817. end
  818.  
  819. -- î÷èñòêà òàáëèöû
  820. function clear_table (t)
  821. while table.getn (t) > 0 do
  822. table.remove (t, table.getn (t))
  823. end
  824. end
  825.  
  826. --ˆá¯®«ì§ã¥â ¤«ï ¬®­áâ஢. ‚ë¡®à â®çª¨, ªã¤  ¨¤â¨ ¢ ­¥ª®â®à®¬ à ¤¨ãᥠ¨ ç⮡ â®çª  ¡ë«  ¤ «ìè¥ ­  à ááâ®ï­¨¨
  827. -- min_radius ®â ⥪ã饩 ¯®§¨æ¨¨(¥á«¨ íâ® ¯®«ãç¨âáï). center_id - 業âà ¯®§¨æ¨¨, ¢®ªà㣠ª®â®à®© ¦¨¢¥¬,
  828. -- position_id - âãªãé ï ¯®§¨æ¨ï, radius - ¢ ª ª®¬ à ¤¨ãᥠ¢ë¡¨à âì â®çªã, min_radius - ¬¨­¨¬ «ì­®¥ à ááâ®ï­¨¥, ®â ⥪ã饩 ¯®§¨æ¨¨ ¤® ­®¢®© â®çª¨.
  829. function new_point(center_id, position_id,radius, min_radius)
  830. local dir = vector():set(math.random(-1000, 1000)/1000.0, 0.0001, math.random(-1000, 1000)/1000.0)
  831. local pos = level.vertex_in_direction(center_id, dir, radius)
  832. local i = 1
  833.  
  834. while(level.vertex_position(position_id):distance_to(level.vertex_position(pos) ) < min_radius and i < 20) do
  835. dir = vector():set(math.random(-1000, 1000)/1000.0, 0.0001, math.random(-1000, 1000)/1000.0)
  836. pos = level.vertex_in_direction(center_id, dir, radius)
  837. i = i + 1
  838. end
  839.  
  840. return (level.vertex_position(pos))
  841. end
  842.  
  843. function stop_play_sound(obj)
  844. if obj:alive() == true then
  845. obj:set_sound_mask(-1)
  846. obj:set_sound_mask(0)
  847. end
  848. end
  849.  
  850. function object_type(obj)
  851. local otype = get_clsid(obj)
  852. local type
  853.  
  854. if otype == clsid.actor or
  855. otype == clsid.script_stalker or
  856. otype == clsid.script_trader
  857. then
  858. type = "stalker"
  859. elseif otype == clsid.crow or
  860. otype == clsid.zombie or
  861. otype == clsid.flesh or
  862. otype == clsid.controller or
  863. otype == clsid.bloodsucker or
  864. otype == clsid.burer or
  865. otype == clsid.chimera or
  866. otype == clsid.boar or
  867. otype == clsid.flesh_group or
  868. otype == clsid.dog_red or
  869. otype == clsid.dog_black or
  870. otype == clsid.pseudo_gigant
  871. then
  872. type = "monstr"
  873. elseif otype == clsid.wpn_fn2000 or
  874. otype == clsid.wpn_ak74 or
  875. otype == clsid.wpn_lr300 or
  876. otype == clsid.wpn_hpsa or
  877. otype == clsid.wpn_pm or
  878. otype == clsid.wpn_fort or
  879. otype == clsid.wpn_binocular or
  880. otype == clsid.wpn_shotgun or
  881. otype == clsid.wpn_svd or
  882. otype == clsid.wpn_svu or
  883. otype == clsid.wpn_rpg7 or
  884. otype == clsid.wpn_val or
  885. otype == clsid.wpn_vintorez or
  886. otype == clsid.wpn_walther or
  887. otype == clsid.wpn_usp45 or
  888. otype == clsid.wpn_groza or
  889. otype == clsid.wpn_knife or
  890. otype == clsid.wpn_scope or
  891. otype == clsid.wpn_silencer or
  892. otype == clsid.wpn_grenade_launcher or
  893. otype == clsid.obj_physic or
  894. otype == clsid.obj_breakable or
  895. otype == clsid.device_pda or
  896. otype == clsid.device_torch or
  897. otype == clsid.device_detector_simple or
  898. otype == clsid.obj_bolt or
  899. otype == clsid.obj_medkit or
  900. otype == clsid.obj_food or
  901. otype == clsid.obj_bottle or
  902. otype == clsid.obj_antirad or
  903. otype == clsid.obj_explosive or
  904. otype == clsid.obj_document or
  905. otype == clsid.obj_attachable or
  906. otype == clsid.wpn_grenade_f1 or
  907. otype == clsid.wpn_grenade_rpg7 or
  908. otype == clsid.wpn_grenade_rgd5 or
  909. otype == clsid.wpn_grenade_fake or
  910. otype == clsid.equ_scientific or
  911. otype == clsid.equ_stalker or
  912. otype == clsid.equ_military or
  913. otype == clsid.equ_exo or
  914. otype == clsid.wpn_ammo or
  915. otype == clsid.wpn_ammo_vog25 or
  916. otype == clsid.wpn_ammo_og7b or
  917. otype == clsid.wpn_ammo_m209
  918. then
  919. type = "item"
  920. else
  921. type = "none"
  922. end
  923.  
  924. -- ¯à®¢¥à塞 ­¥ âà㯠«¨ íâ®
  925. if type == "stalker" or
  926. type == "monstr" then
  927. if obj:alive() == false then
  928. type = "corpse"
  929. end
  930. end
  931.  
  932. return type
  933. end
  934.  
  935.  
  936. // ßâëÿåòñÿ ëè îbj ìîíñòðîì
  937. function is_object_monster(obj)
  938. local otype = get_clsid(obj)
  939. if(otype == clsid.crow or
  940. otype == clsid.zombie or
  941. otype == clsid.flesh or
  942. otype == clsid.controller or
  943. otype == clsid.bloodsucker or
  944. otype == clsid.burer or
  945. otype == clsid.chimera or
  946. otype == clsid.boar or
  947. otype == clsid.dog_red or
  948. otype == clsid.dog_black or
  949. otype == clsid.poltergeist or
  950. otype == clsid.pseudo_gigant )
  951. then
  952. return true
  953. end
  954.  
  955. return false
  956. end
  957.  
  958. --¢®§¢à é ¥â ¯à®¨§¢®«ì­ãî â®çªã ¯ã⨠㠪®â®à®© ãáâ ­®¢«¥­ ¡¨â
  959. function point_with_bit(patrol_path, bit, old_point) -- old_point - ¨­¤¥ªá â®çª¨, ª®â®àãî ­¥ ­ ¤® ¢ë¡¨à âì,
  960. local points = {} -- ¯ à ¬¥âà ­¥ ®¡ï§ â¥«ì­ë©( ­ ¯à¨¬¥à ⥪ã饩 â®çª¨ )
  961.  
  962. for i = 0, patrol_path:count()-1 do
  963. --„®¡®¢«ï¥¬ ¢ â ¡«¨æã â®çª¨ á ­ã¦­ë¬ ¡¨â®¬
  964. if( patrol_path:flag(i, bit)) then
  965. --„®¡ ¢«ï¥¬ â®çªã ¥á«¨ old_point == nil ¨«¨ ­®¢ ï â®çª  ­¥ ᮢ¯ ¤ ¥â á old_point
  966. if(old_point == nil) then
  967. table.insert(points, patrol_path:point(i))
  968. elseif(old_point ~= i) then
  969. table.insert(points, patrol_path:point(i))
  970. end
  971. end
  972. end
  973.  
  974. local number_point = table.getn(points)
  975.  
  976. if(number_point == 0) then
  977. return nil
  978. elseif(number_point == 1) then
  979. return points[1]
  980. else
  981. return points[math.random(1, number_point)]
  982. end
  983. end
  984.  
  985. --¢®§¢à é ¥â ¯à®¨§¢®«ì­ãî â®çªã ¯ã⨠㠪®â®à®© ãáâ ­®¢«¥­ ¡¨â
  986. function point_with_bit_id(patrol_path, bit, old_point) -- old_point - ¨­¤¥ªá â®çª¨, ª®â®àãî ­¥ ­ ¤® ¢ë¡¨à âì,
  987. local points = {} -- ¯ à ¬¥âà ­¥ ®¡ï§ â¥«ì­ë©( ­ ¯à¨¬¥à ⥪ã饩 â®çª¨ )
  988.  
  989. for i = 0, patrol_path:count()-1 do
  990. --„®¡®¢«ï¥¬ ¢ â ¡«¨æã â®çª¨ á ­ã¦­ë¬ ¡¨â®¬
  991. if( patrol_path:flag(i, bit)) then
  992. --„®¡ ¢«ï¥¬ â®çªã ¥á«¨ old_point == nil ¨«¨ ­®¢ ï â®çª  ­¥ ᮢ¯ ¤ ¥â á old_point
  993. if(old_point == nil) then
  994. table.insert(points, i)
  995. elseif(old_point ~= i) then
  996. table.insert(points, i)
  997. end
  998. end
  999. end
  1000.  
  1001. local number_point = table.getn(points)
  1002.  
  1003. if(number_point == 0) then
  1004. return nil
  1005. elseif(number_point == 1) then
  1006. return patrol_path:level_vertex_id(points[1])
  1007. else
  1008. return patrol_path:level_vertex_id(points[math.random(1, number_point)])
  1009. end
  1010. end
  1011.  
  1012. --‚®§¢à é ¥â ¨­¤¥ªá á ¬®© ¡«¨¦­¥© â®çª¨ ¯ãâ¨ á § ¤ ­ë¬ ¡¨â®¬, ®â ⥪ã饩 â®çª¨
  1013. function near_point_with_bit(point, patrol_path, bit)
  1014. local new_point = nil
  1015. local index = nil
  1016. local dist = 1000.0
  1017.  
  1018. for i = 0, patrol_path:count()-1 do
  1019. if( patrol_path:flag(i, bit) ) then
  1020. if(new_point == nil or patrol_path:point(i):distance_to(point) < dist) then
  1021. --…᫨ íâ  â®çª  ¯¥à¢ ï ¨§ ­ è¥¤è¨åáï, «¨¡® ®â ­¥¥ ¯ãâì ¡«¨¦¥, â® § ¯®¬¨­ ¥¬ ¥¥
  1022. new_point = patrol_path:point(i)
  1023. index = i
  1024. dist = new_point:distance_to(point)
  1025. end
  1026. end
  1027. end
  1028.  
  1029. return index
  1030. end
  1031.  
  1032. -- ¥ªãàᨢ­ ï à á¯¥ç âª  â ¡«¨æë
  1033. function print_table(table, subs)
  1034. local sub
  1035. if subs ~= nil then
  1036. sub = subs
  1037. else
  1038. sub = ""
  1039. end
  1040. for k,v in pairs(table) do
  1041. if type(v) == "table" then
  1042. printf(sub.."%s:", tostring(k))
  1043. print_table(v, sub.." ")
  1044. elseif type(v) == "function" then
  1045. printf(sub.."%s:function", tostring(k))
  1046. elseif type(v) == "userdata" then
  1047. printf(sub.."%s:userdata", tostring(k))
  1048. elseif type(v) == "boolean" then
  1049. if v == true then
  1050. printf(sub.."%s:true", tostring(k))
  1051. else
  1052. printf(sub.."%s:false", tostring(k))
  1053. end
  1054. else
  1055. if v ~= nil then
  1056. printf(sub.."%s:%s", tostring(k),v)
  1057. else
  1058. printf(sub.."%s:nil", tostring(k),v)
  1059. end
  1060. end
  1061. end
  1062. end
  1063.  
  1064. -------------------------------------------------------------------------------------------
  1065. function switch_online (id)
  1066. if id == -1 then return end
  1067. local sim = alife ()
  1068. if sim ~= nil then
  1069. sim:set_switch_online (id, true)
  1070. sim:set_switch_offline (id, false)
  1071. end
  1072. end
  1073. -------------------------------------------------------------------------------------------
  1074. function switch_offline (npc)
  1075. if npc == nil or npc:alive () == false then return end
  1076. local sim = alife ()
  1077. if sim ~= nil then
  1078. sim:set_switch_online (npc:id (), false)
  1079. sim:set_switch_offline (npc:id (), true)
  1080. end
  1081. end
  1082. -------------------------------------------------------------------------------------------
  1083. function get_actor_id()
  1084. if(level.actor() == nil) then return -1 end
  1085. return level.actor():id()
  1086. end
  1087. -------------------------------------------------------------------------------------------
  1088. function IsMonster (object, class_id)
  1089. local id = class_id or get_clsid (object)
  1090. if id == clsid.boar_s or
  1091. id == clsid.bloodsucker_s or
  1092. id == clsid.dog_s or
  1093. id == clsid.flesh_s or
  1094. id == clsid.pseudodog_s or
  1095. id == clsid.psy_dog_s or
  1096. id == clsid.burer_s or
  1097. id == clsid.cat_s or
  1098. id == clsid.chimera_s or
  1099. id == clsid.controller_s or
  1100. id == clsid.fracture_s or
  1101. id == clsid.poltergeist_s or
  1102. id == clsid.gigant_s or
  1103. id == clsid.zombie_s or
  1104. id == clsid.tushkano_s or
  1105. id == clsid.snork_s
  1106. then
  1107. return true
  1108. end
  1109. return false
  1110. end
  1111. -------------------------------------------------------------------------------------------
  1112. function IsStalker (object, class_id)
  1113. local id = class_id or get_clsid (object)
  1114.  
  1115. --[[ if id == clsid.actor or id == clsid.script_stalker then
  1116. return true
  1117. end
  1118. return false]]
  1119. local Stalkers = {
  1120. [clsid.actor] = true,
  1121. [clsid.script_stalker] = true
  1122. }
  1123. return Stalkers[id] or false
  1124. end
  1125. IAmAStalker = {}
  1126. function IAmAStalkerInit()
  1127. IAmAStalker = {
  1128. [clsid.actor] = true,
  1129. [clsid.script_stalker] = true
  1130. }
  1131. end
  1132. IAmAMonster = {}
  1133. function IAmAMonsterInit()
  1134. IAmAMonster = {
  1135. [clsid.boar_s] = true,
  1136. [clsid.bloodsucker_s] = true,
  1137. [clsid.dog_s] = true,
  1138. [clsid.flesh_s] = true,
  1139. [clsid.pseudodog_s] = true,
  1140. [clsid.psy_dog_s] = true,
  1141. [clsid.burer_s] = true,
  1142. [clsid.cat_s] = true,
  1143. [clsid.chimera_s] = true,
  1144. [clsid.controller_s] = true,
  1145. [clsid.fracture_s] = true,
  1146. [clsid.poltergeist_s] = true,
  1147. [clsid.gigant_s] = true,
  1148. [clsid.zombie_s] = true,
  1149. [clsid.tushkano_s] = true,
  1150. [clsid.snork_s] = true
  1151. }
  1152. end
  1153. -------------------------------------------------------------------------------------------
  1154. function level_object_by_sid( sid )
  1155. local sim = alife()
  1156.  
  1157. if sim then
  1158. local se_obj = sim:story_object( sid )
  1159. if se_obj then
  1160. return level.object_by_id( se_obj.id )
  1161. end
  1162. end
  1163.  
  1164. return nil
  1165. end
  1166.  
  1167. function id_by_sid( sid )
  1168. local sim = alife()
  1169.  
  1170. if sim then
  1171. local se_obj = sim:story_object( sid )
  1172. if se_obj then
  1173. return se_obj.id
  1174. end
  1175. end
  1176.  
  1177. return nil
  1178. end
  1179.  
  1180. -- Êðåøíóòü èãðó (ïîñëå âûâîäà ñîîáùåíèÿ îá îøèáêå â ëîã)
  1181. function abort(fmt, ...)
  1182. local reason = string.format(fmt, ...)
  1183. -- assert("ERROR: " .. reason)
  1184. -- printf("ERROR: " .. reason)
  1185. -- printf("%s")
  1186. dbglog("ABORT()_called:__%s", reason)
  1187. if quit_on_abort then
  1188. get_console():execute("quit")
  1189. end
  1190. end
  1191.  
  1192. function set_postprocess(name_ini_file)
  1193. bind_stalker.post_process = postprocess.PostProcess(ini_file(name_ini_file))
  1194. end
  1195. function remove_postprocess()
  1196. bind_stalker.post_process = nil
  1197. end
  1198.  
  1199. function set_inactivate_input_time(delta)
  1200. db.storage[db.actor:id()].disable_input_time = game.get_game_time()
  1201. db.storage[db.actor:id()].disable_input_idle = delta
  1202. level.disable_input()
  1203. end
  1204. -- Ïðèíèìàåò: ïîçèöèþ ïîëîæåíèÿ, ïîçèöèþ êóäà ñìîòðåòü, âðåìÿ ñíà â ìèíóòàõ.
  1205. function set_sleep_relocate(point, look, timeout)
  1206. db.storage[db.actor:id()].sleep_relocate_time = game.get_game_time()
  1207. db.storage[db.actor:id()].sleep_relocate_idle = timeout*60
  1208. db.storage[db.actor:id()].sleep_relocate_point = point
  1209. db.storage[db.actor:id()].sleep_relocate_look = look
  1210.  
  1211. --set_inactivate_input_time(timeout*60)
  1212. --db.actor:actor_sleep(0, timeout)
  1213. end
  1214.  
  1215. -- ïðîâåðÿåò öåëóþ ÷àñòü ÷èñëà íà íå÷¸òíîñòü
  1216. function odd( x )
  1217. return math.floor( x * 0.5 ) * 2 == math.floor( x )
  1218. end
  1219.  
  1220. --' Óñòàëîñòü
  1221. function on_actor_critical_power()
  1222. if has_alife_info("esc_trader_newbie") then
  1223. game.start_tutorial("part_11_weakness")
  1224. end
  1225. if not has_alife_info("encyclopedy_tutorial_weakness") then
  1226. db.actor:give_info_portion("encyclopedy_tutorial_weakness")
  1227. end
  1228. end
  1229.  
  1230. function on_actor_critical_max_power()
  1231. end
  1232.  
  1233. --' Êðîâîòå÷åíèå
  1234. function on_actor_bleeding()
  1235. if has_alife_info("esc_trader_newbie") then
  1236. game.start_tutorial("part_8_wound")
  1237. end
  1238. if not has_alife_info("encyclopedy_tutorial_wound") then
  1239. db.actor:give_info_portion("encyclopedy_tutorial_wound")
  1240. end
  1241. end
  1242.  
  1243. function on_actor_satiety()
  1244. end
  1245.  
  1246. --' Ðàäèàöèÿ
  1247. function on_actor_radiation()
  1248. if has_alife_info("esc_trader_newbie") then
  1249. game.start_tutorial("part_6_radiation")
  1250. end
  1251. if not has_alife_info("encyclopedy_tutorial_radiation") then
  1252. db.actor:give_info_portion("encyclopedy_tutorial_radiation")
  1253. end
  1254. end
  1255.  
  1256. --' Çàêëèíèëî îðóæèå
  1257. function on_actor_weapon_jammed()
  1258. if has_alife_info("esc_trader_newbie") then
  1259. game.start_tutorial("part_9_weapon")
  1260. end
  1261. if not has_alife_info("encyclopedy_tutorial_weapon") then
  1262. db.actor:give_info_portion("encyclopedy_tutorial_weapon")
  1263. end
  1264. end
  1265.  
  1266. --' íå ìîæåò õîäèòü èççà âåñà
  1267. function on_actor_cant_walk_weight()
  1268. if has_alife_info("esc_trader_newbie") then
  1269. game.start_tutorial("part_14_overload")
  1270. end
  1271. if not has_alife_info("encyclopedy_tutorial_overload") then
  1272. db.actor:give_info_portion("encyclopedy_tutorial_overload")
  1273. end
  1274. end
  1275.  
  1276. --' ïñè âîçäåéñòâèå
  1277. function on_actor_psy()
  1278. end
  1279.  
  1280. function set_actor_rank(rank)
  1281. if rank == "novice" then
  1282. db.actor:set_character_rank(0)
  1283. elseif rank == "stalker" then
  1284. db.actor:set_character_rank(300)
  1285. elseif rank == "veteran" then
  1286. db.actor:set_character_rank(600)
  1287. elseif rank == "master" then
  1288. db.actor:set_character_rank(900)
  1289. end
  1290. end
  1291.  
  1292. function get_texture_info(id_name, id_default)
  1293. if id_default == nil then id_default = id_name end
  1294.  
  1295. local task_info = GetTextureInfo(id_name, id_default)
  1296. local r = task_info:get_rect()
  1297.  
  1298. r.x2 = r.x2 - r.x1
  1299. r.y2 = r.y2 - r.y1
  1300. return task_info:get_file_name(), r
  1301. end
  1302.  
  1303. function start_game_callback()
  1304. printf ("start_game_callback called")
  1305. task_manager.clear_task_manager()
  1306. treasure_manager.clear_treasure_manager()
  1307. xr_sound.clear_all_sound_object()
  1308. dialog_manager.fill_phrase_table()
  1309. end
  1310.  
  1311. ammo_section = {}
  1312. ammo_section["ammo_9x18_fmj"] = true
  1313. ammo_section["ammo_9x18_pbp"] = true
  1314. ammo_section["ammo_9x18_pmm"] = true
  1315. ammo_section["ammo_9x19_fmj"] = true
  1316. ammo_section["ammo_9x19_pbp"] = true
  1317. ammo_section["ammo_5.45x39_fmj"] = true
  1318. ammo_section["ammo_5.45x39_ap"] = true
  1319. ammo_section["ammo_5.56x45_ss190"] = true
  1320. ammo_section["ammo_5.56x45_ap"] = true
  1321. ammo_section["ammo_5.7x28_fmj"] = true
  1322. ammo_section["ammo_5.7x28_ap"] = true
  1323. ammo_section["ammo_7.62x54_7h1"] = true
  1324. ammo_section["ammo_7.62x54_ap"] = true
  1325. ammo_section["ammo_7.62x54_7h14"] = true
  1326. ammo_section["ammo_9x39_pab9"] = true
  1327. ammo_section["ammo_gauss"] = true
  1328. ammo_section["ammo_9x39_ap"] = true
  1329. ammo_section["ammo_9x39_sp5"] = true
  1330. ammo_section["ammo_11.43x23_fmj"] = true
  1331. ammo_section["ammo_11.43x23_hydro"] = true
  1332. ammo_section["ammo_12x70_buck"] = true
  1333. ammo_section["ammo_12x76_dart"] = true
  1334. ammo_section["ammo_12x76_zhekan"] = true
  1335.  
  1336. quest_section = {}
  1337. quest_section["gunslinger_flash"] = true
  1338. quest_section["af_blood_tutorial"] = true
  1339. quest_section["esc_wounded_flash"] = true
  1340. quest_section["quest_case_02"] = true
  1341. quest_section["dar_document1"] = true
  1342. quest_section["dar_document2"] = true
  1343. quest_section["dar_document3"] = true
  1344. quest_section["dar_document4"] = true
  1345. quest_section["dar_document5"] = true
  1346. quest_section["kruglov_flash"] = true
  1347. quest_section["lab_x16_documents"] = true
  1348. quest_section["good_psy_helmet"] = true
  1349. quest_section["bad_psy_helmet"] = true
  1350. quest_section["decoder"] = true
  1351. quest_section["dynamite"] = true
  1352. quest_section["quest_case_01"] = true
  1353. quest_section["hunters_toz"] = true
  1354. quest_section["hunters_toz_34"] = true
  1355. quest_section["bar_ecolog_flash"] = true
  1356. quest_section["bar_tiran_pda"] = true
  1357. quest_section["bar_lucky_pda"] = true
RAW Paste Data