Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---- Rulix aka Bak --- 25.3.2009
- --------------------------------------utils------------------------------------------
- function item_is_fa(o)
- local c = o and o:clsid()
- local t = {
- [clsid.wpn_pm_s] = true,
- [clsid.wpn_walther_s] = true,
- [clsid.wpn_usp45_s] = true,
- [clsid.wpn_hpsa_s] = true,
- [clsid.wpn_bm16_s] = true,
- [clsid.wpn_shotgun_s] = true,
- [clsid.wpn_ak74_s] = true,
- [clsid.wpn_lr300_s] = true,
- [clsid.wpn_groza_s] = true,
- [clsid.wpn_val_s] = true,
- [clsid.wpn_vintorez_s] = true,
- [clsid.wpn_svu_s] = true,
- [clsid.wpn_svd_s] = true,
- [clsid.wpn_rg6_s] = true,
- [clsid.wpn_rpg7_s] = true,
- [clsid.wpn_knife_s] = true}
- if c and t[c] then
- return true
- end
- return false
- end
- function printf(str,...)
- if not str then
- str = "((string is nil))"
- end
- get_console():execute("load ~#I#:"..string.format(str,...))
- get_console():execute("flush")
- end
- function read_from_ini(ini,sec,val,def,typ)
- if not ini then
- ini = system_ini()
- end
- if ini:section_exist(sec) and ini:line_exist(sec,val) then
- if typ == 0 then
- return ini:r_bool(sec,val)
- elseif typ == 1 then
- return ini:r_string(sec,val)
- elseif typ == 2 then
- return ini:r_string_wq(sec,val)
- else
- return ini:r_float(sec,val)
- end
- else
- return def
- end
- end
- function str_explode(a,b,c)
- return xr_s.str_explode(a,b,c)
- end
- function get_weapon_data(a)
- return {}
- end
- function collect_sections(ini,sections)
- local r,p = {},{}
- for k,v in ipairs(sections) do
- if ini:section_exist(v) then
- local n = ini:line_count(v)
- if n > 0 then
- for i = 0,n-1 do
- local res, id, val = ini:r_line(v,i,"","")
- if r[id] == nil then
- r[id] = val
- end
- end
- end
- p[k] = n
- else
- p[k] = 0
- end
- end
- return r,p
- end
- function count_table(t)
- if type(t) ~= "table" then
- return
- end
- local cnt = 0
- for k,v in pairs(t) do
- cnt = cnt+1
- end
- return cnt
- end
- ------------------------------------callbacks--------------------------------------
- function actor_update()
- if db.actor and db.actor:alive() then
- if rx_wmgr then
- rx_wmgr.global_update()
- end
- -- db.actor.power = 1
- -- db.actor.health = 1
- end
- if rx_gl then
- rx_gl.update()
- end
- end
- function actor_net_spawn()
- if rx_gl then
- rx_gl.net_spawn()
- end
- end
- function actor_item_take(item)
- if rx_gl then
- rx_gl.fake_pickup(item)
- end
- end
- function actor_save(p)
- if rx_wmgr then
- rx_wmgr.return_all()
- end
- end
- function npc_update(npc,st)
- if npc and npc:alive() then
- if st.wm then
- st.wm:update()
- end
- if rx_gl then
- rx_gl.npc_update(npc,st)
- end
- eat_medkit(npc)
- --[[ local amgr = npc:motivation_action_manager()
- if db.actor and npc:position():distance_to(db.actor:position()) < 4 then
- printf("npc:name = [%s], power = [%s]",npc:name(),npc.power)
- printf("npc: name = [%s], section = [%s]",npc:name(),npc:section())
- local actid = amgr:current_action_id()
- printf("action id[%s] = [%s]",npc:character_name(),tostring(actid))
- end]]
- end
- end
- function npc_switch_offline(npc)
- if rx_wmgr then
- rx_wmgr.kill_wm(npc)
- end
- end
- function npc_death(npc,who)
- if npc then
- if rx_wmgr then
- rx_wmgr.kill_wm(npc)
- end
- if rx_gl then
- rx_gl.death(npc)
- end
- -- issue_event(npc,"death_callback",who)
- unsubscribe_from_events(npc)
- end
- end
- function npc_hit(npc,amount,dir,who,bone_id)
- if npc and amount ~= 0 then
- issue_event(npc,"hit_callback",amount,dir,who,bone_id)
- -- printf("hit!,npc %s,bone %s,who %s,amount %s",npc:id(),bone_id,who:name(),amount)
- end
- end
- function issue_event(npc,name,...)
- local st = db.storage[npc:id()]
- if not st or not st.rx_callbacks then
- return
- end
- -- printf("issue[%s]:%s",npc:name(),name)
- for k,v in pairs(st.rx_callbacks) do
- if v and k[name] then
- k[name](k,...)
- end
- end
- end
- function subscribe_for_events(npc,obj)
- local st = db.storage[npc:id()]
- -- printf("subscribe[%s]",npc:name())
- if not st.rx_callbacks then
- st.rx_callbacks = {}
- end
- st.rx_callbacks[obj] = true
- end
- function unsubscribe_from_events(npc,obj)
- -- printf("unsubscribe[%s]",npc:name())
- local st = db.storage[npc:id()]
- if st and st.rx_callbacks then
- if obj then
- st.rx_callbacks[obj] = nil
- else
- st.rx_callbacks = nil
- end
- end
- end
- function load_schemes()
- if rx_reload then
- load_scheme("rx_reload","reload",stype_stalker)
- end
- if rx_gl then
- load_scheme("rx_gl","launch_grenade",stype_stalker)
- end
- if rx_facer then
- load_scheme("rx_facer","facer",stype_stalker)
- end
- if rx_knife then
- load_scheme("rx_knife","knife",stype_stalker)
- end
- if rx_ff then
- load_scheme("rx_ff","rx_ff",stype_stalker)
- end
- end
- function disable_schemes(npc)
- --[[ if rx_reload then
- rx_reload.disable_scheme(npc,"reload")
- end
- if rx_gl then
- rx_gl.disable_scheme(npc,"launch_grenade")
- end
- if rx_facer then
- rx_facer.disable_scheme(npc,"facer")
- end
- if rx_knife then
- rx_knife.disable_scheme(npc,"knife")
- end]]
- end
- function enable_schemes(ini,npc)
- if rx_reload then
- rx_reload.set_scheme(npc,ini,"reload","reload")
- end
- if rx_gl then
- rx_gl.set_scheme(npc,ini,"launch_grenade","launch_grenade")
- end
- if rx_facer then
- rx_facer.set_scheme(npc,ini,"facer","facer")
- end
- if rx_knife then
- rx_knife.set_scheme(npc,ini,"knife","knife")
- end
- if rx_ff then
- rx_ff.set_scheme(npc,ini,"rx_ff","rx_ff")
- end
- end
- function addCommonPrecondition(action)
- if rx_reload then
- action:add_precondition(world_property(rx_reload.evid_reload,false))
- end
- if rx_gl then
- -- action:add_precondition(world_property(rx_gl.evid_gl_fire,false))
- action:add_precondition(world_property(rx_gl.evid_gl_reload,false))
- end
- if rx_knife then
- -- action:add_precondition(world_property(rx_knife.evid_knife_attack,false))
- end
- end
- ------------------------------------eating----------------------------------------
- local rx_ini = ini_file("misc\\rx_ai.ltx")
- local eating = {enabled = rx_ini:section_exist("npc_eating") and rx_ini:r_bool("npc_eating","enabled")}
- if eating.enabled then
- eating.oic = rx_ini:r_bool("npc_eating","only_in_combat")
- eating.max_h = rx_ini:r_float("npc_eating","medkit_health")/100
- eating.min_b = rx_ini:r_float("npc_eating","bandage_bleeding")
- eating.medkits = str_explode(",",rx_ini:r_string("npc_eating","medkits"),true)
- eating.bandages = str_explode(",",rx_ini:r_string("npc_eating","bandages"),true)
- eating.delay = str_explode(",",rx_ini:r_string("npc_eating","delay"),true)
- end
- function eat_medkit(npc)
- if not eating.enabled then
- return
- end
- local id = npc:id()
- if eating.oic and not npc:best_enemy() then
- eating[id] = nil
- return
- end
- if eating[id] and eating[id].item and eating[id].time then
- if eating[id].time < time_global() then
- -- printf("[%s]eat[%s]",npc:character_name(),eating[id].item:section())
- npc:eat(eating[id].item)
- eating[id].item = nil
- end
- return
- end
- if npc.health < eating.max_h and not xr_wounded.is_wounded(npc) then
- for k,v in ipairs(eating.medkits) do
- local medkit = npc:object(v)
- if medkit then
- -- printf("health[%s]=%s:set[%s]",npc:character_name(),npc.health,v)
- eating[id] = {}
- eating[id].time = time_global() + math.random(eating.delay[1],eating.delay[2])
- eating[id].item = medkit
- return
- end
- end
- end
- if npc:get_bleeding() > eating.min_b then
- for k,v in ipairs(eating.bandages) do
- local bandage = npc:object(v)
- if bandage then
- -- printf("bleeding[%s]=%s:set[%s]",npc:character_name(),npc:get_bleeding(),v)
- eating[id] = {}
- eating[id].time = time_global() + math.random(eating.delay[1],eating.delay[2])
- eating[id].item = bandage
- return
- end
- end
- end
- end
- function on_menu_close()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement