ItsMods

Full Version: Flag plugin for users 1.6
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8
(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. Sad

You used wrong format

PM me the Source code and i will get rid of the threads
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());
            }
        }
    }
}
(09-11-2012, 21:32)hillbilly Wrote: [ -> ]The code is on page one

LOL Will do it tomorrow, going to sleep nauw
(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.
(09-12-2012, 07:46)litgar Wrote: [ -> ]http://www.itsmods.com/forum/Thread-Rele...opers.html

No threads - No crash! Tongue

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?
(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! Tongue

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.
Here is the Code without Threads:

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
(09-12-2012, 12:22)Ich1994 Wrote: [ -> ]Here is the Code without Threads:

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
Does anyone server use this plugin?
Pages: 1 2 3 4 5 6 7 8