sr2lua/hud_zombie.lua

  1. Hud_zombie = { 
  2. 	handles = {}, 
  3. } 
  4. -- 
  5. function hud_zombie_init() 
  6. 	local h = -1 
  7. 	 
  8. 	peg_load("ui_hud_zombie") 
  9. 	 
  10. 	--players 
  11. 	Hud_zombie.handles.players = vint_object_find("players") 
  12. 	 
  13. 		--player 1 
  14. 		Hud_zombie.handles.player_1 = vint_object_find("player_1") 
  15. 		h = Hud_zombie.handles.player_1 
  16. 		Hud_zombie.handles.health_1 = vint_object_find("health_1", h) 
  17. 		Hud_zombie.handles.head_1 = vint_object_find("head_1", h) 
  18. 		 
  19. 		--player 2 
  20. 		Hud_zombie.handles.player_2 = vint_object_find("player_2") 
  21. 		h = Hud_zombie.handles.player_2 
  22. 		Hud_zombie.handles.health_2 = vint_object_find("health_2", h) 
  23. 		Hud_zombie.handles.head_2 = vint_object_find("head_2", h) 
  24. 		 
  25. 	--score grp 
  26. 	Hud_zombie.handles.score_grp = vint_object_find("score_grp") 
  27. 	h = Hud_zombie.handles.score_grp 
  28. 	Hud_zombie.handles.main_score_num = vint_object_find("main_score_num", h) 
  29. 	Hud_zombie.handles.high_score_num = vint_object_find("high_score_num", h) 
  30. 	 
  31. 	--STATS zombies left + killed 
  32. 	Hud_zombie.handles.stats = vint_object_find("stats") 
  33. 	h = Hud_zombie.handles.stats 
  34. 	Hud_zombie.handles.zombies_killed_num = vint_object_find("zombies_killed_num", h) 
  35. 	Hud_zombie.handles.zombies_left_num = vint_object_find("zombies_left_num", h) 
  36. 	 
  37. 	vint_dataitem_add_subscription("sr2_local_player_hud_zombie", "update", "hud_zombie_update") 
  38.  
  39. end 
  40.  
  41. function hud_zombie_cleanup() 
  42. 	peg_unload("ui_hud_zombie") 
  43. end 
  44.  
  45. function hud_zombie_update(di_h, event) 
  46. 	 
  47. 	local score, high_score, health_1, health_2, zombies_left, zombies_killed = vint_dataitem_get(di_h) 
  48. 	 
  49. 	local p1 = Hud_zombie.handles.player_1 
  50. 	local p1_health = Hud_zombie.handles.health_1 
  51. 	local p2 = Hud_zombie.handles.player_2 
  52. 	local p2_health = Hud_zombie.handles.health_2 
  53.  
  54. 	--current score 
  55. 	vint_set_property(Hud_zombie.handles.main_score_num, "text_tag", format_cash(score)) 
  56. 	 
  57. 	--high score 
  58. 	vint_set_property(Hud_zombie.handles.high_score_num, "text_tag", format_cash(high_score)) 
  59. 	 
  60. 	--zombies 
  61. 	vint_set_property(Hud_zombie.handles.zombies_killed_num, "text_tag", format_cash(zombies_killed)) 
  62. 	vint_set_property(Hud_zombie.handles.zombies_left_num, "text_tag", format_cash(zombies_left)) 
  63.  
  64. 	--player 1 
  65. 	vint_set_property(p1_health, "text_tag", ceil(health_1 * 100)) 
  66. 	 
  67. 	--player 2  
  68. 	if health_2 == -1 or health_2 < 0 then 
  69. 		vint_set_property(p2, "visible", false) 
  70. 	else 
  71. 		vint_set_property(p2, "visible", true) 
  72. 		vint_set_property(p2_health, "text_tag", ceil(health_2 * 100)) 
  73. 	end 
  74. end 
  75.