Advertisement
Guest User

Untitled

a guest
Oct 27th, 2015
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. -- Handler for scripted keybinds
  2.  
  3.  
  4. -- keybind_name = default
  5. -- To add new keybinds, simplay add name here and default keypress. Then make an action.<name> function for it. Param passed is true if pressed or false if released
  6. local keybinds = {
  7. ["companion_cycle_combat_mode"] = "DIK_NUMPAD1",
  8. ["companion_cycle_move_mode"] = "DIK_NUMPAD2",
  9. ["companion_move_to_point"] = "DIK_NUMPAD3",
  10. ["debug_demo_record"] = "DIK_NUMPAD0",
  11. ["debug_select_object"] = "DIK_NUMPAD9",
  12. ["debug_attachment_ui"] = "DIK_INSERT",
  13. ["debug_test"] = "DIK_NUMPADENTER",
  14. ["debug_reload_game"] = "DIK_END",
  15. ["debug_hold_action"] = "DIK_NUMPAD8",
  16. ["photo_increase_middlegray"] = "DIK_ADD",
  17. ["photo_decrease_middlegray"] = "DIK_SUBTRACT"
  18. }
  19. local action = {}
  20.  
  21. local middlegray_value = 1.0
  22. ------------------------------------------------------------------
  23. -- Keypress actions
  24. ------------------------------------------------------------------
  25. function action.companion_cycle_combat_mode(p)
  26. if (p==1) then
  27. axr_companions.cycle_companions_combat_mode()
  28. end
  29. end
  30.  
  31. function action.companion_cycle_move_mode(p)
  32. if (p==1) then
  33. axr_companions.cycle_companions_move_mode()
  34. end
  35. end
  36.  
  37. function action.companion_move_to_point(p)
  38. axr_companions.move_to_point(p)
  39. end
  40.  
  41. function action.debug_demo_record(p)
  42. if not (DEV_DEBUG) then
  43. return
  44. end
  45. if (p==1) then
  46. get_console():execute("demo_record t")
  47. end
  48. end
  49.  
  50. function action.debug_attachment_ui(p)
  51. if not (DEV_DEBUG) then
  52. return
  53. end
  54. if (p==1) then
  55. if not (this.debug_ui_attach) then
  56. this.debug_ui_attach = ui_debug_main.debug_ui_attach()
  57. end
  58.  
  59. if (this.debug_ui_attach) then
  60. if not (this.debug_ui_attach:IsShown()) then
  61. this.debug_ui_attach:ShowDialog(true)
  62. else
  63. this.debug_ui_attach:HideDialog()
  64. end
  65. end
  66. end
  67. end
  68.  
  69. function action.debug_select_object(p)
  70. if not (DEV_DEBUG) then
  71. return
  72. end
  73. if (p==1) then
  74. DEBUG_NPC = level.get_target_obj and level.get_target_obj()
  75. if (DEBUG_NPC) then
  76. SetHudMsg(strformat("%s Hold then release key to new position",DEBUG_NPC:name()),8)
  77. end
  78. elseif (p==0) then
  79. if (DEBUG_NPC) then
  80. local r = level.get_target_dist and level.get_target_dist()
  81. if (r) then
  82. if (IsStalker(DEBUG_NPC) or IsMonster(DEBUG_NPC)) then
  83. local lvid = level.vertex_in_direction(level.vertex_id(device().cam_pos),device().cam_dir,r)
  84. if (lvid) then
  85. DEBUG_NPC:set_npc_position(level.vertex_position(lvid))
  86. end
  87. else
  88. local pos = vector():set(device().cam_pos)
  89. pos:add(device().cam_dir:mul(r))
  90.  
  91. local lvid = level.vertex_id(pos)
  92. if (lvid < 4294967295) then
  93. TeleportObject(DEBUG_NPC:id(),pos,lvid,db.actor:game_vertex_id())
  94. else
  95. SetHudMsg("Position not on AI Map",4)
  96. end
  97. end
  98. end
  99. SetHudMsg("",1)
  100. end
  101. end
  102. end
  103.  
  104. function action.debug_test(p)
  105. if not (DEV_DEBUG) then
  106. return
  107. end
  108. if (p==2) then
  109.  
  110. local obj = level.get_target_obj and level.get_target_obj()
  111. if ( obj ) then
  112. SetHudMsg( strformat("Object: %s", obj:name()),8)
  113. end
  114.  
  115. -- local se_obj = alife():object(obj:id())
  116. -- if (se_obj) then
  117.  
  118.  
  119. -- RELEASES TASK GIVER FOR ALL TASKS WITH task_giver_id; useful for testing how a task works when giver is dead
  120. --[[
  121. local debug_task_infos = task_manager.get_task_manager().task_info
  122. local task_ini = task_manager.task_ini
  123. for k,v in pairs(debug_task_infos) do
  124. local squad = v.task_giver_id and alife():object(v.task_giver_id)
  125. if (squad) then
  126. if (squad:clsid() == clsid.online_offline_group_s) then
  127. printf("%s removing squad task giver!",k)
  128. SIMBOARD:assign_squad_to_smart(squad, nil)
  129. squad:remove_squad()
  130. elseif (IsStalker(squad)) then
  131. printf("%s removing npc task giver!",k)
  132. alife():release(squad,true)
  133. end
  134. end
  135. end
  136. --]]
  137.  
  138. -- SET ALL ACTIVE TASKS TO COMPLETE STAGE
  139. --[[
  140. local debug_task_infos = task_manager.get_task_manager().task_info
  141. local task_ini = task_manager.task_ini
  142. for k,v in pairs(debug_task_infos) do
  143. local stage = tonumber(utils.cfg_get_string(task_ini, k, "stage_complete", nil, false, "")) or 0
  144. if (stage > 0 and stage ~= 255) then
  145. v.stage = stage
  146. end
  147. end
  148. --]]
  149.  
  150. -- test
  151. --[[
  152. local function spawn_in_front_quadrant(sec)
  153. local base_point = db.actor:level_vertex_id()
  154. local dist = math.random(15,25)
  155. local dir = device().cam_dir
  156. local spawn_lvid, ang, new_dir
  157. while (spawn_lvid == nil or spawn_lvid >= 4294967295 or dist <= 1) do
  158. ang = math.random(-50,50)
  159. new_dir = vector_rotate_y(utils.vector_copy_by_val(dir),ang)
  160. spawn_lvid = level.vertex_in_direction(base_point, new_dir, dist)
  161. dist = dist - 2
  162. end
  163. if (spawn_lvid and spawn_lvid < 4294967295) then
  164. alife():create(sec,level.vertex_position(spawn_lvid),spawn_lvid,db.actor:game_vertex_id())
  165. end
  166. end
  167.  
  168. spawn_in_front_quadrant("wpn_pm")
  169. --]]
  170. elseif (p==0) then
  171. SetHudMsg("",1)
  172. end
  173. end
  174.  
  175. function action.debug_reload_game(p)
  176. -- Reloads game files in-game so that application does not need restart
  177. if not (DEV_DEBUG) then
  178. return
  179. end
  180. if (p==0) then
  181. local fs = getFS()
  182. fs:rescan_path('$game_config$')
  183. fs:rescan_path('$game_scripts$')
  184. reload_system_ini()
  185. local p = net_packet()
  186. p:w_begin(15) -- reload game
  187. level.send(p,true)
  188. end
  189. end
  190.  
  191. function action.debug_hold_action(p)
  192. if (p == 1) then
  193. _G.DEV_DEBUG_HOLD_ACTION_1 = true
  194. local squad
  195. local sim = alife()
  196. for i=1,65534 do
  197. squad = sim:object(i)
  198. if (squad and squad:clsid() == clsid.online_offline_group_s) then
  199. if (squad.first_update) then
  200. squad:hide()
  201. end
  202. end
  203. end
  204. elseif (p == 0) then
  205. _G.DEV_DEBUG_HOLD_ACTION_1 = false
  206. end
  207. end
  208.  
  209. function action.photo_increase_middlegray( p )
  210. if ( p == 1 ) then
  211. middlegray_value = middlegray_value + 0.1
  212. if ( middlegray_value > 2 ) then
  213. middlegray_value = 2
  214. end
  215.  
  216. get_console():execute("r2_tonemap_middlegray " .. middlegray_value )
  217. SetHudMsg( strformat("Middlegray set to: %s", middlegray_value ), 8 )
  218. elseif ( p == 0 ) then
  219. SetHudMsg("", 1 )
  220. end
  221. end
  222.  
  223. function action.photo_decrease_middlegray( p )
  224. if ( p == 1 ) then
  225. middlegray_value = middlegray_value - 0.1
  226. if ( middlegray_value < 0 ) then
  227. middlegray_value = 0
  228. end
  229.  
  230. get_console():execute("r2_tonemap_middlegray " .. middlegray_value )
  231. SetHudMsg( strformat("Middlegray set to: %s", middlegray_value ), 8 )
  232. elseif ( p == 0 ) then
  233. SetHudMsg("", 1 )
  234. end
  235. end
  236.  
  237. -------------------------------------------
  238. -- callbacks
  239. -------------------------------------------
  240. local function on_key_release(key)
  241. for k,v in pairs(keybinds) do
  242. if (action[k] and key == DIK_keys[axr_main.config:GetValue("global_keybinds",k,0,"")]) then
  243. action[k](0)
  244. end
  245. end
  246. end
  247.  
  248. local function on_key_press(key)
  249. for k,v in pairs(keybinds) do
  250. if (action[k] and key == DIK_keys[axr_main.config:GetValue("global_keybinds",k,0,"")]) then
  251. action[k](1)
  252. end
  253. end
  254. end
  255.  
  256. local function on_key_hold(key)
  257. for k,v in pairs(keybinds) do
  258. if (action[k] and key == DIK_keys[axr_main.config:GetValue("global_keybinds",k,0,"")]) then
  259. action[k](2)
  260. end
  261. end
  262. end
  263.  
  264. function on_game_start()
  265. RegisterScriptCallback("on_key_press",on_key_press)
  266. RegisterScriptCallback("on_key_release",on_key_release)
  267. RegisterScriptCallback("on_key_hold",on_key_hold)
  268.  
  269. local need_save
  270. for k,v in pairs(keybinds) do
  271. if not (axr_main.config:KeyExist("global_keybinds",k)) then
  272. axr_main.config:SetValue("global_keybinds",k,v)
  273. need_save = true
  274. end
  275. end
  276.  
  277. if (need_save) then
  278. axr_main.config:Save()
  279. end
  280. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement