Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Release LocationHUD
#1
Hey, I saw many people got problems with getting locations for flags and other stuff. This is a plugin which shows you your location in a HUD.

Commands
Code:
!printloc - printing the location in your console
!lochud - toggle HUD on and off

Also feel free to edit the code for HUD location etc.
CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Addon;
  5.  
  6. namespace ClassLibrary1
  7. {
  8. public class Class1:CPlugin
  9. {
  10. Dictionary<int, int> HudElem = new Dictionary<int, int>();
  11.  
  12. string locX = "";
  13. string locY = "";
  14. string locZ = "";
  15. bool hudOn = true;
  16. int interval = 10;
  17.  
  18. public override void OnServerLoad()
  19. {
  20. ServerPrint("LocationHUD loaded");
  21. }
  22. public override ChatType OnSay(string Message, ServerClient Client)
  23. {
  24. if (Message.ToLower().StartsWith("!printloc"))
  25. {
  26. ServerPrint(Client.OriginX+ "," +Client.OriginY+ "," + Client.OriginZ);
  27. return ChatType.ChatNone;
  28. }
  29. else if (Message.ToLower().StartsWith("!lochud"))
  30. {
  31. if (hudOn == true)
  32. {
  33. hudOn = false;
  34. HudElem hud2 = GetHudElement(HudElem[Client.ClientNum]);
  35. hud2.Type = HudElementTypes.None;
  36. HudElem.Remove(Client.ClientNum);
  37. }
  38. else
  39. {
  40. hudOn = true;
  41. int HudElem1 = CreateHud(Client.ClientNum);
  42. if (HudElem.ContainsKey(Client.ClientNum))
  43. HudElem[Client.ClientNum] = HudElem1;
  44. else
  45. HudElem.Add(Client.ClientNum, HudElem1);
  46. }
  47. return ChatType.ChatNone;
  48. }
  49. return ChatType.ChatContinue;
  50. }
  51. public override void OnAddonFrame()
  52. {
  53. foreach (ServerClient c in GetClients())
  54. {
  55. if (hudOn != false)
  56. {
  57. HudElem hud = GetHudElement(HudElem[c.ClientNum]);
  58. interval--;
  59. if (interval <= 0) //for slower updating
  60. {
  61. locX = c.OriginX.ToString();
  62. locY = c.OriginY.ToString();
  63. locZ = c.OriginZ.ToString();
  64.  
  65. string location = string.Format("X:^1 {0}^7 Y:^1 {1} ^7Z:^1 {2}", locX, locY, locZ);
  66. hud.SetString(location);
  67. interval = 2;
  68. }
  69. }
  70. }
  71. }
  72. private int CreateHud(int ClientNum)
  73. {
  74. HudElem hud = CreateNewHudElem();
  75. hud.Type = HudElementTypes.Text;
  76. hud.ShowToEnt = ClientNum;
  77. hud.HideInMenu = true;
  78. hud.Font = HudElementFonts.Default;
  79. hud.FontScale = 1.4f;
  80. hud.PointType = 0;
  81. hud.OriginY = 0f;
  82. hud.OriginX = 0f;
  83. hud.SetString("");
  84. return hud.HudElementNum;
  85. }
  86. public override void OnPlayerDisconnect(ServerClient Client)
  87. {
  88. if (HudElem.ContainsKey(Client.ClientNum))
  89. {
  90. HudElem hud2 = GetHudElement(HudElem[Client.ClientNum]);
  91. hud2.Type = HudElementTypes.None;
  92. HudElem.Remove(Client.ClientNum);
  93. }
  94. }
  95. public override void OnPlayerConnect(ServerClient Client)
  96. {
  97. int HudElem1 = CreateHud(Client.ClientNum);
  98. if (HudElem.ContainsKey(Client.ClientNum))
  99. HudElem[Client.ClientNum] = HudElem1;
  100. else
  101. HudElem.Add(Client.ClientNum, HudElem1);
  102. }
  103. }
  104. }


EDIT: forgot to add the .dll


Attached Files
.zip   LocationHUD.zip (Size: 2.84 KB / Downloads: 91)
Reply

#2
So if you walk around with hudelement on, it updates and you see the coords? cool
[Image: b_560_95_1.png]
[Image: hax0r3ez.gif]
Reply

#3
(01-21-2013, 19:51)99IRock Wrote: So if you walk around with hudelement on, it updates and you see the coords? cool

ye if u walk the coordinates will follow you Smile
Reply

#4
Instead of using OnAddonFrame , a timer would be a better alternative
Reply



Forum Jump:


Users browsing this thread:
3 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.