ItsMods

Full Version: TeamCounter class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey everyone

I created a pretty simple class to count the players in a team.
It's a class that makes it easier for plugin developers to count the players in a team, it's not a plugin so don't ask why it doesn't work.

Functions:

Count(teamname); - returns the number of players in the team
GetLastAlive(); - if there's only one player in team allies it returns the client, if not it returns null.
Allies(); - a list of all survivors/team allies
Axis(); - a list of all zombies/team axis
_Team.TeamName - used for Count()

here's an example of how you can use the class, add TeamCounter.dll as a reference and inherit: TeamCounter.Counter

it's adding a waypoint on the radar to mark the last player alive

CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using Addon;
  5. using System.Timers;
  6.  
  7. namespace Point
  8. {
  9. #region VecClass
  10. public class VecXY
  11. {
  12. public float xVec;
  13. public float yVec;
  14. public int Icon;
  15.  
  16. public VecXY(float x, float y, int icon)
  17. {
  18. xVec = x;
  19. yVec = y;
  20. Icon = icon;
  21. }
  22. }
  23. #endregion
  24.  
  25. public class main :TeamCounter.Counter
  26. {
  27. Timer timer = new Timer();
  28. Timer timer2 = new Timer();
  29.  
  30. public void checking(object s, ElapsedEventArgs e)
  31. {
  32.  
  33. if (Count(_Team.Allies) == 1)
  34. {
  35. timer2.Enabled = true;
  36. }
  37. }
  38.  
  39. public void updateLocation(object s, ElapsedEventArgs e)
  40. {
  41. if (GetLastAlive() != null)
  42. {
  43. Activate();
  44. x = GetLastAlive().OriginX;
  45. y = GetLastAlive().OriginY;
  46. ChangeIcon();
  47. SetPosition();
  48. }
  49. else
  50. {
  51. Deactivate();
  52. timer2.Enabled = false;
  53. }
  54. }
  55.  
  56. public override void OnAddonFrame()
  57. {
  58. foreach (ServerClient c in Allies())
  59. {
  60.  
  61. }
  62. foreach (ServerClient c in Axis())
  63. {
  64.  
  65. }
  66. }
  67.  
  68. #region PointStuff
  69. IntPtr activate, icon, X, Y;
  70.  
  71. public static int iconNum;
  72. public static float x;
  73. public static float y;
  74.  
  75. public override void OnServerLoad()
  76. {
  77. activate = (IntPtr)Convert.ToInt32(0x01B1EE9C);
  78. icon = (IntPtr)Convert.ToInt32(0x01B1EEBC);
  79. X = (IntPtr)Convert.ToInt32(0x01B1EEA0);
  80. Y = (IntPtr)Convert.ToInt32(0x01B1EEA4);
  81.  
  82. timer.Elapsed += new ElapsedEventHandler(checking);
  83. timer.Interval = 2000;
  84. timer.Enabled = true;
  85.  
  86. timer2.Elapsed += new ElapsedEventHandler(updateLocation);
  87. timer2.Interval = 100;
  88. timer2.Enabled = false;
  89.  
  90. iconNum = 204;
  91. }
  92.  
  93. unsafe public void Activate()
  94. {
  95. *(int*)activate = 1;
  96. }
  97. unsafe public void ChangeIcon()
  98. {
  99.  
  100. *(int*)icon = iconNum;
  101. }
  102. unsafe public void Deactivate()
  103. {
  104.  
  105. *(int*)activate = 0;
  106. }
  107. unsafe public void SetPosition()
  108. {
  109.  
  110. *(float*)X = x;
  111. *(float*)Y = y;
  112.  
  113. }
  114. #endregion
  115. }
  116. }
Nice one! But why there is this code:
Code:
public override void OnAddonFrame()
        {
            foreach (ServerClient c in Allies())
            {

            }
            foreach (ServerClient c in Axis())
            {

            }
        }


( In AddonFrame, is it necessary? )
(05-18-2013, 19:30)SailorMoon Wrote: [ -> ]Nice one! But why there is this code:
Code:
public override void OnAddonFrame()
        {
            foreach (ServerClient c in Allies())
            {

            }
            foreach (ServerClient c in Axis())
            {

            }
        }


( In AddonFrame, is it necessary? )

No, I added it to show an example of how you can use the Allies() or Axis() method
How change point?