Advertisement
Guest User

rx_ai.script

a guest
Feb 18th, 2014
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.70 KB | None | 0 0
  1. ---- Rulix aka Bak --- 25.3.2009
  2.  
  3. --------------------------------------utils------------------------------------------
  4. function item_is_fa(o)
  5. local c = o and o:clsid()
  6. local t = {
  7. [clsid.wpn_pm_s] = true,
  8. [clsid.wpn_walther_s] = true,
  9. [clsid.wpn_usp45_s] = true,
  10. [clsid.wpn_hpsa_s] = true,
  11. [clsid.wpn_bm16_s] = true,
  12. [clsid.wpn_shotgun_s] = true,
  13. [clsid.wpn_ak74_s] = true,
  14. [clsid.wpn_lr300_s] = true,
  15. [clsid.wpn_groza_s] = true,
  16. [clsid.wpn_val_s] = true,
  17. [clsid.wpn_vintorez_s] = true,
  18. [clsid.wpn_svu_s] = true,
  19. [clsid.wpn_svd_s] = true,
  20. [clsid.wpn_rg6_s] = true,
  21. [clsid.wpn_rpg7_s] = true,
  22. [clsid.wpn_knife_s] = true}
  23. if c and t[c] then
  24. return true
  25. end
  26. return false
  27. end
  28.  
  29. function printf(str,...)
  30. if not str then
  31. str = "((string is nil))"
  32. end
  33. get_console():execute("load ~#I#:"..string.format(str,...))
  34. get_console():execute("flush")
  35. end
  36.  
  37. function read_from_ini(ini,sec,val,def,typ)
  38. if not ini then
  39. ini = system_ini()
  40. end
  41. if ini:section_exist(sec) and ini:line_exist(sec,val) then
  42. if typ == 0 then
  43. return ini:r_bool(sec,val)
  44. elseif typ == 1 then
  45. return ini:r_string(sec,val)
  46. elseif typ == 2 then
  47. return ini:r_string_wq(sec,val)
  48. else
  49. return ini:r_float(sec,val)
  50. end
  51. else
  52. return def
  53. end
  54. end
  55.  
  56. function str_explode(a,b,c)
  57. return xr_s.str_explode(a,b,c)
  58. end
  59.  
  60. function get_weapon_data(a)
  61. return {}
  62. end
  63.  
  64. function collect_sections(ini,sections)
  65. local r,p = {},{}
  66. for k,v in ipairs(sections) do
  67. if ini:section_exist(v) then
  68. local n = ini:line_count(v)
  69. if n > 0 then
  70. for i = 0,n-1 do
  71. local res, id, val = ini:r_line(v,i,"","")
  72. if r[id] == nil then
  73. r[id] = val
  74. end
  75. end
  76. end
  77. p[k] = n
  78. else
  79. p[k] = 0
  80. end
  81. end
  82. return r,p
  83. end
  84.  
  85. function count_table(t)
  86. if type(t) ~= "table" then
  87. return
  88. end
  89. local cnt = 0
  90. for k,v in pairs(t) do
  91. cnt = cnt+1
  92. end
  93. return cnt
  94. end
  95.  
  96. ------------------------------------callbacks--------------------------------------
  97. function actor_update()
  98. if db.actor and db.actor:alive() then
  99. if rx_wmgr then
  100. rx_wmgr.global_update()
  101. end
  102. -- db.actor.power = 1
  103. -- db.actor.health = 1
  104. end
  105. if rx_gl then
  106. rx_gl.update()
  107. end
  108. end
  109.  
  110. function actor_net_spawn()
  111. if rx_gl then
  112. rx_gl.net_spawn()
  113. end
  114. end
  115.  
  116. function actor_item_take(item)
  117. if rx_gl then
  118. rx_gl.fake_pickup(item)
  119. end
  120. end
  121.  
  122. function actor_save(p)
  123. if rx_wmgr then
  124. rx_wmgr.return_all()
  125. end
  126. end
  127.  
  128. function npc_update(npc,st)
  129. if npc and npc:alive() then
  130. if st.wm then
  131. st.wm:update()
  132. end
  133. if rx_gl then
  134. rx_gl.npc_update(npc,st)
  135. end
  136. eat_medkit(npc)
  137. --[[ local amgr = npc:motivation_action_manager()
  138. if db.actor and npc:position():distance_to(db.actor:position()) < 4 then
  139. printf("npc:name = [%s], power = [%s]",npc:name(),npc.power)
  140. printf("npc: name = [%s], section = [%s]",npc:name(),npc:section())
  141. local actid = amgr:current_action_id()
  142. printf("action id[%s] = [%s]",npc:character_name(),tostring(actid))
  143. end]]
  144. end
  145. end
  146.  
  147. function npc_switch_offline(npc)
  148. if rx_wmgr then
  149. rx_wmgr.kill_wm(npc)
  150. end
  151. end
  152.  
  153. function npc_death(npc,who)
  154. if npc then
  155. if rx_wmgr then
  156. rx_wmgr.kill_wm(npc)
  157. end
  158. if rx_gl then
  159. rx_gl.death(npc)
  160. end
  161. -- issue_event(npc,"death_callback",who)
  162. unsubscribe_from_events(npc)
  163. end
  164. end
  165.  
  166. function npc_hit(npc,amount,dir,who,bone_id)
  167. if npc and amount ~= 0 then
  168. issue_event(npc,"hit_callback",amount,dir,who,bone_id)
  169. -- printf("hit!,npc %s,bone %s,who %s,amount %s",npc:id(),bone_id,who:name(),amount)
  170. end
  171. end
  172.  
  173. function issue_event(npc,name,...)
  174. local st = db.storage[npc:id()]
  175. if not st or not st.rx_callbacks then
  176. return
  177. end
  178. -- printf("issue[%s]:%s",npc:name(),name)
  179. for k,v in pairs(st.rx_callbacks) do
  180. if v and k[name] then
  181. k[name](k,...)
  182. end
  183. end
  184. end
  185.  
  186. function subscribe_for_events(npc,obj)
  187. local st = db.storage[npc:id()]
  188. -- printf("subscribe[%s]",npc:name())
  189. if not st.rx_callbacks then
  190. st.rx_callbacks = {}
  191. end
  192. st.rx_callbacks[obj] = true
  193. end
  194.  
  195. function unsubscribe_from_events(npc,obj)
  196. -- printf("unsubscribe[%s]",npc:name())
  197. local st = db.storage[npc:id()]
  198. if st and st.rx_callbacks then
  199. if obj then
  200. st.rx_callbacks[obj] = nil
  201. else
  202. st.rx_callbacks = nil
  203. end
  204. end
  205. end
  206.  
  207. function load_schemes()
  208. if rx_reload then
  209. load_scheme("rx_reload","reload",stype_stalker)
  210. end
  211. if rx_gl then
  212. load_scheme("rx_gl","launch_grenade",stype_stalker)
  213. end
  214. if rx_facer then
  215. load_scheme("rx_facer","facer",stype_stalker)
  216. end
  217. if rx_knife then
  218. load_scheme("rx_knife","knife",stype_stalker)
  219. end
  220. if rx_ff then
  221. load_scheme("rx_ff","rx_ff",stype_stalker)
  222. end
  223. end
  224.  
  225. function disable_schemes(npc)
  226. --[[ if rx_reload then
  227. rx_reload.disable_scheme(npc,"reload")
  228. end
  229. if rx_gl then
  230. rx_gl.disable_scheme(npc,"launch_grenade")
  231. end
  232. if rx_facer then
  233. rx_facer.disable_scheme(npc,"facer")
  234. end
  235. if rx_knife then
  236. rx_knife.disable_scheme(npc,"knife")
  237. end]]
  238. end
  239.  
  240. function enable_schemes(ini,npc)
  241. if rx_reload then
  242. rx_reload.set_scheme(npc,ini,"reload","reload")
  243. end
  244. if rx_gl then
  245. rx_gl.set_scheme(npc,ini,"launch_grenade","launch_grenade")
  246. end
  247. if rx_facer then
  248. rx_facer.set_scheme(npc,ini,"facer","facer")
  249. end
  250. if rx_knife then
  251. rx_knife.set_scheme(npc,ini,"knife","knife")
  252. end
  253. if rx_ff then
  254. rx_ff.set_scheme(npc,ini,"rx_ff","rx_ff")
  255. end
  256. end
  257.  
  258. function addCommonPrecondition(action)
  259. if rx_reload then
  260. action:add_precondition(world_property(rx_reload.evid_reload,false))
  261. end
  262. if rx_gl then
  263. -- action:add_precondition(world_property(rx_gl.evid_gl_fire,false))
  264. action:add_precondition(world_property(rx_gl.evid_gl_reload,false))
  265. end
  266. if rx_knife then
  267. -- action:add_precondition(world_property(rx_knife.evid_knife_attack,false))
  268. end
  269. end
  270. ------------------------------------eating----------------------------------------
  271.  
  272. local rx_ini = ini_file("misc\\rx_ai.ltx")
  273. local eating = {enabled = rx_ini:section_exist("npc_eating") and rx_ini:r_bool("npc_eating","enabled")}
  274. if eating.enabled then
  275. eating.oic = rx_ini:r_bool("npc_eating","only_in_combat")
  276. eating.max_h = rx_ini:r_float("npc_eating","medkit_health")/100
  277. eating.min_b = rx_ini:r_float("npc_eating","bandage_bleeding")
  278. eating.medkits = str_explode(",",rx_ini:r_string("npc_eating","medkits"),true)
  279. eating.bandages = str_explode(",",rx_ini:r_string("npc_eating","bandages"),true)
  280. eating.delay = str_explode(",",rx_ini:r_string("npc_eating","delay"),true)
  281. end
  282.  
  283.  
  284. function eat_medkit(npc)
  285. if not eating.enabled then
  286. return
  287. end
  288. local id = npc:id()
  289. if eating.oic and not npc:best_enemy() then
  290. eating[id] = nil
  291. return
  292. end
  293. if eating[id] and eating[id].item and eating[id].time then
  294. if eating[id].time < time_global() then
  295. -- printf("[%s]eat[%s]",npc:character_name(),eating[id].item:section())
  296. npc:eat(eating[id].item)
  297. eating[id].item = nil
  298. end
  299. return
  300. end
  301. if npc.health < eating.max_h and not xr_wounded.is_wounded(npc) then
  302. for k,v in ipairs(eating.medkits) do
  303. local medkit = npc:object(v)
  304. if medkit then
  305. -- printf("health[%s]=%s:set[%s]",npc:character_name(),npc.health,v)
  306. eating[id] = {}
  307. eating[id].time = time_global() + math.random(eating.delay[1],eating.delay[2])
  308. eating[id].item = medkit
  309. return
  310. end
  311. end
  312. end
  313. if npc:get_bleeding() > eating.min_b then
  314. for k,v in ipairs(eating.bandages) do
  315. local bandage = npc:object(v)
  316. if bandage then
  317. -- printf("bleeding[%s]=%s:set[%s]",npc:character_name(),npc:get_bleeding(),v)
  318. eating[id] = {}
  319. eating[id].time = time_global() + math.random(eating.delay[1],eating.delay[2])
  320. eating[id].item = bandage
  321. return
  322. end
  323. end
  324. end
  325. end
  326.  
  327. function on_menu_close()
  328. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement