Page 1 of 1

How to set all weapon types to be the same

Posted: Fri Sep 18, 2020 8:48 pm
by HelpMeIAmSerious
Hello! I'm pretty unexperienced with C#, so I'm not sure how to make a script that lets me set all weapon types to be the same. In short, I want to make it so that people can only hold one weapon at a time and this weapon will be assigned to the same inventory spot. Here's what I have below.

public void OnStartup(){
IObject[] Obj = Game.GetObjectsByName(new string[]{
"SpawnWeaponArea", "SpawnWeaponAreaCeiling"});
foreach(IObject Object in Obj){
obj.SetWeaponType(1);
}
}

I pretty much stole "ARMADYL5"'s script which deletes all weapons

Re: How to set all weapon types to be the same

Posted: Sat Sep 19, 2020 3:04 pm
by Odex64
Do you wanna change weapons' spawn chance or just give everyone the same weapon? If it's the first case, I already wrote a small script a while ago.

Code: Select all

string[] weapons = { "MAGNUM 1", "SHOTGUN 2", "KATANA 3", "PIPE 4", "TOMMYGUN 5", "M60 6", "MACHETE 8", "SNIPER 9", "SAWED OFF 10", "BAT 11",
            "UZI 12", "PILLS 13", "MEDKIT 14", "SLOWMO_5 15", "SLOWMO_10 16", "BAZOOKA 17", "AXE 18", "ASSAULT 19", "GRENADES 20", "LAZER 21", "CARBINE 23",
            "PISTOL 24", "MOLOTOVS 25", "FLAMETHROWER 26", "FLAREGUN 27", "REVOLVER 28", "GRENADE_LAUNCHER 29", "SMG 30", "HAMMER 31", "SILENCEDPISTOL 39",
            "SILENCEDUZI 40", "BATON 41", "C4 42", "MINES 44", "SHURIKEN 45", "CHAIN 46", "KNIFE 49", "MACHINE_PISTOL 53", "DARK_SHOTGUN 54", "MP50 55",
            "LEAD_PIPE 56", "SHOCK_BATON 57", "CHAINSAW 59", "PISTOL45 61", "STRENGTHBOOST 62", "SPEEDBOOST 63", "BOW 64", "WHIP 65", "BOUNCINGAMMO 66", "FIREAMMO 67" };

Dictionary<short, int> def = new Dictionary<short, int>();
public void OnStartup()
{
    string value = null;
    def = Game.GetWeaponSpawnChances();
    if (Game.LocalStorage.TryGetItemString("chances", out value))
    {
        Game.ClearWeaponSpawnChances();
        string[] info = value.Split(' ');
        for (int i = 0; i < info.Count() - 1; i++)
            Game.UpdateWeaponSpawnChances(new Dictionary<short, int> { { short.Parse(info[i]), 100 } });
    }
    Events.UserMessageCallback.Start(Commands);
}

public void Commands(UserMessageCallbackArgs args)
{
    if (args.IsCommand && args.User.IsModerator)
    {
        switch (args.Command)
        {
            case "CMDS":
                Game.ShowChatMessage("SPAWN <weapons name> - set weapons spawn", Color.Yellow, args.User.UserIdentifier);
                Game.ShowChatMessage("RESET - reset default weapons spawn", Color.Yellow, args.User.UserIdentifier);
                break;

            case "SPAWN":
                string temp = "";
                string[] extra = args.CommandArguments.Split(' ');
                Dictionary<short, int> dic = new Dictionary<short, int>();
                for (int i = 0; i <= extra.Count() - 1; i++)
                {
                    foreach (string wep in weapons)
                    {
                        string[] info = wep.Split(' ');
                        if (info[0].Contains(extra[i].ToUpper()))
                        {
                            dic.Add(short.Parse(info[1]), 100);
                            temp += info[1] + ' ';
                            Game.LocalStorage.SetItem("chances", temp);
                        }
                    }
                }
                if (dic.Count() > 0)
                {
                    Game.ClearWeaponSpawnChances();
                    Game.UpdateWeaponSpawnChances(dic);
                    Game.ShowChatMessage("Spawn chances changed");
                }
                else
                    Game.ShowChatMessage("Error!");
                break;

            case "NORMAL":
                Game.LocalStorage.RemoveItem("chances");
                Game.UpdateWeaponSpawnChances(def);
                Game.ShowChatMessage("Spawn chances reset");
                break;
        }
    }
}
HOW TO USE IT: with /spawn magnum katana sniper the game will spawn only magnum, katana and snipers during the match, you can do it with any other spawnable weapon. The good thing is that your settings will be saved so you don't have to type the same command for every round (this is good for competitive matches where you you want to exclude some weapons).
With /normal command you can reset the default spawns.

Re: How to set all weapon types to be the same

Posted: Fri Oct 16, 2020 8:48 pm
by HelpMeIAmSerious
Thank you very much! Sorry for the late response.