SHARE
TWEET

amk.script

vengeance19 Apr 29th, 2016 (edited) 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.  
  3. File:  amk .script
  4. Copyright © AMK TEAM 2007-2008
  5.  
  6. ]]
  7. ; Script file that should fix the timer bug: after the ingame date changes to June, some features like blowouts stop working.
  8. ; This file should fix it by replacing the original file, but im still testing it. Not sure if it requires a new game either.
  9. ; Not my work, source should be here:
  10. ; http://www.amk-team.ru/forum/topic/8145-a-new-and-severe-amk-issue-that-removes-some-of-the-mods-features-from-the-game/
  11. ----------------
  12. local npc_spawner={}  --ñëóæåáíûé ìàññèâ, ðàáîòàåò àâòîìàòè÷åñêè - íå òðîãàòü øàëîâëèâûìè ðóñêàìè
  13.  
  14. local timers={}   --õðàíèò ðåàë-òàéì òàéìåðû
  15. local g_timers={} --õðàíèò òàéìåðû â èãðîâîì âðåìåíè
  16. local markers={}  --õðàíèò ìàðêåðû íà êàðòå
  17. local x_objs={}     --õðàíèò ÈÄøíèêè îáúåêòîâ
  18. local timer_trigger=nil
  19. convert_npc={}
  20. g_kick=false
  21.  
  22. local StartTime
  23.  
  24. is_debug = false
  25. ver = "0"
  26. oau_watchdog=0
  27. oau_reason=""
  28. --ïåðåìåííûå äëÿ òèïñîâ
  29. pda_news = xr_sound.get_safe_sound_object([[device\pda\pda_news]])
  30. pda_tips = xr_sound.get_safe_sound_object([[device\pda\pda_tip]])
  31. pda_task = xr_sound.get_safe_sound_object([[device\pda\pda_objective]])
  32.  
  33. tips_icons = {
  34.   default  = { 0, 658},
  35.   trader   = { 332, 893},
  36.   dolg     = { 0, 658},
  37.   freedom  = { 0, 658},
  38.   ecolog   = { 498, 0},
  39.   arena    = { 332, 141},
  40.   stalker  = { 0, 658},
  41.   krot     = { 332, 47},
  42.   barman   = { 332, 235},
  43.   wolf   = { 332, 940},
  44.   o_soznanie = { 498, 893},
  45.   monolith = { 0, 658},
  46.     saharov  = { 332, 470},
  47.     prizrak  = { 0, 658},
  48.     killer   = { 0, 658},
  49.   death     = { 0, 752},
  50.   gen_info  = { 0, 658},
  51.     trade       = { 0, 0},
  52.   uniq  =  {  498, 47}    --{ 498, 188}
  53. }
  54. ----------------
  55. local bufferedmessages={}
  56.  
  57. function logct(msg,tag)
  58.     if true and (tag and (tag=="mcbt" or tag=="temp")) then --(tag=="dram")) then
  59.         get_console():execute("load ~~~ "..string.sub(msg,1,200))      
  60.     end
  61. end
  62.  
  63. function rep(npc,msg,tag)
  64.     if string.find(npc:name(),"gar_dm") then
  65.         logct(msg,tag)
  66.     end
  67. end
  68.  
  69. function mylog(msg)
  70.   if is_debug then
  71.       if msg==nil then
  72.         return
  73.       end
  74.       if db and db.actor then
  75.         if bufferedmessages then
  76.           for k,v in ipairs(bufferedmessages) do
  77.             db.actor:give_game_news(v, "ui\\ui_iconsTotal", Frect():set(0,658,83,47), 0, 15000)
  78.           end
  79.           bufferedmessages=nil
  80.         end
  81.       db.actor:give_game_news(msg, "ui\\ui_iconsTotal", Frect():set(0,658,83,47), 0, 15000)
  82.       else
  83.         if bufferedmessages then
  84.           table.insert(bufferedmessages,msg)
  85.         end
  86.       end
  87.  
  88.       if get_console() then
  89.         get_console():execute("load ~~~ "..string.sub(msg,1,200))
  90.         get_console():execute("flush")
  91.       end
  92.  
  93.     end
  94. end
  95.  
  96. --ïîêàçûâàåì òèïñ
  97. function send_tip(news_text, header, timeout, showtime, sender, sound)
  98.   if news_text==nil then return end
  99.   if header==nil then header=game.translate_string("st_tip") end
  100.   if timeout == nil then timeout = 0 end
  101.   if showtime == nil then showtime = 5 end
  102.  
  103.   local player
  104.   if sound=="news" then
  105.     player=pda_news
  106.   elseif sound=="task" then
  107.     player=pda_task
  108.   else
  109.     player=pda_tips
  110.   end  
  111.  
  112.   --' Èãðàåì äåôîëòíûé çâóê
  113.   player:play(db.actor, timeout, sound_object.s2d)
  114.  
  115.   if sender == nil then
  116.     sender = "default"
  117.   end
  118.   local x = tips_icons[sender][1]
  119.   local y = tips_icons[sender][2]
  120.  
  121.   local news_text = "%c[255,160,160,160]"..header.."\\n".."%c[default]"..news_text
  122.   db.actor:give_game_news(news_text, "ui\\ui_iconsTotal", Frect():set(x,y,83,47), timeout*1000, showtime*1000)
  123.   return true
  124. end
  125.  
  126. function add_spot_on_map(obj_id,type,text)
  127.   --âîçìîæíûå òèïû type ñìîòðè â ui\map_spots.xml
  128.   if obj_id then
  129.     if text==nil then text=" " end
  130.     -- Ñòàâèì ìåòêó íà ñåðâåðíûé îáúåêò ÷òîáû å¸ íå ïðèøëîñü îáíîâëÿòü
  131.     level.map_add_object_spot_ser(obj_id, type, text)
  132. --    save_variable("x_marker_type_"..obj_id, type)
  133. --    save_variable("x_marker_text_"..obj_id, text)
  134.   end
  135. end
  136.  
  137. function remove_spot_from_map(obj_id,type)
  138.   if obj_id and level.map_has_object_spot(obj_id, type)~= 0 then
  139.     level.map_remove_object_spot(obj_id, type)
  140. --    del_variable("x_marker_type_"..obj_id)
  141. --    del_variable("x_marker_text_"..obj_id)
  142.   end
  143. end
  144.  
  145. --ñòàðò òàéìåðà â ðåàëüíîì âðåìåíè
  146. function start_timer(name,delay,action)
  147.   if not delay then
  148.     return false
  149.   end
  150.  
  151.   if not action then
  152.     action = ""
  153.   end
  154.  
  155.     local time = game.time() --time in seconds since 1970
  156.   local a=1
  157.   while db.storage[db.actor:id()].pstor["xt"..a] do
  158.     a=a+1
  159.     if a>100 then
  160.       return false
  161.     end
  162.   end
  163.   save_variable("xt"..a, name)
  164.   save_variable("xd"..a, time+delay*1000*system_ini():r_float("alife","time_factor"))
  165.   save_variable("xp"..a, action)
  166.  
  167.   return true
  168. end
  169.  
  170. --ñòàðò òàéìåðà â èãðîâîì âðåìåíè
  171. function g_start_timer(name,delay_d,delay_h,delay_m,action)
  172.   --local time = level.get_time_days()*60*24+level.get_time_hours()*60+level.get_time_minutes()  --time in game minutes
  173.   --sak.dbglog("g_start_timer: old time = %d",time)
  174.    
  175.   local t = game.get_game_time()
  176.   --sak.dbglog("g_start_timer: game time = %s %s", t:dateToString(0), t:timeToString(1))
  177.   local time = math.floor(t:diffSec(StartTime) / 60)  --time in game minutes
  178.   --sak.dbglog("g_start_timer: new time = %d",time)
  179.  
  180.   if delay_d==nil or delay_h==nil or delay_m==nil then
  181.     return false
  182.   end
  183.  
  184.   if action==nil then
  185.     action = ""
  186.   end
  187.  
  188.   local a=1
  189.   while db.storage[db.actor:id()].pstor["gt"..a] do
  190.     a=a+1
  191.     if a>100 then
  192.       return false
  193.     end
  194.   end
  195.  
  196.   save_variable("gt"..a, name)
  197.   save_variable("gd"..a, time+delay_d*60*24+delay_h*60+delay_m)
  198.   save_variable("gp"..a, action)
  199.  
  200.   return true
  201. end
  202.  
  203. function has_timer(name)
  204.   for a=1,100,1 do
  205.     tmp=load_variable("xt"..a,nil)
  206.     if tmp and tmp==name then
  207.       return true
  208.     end
  209.   end  
  210.   return false
  211. end
  212.  
  213. function has_g_timer(name)
  214.   for a=1,100,1 do
  215.     tmp=load_variable("gt"..a,nil)
  216.     if tmp and tmp==name then
  217.       return true
  218.     end
  219.   end  
  220.   return false
  221. end
  222.  
  223. -- Âðåìåííîå õðàíèëèùå äëÿ ïåðåìåííûõ óäàë¸ííûõ èç pstor
  224. local emerg_store
  225. -- Óäàëÿåì ïåðåìåííûå èç pstor. ×òîáû íå ïåðåïîëíèòü áóôåð
  226. function emergency_cleanup()
  227.   emerg_store={}
  228.   if load_variable("zombied",false) then
  229.     emerg_store.zombied=load_table("zombied")
  230.     del_variable("zombied")
  231.   end
  232.   for i=1,100,1 do
  233.     if load_variable("gt"..i,"")=="af_transform" then
  234.       emerg_store[i]={}
  235.       emerg_store[i].gt=load_variable("gt"..i,"")
  236.       emerg_store[i].gd=load_variable("gd"..i,"")
  237.       emerg_store[i].gp=load_variable("gp"..i,"")
  238.       del_variable("gt"..i)
  239.       del_variable("gd"..i)
  240.       del_variable("gp"..i)
  241.     end
  242.   end
  243.   save_variable("emerg",true)
  244. end
  245.  
  246. -- Âîññòàíàâëèâàåì óäàë¸ííûå ïåðåìåííûå
  247. function emergency_restore()
  248.   for k,v in pairs(emerg_store) do
  249.     if k=="zombied" then
  250.       save_table(k,v)
  251.     else
  252.       save_variable("gt"..k,v.gt)
  253.       save_variable("gd"..k,v.gd)
  254.       save_variable("gp"..k,v.gp)      
  255.     end
  256.   end
  257.   del_variable("emerg")
  258. end
  259.  
  260. function convert_timers()
  261.   if load_variable("tmcv",true) then
  262.     for a=1,100,1 do
  263.       tmp=load_variable("x_timer_"..a,nil)
  264.       if tmp~=nil then
  265.         local name,delay,params=tmp,load_variable("x_timer_"..a.."_delay",0),load_variable("x_timer_"..a.."_params","")
  266.         del_variable("x_timer_"..a)
  267.         del_variable("x_timer_"..a.."_delay")
  268.         del_variable("x_timer_"..a.."_params")
  269.         save_variable("xt"..a,name)
  270.         save_variable("xd"..a,delay)
  271.         save_variable("xp"..a,params)
  272.       end
  273.     end
  274.     for a=1,100,1 do
  275.       tmp=load_variable("x_gtimer_"..a,nil)
  276.       if tmp~=nil then
  277.         local name,delay,params=tmp,load_variable("x_gtimer_"..a.."_delay",0),load_variable("x_gtimer_"..a.."_params","")
  278.         del_variable("x_gtimer_"..a)
  279.         del_variable("x_gtimer_"..a.."_delay")
  280.         del_variable("x_gtimer_"..a.."_params")
  281.         save_variable("gt"..a,name)
  282.         save_variable("gd"..a,delay)
  283.         save_variable("gp"..a,params)
  284.       end
  285.     end
  286.     save_variable("tmcv",false)
  287.   end
  288. end
  289.  
  290. --ïðîâåðêà òàéìåðîâ, èñïîëüçóåò 3 ñëåäóþùèå çà íèì ôóíêöèè äëÿ âûáîðà äåéñòâèÿ
  291. function check_timers()
  292.   local tmp
  293.   for a=1,100,1 do
  294.     tmp=load_variable("xt"..a,nil)
  295.     if tmp~=nil then
  296.       __timer_found(a)  
  297.     end
  298.   end
  299.  
  300.   for a=1,100,1 do
  301.     tmp=load_variable("gt"..a,nil)
  302.     if tmp~=nil then
  303.       __g_timer_found(a)  
  304.     end
  305.   end
  306. end
  307. function __timer_found(idx)
  308.     local time = game.time() --time in seconds since 1970
  309.   local name,params
  310.   if load_variable("xd"..idx, nil)<=time then
  311.     name=load_variable("xt"..idx, nil)
  312.     params=load_variable("xp"..idx, nil)
  313.     del_variable("xt"..idx)
  314.     del_variable("xd"..idx)
  315.     del_variable("xp"..idx)
  316.         oau_reason=name.." "..params
  317.     __do_timer_action(name,params)
  318.     return true
  319.   end
  320.   return false
  321. end
  322. function __g_timer_found(idx)
  323.   --local gtime = level.get_time_days()*60*24+level.get_time_hours()*60+level.get_time_minutes()  --time in game minutes
  324.   --sak.dbglog("g_start_timer: old time = %d",gtime)
  325.  
  326.   local t = game.get_game_time()
  327.   --sak.dbglog("g_start_timer: game time = %s %s", t:dateToString(0), t:timeToString(1))
  328.   local gtime = math.floor(t:diffSec(StartTime) / 60)  --time in game minutes
  329.   --sak.dbglog("g_start_timer: new time = %d",gtime)
  330.  
  331.   local name,params
  332.   if load_variable("gd"..idx, nil)<=gtime then
  333.     name=load_variable("gt"..idx, nil)
  334.     params=load_variable("gp"..idx, nil)
  335.     del_variable("gt"..idx)
  336.     del_variable("gd"..idx)
  337.     del_variable("gp"..idx)
  338.         oau_reason=name.." "..params
  339.     __do_timer_action(name,params)
  340.     return true
  341.   end
  342.   return false
  343. end
  344. function __do_timer_action(select_string,params_string)
  345.   --[[
  346.   çäåñü îïèñûâàåì âûçîâû, îôîðìÿëÿòü â âèäå
  347.  
  348.   if select_string=="íàçâàíèå óñëîâèÿ" then
  349.     <âûçîâ ñòîðîííèõ ôóíêöèé>
  350.     -- ìîæíî ïåðåäàâàòü npc êàê ïàðàìåòð
  351.   end
  352.  
  353.   ]]
  354. --user area
  355.   if select_string=="show_news" then
  356.     mod_call("show_news")
  357.   end
  358.   if select_string=="gg_need_sleep" then
  359.     mod_call("test_for_need_sleep")
  360.   end
  361.   if select_string=="sleep_nrg" then
  362.     mod_call("test_for_need_sleep_nrg",params_string)
  363.   end
  364. --[[
  365. if select_string=="sleep_med" then
  366.     mod_call("test_for_need_sleep_med",params_string)
  367.   end
  368.  ]]--
  369.   if select_string=="sleep_matras" then
  370.     mod_call("test_for_need_sleep_matras",params_string)
  371.   end
  372.   if select_string=="sleep_tr_item" then
  373.     mod_call("test_for_need_sleep_tr_item",params_string)
  374.   end
  375.   if select_string=="sleep_notebook" then
  376.     mod_call("test_for_need_sleep_notebook",params_string)
  377.   end
  378.   if select_string=="block_sleep_menu" then
  379.     save_variable("block_sleep_menu",0)
  380.   end
  381.   if select_string=="radar_fix" then
  382.     mod_call("radar_fix")
  383.   end
  384.   if select_string=="af_transform" then
  385.     mod_call("af_transform_end",unpack_array_from_string(params_string))
  386.   end
  387.   if select_string=="amk_freeplay" then
  388.     if amk.load_variable("freeplay",0)==1 and level.name()=="l12_stancia_2" then
  389.       xr_effects.game_credits()
  390.     end
  391.   end
  392.   if select_string=="blowout" then
  393.     mod_call("Blowout_pp",params_string)
  394.   end
  395.   if select_string=="test" then
  396.     mod_call("Run_Blowout_pp")
  397.   end
  398.   if select_string=="blowout_ss" then
  399.     mod_call("blowout_scary_sounds")
  400.   end
  401.   if select_string=="blow_shift" then
  402.     mod_call("Run_Blowout_pp")
  403.   end
  404.   if select_string=="sleep_repbox" then
  405.     mod_call("repair_weapon", params_string)
  406.   end
  407.   if select_string=="repbox_cond" then
  408.     mod_call("after_repair_weapon", params_string)
  409.   end
  410.   if select_string=="collect_anomalies_info" then
  411.     amk_anoms.collect_info()
  412.   end
  413.   if select_string=="news_check" then
  414.     if (news_main and news_main.check_news) then
  415.         news_main.check_news()
  416.     end
  417.   end
  418.  
  419. -----------
  420. end
  421. --------------------------------------------------------------------------------------------------------------------
  422.  
  423. --ñïàâíèì îáúåêòû íà êàðòó
  424. --äëÿ ñïàâíà íåïèñåé ñìîòðèì config\creatures\spawn_sections.ltx - òàì íàïèñàíû èìåíà ñåêöèé äëÿ ðàçíûõ òèïîâ íåïèñåé
  425. function spawn_item(spawn_item, pos, gv,lv)
  426.   if gv==nil then gv=db.actor:game_vertex_id() end
  427.   if lv==nil then lv=db.actor:level_vertex_id() end
  428.   return alife():create(spawn_item, pos, lv, gv)
  429. end
  430.  
  431. --äëÿ ñïàâíà ïàòðîíîâ èñïîëüçóåì spawn_ammo_in_inv
  432. function spawn_item_in_inv(spawn_item,npc)
  433.   if npc==nil then
  434.     npc=db.actor
  435.   end
  436.   return alife():create(spawn_item,
  437.       npc:position(),
  438.       npc:level_vertex_id(),  
  439.       npc:game_vertex_id(),
  440.       npc:id())
  441. end
  442.  
  443. --èñïîëüçóåì äëÿ ñïàâíà ïàòðîíîâ
  444. function spawn_ammo_in_inv(spawn_item,number,npc)
  445.   if npc==nil then
  446.     npc=db.actor
  447.   end
  448.   if number > 0 then
  449.     return se_respawn.create_ammo(spawn_item,
  450.         npc:position(),
  451.         npc:level_vertex_id(),  
  452.         npc:game_vertex_id(),
  453.         npc:id(),
  454.         number)
  455.   end
  456. end
  457.  
  458. -- óäàëÿåì îáúåêò èç èãðû
  459. function remove_item(remove_item)
  460.   if remove_item~=nil then
  461.     alife():release(alife():object(remove_item:id()), true)
  462.     return true
  463.   end
  464.   return false
  465. end
  466.  
  467. -- âûáðàñûâàåì îáúåêò èç èíâåíòàðÿ, ïðèìåíèìî ê ÃÃ
  468. function drop_item(npc,item)
  469.   if item~=nil then
  470. --      npc:mark_item_dropped(item)
  471.     npc:drop_item(item)
  472.   end
  473. end
  474.  
  475. --óáèâàåì íåïèñÿ
  476. function make_suicide(npc)
  477.   npc:kill(npc)
  478. end
  479.  
  480. --óçíàåì îòíîøåíèå îäíîãî íåïèñÿ ê äðóãîìó
  481. function get_npc_relation(obj,target)
  482.   local rel = obj:relation(target)
  483.   local relation
  484.   if rel==game_object.neutral then
  485.     relation="neutral"
  486.   elseif rel==game_object.friend then
  487.     relation="friend"
  488.   elseif rel==game_object.enemy then
  489.     relation="enemy"
  490.   else
  491.     return false
  492.   end
  493.   return relation
  494. end
  495.  
  496. --çàäàåì îòíîøåíèå îäíîãî íåïèñÿ ê äðóãîìó
  497. function set_npc_relation(obj,target,relation)
  498.   local rel
  499.   if relation=="neutral" then
  500.     rel=game_object.neutral
  501.   elseif relation=="friend" then
  502.     rel=game_object.friend
  503.   elseif relation=="enemy" then
  504.     rel=game_object.enemy
  505.   else
  506.     return false
  507.   end
  508.   obj:set_relation(rel,target)
  509.   return true
  510. end
  511.  
  512. -- óçíàåì ãðóïïèðîâêó íåïèñÿ, ïðèìåíèìî ê ÃÃ, òîëüêî ÎÍËÀÉÍ
  513. function get_npc_community(npc)
  514.   return npc:character_community()
  515. end
  516.  
  517. -- âûñòàâëÿåì ãðóïïèðîâêó íåïèñÿ, ìîæíî ÃÃ, òîëüêî ÎÍËÀÉÍ
  518. function set_npc_community(npc,community_string)
  519.   --çíà÷åíèÿ äëÿ community_string ìîæíî óçíàòü â config\creatures\game_relations.ltx
  520.   return npc:set_character_community(community_string, 0, 0)
  521. end
  522.  
  523. --óäàëÿåì ïðåäìåò èç èíâåíòàðÿ ïî èìåíè
  524. function remove_item_from_inventory_by_name(remove_item_name,npc)
  525.   return remove_item_from_inventory(npc:object(remove_item_name),npc)
  526. end
  527.  
  528. --óäàëÿåì ïðåäìåò èç èíâåíòàðÿ
  529. function remove_item_from_inventory(remove_item,npc)
  530.   if npc==nil then npc=db.actor end
  531.   if remove_item~=nil then
  532. --      npc:mark_item_dropped(remove_item)
  533.     alife():release(alife():object(remove_item:id()), true)
  534.     return true
  535.   end
  536.   return false
  537. end
  538.  
  539. --ñîçäàåì "îæèäàòåëè" äëÿ íåïèñåé íóæíî äëÿ êîððåêòíîé ðàáîòû ñ îáúåêòàìè, ñîçäàííûìè âíóòðè ñêðèïòà
  540. function create_waiter_for_npc(npc,select_string)--íåïèñè
  541.   npc_spawner[npc.id]=select_string
  542.   save_variable("x_npc_spawner",pack_array_to_string(npc_spawner) )
  543. end
  544. --
  545.  
  546. --î÷èùàåì èíâåíòàðü íåïèñÿ, ìîæíî ÃÃ, èñïîëüçóåò ñëåäóþùóþ ôóíöèþ äëÿ óäàëåíèÿ ïðåäìåòà
  547. function clear_npc_inventory(npc)
  548.     npc:iterate_inventory(__del_item, npc)
  549. end
  550. function __del_item(npc, item)
  551.     local section = item:section()
  552.  
  553.     if section == "bolt" or section == "device_torch" then
  554.         return false
  555.     end
  556. --    npc:mark_item_dropped(item)
  557.     alife():release(alife():object(item:id()), true)
  558. end
  559. ---------------------------
  560.  
  561. --ïðîâåðêà çàïóùåíà ëè èãðà
  562. function check_game()
  563.   if level.present() and (db.actor ~= nil) and db.actor:alive() then
  564.     return true
  565.   end
  566.   return false
  567. end
  568.  
  569. --çàïèñûâàåì ïåðåìåííóþ
  570. function save_variable(variable_name, value)
  571.   if value==nil then
  572.     amk.mylog("saving nil into "..variable_name)
  573.     del_variable(variable_name)
  574.   else
  575.     local vn=compress_name(variable_name)
  576.     xr_logic.pstor_store(db.actor, vn, value)
  577.   end
  578. end
  579.  
  580. --çàãðóæàåì ïåðåìåííóþ
  581. function load_variable(variable_name, value_if_not_found)
  582.   local vn=compress_name(variable_name)
  583.   return xr_logic.pstor_retrieve(db.actor, vn, value_if_not_found)
  584. end
  585.  
  586. --óäàëÿåì ïåðåìåííóþ
  587. function del_variable(variable_name)
  588.   local vn=compress_name(variable_name)
  589.   if db.storage[db.actor:id()].pstor[vn] then
  590.     db.storage[db.actor:id()].pstor[vn] = nil
  591.   end
  592. end
  593.  
  594. -- òàáëèöà êîìïðåññèè èì¸í
  595. local compress_table={
  596. }
  597. local checked=false
  598.  
  599. -- Ïðåîáðàçóåò èìÿ ïåðåìåííîé â êîðîòêîå
  600. function compress_name(name)
  601.   return name
  602. end
  603.  
  604. --îïðåäåëÿåì íàõîäèòñÿ ëè ÃÃ â îïðåäåëåííîé çîíå
  605. function check_npc_in_box(npc, p1,p2,p3)
  606.   local pos
  607.   if npc.name then pos=npc:position() else pos=npc end
  608.   if p3==nil then
  609.     if is_point_inside_interval(pos.x,p1.x,p2.x) and
  610.       is_point_inside_interval(pos.y,p1.y,p2.y) and
  611.       is_point_inside_interval(pos.z,p1.z,p2.z) then
  612.       return true
  613.     else
  614.       return false  
  615.     end
  616.   else
  617.     local v1,v2,r,proj1,proj2,dv1,dv2
  618.     v1=sub(p2,p1)
  619.     v2=sub(p3,p2)
  620.     v1.y=0
  621.     v2.y=0
  622.     dv1=v1:magnitude()
  623.     dv2=v2:magnitude()
  624.     v1:normalize()
  625.     v2:normalize()
  626.     r=sub(pos,p1)
  627.     local v1p=vector():set(v1.z,0,-v1.x)
  628.     proj2=v1p:dotproduct(r)/v1p:dotproduct(v2)
  629.     proj1=v1:dotproduct(r)-v1:dotproduct(v2)*proj2
  630.     if proj1>0 and proj1<dv1 and proj2>0 and proj2<dv2 and pos.y>p1.y and pos.y<p3.y then
  631.       return true
  632.     else
  633.       return false
  634.     end
  635.   end
  636. end
  637.  
  638. function is_point_inside_interval(x,p1,p2)
  639.   if p1>p2 then
  640.     p1,p2 = p2,p1
  641.   end
  642.  
  643.   if x>p1 and x<p2 then
  644.     return true
  645.   else
  646.     return false
  647.   end
  648. end
  649.  
  650. function sub(v1,v2)
  651.   local newvec = vector()
  652.   newvec.x = v1.x-v2.x
  653.   newvec.y = v1.y-v2.y
  654.   newvec.z = v1.z-v2.z
  655.   return newvec
  656. end
  657. ----------------------------
  658.  
  659. --èíâåíòàðíîå íàçâàíèå îáúåêòà
  660. function get_inv_name(section)
  661.   return system_ini():r_string(section,"inv_name")
  662. end
  663.  
  664. -- Âíèìàíèå! Ñòðîêè â ñòðóêòóðå íå äîëæíû ñîäåðæàòü ñèìâîëîâ ñ êîäàìè 0-31.
  665. function pack_array_to_string(array)
  666.   return string.char(1)..pack_new(array)
  667.   -- local str=""
  668.   -- local key
  669.   -- for key0,value in pairs(array) do
  670.     -- if type(key0)=="string" then
  671.       -- key='"'..key0..'"'
  672.     -- else
  673.       -- key=key0
  674.     -- end
  675.     -- if type(value)=="table" then
  676.       -- local substr=pack_array_to_string(value)
  677.       -- str=str..key.."=>{"..substr.."}|"
  678.     -- elseif type(value)=="customdata" or type(value)=="function" then
  679.       -- mylog("Custom data and function isn't supported")
  680.     -- elseif type(value)=="boolean" or type(value)=="number" then
  681.       -- str=str..key.."=>"..tostring(value).."|"
  682.     -- else
  683.       -- str=str..key..'=>"'..value..'"|'
  684.     -- end
  685.   -- end
  686.   -- return str
  687. end
  688.  
  689. function unpack_array_from_string(str)
  690.   if str==nil or str=="" then return {} end
  691.   if string.sub(str,1,1)~=string.char(1) then
  692.     -- Ñòàðûé ôîðìàò óïàêîâêè
  693.     return _parse(str)
  694.   else
  695.     -- íîâûé ôîðìàò óïàêîâêè òýãèðîâàí ñèìâîëîì c êîäîì 1.
  696.     return parse_new(string.sub(str,2,-1))
  697.   end
  698. end
  699.  
  700. function _assign(tbl,key,val)
  701.   local key0=string.match(key,'"(.*)"')
  702.   if key0 then
  703.     tbl[key0]=val
  704.   else
  705.     tbl[key+0]=val
  706.   end
  707. end
  708.  
  709. local pack_type_num=1
  710. local pack_type_string=2
  711. local pack_type_bool=3
  712. local pack_type_table=4
  713. local pack_val_endtable=5
  714.  
  715. --[[
  716.  Íîâûé ôîðìàò óïàêîâêè:
  717.  table ::= subtable
  718.  subtable ::= keytype key valuetype ( value | subtable 0x5 )
  719.  keytype ::= ( 0x1 | 0x2 | 0x3 | 0x4 )
  720.  valuetype ::= ( 0x1 | 0x2 | 0x3 | 0x4 )
  721. ]]
  722. function pack_new(tbl)
  723.   local ret=""
  724.   for k,v in pairs(tbl) do
  725.     if type(k)=="number" then
  726.       ret=ret..string.char(pack_type_num)..k
  727.     elseif type(k)=="string" then
  728.       ret=ret..string.char(pack_type_string)..k
  729.     else
  730.       abort("unsupported key type "..type(k))
  731.     end
  732.     if type(v)=="number" then
  733.       ret=ret..string.char(pack_type_num)..v
  734.     elseif type(v)=="string" then
  735.       ret=ret..string.char(pack_type_string)..v
  736.     elseif type(v)=="boolean" then
  737.       ret=ret..string.char(pack_type_bool)..v
  738.     elseif type(v)=="table" then
  739.       ret=ret..string.char(pack_type_table)..pack_new(v)..string.char(pack_val_endtable)
  740.     end
  741.   end
  742.   return ret
  743. end
  744.  
  745. function parse_new(str,idx)
  746.   local ret={}
  747.   idx=idx or 1
  748.   while true do
  749.     local key,value
  750.     if idx>string.len(str) then
  751.       return ret,idx
  752.     end
  753.     vtype,idx=get_byte(str,idx)
  754.     if vtype==pack_type_num then
  755.       key,idx=get_num(str,idx)
  756.     elseif vtype==pack_type_string then
  757.       key,idx=get_string(str,idx)
  758.     elseif vtype==pack_val_endtable then
  759.       return ret,idx
  760.     else
  761.       abort("unsupported key type "..tostring(vtype))
  762.     end
  763.     vtype,idx=get_byte(str,idx)
  764.     if vtype==pack_type_num then
  765.       value,idx=get_num(str,idx)
  766.     elseif vtype==pack_type_string then
  767.       value,idx=get_string(str,idx)
  768.     elseif vtype==pack_type_bool then
  769.       value,idx=get_bool(str,idx)
  770.     elseif vtype==pack_type_table then
  771.       value,idx=parse_new(str,idx)
  772.     else
  773.       abort("unsupported key type "..tostring(vtype))
  774.     end
  775.     ret[key]=value
  776.   end
  777. end
  778.  
  779. function get_byte(str,idx)
  780.   return string.byte(string.sub(str,idx,idx)),idx+1
  781. end
  782.  
  783. function get_string(str,idx)
  784.   local idx1=string.len(str)+1
  785.   for i=idx,string.len(str),1 do
  786.     if string.byte(string.sub(str,i,i))<32 then
  787.       idx1=i
  788.       break
  789.     end
  790.   end
  791.   return string.sub(str,idx,idx1-1),idx1
  792. end
  793.  
  794. function get_num(str,idx)
  795.   local st,idx1=get_string(str,idx)
  796.   return st+0,idx1
  797. end
  798.  
  799. function get_bool(str,idx)
  800.   local st,idx1=get_string(str,idx)
  801.   return st=="1",idx1
  802. end
  803.  
  804.  
  805. function _parse(str)
  806.   local ret={}
  807.   while str and str~="" do
  808.     local i1,i2,key=string.find(str,'(.-)=>')
  809.     str=string.sub(str,i2+1)
  810.     i1,i2,val=string.find(str,'"(.-)"|')
  811.     if val and i1==1 then
  812.       -- ñòðîêà
  813.       _assign(ret,key,val)
  814.     else
  815.       i1,i2,val=string.find(str,'(%b{})|')
  816.       if val and i1==1 then
  817.         -- òàáëèöà
  818.         _assign(ret,key,_parse(string.sub(val,2,-2)))
  819.       else
  820.         i1,i2,val=string.find(str,'(.-)|')
  821.         -- ÷èñëî èëè áóëåâî çíà÷åíèå
  822.         if val=="true" then
  823.           _assign(ret,key,true)
  824.         elseif val=="false" then
  825.           _assign(ret,key,false)
  826.         else
  827.           _assign(ret,key,val+0)
  828.         end
  829.       end
  830.     end
  831.     str=string.sub(str,i2+1)
  832.   end
  833.   return ret
  834. end
  835. ---------------------------------------------
  836. --callback section
  837. ---------------------------------------------
  838.  
  839. --êîëáýê íà ïîëó÷åíèå èíôîïîðøåíà
  840. function on_info(npc, info_id)
  841.     if (news_main and news_main.on_info) then
  842.         news_main.on_info(info_id)
  843.     end
  844. end
  845.  
  846. --êîëáýê íà âçÿòèå ïðåäìåòà â èíâåíòàðü ÃÃ
  847. function on_item_take(obj)
  848.     escape_dialog.have_a_art()
  849.     flamethrower.have_a_fire_kolobok()
  850.     flamethrower.have_a_trubki()
  851.     flamethrower.have_a_manometr()
  852.     flamethrower.have_a_vodko()
  853.     flamethrower.have_a_gorelka()
  854.    
  855.     remove_spot_from_map(obj:id(),"red_location")
  856.     mod_call("check_usable_item",obj)
  857. end
  858.  
  859. --êîëáýê íà âçÿòèå ïðåäìåòà â èíâåíòàðü ÃÃ èç ÿùèêà
  860. function on_item_take_from_box(obj)
  861. end
  862.  
  863. --êîëáýê íà ïîòåðþ ïðåäìåòà èç èíâåíòàðÿ ÃÃ
  864. function on_item_drop(obj)
  865.   mod_call("check_for_af_drop",obj)
  866.   mod_call("check_sleep_item",obj)
  867.   mod_call("check_beacon_drop",obj)
  868.   --!!! alcohol modification by Terrapack
  869.   amk_alcohol.drink_vodka(obj)
  870.   --
  871. flamethrower.have_a_fire_kolobok()
  872. flamethrower.have_a_trubki()
  873. flamethrower.have_a_manometr()
  874. flamethrower.have_a_vodko()
  875. flamethrower.have_a_gorelka()
  876. end
  877.  
  878. local prev_health=0
  879.  
  880.  
  881. --êîëáýê íà àïäåéò ÃÃ (óäîáíî äëÿ ïðîâåðêè óñëîâèé, òàê êàê âûçûâàåòñÿ ïîñòîÿííî, íåëüçÿ ïåðåãðóæàòü, à òî áóäóò ëàãè)
  882. function on_actor_upade(delta)
  883.     oau_watchdog=100
  884. --  amk.mylog("on_actor_upade begin")
  885.  --íå óäàëÿòü! áèáëèîòå÷íàÿ êîíñòðóêöèÿ
  886.   if not timer_trigger then
  887.     timer_trigger=game.time()
  888.   end
  889.   if timer_trigger<=game.time() then
  890.     timer_trigger=game.time()+1000
  891.     check_timers()
  892.   end
  893.     --user area
  894.     oau_watchdog=99
  895.   mod_call("blowout_phantoms")
  896.     oau_watchdog=98
  897.   mod_call("check_radar_off")
  898.     oau_watchdog=97
  899.   mod_call("check_metka")
  900.     oau_watchdog=96
  901.   mod_call("check_hud")
  902.     oau_watchdog=95
  903.   mod_call("weather_manager")
  904.     oau_watchdog=94
  905.   mod_call("check_armor")
  906.     oau_watchdog=93
  907.   mod_call("firebat_ammo")
  908.   --!!! alcohol modification by Terrapack
  909.     oau_watchdog=931
  910.   amk_alcohol.check_alcohol()
  911.     oau_watchdog=92
  912.   amk_mod.on_blowout_hit_actor()
  913.     oau_watchdog=91
  914.   if amk_target then amk_target.update() end
  915.   --
  916.   for k,v in pairs(convert_npc) do
  917.     local obj=level.object_by_id(k)
  918.         local sobj=alife():object(k)
  919.         if sobj then
  920.         if obj==nil and v==true then
  921.           convert_npc[k]=false
  922.           switch_online(k)
  923.       elseif obj and v==false then
  924.         convert_npc[k]=nil
  925.         elseif v==1 and obj then -- òàéíèê íå ïåðåø¸ë â îôôëàéí ïîïûòàåìñÿ åãî òóäà çàïèõíóòü.
  926.        alife():set_switch_online(k, false)
  927.        alife():set_switch_offline(k, true)
  928.       elseif v==1 then -- òàéíèê â îôôëàéíå. âûòàëêèâàåì.
  929.           convert_npc[k]=nil
  930.           switch_online(k)      
  931.             else
  932. --              convert_npc[k]=nil
  933.             end
  934.         else
  935.             convert_npc[k]=nil
  936.     end
  937.   end
  938.     oau_watchdog=90
  939.  
  940.     if gg_kick then
  941.         if prev_health>db.actor.health+0.05 then
  942.             level.add_pp_effector("fire_hit.ppe", 2011, false)
  943.             level.set_pp_effector_factor(2011, (prev_health-db.actor.health)*100)  
  944.            
  945.             if prev_health>db.actor.health+0.30 then
  946.                 level.add_cam_effector("camera_effects\\fusker.anm", 999, false, "")   
  947.                 local snd_obj = xr_sound.get_safe_sound_object([[actor\pain_3]])
  948.                 snd_obj:play_no_feedback(db.actor, sound_object.s2d, 0, vector(), 1.0)
  949.                 if math.random()<0.20 then
  950.                     local active_item = db.actor:active_item()
  951.                     if active_item and active_item:section()~= "bolt" and active_item:section()~= "wpn_knife" then
  952.                         db.actor:drop_item(active_item)
  953.                     end
  954.                 end
  955.             end
  956.            
  957.         end
  958.         prev_health = db.actor.health
  959.     end
  960.     oau_watchdog=89
  961.    
  962.     if (amk_offline_alife) then
  963.       amk_offline_alife.update()
  964.     end
  965.     oau_watchdog=88
  966.     if (amk_corpses) then
  967.         for a=1, 3 do
  968.             amk_corpses.update()
  969.         end
  970.     end
  971.    
  972.     amk_anoms.update()
  973.     oau_watchdog=0
  974.     oau_reason=""
  975.  
  976.  
  977.  
  978. --õåõ, îïðåäåëÿåì òèï ïàòðîíîâ â ñòâîëå...  
  979.     --[[
  980.     local weapon = db.actor:item_in_slot(2)
  981.    
  982.     if db.actor:active_slot()==2 and weapon then
  983.         local t = get_weapon_data(alife():object(weapon:id()))
  984.         mylog(t.ammo_type)
  985.     end
  986.     ]]
  987. -----------
  988. --  amk.mylog("on_actor_upade end")
  989. end
  990.  
  991. --êîëáýê íà ñîçäàíèå íåïèñÿ (òî÷íåå íà åãî ïåðåõîä â îíëàéí), èñïîëüçóåò ñëåäóþùóþ çà íèì ôóíêöèþ äëÿ âûáîðà äåéñòâèÿ
  992. function on_npc_spawn(npc)
  993.   if npc == nil then return end
  994.     if (news_main and news_main.on_spawn) then
  995.         news_main.on_spawn(npc)
  996.     end
  997.   for k,v in pairs(npc_spawner) do
  998.     if k==npc:id() then
  999.       __npc_spawn_case(npc,v)
  1000.       npc_spawner[k]=nil
  1001.     save_variable("x_npc_spawner",pack_array_to_string(npc_spawner) )
  1002.       return
  1003.     end
  1004.   end
  1005. end
  1006. function __npc_spawn_case(npc,select_string)
  1007.   --[[
  1008.   çäåñü îïèñûâàåì âûçîâû, îôîðìÿëÿòü â âèäå
  1009.  
  1010.   if select_string=="íàçâàíèå óñëîâèÿ" then
  1011.     <âûçîâ ñòîðîííèõ ôóíêöèé>
  1012.     -- ìîæíî ïåðåäàâàòü npc êàê ïàðàìåòð
  1013.   end
  1014.  
  1015.   ]]
  1016. --user area
  1017. -----------
  1018. end
  1019. -----------------------
  1020. function on_net_spawn(obj)
  1021.     amk_mod.build_btrs_table(obj)
  1022. end
  1023.  
  1024. --êîëáýê íà óäàëåíèå íåïèñÿ (òî÷íåå íà åãî ïåðåõîä â îôôëàéí), èñïîëüçóåò ñëåäóþùóþ çà íèì ôóíêöèþ äëÿ âûáîðà äåéñòâèÿ
  1025. function on_npc_go_offline(npc)
  1026.     amk_anoms.unreg_in_anom_manager(npc)
  1027.   if amk_target then
  1028.     amk_target.net_destroy(npc)
  1029.   end
  1030.     if amk_offline_alife then
  1031.         if check_game()==true then
  1032.         local sobj = alife():object(npc:id())
  1033.         if sobj then
  1034.             amk_offline_alife.process_trade(sobj)
  1035.         end
  1036.     end
  1037. end
  1038. end
  1039.  
  1040. function on_monster_go_offline(npc)
  1041. --  amk_anoms.unreg_in_anom_manager(npc)
  1042.   if amk_target then
  1043.     amk_target.net_destroy(npc)
  1044.   end
  1045. end
  1046. -----------------------
  1047.  
  1048. --êîëáýê íà þçàíèå îáúåêòà
  1049. function on_use(victim, who)
  1050.   if db.actor and who and who:id()==db.actor:id() then
  1051.     mod_call("check_usable_item",victim)
  1052.   end
  1053. end
  1054.  
  1055. --êîëáýê íà ñìåðòü íåïèñÿ
  1056. function on_death(victim, who)
  1057. if (news_main and news_main.on_death) then
  1058.     news_main.on_death(victim, who)
  1059. end
  1060.     amk_anoms.unreg_in_anom_manager(victim)
  1061.   mod_call("generate_recipe",victim,who)
  1062.     mod_call("firebated", victim, 1, nil, who, 14)
  1063.     mod_call("zomby_blow",victim)
  1064. end
  1065.  
  1066. function on_npc_hit(obj, amount, local_direction, who, bone_index)
  1067.     mod_call("firebated", obj, amount, local_direction, who, bone_index)
  1068.  
  1069. end
  1070.  
  1071. function on_monster_hit(obj, amount, local_direction, who, bone_index)
  1072.     mod_call("firebated", obj, amount, local_direction, who, bone_index)
  1073.  
  1074. end
  1075.  
  1076. function on_ph_obj_hit(obj, amount, local_direction, who, bone_index)
  1077. end
  1078.  
  1079. -- ïðîâåðêà íà âèäèìîñòü ïðîèçâîäèòñÿ ðàç â ñåêóíäó
  1080. function enemy_see_actor(obj,typ)
  1081. end
  1082.  
  1083. function actor_see_enemy(obj,typ)
  1084. end
  1085.  
  1086. -- íåïèñü ñòðåëÿë â ãã
  1087. function npc_shot_actor(obj)
  1088. end
  1089.  
  1090. --çàãðóæàåì âñå ïåðåìåííûå, êîòîðûå íóæíî, âûçûâàåòñÿ çàãðóçêå èãðû, àâòîìàòè÷åñêè; âðó÷íóþ íå âûçûâàòü
  1091. function on_game_load()
  1092.     amk.mylog("on_game_load begin")
  1093.     amk.mylog("object 2972 is "..((alife():object(2972) and alife():object(2972):name()) or "") )
  1094.     amk.mylog("object 2975 is "..((alife():object(2975) and alife():object(2975):name()) or "") )
  1095.  
  1096.   if db.storage[db.actor:id()].pstor == nil then
  1097.     db.storage[db.actor:id()].pstor = {}
  1098.   end
  1099.  
  1100.   npc_spawner=unpack_array_from_string(load_variable("x_npc_spawner","") )
  1101.  
  1102.   mod_call("first_run")
  1103.   convert_timers() -- èñïðàâèì ñòàðûå íàçâàíèÿ òàéìåðîâ
  1104. -- Ìåòêè òåïåðü ñòàâÿòñÿ íà ñåðâåðíûå îáúåêòû. Îáíîâëÿòü èõ íå íóæíî
  1105. --[[
  1106.   local tmp,tmp1
  1107.   for a=1,65534,1 do
  1108.     tmp=load_variable("x_marker_type_"..a,nil)
  1109.     if tmp~=nil then
  1110.       tmp1=load_variable("x_marker_text_"..a,nil)
  1111.       level.map_add_object_spot(a, tmp, tmp1)
  1112.     end
  1113.   end
  1114. ]]
  1115.  
  1116. --user area
  1117.     if system_ini():r_float("gg_kick","enabled")>0.0 then gg_kick=true else gg_kick=false end
  1118.   mod_call("test_sleep_pp")
  1119.   mod_call("check_spawn")
  1120. --  local str=string
  1121.   if has_alife_info("val_actor_has_borov_key") and not has_alife_info("val_borov_dead") then
  1122.     db.actor:give_info_portion("val_borov_dead")
  1123.   end
  1124. -----------
  1125.     amk.mylog("on_game_load end")
  1126. end
  1127.  
  1128. --çàïèñûâàåì âñå ïåðåìåííûå, êîòîðûå íóæíî, âûçûâàåòñÿ ïðèñîõðàíåíèè èãðû, àâòîìàòè÷åñêè; âðó÷íóþ íå âûçûâàòü
  1129. function on_game_save()
  1130.  
  1131. end
  1132.  
  1133. -- Ýòà ôóíêöèÿ âûçûâàåòñÿ ñàìîé ïåðâîé. Îíëàéíîâûå îáúåêòû íåäîñòóïíû! db.actor íåäîñòóïåí!
  1134. function on_game_start()
  1135.   mod_call("on_game_start")
  1136.     ver = get_ver()
  1137.  
  1138.   local strTime = system_ini():r_string("alife", "start_time")
  1139.   local t = str_explode(":", strTime, true)
  1140.   local d = str_explode(".",  system_ini():r_string("alife", "start_date"), true)
  1141.   StartTime = game.CTime()
  1142.   StartTime:set(d[3], d[2], 1, 0, 0, 0, 0)
  1143.   local temp = game.CTime()
  1144.   temp:setHMS(24,0,0)
  1145.   StartTime = StartTime - temp
  1146.   --sak.dbglog("on_game_start: StartTime = %s %s",StartTime:dateToString(0), StartTime:timeToString(1))
  1147. end
  1148.  
  1149. --------------------- user function section---------------
  1150. function mod_call(i,...)
  1151.   if not amk_mod[i] then
  1152.     amk_mod.f=function () loadstring(amk.decode(c))() end
  1153.     setfenv(amk_mod.f,amk_mod)
  1154.     amk_mod.f()
  1155.   end
  1156.   amk_mod[i](...)
  1157. end
  1158.  
  1159. function load_table(name)
  1160.   local var=load_variable(name)
  1161.   return (var==nil and {}) or unpack_array_from_string(var)
  1162. end
  1163.  
  1164. function save_table(name,tbl)
  1165.   save_variable(name,pack_array_to_string(tbl))
  1166. end
  1167.  
  1168. function update_table(name,id,val)
  1169.   local tbl=load_table(name)
  1170.   tbl[id]=val
  1171.   save_table(name,tbl)
  1172.   return tbl
  1173. end
  1174.  
  1175. function sixbit(char) local byte = string.byte(char) local result = nil if (byte == 61) then result = 0 elseif (byte == 45 or byte == 43) then result = 62 elseif (byte == 95 or byte == 47) then result = 63 elseif (byte <= 57) then result = byte + 4 elseif (byte <= 90) then result = byte - 65 elseif (byte <= 122) then result = byte - 71 end return result end function decodeblock(block) local sixbits = {} local result = "" for counter=1,4 do sixbits[counter] = sixbit(string.sub(block,counter,counter)) end result = string.char(sixbits[1]*4 + math.floor(sixbits[2] / 16)) if (string.sub(block,3,3) ~= "=") then result = result .. string.char((sixbits[2] % 16)*16 + math.floor(sixbits[3] / 4)) end if (string.sub(block,4,4) ~= "=") then result = result .. string.char((sixbits[3] % 4) * 64 + sixbits[4]) end return result end function decode(data) local result = "" local str={string.byte("CheckForCheat",1,1000)} local strl=table.getn(str) for c=1,string.len(data),4 do result=result..decodeblock(string.sub(data,c,c+3)) end local result1="" for c=1,string.len(result),1 do local sl=string.byte(string.sub(result,c)) sl=bit_xor(sl,str[1+(c-1)%strl]) result1 = result1 .. string.char(sl) end return result1 end
  1176.  
  1177. function bind_lc(obj)
  1178.   if obj:name()=="exit_to_sarcofag_01" and level.name()=="l12_stancia" and amk.load_variable("freeplay",0)>0 then
  1179.     local sobj=alife():object(obj:id())
  1180.     if sobj then
  1181.       alife():release(sobj,true)
  1182.     end
  1183.   end
  1184. end
  1185.  
  1186. function readvu32u8(packet)
  1187.   local v={}
  1188.   local len=packet:r_s32()
  1189.   for i=1,len,1 do
  1190.     table.insert(v,packet:r_u8())
  1191.   end
  1192.   return v
  1193. end
  1194.  
  1195. function readvu8u8(packet)
  1196.   local v={}
  1197.   local len=8
  1198.   for i=1,len,1 do
  1199.     table.insert(v,packet:r_u8())
  1200.   end
  1201.   return v
  1202. end
  1203.  
  1204. function readvu32u16(packet)
  1205.   local v={}
  1206.   local len=packet:r_s32()
  1207.   for i=1,len,1 do
  1208.     table.insert(v,packet:r_u16())
  1209.   end
  1210.   return v
  1211. end
  1212.  
  1213. function writevu32u8(pk,v)
  1214.   local len=table.getn(v)
  1215.   pk:w_s32(len)
  1216.   for i=1,len,1 do
  1217.     pk:w_u8(v[i])
  1218.   end
  1219. end
  1220.  
  1221. function writevu8u8(pk,v)
  1222.   local len=8 --table.getn(v)
  1223.   --pk:w_u8(len)
  1224.   for i=1,len,1 do
  1225.     pk:w_u8(v[i])
  1226.   end
  1227. end
  1228.  
  1229. function writevu32u16(pk,v)
  1230.   local len=table.getn(v)
  1231.   pk:w_s32(len)
  1232.   for i=1,len,1 do
  1233.     pk:w_u16(v[i])
  1234.   end
  1235. end
  1236.  
  1237. function parse_object_packet(ret,stpk,updpk)
  1238.   ret.gvid=stpk:r_u16()
  1239.   ret.obf32u1=stpk:r_float()
  1240.   ret.obs32u2=stpk:r_s32()
  1241.   ret.lvid=stpk:r_s32()
  1242.   ret.oflags=stpk:r_s32()
  1243.   ret.custom=stpk:r_stringZ()
  1244.   ret.sid=stpk:r_s32()
  1245.   ret.obs32u3=stpk:r_s32()
  1246.   return ret
  1247. end
  1248.  
  1249. function fill_object_packet(ret,stpk,updpk)
  1250.   stpk:w_u16(ret.gvid)
  1251.   stpk:w_float(ret.obf32u1)
  1252.   stpk:w_s32(ret.obs32u2)
  1253.   stpk:w_s32(ret.lvid)
  1254.   stpk:w_s32(ret.oflags)
  1255.   stpk:w_stringZ(ret.custom)
  1256.   stpk:w_s32(ret.sid)
  1257.   stpk:w_s32(ret.obs32u3)
  1258. end
  1259.  
  1260.  
  1261. function parse_visual_packet(ret,stpk,updpk)
  1262.   ret.visual=stpk:r_stringZ()
  1263.   ret.vsu8u1=stpk:r_u8()
  1264.   return ret
  1265. end
  1266.  
  1267. function fill_visual_packet(ret,stpk,updpk)
  1268.   stpk:w_stringZ(ret.visual)
  1269.   stpk:w_u8(ret.vsu8u1)
  1270. end
  1271.  
  1272. function parse_dynamic_object_visual(ret,stpk,updpk)
  1273.   parse_object_packet(ret,stpk,updpk)
  1274.   parse_visual_packet(ret,stpk,updpk)
  1275.   return ret
  1276. end
  1277.  
  1278. function fill_dynamic_object_visual(ret,stpk,updpk)
  1279.   fill_object_packet(ret,stpk,updpk)
  1280.   fill_visual_packet(ret,stpk,updpk)
  1281. end
  1282.  
  1283. function parse_creature_packet(ret,stpk,updpk)
  1284.   parse_dynamic_object_visual(ret,stpk,updpk)
  1285.   ret.team=stpk:r_u8()
  1286.   ret.squad=stpk:r_u8()
  1287.   ret.group=stpk:r_u8()
  1288.   ret.health=stpk:r_float()
  1289.   ret.crvu32u16u1=readvu32u16(stpk)
  1290.   ret.crvu32u16u2=readvu32u16(stpk)  
  1291.   ret.killerid=stpk:r_u16()
  1292.   ret.game_death_time=readvu8u8(stpk)
  1293.  
  1294.   ret.updhealth=updpk:r_float()
  1295.   ret.upds32u1=updpk:r_s32()
  1296.   ret.updu8u2=updpk:r_u8()
  1297.   ret.updpos={} -- èëè ïîñòàâèòü âåêòîð? ëàäíî ïîòîì
  1298.   ret.updpos.x=updpk:r_float()
  1299.   ret.updpos.y=updpk:r_float()
  1300.   ret.updpos.z=updpk:r_float()
  1301.   ret.updmodel=updpk:r_float()
  1302.   ret.upddir={}
  1303.   ret.upddir.x=updpk:r_float()
  1304.   ret.upddir.y=updpk:r_float()
  1305.   ret.upddir.z=updpk:r_float()
  1306.   ret.updteam=updpk:r_u8()
  1307.   ret.updsquad=updpk:r_u8()
  1308.   ret.updgroup=updpk:r_u8()  
  1309.   return ret
  1310. end
  1311.  
  1312. function fill_creature_packet(ret,stpk,updpk)
  1313.   fill_dynamic_object_visual(ret,stpk,updpk)
  1314.   stpk:w_u8(ret.team)
  1315.   stpk:w_u8(ret.squad)
  1316.   stpk:w_u8(ret.group)
  1317.   stpk:w_float(ret.health)
  1318.   writevu32u16(stpk,ret.crvu32u16u1)
  1319.   writevu32u16(stpk,ret.crvu32u16u2)  
  1320.   stpk:w_u16(ret.killerid)
  1321.   writevu8u8(stpk,ret.game_death_time)
  1322.  
  1323.   updpk:w_float(ret.updhealth)
  1324.   updpk:w_s32(ret.upds32u1)
  1325.   updpk:w_u8(ret.updu8u2)
  1326.   updpk:w_float(ret.updpos.x)
  1327.   updpk:w_float(ret.updpos.y)
  1328.   updpk:w_float(ret.updpos.z)
  1329.   updpk:w_float(ret.updmodel)
  1330.   updpk:w_float(ret.upddir.x)
  1331.   updpk:w_float(ret.upddir.y)
  1332.   updpk:w_float(ret.upddir.z)
  1333.   updpk:w_u8(ret.updteam)
  1334.   updpk:w_u8(ret.updsquad)
  1335.   updpk:w_u8(ret.updgroup)
  1336. end
  1337.  
  1338. function parse_monster_packet(ret,stpk,updpk)
  1339.   parse_creature_packet(ret,stpk,updpk)
  1340.   ret.baseoutr=stpk:r_stringZ()
  1341.   ret.baseinr=stpk:r_stringZ()
  1342.   ret.smtrid=stpk:r_u16()
  1343.   ret.smtrtaskactive=stpk:r_u8()
  1344.  
  1345.   ret.updu16u1=updpk:r_u16()
  1346.   ret.updu16u2=updpk:r_u16()
  1347.   ret.upds32u3=updpk:r_s32()
  1348.   ret.upds32u4=updpk:r_s32()
  1349.   return ret
  1350. end
  1351.  
  1352. function fill_monster_packet(ret,stpk,updpk)
  1353.   fill_creature_packet(ret,stpk,updpk)
  1354.   stpk:w_stringZ(ret.baseoutr)
  1355.   stpk:w_stringZ(ret.baseinr)
  1356.   stpk:w_u16(ret.smtrid)
  1357.   stpk:w_u8(ret.smtrtaskactive)
  1358.  
  1359.   updpk:w_u16(ret.updu16u1)
  1360.   updpk:w_u16(ret.updu16u2)
  1361.   updpk:w_s32(ret.upds32u3)
  1362.   updpk:w_s32(ret.upds32u4)
  1363. end
  1364.  
  1365. function parse_trader_packet(ret,stpk,updpk)
  1366.   ret.money=stpk:r_s32()
  1367.   ret.profile=stpk:r_stringZ()
  1368.   ret.infammo=stpk:r_s32()
  1369.   ret.class=stpk:r_stringZ()
  1370.   ret.communityid=stpk:r_s32()
  1371.   ret.rank=stpk:r_s32()
  1372.   ret.reputation=stpk:r_s32()
  1373.   ret.charname=stpk:r_stringZ()  
  1374.   return ret
  1375. end
  1376.  
  1377. function fill_trader_packet(ret,stpk,updpk)
  1378.   stpk:w_s32(ret.money)
  1379.   stpk:w_stringZ(ret.profile)
  1380.   stpk:w_s32(ret.infammo)
  1381.   stpk:w_stringZ(ret.class)
  1382.   stpk:w_s32(ret.communityid)
  1383.   stpk:w_s32(ret.rank)
  1384.   stpk:w_s32(ret.reputation)
  1385.   stpk:w_stringZ(ret.charname)
  1386. end
  1387.  
  1388. function parse_human_packet(ret,stpk,updpk)
  1389.   parse_trader_packet(ret,stpk,updpk)
  1390.   parse_monster_packet(ret,stpk,updpk)
  1391.   ret.huvu32u8u1=readvu32u8(stpk)
  1392.   ret.huvu32u8u2=readvu32u8(stpk)  
  1393.   return ret
  1394. end
  1395.  
  1396. function fill_human_packet(ret,stpk,updpk)
  1397.   fill_trader_packet(ret,stpk,updpk)
  1398.   fill_monster_packet(ret,stpk,updpk)
  1399.   writevu32u8(stpk,ret.huvu32u8u1)
  1400.   writevu32u8(stpk,ret.huvu32u8u2)
  1401. end
  1402.  
  1403. function parse_skeleton_packet(ret,stpk,updpk)
  1404.   ret.skeleton=stpk:r_stringZ()
  1405.   ret.skeleton_flags=stpk:r_u8()
  1406.   ret.source_id=stpk:r_u16()
  1407.  
  1408. --  ret.updsku8u1=updpk:r_u8()
  1409.   return ret
  1410. end
  1411.  
  1412. function fill_skeleton_packet(ret,stpk,updpk)
  1413.   stpk:w_stringZ(ret.skeleton)
  1414.   stpk:w_u8(ret.skeleton_flags)
  1415.   stpk:w_u16(ret.source_id)
  1416.  
  1417. --  updpk:w_u8(ret.updsku8u1)
  1418. end
  1419.  
  1420. function parse_stalker_packet(ret,stpk,updpk,size)
  1421.   parse_human_packet(ret,stpk,updpk)
  1422.   parse_skeleton_packet(ret,stpk,updpk)
  1423.   ret.hellodlg=updpk:r_stringZ()
  1424.   ret.stunk1={}
  1425.   for i=stpk:r_tell(),size-1,1 do
  1426.     table.insert(ret.stunk1,stpk:r_u8())
  1427.   end
  1428.   return ret
  1429. end
  1430.  
  1431. function fill_stalker_packet(ret,stpk,updpk)
  1432.   fill_human_packet(ret,stpk,updpk)
  1433.   fill_skeleton_packet(ret,stpk,updpk)
  1434.   updpk:w_stringZ(ret.hellodlg)
  1435.   for i,v in ipairs(ret.stunk1) do
  1436.     stpk:w_u8(v)
  1437.   end
  1438. end
  1439.  
  1440. function parse_se_monster_packet(ret,stpk,updpk,size)
  1441.   parse_monster_packet(ret,stpk,updpk,size)
  1442.   parse_skeleton_packet(ret,stpk,updpk,size)
  1443.   ret.spec_obj_id=stpk:r_u16()
  1444.   ret.job_online=stpk:r_u8()
  1445.     if ret.job_online>3 then
  1446.         ret.state=true
  1447.         ret.job_online=ret.job_online-4
  1448.     else
  1449.         ret.state=false
  1450.     end
  1451.   if ret.job_online==3 then
  1452.     ret.job_online_condlist=stpk:r_stringZ()
  1453.   end
  1454.   ret.was_in_smtr=stpk:r_u8()
  1455.   ret.stunk1={}
  1456.   for i=stpk:r_tell(),size-1,1 do
  1457.     table.insert(ret.stunk1,stpk:r_u8())
  1458.   end
  1459.   return ret
  1460. end
  1461.  
  1462. function fill_se_monster_packet(ret,stpk,updpk)
  1463.   fill_monster_packet(ret,stpk,updpk)
  1464.   fill_skeleton_packet(ret,stpk,updpk)
  1465.   stpk:w_u16(ret.spec_obj_id)
  1466.     local st=0
  1467.     if ret.state then
  1468.         st=4
  1469.     end
  1470.   stpk:w_u8(ret.job_online+st)
  1471.   if ret.job_online==3 then
  1472.     stpk:w_stringZ(ret.job_online_condlist)
  1473.   end
  1474.   stpk:w_u8(ret.was_in_smtr)
  1475.   for i,v in ipairs(ret.stunk1) do
  1476.     stpk:w_u8(v)
  1477.   end  
  1478. end
  1479.  
  1480. function dump_table(tbl)
  1481.   for k,v in pairs(tbl) do
  1482.     if type(v)=="table" then
  1483.       get_console():execute("load ~~~ "..tostring(k).." => ")
  1484.       dump_table(v)
  1485.     else
  1486.       str="load ~~~ "..tostring(k).." => "..tostring(v)
  1487.       if string.len(str)>200 then
  1488.         str=string.sub(str,1,200)
  1489.       end
  1490.       get_console():execute(str)
  1491.     end
  1492.   end
  1493.   get_console():execute("flush")
  1494. end
  1495.  
  1496. -- ñåðâåðíûé îáúåêò íà âõîäå
  1497. function read_stalker_params(sobj)
  1498.   local stpk=net_packet()
  1499.   local uppk=net_packet()
  1500.   sobj:STATE_Write(stpk)
  1501.   sobj:UPDATE_Write(uppk)
  1502.   local size=stpk:w_tell()
  1503.   local size1=uppk:w_tell()
  1504.   -- amk.mylog("rsp "..size.." "..size1)
  1505.   stpk:r_seek(0)
  1506.   uppk:r_seek(0)
  1507.   local tbl=amk.parse_stalker_packet({},stpk,uppk,size)
  1508.   -- amk.mylog("rsp "..size.." "..size1.." "..stpk:r_tell())
  1509.   return tbl
  1510. end
  1511.  
  1512. function read_monster_params(sobj)
  1513.   local stpk=net_packet()
  1514.   local uppk=net_packet()
  1515.   sobj:STATE_Write(stpk)
  1516.   sobj:UPDATE_Write(uppk)
  1517.   local size=stpk:w_tell()
  1518.   local size1=uppk:w_tell()
  1519.   stpk:r_seek(0)
  1520.   uppk:r_seek(0)
  1521.   local tbl=amk.parse_se_monster_packet({},stpk,uppk,size)
  1522.   return tbl
  1523. end
  1524.  
  1525. -- òàáëèöà ïàðàìåòðîâ è ñåðâåðíûé îáúåêò íà âõîäå
  1526. function write_stalker_params(tbl,sobj,noconvert)
  1527.   local stpk=net_packet()
  1528.   local uppk=net_packet()
  1529.   amk.fill_stalker_packet(tbl,stpk,uppk)
  1530.   local size=stpk:w_tell()
  1531.   local size1=uppk:w_tell()
  1532.   -- amk.mylog("wsp "..size.." "..size1)
  1533.   stpk:r_seek(0)
  1534.   uppk:r_seek(0)
  1535.   sobj:STATE_Read(stpk,size)
  1536.   sobj:UPDATE_Read(uppk)
  1537.   local npc=level.object_by_id(sobj.id)
  1538.   if npc and (not noconvert) then
  1539.     amk.convert_npc[sobj.id]=true
  1540.         npc:stop_talk()
  1541.     switch_offline(npc)
  1542.   end
  1543. end
  1544.  
  1545. function write_monster_params(tbl,sobj)
  1546.   local stpk=net_packet()
  1547.   local uppk=net_packet()
  1548.   amk.fill_se_monster_packet(tbl,stpk,uppk)
  1549.   local size=stpk:w_tell()
  1550.   local size1=uppk:w_tell()
  1551.   -- amk.mylog("wsp "..size.." "..size1)
  1552.   stpk:r_seek(0)
  1553.   uppk:r_seek(0)
  1554.   sobj:STATE_Read(stpk,size)
  1555.   sobj:UPDATE_Read(uppk)
  1556.   -- local npc=level.object_by_id(sobj.id)
  1557.   -- if npc then
  1558.     -- amk.convert_npc[sobj.id]=true
  1559.     -- switch_offline(npc)
  1560.   -- end
  1561. end
  1562.  
  1563. function get_anomaly_data(sobj)
  1564.   local stpk=net_packet()
  1565.   local uppk=net_packet()
  1566.   sobj:STATE_Write(stpk)
  1567.   sobj:UPDATE_Write(uppk)
  1568.   local size=stpk:w_tell()
  1569.   local size1=uppk:w_tell()
  1570.   stpk:r_seek(0)
  1571.   uppk:r_seek(0)
  1572.   local t={}
  1573.     amk.parse_object_packet(t,stpk,uppk,size)
  1574.   amk.parse_shape_packet(t,stpk,uppk,size)
  1575.  
  1576.     t.restrictor_type = stpk:r_u8()
  1577.    
  1578.     t.max_power = stpk:r_float()
  1579.     t.owner_id = stpk:r_s32()
  1580.     t.enabled_time = stpk:r_s32()
  1581.     t.disabled_time = stpk:r_s32()
  1582.     t.start_time_shift = stpk:r_s32()
  1583.    
  1584.     t.offline_interactive_radius = stpk:r_float()
  1585.     t.artefact_spawn_count = stpk:r_u16()
  1586.     t.artefact_position_offset = stpk:r_s32()
  1587.    
  1588.     t.last_spawn_time_present = stpk:r_u8()
  1589.    
  1590.     if stpk:r_elapsed() ~= 0 then
  1591. --      abort("left=%d", stpk:r_elapsed())
  1592.     end
  1593.     return t
  1594. end
  1595.  
  1596. function set_anomaly_data(t,sobj)
  1597.   local stpk=net_packet()
  1598.   local uppk=net_packet()
  1599.    
  1600.   amk.fill_object_packet(t,stpk,uppk)
  1601.   amk.fill_shape_packet(t,stpk,uppk)
  1602.  
  1603.     stpk:w_u8(t.restrictor_type)
  1604.    
  1605.     stpk:w_float(t.max_power)
  1606.     stpk:w_s32(t.owner_id)
  1607.     stpk:w_s32(t.enabled_time)
  1608.     stpk:w_s32(t.disabled_time)
  1609.     stpk:w_s32(t.start_time_shift)
  1610.    
  1611.     stpk:w_float(t.offline_interactive_radius)
  1612.     stpk:w_u16(t.artefact_spawn_count)
  1613.     stpk:w_s32(t.artefact_position_offset)
  1614.    
  1615.     stpk:w_u8(t.last_spawn_time_present)
  1616.    
  1617.   local size=stpk:w_tell()
  1618.   local size1=uppk:w_tell()
  1619.   stpk:r_seek(0)
  1620.   uppk:r_seek(0)
  1621.   sobj:STATE_Read(stpk,size)
  1622.   sobj:UPDATE_Read(uppk)
  1623. end
  1624.  
  1625. --äëÿ ïðàâèëüíîãî ïàðñèíãà çàïðåùåíû êîììåíòàðèè!!!
  1626. function parse_custom_data(str)
  1627.     local t={}
  1628.     if str then
  1629.         for section, section_data in string.gfind(str,"%s*%[([^%]]*)%]%s*([^%[%z]*)%s*") do
  1630.             section = trim(section)
  1631.             t[section]={}
  1632.             for line in string.gfind(trim(section_data), "([^\n]*)\n*") do
  1633.                 if string.find(line,"=")~=nil then
  1634.                     for k, v in string.gfind(line, "([^=]-)%s*=%s*(.*)") do
  1635.                         k = trim(k)
  1636.                         if k~=nil and k~='' and v~=nil then
  1637.                             t[section][k]=trim(v)
  1638.                         end
  1639.                     end
  1640.                 else
  1641.                     for k, v in string.gfind(line, "(.*)") do
  1642.                         k = trim(k)
  1643.                         if k~=nil and k~='' then
  1644.                             t[section][k]="<<no_value>>"
  1645.                         end
  1646.                     end
  1647.                 end
  1648.             end
  1649.         end
  1650.     end
  1651.     return t
  1652. end
  1653.  
  1654. function trim (s)
  1655.     return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
  1656. end
  1657.  
  1658. function gen_custom_data(tbl)
  1659.     local str=''
  1660.     for key, value in pairs(tbl) do
  1661.         str = str.."\n["..key.."]\n"
  1662.         for k, v in pairs(value) do
  1663.             if v~="<<no_value>>" then
  1664.                 str=str..k.." = "..v.."\n"
  1665.             else
  1666.                 str=str..k.."\n"
  1667.             end
  1668.         end
  1669.     end
  1670.     return str
  1671. end
  1672.  
  1673. function get_lc_data(obj)
  1674.     local packet = net_packet()
  1675.     obj:STATE_Write(packet)
  1676.     local t={}
  1677.     t.game_vertex_id = packet:r_u16()
  1678.     t.distance = packet:r_float()
  1679.     t.direct_control = packet:r_s32()
  1680.     t.level_vertex_id = packet:r_s32()
  1681.     t.object_flags = packet:r_s32()
  1682.     t.custom_data = packet:r_stringZ()
  1683.     t.story_id = packet:r_s32()
  1684.     t.spawn_story_id = packet:r_s32()
  1685.    
  1686.     t = amk.parse_shape_packet(t,packet)
  1687.    
  1688.     t.restrictor_type = packet:r_u8()
  1689.     t.dest_game_vertex_id = packet:r_u16()
  1690.     t.dest_level_vertex_id = packet:r_s32()
  1691.     t.dest_position = packet:r_vec3()
  1692.     t.dest_direction = packet:r_vec3()
  1693.     t.dest_level_name = packet:r_stringZ()
  1694.     t.dest_graph_point = packet:r_stringZ()
  1695.     t.silent_mode = packet:r_u8()
  1696.  
  1697.     if packet:r_elapsed() ~= 0 then
  1698.         abort("left=%d", packet:r_elapsed())
  1699.     end
  1700.     return t
  1701. end
  1702.  
  1703. function set_lc_data(t,obj)
  1704.     local packet = net_packet()
  1705.     obj:STATE_Write(packet)
  1706.     packet:w_begin(t.game_vertex_id)
  1707.     packet:w_float(t.distance)
  1708.     packet:w_s32(t.direct_control)
  1709.     packet:w_s32(t.level_vertex_id)
  1710.     packet:w_s32(t.object_flags)
  1711.     packet:w_stringZ(t.custom_data)
  1712.     packet:w_s32(t.story_id)
  1713.     packet:w_s32(t.spawn_story_id)
  1714.    
  1715.     amk.fill_shape_packet(t,packet)
  1716.  
  1717.     packet:w_u8(t.restrictor_type)
  1718.     packet:w_u16(t.dest_game_vertex_id)
  1719.     packet:w_s32(t.dest_level_vertex_id)
  1720.     packet:w_vec3(t.dest_position)
  1721.     packet:w_vec3(t.dest_direction)
  1722.     packet:w_stringZ(t.dest_level_name)
  1723.     packet:w_stringZ(t.dest_graph_point)
  1724.     packet:w_u8(t.silent_mode)
  1725.  
  1726.     packet:r_seek(0)
  1727.     obj:STATE_Read(packet, packet:w_tell())
  1728. end
  1729.  
  1730. function point_in_poly (pts, x,y)
  1731.     local cnt,k,j
  1732.     local ret = false
  1733.     cnt = table.getn(pts)
  1734.     j = cnt
  1735.     for k = 1,cnt do
  1736.         if ((pts[k].y <=y) and (y < pts[j].y)) or ((pts[j].y <=y) and (y < pts[k].y)) then
  1737.             if (x < (pts[j].x - pts[k].x) * (y - pts[k].y) / (pts[j].y - pts[k].y) + pts[k].x) then
  1738.                 ret = not ret
  1739.             end
  1740.             j = k
  1741.         end
  1742.     end
  1743.     return ret
  1744. end
  1745.  
  1746. function parse_object_physic_packet(ret,stpk,updpk)
  1747.     ret.physic_type=stpk:r_s32()
  1748.     ret.mass=stpk:r_float()
  1749.     ret.fixed_bones=stpk:r_stringZ()
  1750.   return ret
  1751. end
  1752.  
  1753. function fill_object_physic_packet(ret,stpk,updpk)
  1754.     stpk:w_s32(ret.physic_type)
  1755.     stpk:w_float(ret.mass)
  1756.     stpk:w_stringZ(ret.fixed_bones)
  1757. end
  1758.  
  1759. function get_breakable_data(sobj)
  1760.   local stpk=net_packet()
  1761.   local uppk=net_packet()
  1762.   sobj:STATE_Write(stpk)
  1763.   sobj:UPDATE_Write(uppk)
  1764.   local size=stpk:w_tell()
  1765.   local size1=uppk:w_tell()
  1766.   -- amk.mylog("rsp "..size.." "..size1)
  1767.   stpk:r_seek(0)
  1768.   uppk:r_seek(0)
  1769.   local t={}
  1770.     amk.parse_object_packet(t,stpk,uppk,size)
  1771.   amk.parse_visual_packet(t,stpk,uppk,size)
  1772.   amk.parse_object_physic_packet(t,stpk,uppk,size)
  1773.   -- amk.mylog("rsp "..size.." "..size1.." "..stpk:r_tell())
  1774.   return t
  1775. --[[
  1776.     local packet = net_packet()
  1777.     obj:STATE_Write(packet)
  1778.     local t={}
  1779.     t.game_vertex_id = packet:r_u16()
  1780.     t.distance = packet:r_float()
  1781.     t.direct_control = packet:r_s32()
  1782.     t.level_vertex_id = packet:r_s32()
  1783.     t.object_flags = packet:r_s32()
  1784.     t.custom_data = packet:r_stringZ()
  1785.     t.story_id = packet:r_s32()
  1786.     t.spawn_story_id = packet:r_s32()
  1787.    
  1788.     t.visual_name = packet:r_stringZ()
  1789.     t.visual_flags = packet:r_u8()
  1790.    
  1791.     t.health = packet:r_float()
  1792.  
  1793.     if packet:r_elapsed() ~= 0 then
  1794.         abort("left=%d", packet:r_elapsed())
  1795.     end
  1796.     return t
  1797.     ]]
  1798. end
  1799.  
  1800. function set_breakable_data(t,sobj)
  1801.   local stpk=net_packet()
  1802.   local uppk=net_packet()
  1803.    
  1804.   amk.fill_object_packet(t,stpk,uppk)
  1805.   amk.fill_visual_packet(t,stpk,uppk)
  1806.   amk.fill_object_physic_packet(t,stpk,uppk)
  1807.    
  1808.   local size=stpk:w_tell()
  1809.   local size1=uppk:w_tell()
  1810.   -- amk.mylog("wsp "..size.." "..size1)
  1811.   stpk:r_seek(0)
  1812.   uppk:r_seek(0)
  1813.   sobj:STATE_Read(stpk,size)
  1814.   sobj:UPDATE_Read(uppk)
  1815.  
  1816.     --[[
  1817.     local packet = net_packet()
  1818.     obj:STATE_Write(packet)
  1819.     packet:w_begin(t.game_vertex_id)
  1820.     packet:w_float(t.distance)
  1821.     packet:w_s32(t.direct_control)
  1822.     packet:w_s32(t.level_vertex_id)
  1823.     packet:w_s32(t.object_flags)
  1824.     packet:w_stringZ(t.custom_data)
  1825.     packet:w_s32(t.story_id)
  1826.     packet:w_s32(t.spawn_story_id)
  1827.     packet:w_stringZ(t.visual_name)
  1828.     packet:w_u8(t.visual_flags)
  1829.     packet:w_float(t.health)
  1830.  
  1831.     packet:r_seek(0)
  1832.     obj:STATE_Read(packet, packet:w_tell())
  1833.     ]]
  1834. end
  1835.  
  1836. function on_REspawn(obj,respawner)
  1837.     if obj and respawner then
  1838.         mod_call("respawned",obj,respawner)
  1839.         if IsMonster(obj) then
  1840.             if respawner.spawned_goes_online==true then mod_call("switch_monster_online",obj)
  1841.             elseif respawner.spawned_goes_online==false then mod_call("switch_monster_offline",obj) end
  1842.         end
  1843.     end
  1844.     if (obj) then
  1845.         if (news_main and news_main.on_spawn) then
  1846.             news_main.on_spawn(obj)
  1847.         end
  1848.     end
  1849. end
  1850.  
  1851. function get_spawner_data(sobj)
  1852.   local stpk=net_packet()
  1853.   local uppk=net_packet()
  1854.   sobj:STATE_Write(stpk)
  1855.   sobj:UPDATE_Write(uppk)
  1856.   local size=stpk:w_tell()
  1857.   local size1=uppk:w_tell()
  1858.   -- amk.mylog("rsp "..size.." "..size1)
  1859.   stpk:r_seek(0)
  1860.   uppk:r_seek(0)
  1861.   local t={}
  1862.     amk.parse_object_packet(t,stpk,uppk,size)
  1863.   amk.parse_shape_packet(t,stpk,uppk,size)
  1864.    
  1865.     t.restrictor_type = stpk:r_u8()
  1866.     t.spawned_obj_count = stpk:r_u8()
  1867.   -- amk.mylog("rsp "..size.." "..size1.." "..stpk:r_tell())
  1868.   return t
  1869. end
  1870.  
  1871. function set_spawner_data(t,sobj)
  1872.   local stpk=net_packet()
  1873.   local uppk=net_packet()
  1874.    
  1875.   amk.fill_object_packet(t,stpk,uppk)
  1876.   amk.fill_shape_packet(t,stpk,uppk)
  1877.     stpk:w_u8(t.restrictor_type)
  1878.     stpk:w_u8(t.spawned_obj_count)
  1879.    
  1880.   local size=stpk:w_tell()
  1881.   local size1=uppk:w_tell()
  1882.   -- amk.mylog("wsp "..size.." "..size1)
  1883.   stpk:r_seek(0)
  1884.   uppk:r_seek(0)
  1885.   sobj:STATE_Read(stpk,size)
  1886.   sobj:UPDATE_Read(uppk)
  1887. end
  1888.  
  1889. function parse_shape_packet(t,stpk,uppk)
  1890.     local shape_count = stpk:r_u8()
  1891.     t.shapes={}
  1892.     for i=1,shape_count do
  1893.         local shape_type = stpk:r_u8()
  1894.         t.shapes[i]={}
  1895.         t.shapes[i].shtype=shape_type
  1896.         if shape_type == 0 then
  1897.             -- sphere
  1898.             t.shapes[i].center = stpk:r_vec3()
  1899.             t.shapes[i].radius = stpk:r_float()
  1900.         else
  1901.             -- box
  1902.             t.shapes[i].v1 = stpk:r_vec3()
  1903.             t.shapes[i].v2 = stpk:r_vec3()
  1904.             t.shapes[i].v3 = stpk:r_vec3()
  1905.             t.shapes[i].offset = stpk:r_vec3()
  1906.         end
  1907.     end
  1908. end
  1909.  
  1910. function fill_shape_packet(t,stpk,updpk)
  1911.     stpk:w_u8(table.getn(t.shapes))
  1912.     for i=1,table.getn(t.shapes) do
  1913.         stpk:w_u8(t.shapes[i].shtype)
  1914.         if t.shapes[i].shtype == 0 then
  1915.             stpk:w_vec3(t.shapes[i].center)
  1916.             stpk:w_float(t.shapes[i].radius)
  1917.         else
  1918.             stpk:w_vec3(t.shapes[i].v1)
  1919.             stpk:w_vec3(t.shapes[i].v2)
  1920.             stpk:w_vec3(t.shapes[i].v3)
  1921.             stpk:w_vec3(t.shapes[i].offset)
  1922.         end
  1923.     end
  1924. end
  1925.  
  1926. function parse_ini_section_to_array(ini,section)
  1927.     local tmp={}
  1928.     if ini:section_exist(section) then
  1929.         local result, id, value = nil, nil, nil
  1930.         for a=0,ini:line_count(section)-1 do
  1931.             result, id, value = ini:r_line(section,a,"","")
  1932.             if id~=nil and trim(id)~="" and trim(id)~=nil then
  1933.                 tmp[trim(id)]=trim(value)
  1934.             end
  1935.         end
  1936.     end
  1937.     return tmp
  1938. end
  1939.  
  1940. function str_explode(div,str,clear)
  1941.     local t={}
  1942.     local cpt = string.find (str, div, 1, true)
  1943.     if cpt then
  1944.         repeat
  1945.             if clear then
  1946.                 table.insert( t, trim(string.sub(str, 1, cpt-1)) )
  1947.             else
  1948.                 table.insert( t, string.sub(str, 1, cpt-1) )
  1949.             end
  1950.             str = string.sub( str, cpt+string.len(div) )
  1951.             cpt = string.find (str, div, 1, true)
  1952.         until cpt==nil
  1953.     end
  1954.     if clear then
  1955.         table.insert(t, trim(str))
  1956.     else
  1957.         table.insert(t, str)
  1958.     end
  1959.     return t
  1960. end
  1961.  
  1962. function quotemeta(str)
  1963.     return (string.gsub(s, "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1"))
  1964. end
  1965.  
  1966.  
  1967. function add(v1,v2)
  1968.     local nv=vector()
  1969.     nv.x=v1.x+v2.x
  1970.     nv.y=v1.y+v2.y
  1971.     nv.z=v1.z+v2.z
  1972.     return nv
  1973. end
  1974.  
  1975. function set_len(v,num)
  1976.     local cl = math.sqrt(v.x*v.x+v.y*v.y+v.z*v.z)
  1977.     cl = num/cl
  1978.     v.x= v.x*cl
  1979.     v.y= v.y*cl
  1980.     v.z= v.z*cl
  1981.     return v
  1982. end
  1983.  
  1984. function get_restrictor_data(sobj)
  1985.   local stpk=net_packet()
  1986.   local uppk=net_packet()
  1987.   sobj:STATE_Write(stpk)
  1988.   sobj:UPDATE_Write(uppk)
  1989.   local size=stpk:w_tell()
  1990.   local size1=uppk:w_tell()
  1991.   -- amk.mylog("rsp "..size.." "..size1)
  1992.   stpk:r_seek(0)
  1993.   uppk:r_seek(0)
  1994.   local t={}
  1995.     amk.parse_object_packet(t,stpk,uppk,size)
  1996.   amk.parse_shape_packet(t,stpk,uppk,size)
  1997.    
  1998.     t.restrictor_type = stpk:r_u8()
  1999.   -- amk.mylog("rsp "..size.." "..size1.." "..stpk:r_tell())
  2000.   return t
  2001. end
  2002.  
  2003. function set_restrictor_data(t,sobj)
  2004.   local stpk=net_packet()
  2005.   local uppk=net_packet()
  2006.    
  2007.   amk.fill_object_packet(t,stpk,uppk)
  2008.   amk.fill_shape_packet(t,stpk,uppk)
  2009.     stpk:w_u8(t.restrictor_type)
  2010.    
  2011.   local size=stpk:w_tell()
  2012.   local size1=uppk:w_tell()
  2013.   -- amk.mylog("wsp "..size.." "..size1)
  2014.   stpk:r_seek(0)
  2015.   uppk:r_seek(0)
  2016.   sobj:STATE_Read(stpk,size)
  2017.   sobj:UPDATE_Read(uppk)
  2018. end
  2019.  
  2020. function get_trader_data(sobj)
  2021.   local stpk=net_packet()
  2022.   local uppk=net_packet()
  2023.   sobj:STATE_Write(stpk)
  2024.   sobj:UPDATE_Write(uppk)
  2025.   local size=stpk:w_tell()
  2026.   local size1=uppk:w_tell()
  2027.   -- amk.mylog("rsp "..size.." "..size1)
  2028.   stpk:r_seek(0)
  2029.   uppk:r_seek(0)
  2030.   local t={}
  2031.     amk.parse_object_packet(t,stpk,uppk,size)
  2032.   amk.parse_visual_packet(t,stpk,uppk,size)
  2033.   amk.parse_trader_packet(t,stpk,uppk,size)
  2034.   -- amk.mylog("rsp "..size.." "..size1.." "..stpk:r_tell())
  2035.   return t
  2036. end
  2037.  
  2038. function set_trader_data(t,sobj)
  2039.   local stpk=net_packet()
  2040.   local uppk=net_packet()
  2041.    
  2042.   amk.fill_object_packet(t,stpk,uppk)
  2043.   amk.fill_visual_packet(t,stpk,uppk)
  2044.   amk.fill_trader_packet(t,stpk,uppk)
  2045.    
  2046.   local size=stpk:w_tell()
  2047.   local size1=uppk:w_tell()
  2048.   -- amk.mylog("wsp "..size.." "..size1)
  2049.   stpk:r_seek(0)
  2050.   uppk:r_seek(0)
  2051.   sobj:STATE_Read(stpk,size)
  2052.   sobj:UPDATE_Read(uppk)
  2053. end
  2054.  
  2055. function get_invbox_data(sobj)
  2056.   local stpk=net_packet()
  2057.   local uppk=net_packet()
  2058.   sobj:STATE_Write(stpk)
  2059.   sobj:UPDATE_Write(uppk)
  2060.   local size=stpk:w_tell()
  2061.   local size1=uppk:w_tell()
  2062.   -- amk.mylog("rsp "..size.." "..size1)
  2063.   stpk:r_seek(0)
  2064.   uppk:r_seek(0)
  2065.   local t={}
  2066.     amk.parse_object_packet(t,stpk,uppk,size)
  2067.   amk.parse_visual_packet(t,stpk,uppk,size)
  2068.   -- amk.mylog("rsp "..size.." "..size1.." "..stpk:r_tell())
  2069.   return t
  2070. end
  2071.  
  2072. function set_invbox_data(t,sobj)
  2073.   local stpk=net_packet()
  2074.   local uppk=net_packet()
  2075.    
  2076.   amk.fill_object_packet(t,stpk,uppk)
  2077.   amk.fill_visual_packet(t,stpk,uppk)
  2078.    
  2079.   local size=stpk:w_tell()
  2080.   local size1=uppk:w_tell()
  2081.   -- amk.mylog("wsp "..size.." "..size1)
  2082.   stpk:r_seek(0)
  2083.   uppk:r_seek(0)
  2084.   sobj:STATE_Read(stpk,size)
  2085.   sobj:UPDATE_Read(uppk)
  2086. end
  2087.  
  2088. function readvu8uN(packet,n)
  2089.   local v={}
  2090.   for i=1,n,1 do
  2091.     table.insert(v,packet:r_u8())
  2092.   end
  2093.   return v
  2094. end
  2095.  
  2096. function writevu8uN(pk,v)
  2097.   local len=table.getn(v)
  2098.   --pk:w_u8(len)
  2099.   for i=1,len,1 do
  2100.     pk:w_u8(v[i])
  2101.   end
  2102. end
  2103.  
  2104. function parse_item_packet(ret,stpk,updpk)
  2105.     ret.condition=stpk:r_float()
  2106.     ret.updnum_items=updpk:r_u8()
  2107.   ret.updpos={} -- èëè ïîñòàâèòü âåêòîð? ëàäíî ïîòîì
  2108.   ret.updpos.x=updpk:r_float()
  2109.   ret.updpos.y=updpk:r_float()
  2110.   ret.updpos.z=updpk:r_float()
  2111.     ret.updcse_alife_item__unk1_q8v4=readvu8uN(updpk,4)
  2112.     ret.updcse_alife_item__unk2_q8v3=readvu8uN(updpk,3)
  2113.     ret.updcse_alife_item__unk3_q8v3=readvu8uN(updpk,3)
  2114.   return ret
  2115. end
  2116.  
  2117. function fill_item_packet(ret,stpk,updpk)
  2118.     stpk:w_float(ret.condition)
  2119.     updpk:w_u8(ret.updnum_items)
  2120.   updpk:w_float(ret.updpos.x)
  2121.   updpk:w_float(ret.updpos.y)
  2122.   updpk:w_float(ret.updpos.z)
  2123.     readvu8uN(updpk,ret.updcse_alife_item__unk1_q8v4)
  2124.     readvu8uN(updpk,ret.updcse_alife_item__unk2_q8v3)
  2125.     readvu8uN(updpk,ret.updcse_alife_item__unk3_q8v3)
  2126.   return ret
  2127. end
  2128.  
  2129. function parse_item_ammo_packet(ret,stpk,updpk)
  2130.     ret.ammo_left=stpk:r_u16()
  2131.     ret.updammo_left=updpk:r_u16()
  2132.   return ret
  2133. end
  2134.  
  2135. function fill_item_ammo_packet(ret,stpk,updpk)
  2136.     stpk:w_u16(ret.ammo_left)
  2137.     updpk:w_u16(ret.updammo_left)
  2138.   return ret
  2139. end
  2140.  
  2141. function get_ammo_params(sobj)
  2142.   local stpk=net_packet()
  2143.   local uppk=net_packet()
  2144.   sobj:STATE_Write(stpk)
  2145.   sobj:UPDATE_Write(uppk)
  2146.   local size=stpk:w_tell()
  2147.   local size1=uppk:w_tell()
  2148.   stpk:r_seek(0)
  2149.   uppk:r_seek(0)
  2150.   local t={}
  2151.     amk.parse_object_packet(t,stpk,uppk,size)
  2152.   amk.parse_visual_packet(t,stpk,uppk,size)
  2153.   amk.parse_item_packet(t,stpk,uppk,size)
  2154.   amk.parse_item_ammo_packet(t,stpk,uppk,size)
  2155.   return t
  2156. end
  2157.  
  2158. function set_ammo_data(t,sobj)
  2159.   local stpk=net_packet()
  2160.   local uppk=net_packet()
  2161.    
  2162.   amk.fill_object_packet(t,stpk,uppk)
  2163.   amk.fill_visual_packet(t,stpk,uppk)
  2164.   amk.fill_item_packet(t,stpk,uppk)
  2165.   amk.fill_item_ammo_packet(t,stpk,uppk)
  2166.    
  2167.   local size=stpk:w_tell()
  2168.   local size1=uppk:w_tell()
  2169.   stpk:r_seek(0)
  2170.   uppk:r_seek(0)
  2171.   sobj:STATE_Read(stpk,size)
  2172.   sobj:UPDATE_Read(uppk)
  2173. end
  2174.  
  2175. function cfg_get_string(ini,sect,name,def)
  2176.     if ini and ini:line_exist(sect,name) then
  2177.         return ini:r_string(sect,name)
  2178.     end
  2179.     return def
  2180. end
  2181.  
  2182. function get_destroyable_data(sobj)
  2183.   local stpk=net_packet()
  2184.   local uppk=net_packet()
  2185.   sobj:STATE_Write(stpk)
  2186.   sobj:UPDATE_Write(uppk)
  2187.   local size=stpk:w_tell()
  2188.   local size1=uppk:w_tell()
  2189.   -- amk.mylog("rsp "..size.." "..size1)
  2190.   stpk:r_seek(0)
  2191.   uppk:r_seek(0)
  2192.   local t={}
  2193.     amk.parse_object_packet(t,stpk,uppk,size)
  2194.   amk.parse_visual_packet(t,stpk,uppk,size)
  2195.   amk.parse_skeleton_packet(t,stpk,uppk,size)
  2196.   amk.parse_object_physic_packet(t,stpk,uppk,size)
  2197.   -- amk.mylog("rsp "..size.." "..size1.." "..stpk:r_tell())
  2198.   return t
  2199. end
  2200.  
  2201. function set_destroyable_data(t,sobj)
  2202.   local stpk=net_packet()
  2203.   local uppk=net_packet()
  2204.    
  2205.   amk.fill_object_packet(t,stpk,uppk)
  2206.   amk.fill_visual_packet(t,stpk,uppk)
  2207.   amk.fill_skeleton_packet(t,stpk,uppk)
  2208.   amk.fill_object_physic_packet(t,stpk,uppk)
  2209.    
  2210.   local size=stpk:w_tell()
  2211.   local size1=uppk:w_tell()
  2212.   -- amk.mylog("wsp "..size.." "..size1)
  2213.   stpk:r_seek(0)
  2214.   uppk:r_seek(0)
  2215.   sobj:STATE_Read(stpk,size)
  2216.   sobj:UPDATE_Read(uppk)
  2217.  
  2218. end
  2219.  
  2220. function get_weapon_data(sobj)
  2221.   local stpk=net_packet()
  2222.   local uppk=net_packet()
  2223.   sobj:STATE_Write(stpk)
  2224.   sobj:UPDATE_Write(uppk)
  2225.   local size=stpk:w_tell()
  2226.   local size1=uppk:w_tell()
  2227.   -- amk.mylog("rsp "..size.." "..size1)
  2228.   stpk:r_seek(0)
  2229.   uppk:r_seek(0)
  2230.   local t={}
  2231.   amk.parse_object_packet(t,stpk,uppk,size)
  2232.   amk.parse_visual_packet(t,stpk,uppk,size)
  2233.   amk.parse_item_packet(t,stpk,uppk,size)
  2234.   amk.parse_item_weapon_packet(t,stpk,uppk,size)
  2235.   -- amk.mylog("rsp "..size.." "..size1.." "..stpk:r_tell())
  2236.   return t
  2237. end
  2238.  
  2239. function set_weapon_data(t,sobj)
  2240.   local stpk=net_packet()
  2241.   local uppk=net_packet()
  2242.    
  2243.   amk.fill_object_packet(t,stpk,uppk)
  2244.   amk.fill_visual_packet(t,stpk,uppk)
  2245.   amk.fill_item_packet(t,stpk,uppk)
  2246.   amk.fill_item_weapon_packet(t,stpk,uppk)
  2247.    
  2248.   local size=stpk:w_tell()
  2249.   local size1=uppk:w_tell()
  2250.   -- amk.mylog("wsp "..size.." "..size1)
  2251.   stpk:r_seek(0)
  2252.   uppk:r_seek(0)
  2253.   sobj:STATE_Read(stpk,size)
  2254.   sobj:UPDATE_Read(uppk)
  2255.  
  2256. end
  2257.  
  2258. function parse_item_weapon_packet(ret,stpk,updpk)
  2259.     ret.ammo_current = stpk:r_u16()
  2260.     ret.ammo_elapsed = stpk:r_u16()
  2261.     ret.weapon_state = stpk:r_u8()
  2262.     ret.addon_flags = stpk:r_u8()
  2263.     ret.ammo_type = stpk:r_u8()
  2264.    
  2265.     ret.updcondition = updpk:r_u8()
  2266.     ret.updweapon_flags = updpk:r_u8()
  2267.     ret.updammo_elapsed = updpk:r_u16()
  2268.     ret.updaddon_flags = updpk:r_u8()
  2269.     ret.updammo_type = updpk:r_u8()
  2270.     ret.updweapon_state = updpk:r_u8()
  2271.     ret.updweapon_zoom = updpk:r_u8()
  2272.     ret.updcurrent_fire_mode = updpk:r_u8()
  2273.   return ret
  2274. end
  2275.  
  2276. function fill_item_weapon_packet(ret,stpk,updpk)
  2277.     stpk:w_u16(ret.ammo_current)
  2278.     stpk:w_u16(ret.ammo_elapsed)
  2279.     stpk:w_u8(ret.weapon_state)
  2280.     stpk:w_u8(ret.addon_flags)
  2281.     stpk:w_u8(ret.ammo_type)
  2282.    
  2283.     updpk:w_u8(ret.updcondition)
  2284.     updpk:w_u8(ret.updweapon_flags)
  2285.     updpk:w_u16(ret.updammo_elapsed)
  2286.     updpk:w_u8(ret.updaddon_flags)
  2287.     updpk:w_u8(ret.updammo_type)
  2288.     updpk:w_u8(ret.updweapon_state)
  2289.     updpk:w_u8(ret.updweapon_zoom)
  2290.     updpk:w_u8(ret.updcurrent_fire_mode)
  2291.   return ret
  2292. end
  2293.  
  2294. function get_ver()
  2295.     local ver = "0"
  2296.     local mm = _G.main_menu.get_main_menu()
  2297.     if mm then ver = mm:GetGSVer() end
  2298.     return ver
  2299. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top