Posts: 144
Threads: 5
Joined: Dec 2012
Reputation:
3
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 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.
Posts: 3,704
Threads: 147
Joined: Jan 2011
Reputation:
119
03-14-2013, 21:17
(This post was last modified: 03-14-2013, 21:19 by Nekochan.)
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
Posts: 273
Threads: 14
Joined: Aug 2012
Reputation:
17
CSHARP Code
public override void OnAddonFrame() { foreach (string key in flagsorigin.Keys) { if (key.Split(',')[0] == GetDvar("mapname")) { if (GetClients() != null) { foreach (ServerClient Client in GetClients()) { if (Distance (new Vector (Client. OriginX, Client. OriginY, Client. OriginZ), flagsorigin [key ]) <= 50f ) { if (Client.Other.ButtonPressed(Buttons.Activate)) { Client.OriginX = flagsdesti[key].X; Client.OriginY = flagsdesti[key].Y; Client.OriginZ = flagsdesti[key].Z; } } } } } } }
edited code from flag plugin for users.
Posts: 144
Threads: 5
Joined: Dec 2012
Reputation:
3
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?
Posts: 273
Threads: 14
Joined: Aug 2012
Reputation:
17
(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
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Addon; namespace Teleport { public class Class1 : CPlugin { Dictionary <string, Vector > flagsorigin = new Dictionary <string, Vector >(); Dictionary <string, Vector > flagsdesti = new Dictionary <string, Vector >(); Dictionary <int, int> HudElem = new Dictionary <int, int>(); public override void OnServerLoad() { ServerPrint("Teleport plugin loaded!"); } public override void OnMapChange() { makeflags(); } public override void OnFastRestart() { makeflags(); } 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() { foreach (string key in flagsorigin.Keys) { if (key.Split(',')[0] == GetDvar("mapname")) { if (GetClients() != null) { foreach (ServerClient Client in GetClients()) { HudElem hud = GetHudElement(HudElem[Client.ClientNum]); if (Distance (new Vector (Client. OriginX, Client. OriginY, Client. OriginZ), flagsorigin [key ]) <= 50f ) { hud.SetString("Press ^2" + Buttons.Activate + "^7 to teleport!"); { if (Client.Other.ButtonPressed(Buttons.Activate)) { Client.OriginX = flagsdesti[key].X; Client.OriginY = flagsdesti[key].Y; Client.OriginZ = flagsdesti[key].Z; } } } else { hud.SetString(""); } } } } } } void makeflags() { try { string flag = GetServerCFG("TELEPORTER", "flags", "0"); if (flag != "0") { 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 )); if (!flagsorigin.ContainsValue(vec)) 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 )); if (!flagsdesti.ContainsValue(vec)) 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]); } } } } 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 = 120f; hud.OriginY = 300f; hud.OriginX = -100f; 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); } } }
I didn't test it, but it should work.
Posts: 144
Threads: 5
Joined: Dec 2012
Reputation:
3
(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
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Addon; namespace Teleport { public class Class1 : CPlugin { Dictionary <string, Vector > flagsorigin = new Dictionary <string, Vector >(); Dictionary <string, Vector > flagsdesti = new Dictionary <string, Vector >(); Dictionary <int, int> HudElem = new Dictionary <int, int>(); public override void OnServerLoad() { ServerPrint("Teleport plugin loaded!"); } public override void OnMapChange() { makeflags(); } public override void OnFastRestart() { makeflags(); } 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() { foreach (string key in flagsorigin.Keys) { if (key.Split(',')[0] == GetDvar("mapname")) { if (GetClients() != null) { foreach (ServerClient Client in GetClients()) { HudElem hud = GetHudElement(HudElem[Client.ClientNum]); if (Distance (new Vector (Client. OriginX, Client. OriginY, Client. OriginZ), flagsorigin [key ]) <= 50f ) { hud.SetString("Press ^2" + Buttons.Activate + "^7 to teleport!"); { if (Client.Other.ButtonPressed(Buttons.Activate)) { Client.OriginX = flagsdesti[key].X; Client.OriginY = flagsdesti[key].Y; Client.OriginZ = flagsdesti[key].Z; } } } else { hud.SetString(""); } } } } } } void makeflags() { try { string flag = GetServerCFG("TELEPORTER", "flags", "0"); if (flag != "0") { 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 )); if (!flagsorigin.ContainsValue(vec)) 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 )); if (!flagsdesti.ContainsValue(vec)) 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]); } } } } 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 = 120f; hud.OriginY = 300f; hud.OriginX = -100f; 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); } } }
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?
Posts: 273
Threads: 14
Joined: Aug 2012
Reputation:
17
(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.
Posts: 144
Threads: 5
Joined: Dec 2012
Reputation:
3
i had tried it, and it dont work. the flags will not shows up even not the message!
Posts: 273
Threads: 14
Joined: Aug 2012
Reputation:
17
03-23-2013, 16:08
(This post was last modified: 03-26-2013, 17:09 by 8q4s8.)
(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
Posts: 144
Threads: 5
Joined: Dec 2012
Reputation:
3
the flags worked, but the message will still not shows up!
|