• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Removing threading
#1
I'm trying to go back to this that i was using however the Threading kept making the servers crash any help appreciated, and in current format it obviouslt doesn't work.


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

namespace RW
{
    public class plugin_test : CPlugin
    {
        public override void OnServerFrame()
        { }
             public override void OnServerLoad()
        {
            ServerPrint("rANDOM plugin loaded!");
                  
        }

        public override ChatType OnSay(string Message, ServerClient Client)
        {
          
            return ChatType.ChatContinue;
        }

        public static void SafeSleep(int AmountSec)
        {
            int total = 0;
            while (total != AmountSec)
            {
                total++;
                //Thread.Sleep(1000);
            }

        }
        public override void OnPlayerSpawned(ServerClient Client)
        {
            onInit(Client);
            onmsg(Client);
            
        }
        void onSpam(Object x)
        {
            while (true)
            {
                SafeSleep(45);
                ServerSay("^2RWMod: ^4Type !info to get info", true);
                iPrintLn("^2Created by ^5JayDi", null);
                //SafeSleep(20);
                //ServerSay("^2RWMod: ^4Random Weapon Mod ^5by JayDi", true);
                //iPrintLn("^1INFECTED", null);
                //SafeSleep(10);
                //ServerSay("^2RWMod: ^3Invite your friends!", true);
                //iPrintLn("^2VERSION: 1.0", null);
            }
        }
        void onInit(ServerClient Client)
        {
            //ThreadPool.QueueUserWorkItem(new WaitCallback(weapz), Client);
        }
        void onmsg(ServerClient Client)
        {
            //ThreadPool.QueueUserWorkItem(new WaitCallback(msgz), Client);
        }
        void msgz(Object arg)
        {
            ServerClient Client = (ServerClient)arg;
            iPrintLnBold("^1Welcome to the ^2Random Weapon ^3Mod ^1by ^4JayDi", Client);
            //SafeSleep(1);
            //iPrintLnBold("^2ITSMODS.COM", Client);
        }

        void weapz(Object arg)
        {
            //Thread.Sleep(200);
            ServerClient Client = (ServerClient)arg;
            // magic trick to avoid running in infected and gungame (by: Pieter/JoSchaap)
            bool younoworkokay = false;
            String gametype = GetDvar("g_gametype");
            if (gametype == "gun")
            {
                younoworkokay = true;
            }
            if (gametype == "infect")
            {
                younoworkokay = false;
                if (Client.Team != Teams.Allies)
                {
                    younoworkokay = true;
                }
            }
            if (younoworkokay != true)
            {
                
                
                {
                    Client.Other.ClearPerks(); // Clear perks ffs

                    string[] AllSecondaries = { "iw5_mp9_mp",
                                        "iw5_skorpion_mp", };
                    //"iw5_fmg9_mp",
                    //"iw5_g18_mp",
                    //"iw5_mp412_mp",
                    //"iw5_deserteagle_mp",
                    //"iw5_usp45_mp",
                    //"iw5_p99_mp",
                    //"iw5_fnfiveseven_mp",
                    //"rpg_mp",
                    //"iw5_smaw_mp",
                    //"stinger_mp",
                    //"javelin_mp",
                    //"xm25_mp",
                    string[] AllPrimaries = { "iw5_g36c_mp",
                                    "iw5_m4_mp",
                                    "iw5_fad_mp",
                                    "iw5_acr_mp",
                                    "iw5_type95_mp",
                                    "iw5_mk14_mp",
                                    "iw5_scar_mp",
                                    "iw5_cm901_mp",
                                    "iw5_mp7_mp",
                                    "iw5_p90_mp",
                                    "iw5_ump45_mp",
                                    "iw5_barrett_mp_barrettscope",
                                    "iw5_rsass_mp_rsassscope",
                                    "iw5_dragunov_mp_dragunovscope",
                                    "iw5_msr_mp_msrscope",
                                    "iw5_pp90m1_mp",
                                    "iw5_as50_mp_as50scope", };
                    //"iw5_ak47_mp",
                    //"iw5_m16_mp",
                    //"iw5_sa80_mp",
                    //"iw5_striker_mp",
                    //"iw5_m60_mp",
                    //"iw5_ksg_mp",
                    //"iw5_mp5_mp",
                    //"iw5_pecheneg_mp",
                    //"iw5_mg36_mp",
                    //"iw5_m9_mp",
                    //"iw5_mk46_mp",
                    //"iw5_spas12_mp",
                    //"riotshield_mp",
                    //"iw5_aa12_mp",
                    //"iw5_1887_mp",
                    //"iw5_usas12_mp",
                    //"ac130_105mm_mp",
                    string[] AllPerks = {  "specialty_assists",
                                    "specialty_fastreload",
                                    "specialty_twoprimaries",
                                    "specialty_quickdraw",
                                    "specialty_autospot",
                                    "specialty_stalker",
                                    "specialty_bulletaccuracy",
                                    "specialty_scavenger", };
                    //"specialty_blastshield",
                    //"specialty_hardline",
                    //"specialty_blindeye",
                    //"specialty_coldblooded",
                    //"specialty_paint",
                    //"specialty_quieter",
                    //"specialty_detectexplosive",
                    string[] AllOffhand = { "flash_grenade_mp",
                                    "concussion_grenade_mp",
                                    "trophy_mp", };
                    //"smoke_grenade_mp",
                    //"specialty_scrambler",
                    //"specialty_portable_radar",
                    //"specialty_tacticalinsertion",
                    //"emp_grenade_mp",
                    string[] AllEquipment = { "c4_mp",
                                    "claymore_mp",
                                    "bouncingbetty_mp", };
                    //"frag_grenade_mp",
                    //"semtex_mp",
                    //"specialty_portable_radar",
                    //"throwingknife_mp",
                    // ========== Attachments ================//
                    string[] assAttachs = { "_acog",
                                    "_reflex",
                                    "_silencer",
                                    "_gl",
                                    "_fmj",
                                    "_eotech", };
                    //"_hybrid",
                    //"_heartbeat",
                    //"_thermal",
                    //"_shotgun",
                    //"_xmags",
                    string[] smgAttachs = { "_acogsmg",
                                    "_reflexsmg",
                                    "_rof",
                                    "_eotechsmg", };
                    //"_hamrhybrid",
                    //"_thermalsmg",

                    string[] lmgAttachs = { "_reflexlmg",
                                    "_eotechlmg",
                                    "_grip",
                                    "_acog",};
                    //"_thermal",

                    string[] sniperAttachs = { "_zoomscope",
                                         "_acog", };
                    //"_heartbeat",
                    //"_thermal",
                    //"_xmags",

                    string[] shotgunAttachs = { "_grip",
                                        "_reflex",
                                        "_eotech", };
                    //"_xmags",

                    string[] pistolAttachs = { "_akimbo",
                                       "_tactical", };

                    string[] mpAttachs = { "_akimbo",
                                   "_reflex",
                                   "_eotech", };
                    //"_xmags",
                    string[] camo = { "camo0",
                                "camo01",
                                "camo02",
                                "camo03",
                                "camo05",
                                "camo06",
                                "camo07",
                                "camo8",
                                "camo9",
                                "camo10",
                                "camo11", };
                               //"camo04",

                    // =============== Init ================= //
                    bool assault = false;
                    bool sniper = false;
                    bool smg = false;
                    bool explosive = false;
                    bool other = false;
                    bool mpistol = false;
                    bool special = false;
                    bool riot = false;


                    // ====== Get Random Weapon ===== //
                    // Primary
                    string primary = getRandom(AllPrimaries);
                    int primarywep = GetWeapon(primary);
                    // Secondary
                    string secondary = getRandom(AllSecondaries);
                    int secondarywep = GetWeapon(secondary);
                    // Perk
                    string perk = getRandom(AllPerks);
                    int myperk = GetPerk(perk);
                    // Offhand
                    string offhand = getRandom(AllOffhand);
                    int offhandwep = GetWeapon(offhand);
                    // Equipment
                    string equipment = getRandom(AllEquipment);
                    int equipmentwep = GetWeapon(equipment);

                    //int badwep = 0;
                    //Client.Other.PrimaryWeapon = badwep;
                    //Client.Other.CurrentWeapon = badwep;

                    //int badwep2 = GetWeapon("iw5_barrett_mp_barrettscope");
                    //Client.Other.PrimaryWeapon = badwep2;
                    //Client.Other.CurrentWeapon = badwep2;

                    // ======= OMG SHITLOAD OF CODES GOING NEXT ======== //

                    Client.Other.SetPerk(myperk);
                    Client.Other.OffhandWeapon = offhandwep;
                    Client.Other.Equipment = equipmentwep;

                    iPrintLnBold("^2Random Weapons & perks Initialised. ", Client);
                    if (primary == "iw5_mg36_mp")
                    {

                    }

                    //sniperz
                    else if (primary == "iw5_msr_mp")
                    {
                        sniper = true;

                        int WepID = GetWeapon(primary + getRandom(sniperAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(sniperAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_dragunov_mp")
                    {

                        sniper = true;

                        int WepID = GetWeapon(primary + getRandom(sniperAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(sniperAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_rsass_mp")
                    {
                        sniper = true;

                        int WepID = GetWeapon(primary + getRandom(sniperAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(sniperAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_barrett_mp")
                    {
                        sniper = true;

                        int WepID = GetWeapon(primary + getRandom(sniperAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(sniperAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_l96a1_mp")
                    {
                        sniper = true;

                        int WepID = GetWeapon(primary + getRandom(sniperAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(sniperAttachs) + "_" + getRandom(camo), Client);
                    }
                    // smgzzz
                    else if (primary == "iw5_ump45_mp")
                    {
                        smg = true;

                        int WepID = GetWeapon(primary + getRandom(smgAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(smgAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_pp90m1_mp")
                    {
                        smg = true;

                        int WepID = GetWeapon(primary + getRandom(smgAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(smgAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_p90_mp")
                    {
                        smg = true;

                        int WepID = GetWeapon(primary + getRandom(smgAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(smgAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_m9_mp")
                    {
                        smg = true;

                        int WepID = GetWeapon(primary + getRandom(smgAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(smgAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_mp7_mp")
                    {
                        smg = true;

                        int WepID = GetWeapon(primary + getRandom(smgAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(smgAttachs) + "_" + getRandom(camo), Client);
                    }

                    else if (primary == "iw5_mp5_mp")
                    {
                        smg = true;

                        int WepID = GetWeapon(primary + getRandom(smgAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(smgAttachs) + "_" + getRandom(camo), Client);
                    }
                    // assault
                    else if (primary == "iw5_cm901_mp")
                    {
                        assault = true;

                        int WepID = GetWeapon(primary + getRandom(assAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(assAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_g36c_mp")
                    {
                        assault = true;

                        int WepID = GetWeapon(primary + getRandom(assAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(assAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_scar_mp")
                    {
                        assault = true;

                        int WepID = GetWeapon(primary + getRandom(assAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(assAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_mk14_mp")
                    {
                        assault = true;

                        int WepID = GetWeapon(primary + getRandom(assAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(assAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_type95_mp")
                    {
                        assault = true;

                        int WepID = GetWeapon(primary + getRandom(assAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(assAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_fad_mp")
                    {
                        assault = true;

                        int WepID = GetWeapon(primary + getRandom(assAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(assAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_m4_mp")
                    {
                        assault = true;

                        int WepID = GetWeapon(primary + getRandom(assAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(assAttachs) + "_" + getRandom(camo), Client);
                    }
                    else if (primary == "iw5_ak47_mp")
                    {
                        assault = true;

                        int WepID = GetWeapon(primary + getRandom(assAttachs) + "_" + getRandom(camo));
                        Client.Other.PrimaryWeapon = WepID;
                        Client.Other.CurrentWeapon = WepID;
                        iPrintLn("^1" + primary + getRandom(assAttachs) + "_" + getRandom(camo), Client);
                    }
                    // otherzz
                    else if (primary == "riotshield_mp")
                    {
                        riot = true;

                        Client.Other.PrimaryWeapon = primarywep;
                        Client.Other.CurrentWeapon = primarywep;
                    }

                    // Automachine pistols
                    if (secondary == "iw5_fmg9_mp")
                    {
                        mpistol = true;
                        int WepID = GetWeapon(secondary + getRandom(mpAttachs));
                        Client.Other.SecondaryWeapon = WepID;
                    }
                    if (secondary == "iw5_mp9_mp")
                    {
                        mpistol = true;
                        int WepID = GetWeapon(secondary + getRandom(mpAttachs));
                        Client.Other.SecondaryWeapon = WepID;
                    }
                    if (secondary == "iw5_skorpion_mp")
                    {
                        mpistol = true;
                        int WepID = GetWeapon(secondary + getRandom(mpAttachs));
                        Client.Other.SecondaryWeapon = WepID;
                    }

                    Ammoz(Client);
                }
            }
        }

        // ============== Other =================== //
        public static void Ammoz(ServerClient client)
        {
            client.Ammo.PrimaryAmmoClip = 298;
            client.Ammo.SecondaryAmmoClip = 240;
        }

        string getRandom(string[] input)
        {
            Random r = new Random();
            return input[randomFix().Next(0, input.Length)];
        }
        public static Random randomFix()
        {
            //Thread.Sleep(10);
            return new Random();
        }

        
        
    }
}
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

  Reply
#2
Use stopwatch and elapsedMilisec value, i did this in my 'KillMe' mod, @Ich1994 used it in ezm
C++/Obj-Cdeveloper. Neko engine wip
Steam: Click
  Reply
#3
Meh... I think i should write a tutorial
[Image: compiling.png][Image: aLKA8og_460sa.gif]
  Reply
#4
@SailorMoon sorry i don't know how to do that, anyone willing to help?
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

  Reply
#5
no-one?

EDIT
close if ya want, it's sorted.
[Image: b_560_95_1.png]


[Image: b_560_95_1.png]

  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help threading remove EnVi Sweden Rocks 3 3,018 01-28-2013, 15:26
Last Post: JariZ
  Help Remove Threading/tidyup hillbilly 4 4,192 09-16-2012, 11:09
Last Post: zxz0O0
  Removing crosshair in single player: a challenge? Peyre 0 2,215 11-10-2011, 15:18
Last Post: Peyre
  Removing Names 4FunPlayin 5 3,364 10-06-2011, 19:51
Last Post: Yamato
  [SOLVED] Removing the xp gain number from medal messages Cyborgking 7 4,096 09-15-2011, 16:05
Last Post: Cyborgking
Shocked Changing/Removing a Poll? GoldenWrapper 4 2,893 09-07-2011, 00:55
Last Post: GoldenWrapper
Question Help Removing hud elements FRAN710 3 2,909 08-09-2011, 22:09
Last Post: thre3pi
  removing red dots on minimap / objects in your UI koil 5 2,987 07-26-2011, 07:33
Last Post: koil
  removing red dots on minimap koil 2 2,022 06-27-2011, 13:46
Last Post: AZUMIKKEL
  Removing Class Selection Screen thre3pi 5 2,886 06-27-2011, 00:55
Last Post: koil

Forum Jump:


Users browsing this thread: 1 Guest(s)