Posts: 284
Threads: 21
Joined: Jun 2012
Reputation:
13
(09-11-2012, 15:20) archit Wrote: (09-11-2012, 14:53) jari333 Wrote: Okay, the plugin works now. But when i try to make the flags at the positions i want, get i an error:
System.IndexOutOfRangeException: The index is outside the array bounds.
at teleport.Class1.makeflags ()
System.IndexOutOfRangeException: The index is outside the array bounds.
at teleport.Class1.makeflags ()
System.IndexOutOfRangeException: The index is outside the array bounds.
at teleport.Class1.makeflags ()
This is the [TELEPORT] in my sv_config:
[TELEPORTER]
flags=4
flag1=mp_seatown,(1200,500,180),(1500,500,565)
flag2=mp_lambeth,(750,0,-255),(2500,2500,-200)
flag3=mp_exchange,(-500,1500,130),(-1500,0,2020)
flag4=mp_terminal_cls,(650,3880,340),(-1000,6000,320) Should be
Code:
flags=4
flag1=mp_seatown,(1200_500_180),(1500_500_565)
flag2=mp_lambeth,(750_0_-255),(2500_2500_-200)
flag3=mp_exchange,(-500_1500_130),(-1500_0_2020)
flag4=mp_terminal_cls,(650_3880_340),(-1000_6000_320)
zxz0O0 Wrote: @archit Don't use threads. What to use in place of it? I have no idea about a replacement of thread
(09-11-2012, 14:20) CJGreenLabel Wrote: This plugin crashed the server after nextmap or map restart.
You used wrong format
PM me the Source code and i will get rid of the threads
Posts: 836
Threads: 48
Joined: Feb 2012
Reputation:
11
09-11-2012, 21:32
(This post was last modified: 09-11-2012, 21:33 by hillbilly .)
The code is on page one
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Collections;
using System.Text;
using Addon;
namespace teleport
{
public class Class1:CPlugin
{
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));
}
void monitordist(Vector point, int radius,Vector destination)
{
string map = GetDvar("mapname");
while (GetDvar("mapname") == map)
{
if (GetClients() != null)
{
foreach (ServerClient Client in GetClients())
{
if (Distance(new Vector(Client.OriginX, Client.OriginY, Client.OriginZ), point) <= radius)//same as flag
{
Client.OriginX = destination.X;
Client.OriginY = destination.Y;
Client.OriginZ = destination.Z;
}
}
}
}
}
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]);
Thread distance = new Thread(dist => monitordist(flagsorigin[key], 50, flagsdesti[key]));
distance.Start();
}
}
}
}
catch (Exception e)
{
ServerPrint(e.ToString());
}
}
}
}
Posts: 284
Threads: 21
Joined: Jun 2012
Reputation:
13
(09-11-2012, 21:32) hillbilly Wrote: The code is on page one
Will do it tomorrow, going to sleep nauw
Posts: 1,323
Threads: 24
Joined: Nov 2010
Reputation:
91
(09-11-2012, 15:20) archit Wrote: zxz0O0 Wrote: @archit Don't use threads. What to use in place of it? I have no idea about a replacement of thread
OnAddonFrame is threaded, you can use it instead.
Posts: 322
Threads: 43
Joined: Mar 2012
Reputation:
-4
Posts: 836
Threads: 48
Joined: Feb 2012
Reputation:
11
(09-12-2012, 07:46) litgar Wrote: http://www.itsmods.com/forum/Thread-Rele...opers.html
No threads - No crash!
using System;
using System.Collections.Generic;
using Addon;
using System.Threading;
using System.IO;
using System.Collections;
namespace flags
Doesn't that still crash as your using Threading?
Posts: 284
Threads: 21
Joined: Jun 2012
Reputation:
13
(09-12-2012, 10:27) hillbilly Wrote: (09-12-2012, 07:46) litgar Wrote: http://www.itsmods.com/forum/Thread-Rele...opers.html
No threads - No crash!
using System;
using System.Collections.Generic;
using Addon;
using System.Threading;
using System.IO;
using System.Collections;
namespace flags
Doesn't that still crash as your using Threading?
He just simply forgot to remove "using System.Threading" but he is not creating a single Thread inside his code.
Posts: 284
Threads: 21
Joined: Jun 2012
Reputation:
13
09-12-2012, 12:22
(This post was last modified: 09-12-2012, 12:48 by Ich1994 .)
Here is the Code without Threads:
Code:
using System;
using System.Collections.Generic;
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>();
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)
{
if (Distance(new Vector(Client.OriginX, Client.OriginY, Client.OriginZ), it.point) <= it.radius)//same as flag
{
Client.OriginX = it.destination.X;
Client.OriginY = it.destination.Y;
Client.OriginZ = it.destination.Z;
}
}
}
}
}
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());
}
}
}
}
WARNING: :
I did not tested the Code. Nor i checked if it even compiles.
I edit it Notepad++.
But as i look at the Code. It SHOULD work fine
EDIT: Changed access level of Struct to public
EDIT2: Added a missing ;
EDIT3: Removed unused imports
EDIT4: List.Add instead of List.add
EDIT5: Wow '-.- changed OnServerAddon() to OnServerFrame()
EDIT6: List.Clear instead of List.clear
Posts: 836
Threads: 48
Joined: Feb 2012
Reputation:
11
09-12-2012, 12:24
(This post was last modified: 09-12-2012, 14:08 by hillbilly .)
(09-12-2012, 12:22) Ich1994 Wrote: Here is the Code without Threads:
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Collections;
using System.Text;
using Addon;
namespace teleport
{
public class Class1:CPlugin
{
struct ProcessFlags
{
Vector point;
int radius;
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>();
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 OnServerAddon()
{
List<ServerClient> clients=GetClients()
if(clients != null)
{
foreach(ProcessFlags it in Flags)
{
foreach (ServerClient Client in clients)
{
if (Distance(new Vector(Client.OriginX, Client.OriginY, Client.OriginZ), it.point) <= it.radius)//same as flag
{
Client.OriginX = it.destination.X;
Client.OriginY = it.destination.Y;
Client.OriginZ = it.destination.Z;
}
}
}
}
}
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());
}
}
}
}
WARNING: :
I did not tested the Code. Nor i checked if it even compiles.
I edit it Notepad++.
But as i look at the Code. I SHOULD work fine
code being tested ................
EDIT
Code tested and working.
uploaded by request,
credits .
@
archit
@
Ich1994
@me.. for testing lol
Attached Files
flag.rar (Size: 3.19 KB / Downloads: 39)
Posts: 285
Threads: 15
Joined: Nov 2011
Reputation:
12
Does anyone server use this plugin?