Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
press on buttom.
#1
hi guys, i'll be an good modder here, but i cant be it if i dont know how to do things as u can do Tongue it is so, i want to try to edit the flag plugin with Buttom pressed to teleport, but i dont know how i'll add it. can someone explane to me how to do it and show examples? thx for all answeres.
Reply

#2
You can find example of showing message and button pressing there:
Meow
( In AmmoBox.cs, MysteryBox.cs )
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
Reply

#3
CSHARP Code
  1. public override void OnAddonFrame()
  2. {
  3. foreach (string key in flagsorigin.Keys)
  4. {
  5. if (key.Split(',')[0] == GetDvar("mapname"))
  6. {
  7. if (GetClients() != null)
  8. {
  9. foreach (ServerClient Client in GetClients())
  10. {
  11. if (Distance(new Vector(Client.OriginX, Client.OriginY, Client.OriginZ), flagsorigin[key]) <= 50f)
  12. {
  13. if (Client.Other.ButtonPressed(Buttons.Activate))
  14. {
  15. Client.OriginX = flagsdesti[key].X;
  16. Client.OriginY = flagsdesti[key].Y;
  17. Client.OriginZ = flagsdesti[key].Z;
  18. }
  19. }
  20. }
  21. }
  22. }
  23. }
  24. }


edited code from flag plugin for users.
Reply

#4
hi again, how do i add an message then i'm near the flagg. (HUD) there who says i'll press at F to teleport?
Reply

#5
(03-15-2013, 15:48)EnVi Sweden Rocks Wrote: hi again, how do i add an message then i'm near the flagg. (HUD) there who says i'll press at F to teleport?

CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Addon;
  6.  
  7. namespace Teleport
  8. {
  9. public class Class1 : CPlugin
  10. {
  11.  
  12. Dictionary<string, Vector> flagsorigin = new Dictionary<string, Vector>();
  13. Dictionary<string, Vector> flagsdesti = new Dictionary<string, Vector>();
  14. Dictionary<int, int> HudElem = new Dictionary<int, int>();
  15.  
  16. public override void OnServerLoad()
  17. {
  18. ServerPrint("Teleport plugin loaded!");
  19. }
  20. public override void OnMapChange()
  21. {
  22. makeflags();
  23. }
  24. public override void OnFastRestart()
  25. {
  26. makeflags();
  27. }
  28. public static double Distance(Vector vec1, Vector vec2)
  29. {
  30. return Math.Sqrt(Math.Pow(vec1.X - vec2.X, 2) + Math.Pow(vec1.Y - vec2.Y, 2) + Math.Pow(vec1.Z - vec2.Z, 2));
  31. }
  32.  
  33. public override void OnAddonFrame()
  34. {
  35. foreach (string key in flagsorigin.Keys)
  36. {
  37. if (key.Split(',')[0] == GetDvar("mapname"))
  38. {
  39. if (GetClients() != null)
  40. {
  41. foreach (ServerClient Client in GetClients())
  42. {
  43. HudElem hud = GetHudElement(HudElem[Client.ClientNum]);
  44. if (Distance(new Vector(Client.OriginX, Client.OriginY, Client.OriginZ), flagsorigin[key]) <= 50f)
  45. {
  46. hud.SetString("Press ^2" + Buttons.Activate + "^7 to teleport!");
  47. {
  48. if (Client.Other.ButtonPressed(Buttons.Activate))
  49. {
  50. Client.OriginX = flagsdesti[key].X;
  51. Client.OriginY = flagsdesti[key].Y;
  52. Client.OriginZ = flagsdesti[key].Z;
  53. }
  54. }
  55. }
  56. else
  57. {
  58. hud.SetString("");
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. void makeflags()
  66. {
  67. try
  68. {
  69. string flag = GetServerCFG("TELEPORTER", "flags", "0");
  70. if (flag != "0")
  71. {
  72.  
  73. for (int i = 1; i <= int.Parse(flag); i++)
  74. {
  75. string flaged = GetServerCFG("TELEPORTER", string.Format("flag{0}", i.ToString()), "null");
  76. if (flaged != null)
  77. {
  78. string map = flaged.Split(',')[0];
  79. string vector = flaged.Split(',')[1];
  80. string vector2 = vector.Split('(')[1];
  81. string vector3 = vector2.Split(')')[0];
  82. string vec1 = vector3.Split('_')[0];
  83. string vec2 = vector3.Split('_')[1];
  84. string vec3 = vector3.Split('_')[2];
  85. Vector vec = new Vector(Convert.ToSingle(vec1), Convert.ToSingle(vec2), Convert.ToSingle(vec3));
  86. if (!flagsorigin.ContainsValue(vec))
  87. flagsorigin.Add(string.Format("{0},{1}", map, i.ToString()), vec);
  88. vector = flaged.Split(',')[2];
  89. vector2 = vector.Split('(')[1];
  90. vector3 = vector2.Split(')')[0];
  91. vec1 = vector3.Split('_')[0];
  92. vec2 = vector3.Split('_')[1];
  93. vec3 = vector3.Split('_')[2];
  94. vec = new Vector(Convert.ToSingle(vec1), Convert.ToSingle(vec2), Convert.ToSingle(vec3));
  95. if (!flagsdesti.ContainsValue(vec))
  96. flagsdesti.Add(string.Format("{0},{1}", map, i.ToString()), vec);
  97.  
  98. }
  99.  
  100. }
  101. foreach (string key in flagsdesti.Keys)
  102. {
  103. if (key.Split(',')[0] == GetDvar("mapname"))
  104. {
  105. Entity en = SpawnModel("script_brushmodel", "prop_flag_neutral", flagsdesti[key]);
  106. }
  107. }
  108.  
  109. foreach (string key in flagsdesti.Keys)
  110. {
  111. if (key.Split(',')[0] == GetDvar("mapname"))
  112. {
  113. Entity en = SpawnModel("script_brushmodel", "prop_flag_neutral", flagsorigin[key]);
  114. }
  115. }
  116.  
  117. }
  118. }
  119. catch (Exception e)
  120. {
  121. ServerPrint(e.ToString());
  122. }
  123. }
  124. private int CreateHud(int ClientNum)
  125. {
  126. HudElem hud = CreateNewHudElem();
  127. hud.Type = HudElementTypes.Text;
  128. hud.ShowToEnt = ClientNum;
  129. hud.HideInMenu = true;
  130. hud.Font = HudElementFonts.Default;
  131. hud.FontScale = 1.4f;
  132. hud.PointType = 120f;
  133. hud.OriginY = 300f;
  134. hud.OriginX = -100f;
  135. hud.SetString("");
  136. return hud.HudElementNum;
  137. }
  138. public override void OnPlayerDisconnect(ServerClient Client)
  139. {
  140. if (HudElem.ContainsKey(Client.ClientNum))
  141. {
  142. HudElem hud2 = GetHudElement(HudElem[Client.ClientNum]);
  143. hud2.Type = HudElementTypes.None;
  144. HudElem.Remove(Client.ClientNum);
  145. }
  146. }
  147. public override void OnPlayerConnect(ServerClient Client)
  148. {
  149. int HudElem1 = CreateHud(Client.ClientNum);
  150. if (HudElem.ContainsKey(Client.ClientNum))
  151. HudElem[Client.ClientNum] = HudElem1;
  152. else
  153. HudElem.Add(Client.ClientNum, HudElem1);
  154. }
  155. }
  156. }


I didn't test it, but it should work.
Reply

#6
(03-15-2013, 16:15)8q4s8 Wrote:
(03-15-2013, 15:48)EnVi Sweden Rocks Wrote: hi again, how do i add an message then i'm near the flagg. (HUD) there who says i'll press at F to teleport?

CSHARP Code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Addon;
  6.  
  7. namespace Teleport
  8. {
  9. public class Class1 : CPlugin
  10. {
  11.  
  12. Dictionary<string, Vector> flagsorigin = new Dictionary<string, Vector>();
  13. Dictionary<string, Vector> flagsdesti = new Dictionary<string, Vector>();
  14. Dictionary<int, int> HudElem = new Dictionary<int, int>();
  15.  
  16. public override void OnServerLoad()
  17. {
  18. ServerPrint("Teleport plugin loaded!");
  19. }
  20. public override void OnMapChange()
  21. {
  22. makeflags();
  23. }
  24. public override void OnFastRestart()
  25. {
  26. makeflags();
  27. }
  28. public static double Distance(Vector vec1, Vector vec2)
  29. {
  30. return Math.Sqrt(Math.Pow(vec1.X - vec2.X, 2) + Math.Pow(vec1.Y - vec2.Y, 2) + Math.Pow(vec1.Z - vec2.Z, 2));
  31. }
  32.  
  33. public override void OnAddonFrame()
  34. {
  35. foreach (string key in flagsorigin.Keys)
  36. {
  37. if (key.Split(',')[0] == GetDvar("mapname"))
  38. {
  39. if (GetClients() != null)
  40. {
  41. foreach (ServerClient Client in GetClients())
  42. {
  43. HudElem hud = GetHudElement(HudElem[Client.ClientNum]);
  44. if (Distance(new Vector(Client.OriginX, Client.OriginY, Client.OriginZ), flagsorigin[key]) <= 50f)
  45. {
  46. hud.SetString("Press ^2" + Buttons.Activate + "^7 to teleport!");
  47. {
  48. if (Client.Other.ButtonPressed(Buttons.Activate))
  49. {
  50. Client.OriginX = flagsdesti[key].X;
  51. Client.OriginY = flagsdesti[key].Y;
  52. Client.OriginZ = flagsdesti[key].Z;
  53. }
  54. }
  55. }
  56. else
  57. {
  58. hud.SetString("");
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. void makeflags()
  66. {
  67. try
  68. {
  69. string flag = GetServerCFG("TELEPORTER", "flags", "0");
  70. if (flag != "0")
  71. {
  72.  
  73. for (int i = 1; i <= int.Parse(flag); i++)
  74. {
  75. string flaged = GetServerCFG("TELEPORTER", string.Format("flag{0}", i.ToString()), "null");
  76. if (flaged != null)
  77. {
  78. string map = flaged.Split(',')[0];
  79. string vector = flaged.Split(',')[1];
  80. string vector2 = vector.Split('(')[1];
  81. string vector3 = vector2.Split(')')[0];
  82. string vec1 = vector3.Split('_')[0];
  83. string vec2 = vector3.Split('_')[1];
  84. string vec3 = vector3.Split('_')[2];
  85. Vector vec = new Vector(Convert.ToSingle(vec1), Convert.ToSingle(vec2), Convert.ToSingle(vec3));
  86. if (!flagsorigin.ContainsValue(vec))
  87. flagsorigin.Add(string.Format("{0},{1}", map, i.ToString()), vec);
  88. vector = flaged.Split(',')[2];
  89. vector2 = vector.Split('(')[1];
  90. vector3 = vector2.Split(')')[0];
  91. vec1 = vector3.Split('_')[0];
  92. vec2 = vector3.Split('_')[1];
  93. vec3 = vector3.Split('_')[2];
  94. vec = new Vector(Convert.ToSingle(vec1), Convert.ToSingle(vec2), Convert.ToSingle(vec3));
  95. if (!flagsdesti.ContainsValue(vec))
  96. flagsdesti.Add(string.Format("{0},{1}", map, i.ToString()), vec);
  97.  
  98. }
  99.  
  100. }
  101. foreach (string key in flagsdesti.Keys)
  102. {
  103. if (key.Split(',')[0] == GetDvar("mapname"))
  104. {
  105. Entity en = SpawnModel("script_brushmodel", "prop_flag_neutral", flagsdesti[key]);
  106. }
  107. }
  108.  
  109. foreach (string key in flagsdesti.Keys)
  110. {
  111. if (key.Split(',')[0] == GetDvar("mapname"))
  112. {
  113. Entity en = SpawnModel("script_brushmodel", "prop_flag_neutral", flagsorigin[key]);
  114. }
  115. }
  116.  
  117. }
  118. }
  119. catch (Exception e)
  120. {
  121. ServerPrint(e.ToString());
  122. }
  123. }
  124. private int CreateHud(int ClientNum)
  125. {
  126. HudElem hud = CreateNewHudElem();
  127. hud.Type = HudElementTypes.Text;
  128. hud.ShowToEnt = ClientNum;
  129. hud.HideInMenu = true;
  130. hud.Font = HudElementFonts.Default;
  131. hud.FontScale = 1.4f;
  132. hud.PointType = 120f;
  133. hud.OriginY = 300f;
  134. hud.OriginX = -100f;
  135. hud.SetString("");
  136. return hud.HudElementNum;
  137. }
  138. public override void OnPlayerDisconnect(ServerClient Client)
  139. {
  140. if (HudElem.ContainsKey(Client.ClientNum))
  141. {
  142. HudElem hud2 = GetHudElement(HudElem[Client.ClientNum]);
  143. hud2.Type = HudElementTypes.None;
  144. HudElem.Remove(Client.ClientNum);
  145. }
  146. }
  147. public override void OnPlayerConnect(ServerClient Client)
  148. {
  149. int HudElem1 = CreateHud(Client.ClientNum);
  150. if (HudElem.ContainsKey(Client.ClientNum))
  151. HudElem[Client.ClientNum] = HudElem1;
  152. else
  153. HudElem.Add(Client.ClientNum, HudElem1);
  154. }
  155. }
  156. }


I didn't test it, but it should work.

hi there! i has tested it now, and the flags is there, but the text isn't there. i go to the flag and no message cames up, so i did pressed at F and it teleport. so it worked, but why does not the message comes up?
Reply

#7
(03-19-2013, 20:18)EnVi Sweden Rocks Wrote: hi there! i has tested it now, and the flags is there, but the text isn't there. i go to the flag and no message cames up, so i did pressed at F and it teleport. so it worked, but why does not the message comes up?

It's maybe because the location of the HUD is wrong, try to set pointType OriginX and OriginY to 0. Then it should appear next to the minimap.
Reply

#8
i had tried it, and it dont work. the flags will not shows up even not the message!
Reply

#9
(03-23-2013, 13:18)EnVi Sweden Rocks Wrote: i had tried it, and it dont work. the flags will not shows up even not the message!

I think it's a old code, it doesn't work even without the press F function. I found a code on page 3 and edited it, you should try that one.

Code:
using System;
using System.Collections.Generic;
using System.Collections;
using Addon;

namespace teleport
{
    public class Class1 : CPlugin
    {
        struct ProcessFlags
        {
            public Vector point;
            public int radius;
            public Vector destination;
            public ProcessFlags(Vector point, int radius, Vector destination)
            {
                this.point = point;
                this.radius = radius;
                this.destination = destination;
            }
        };

        List<ProcessFlags> Flags = new List<ProcessFlags>();
        Dictionary<int, int> HudElem = new Dictionary<int, int>();

        public override void OnServerLoad()
        {
            ServerPrint("Teleport plugin loaded!");
        }
        public override void OnMapChange()
        {
            Flags.Clear();
            makeflags();
        }
        public override void OnFastRestart()
        {
            OnMapChange();
        }
        public static double Distance(Vector vec1, Vector vec2)
        {
            return Math.Sqrt(Math.Pow(vec1.X - vec2.X, 2) + Math.Pow(vec1.Y - vec2.Y, 2) + Math.Pow(vec1.Z - vec2.Z, 2));
        }

        public override void OnAddonFrame()
        {
            List<ServerClient> clients = GetClients();
            if (clients != null)
            {
                foreach (ProcessFlags it in Flags)
                {
                    foreach (ServerClient Client in clients)
                    {
                        HudElem hud = GetHudElement(HudElem[Client.ClientNum]);
                        if (Distance(new Vector(Client.OriginX, Client.OriginY, Client.OriginZ), it.point) <= it.radius)//same as flag
                        {
                            hud.SetString("Press ^2F^7 to teleport!");
                            if (Client.Other.ButtonPressed(Buttons.Activate))
                            {
                                Client.OriginX = it.destination.X;
                                Client.OriginY = it.destination.Y;
                                Client.OriginZ = it.destination.Z;
                            }
                        }
                        else
                        {
                            hud.SetString("");
                        }
                    }
                }
            }
        }

        void makeflags()
        {
            try
            {
                string flag = GetServerCFG("TELEPORTER", "flags", "0");
                if (flag != "0")
                {

                    Dictionary<string, Vector> flagsorigin = new Dictionary<string, Vector>();
                    Dictionary<string, Vector> flagsdesti = new Dictionary<string, Vector>();
                    for (int i = 1; i <= int.Parse(flag); i++)
                    {
                        string flaged = GetServerCFG("TELEPORTER", string.Format("flag{0}", i.ToString()), "null");
                        if (flaged != null)
                        {
                            string map = flaged.Split(',')[0];
                            string vector = flaged.Split(',')[1];
                            string vector2 = vector.Split('(')[1];
                            string vector3 = vector2.Split(')')[0];
                            string vec1 = vector3.Split('_')[0];
                            string vec2 = vector3.Split('_')[1];
                            string vec3 = vector3.Split('_')[2];
                            Vector vec = new Vector(Convert.ToSingle(vec1), Convert.ToSingle(vec2), Convert.ToSingle(vec3));
                            flagsorigin.Add(string.Format("{0},{1}", map, i.ToString()), vec);
                            vector = flaged.Split(',')[2];
                            vector2 = vector.Split('(')[1];
                            vector3 = vector2.Split(')')[0];
                            vec1 = vector3.Split('_')[0];
                            vec2 = vector3.Split('_')[1];
                            vec3 = vector3.Split('_')[2];
                            vec = new Vector(Convert.ToSingle(vec1), Convert.ToSingle(vec2), Convert.ToSingle(vec3));
                            flagsdesti.Add(string.Format("{0},{1}", map, i.ToString()), vec);

                        }
                    }
                    foreach (string key in flagsdesti.Keys)
                    {
                        if (key.Split(',')[0] == GetDvar("mapname"))
                        {
                            Entity en = SpawnModel("script_brushmodel", "prop_flag_neutral", flagsdesti[key]);
                        }
                    }

                    foreach (string key in flagsdesti.Keys)
                    {
                        if (key.Split(',')[0] == GetDvar("mapname"))
                        {
                            Entity en = SpawnModel("script_brushmodel", "prop_flag_neutral", flagsorigin[key]);
                            Flags.Add(new ProcessFlags(flagsorigin[key], 50, flagsdesti[key]));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                ServerPrint(e.ToString());
            }
        }
        private int CreateHud(int ClientNum)
        {
            HudElem hud = CreateNewHudElem();
            hud.Type = HudElementTypes.Text;
            hud.ShowToEnt = ClientNum;
            hud.HideInMenu = true;
            hud.Font = HudElementFonts.Default;
            hud.FontScale = 1.4f;
            hud.PointType = 0;
            hud.OriginY = 0f;
            hud.OriginX = 0f;
            hud.SetString("");
            return hud.HudElementNum;
        }
        public override void OnPlayerDisconnect(ServerClient Client)
        {
            if (HudElem.ContainsKey(Client.ClientNum))
            {
                HudElem hud2 = GetHudElement(HudElem[Client.ClientNum]);
                hud2.Type = HudElementTypes.None;
                HudElem.Remove(Client.ClientNum);
            }
        }
        public override void OnPlayerConnect(ServerClient Client)
        {
            int HudElem1 = CreateHud(Client.ClientNum);
            if (HudElem.ContainsKey(Client.ClientNum))
                HudElem[Client.ClientNum] = HudElem1;
            else
                HudElem.Add(Client.ClientNum, HudElem1);
        }
    }
}

Edit: code is tested and working!

Credits:
@archit
@Ich1994
Reply

#10
the flags worked, but the message will still not shows up!
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Request] Ac130(press F) funny 6 4,746 02-21-2013, 11:29
Last Post: Nekochan
  Press any key to continue? ScHmIdTy56789 6 5,369 11-15-2011, 16:31
Last Post: Rendflex
  Action upon a button press cervantes 4 3,558 07-19-2011, 15:38
Last Post: Scripts18
Photo Preview How do i delete this thread, press left then right dont work RadimaKs 0 1,750 07-10-2011, 15:22
Last Post: RadimaKs
  Help Press Attack Button akim14 4 3,397 07-04-2011, 10:00
Last Post: akim14
  E3 2011 Press conference AZUMIKKEL 5 3,389 06-06-2011, 21:33
Last Post: AZUMIKKEL
  [REQUEST] Calling function on button press little morgy 2 2,806 12-10-2010, 08:41
Last Post: d0h!

Forum Jump:


Users browsing this thread:
1 Guest(s)

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