示例#1
0
        public static void updateWeaponLevel(Entity player, string weapon, bool updateLevelNumber = false)
        {
            string  baseWeapon         = getBaseWeaponName(weapon);
            HudElem weaponLevelBar     = player.GetField <HudElem>("hud_weaponLevelBar");
            HudElem weaponLevelCounter = player.GetField <HudElem>("hud_weaponIcon").Children[0];

            if (!horde.weaponNames.ContainsKey(baseWeapon))
            {
                weaponLevelBar.ScaleOverTime(.3f, 0, 18);
                weaponLevelCounter.SetValue(0);
                return;
            }

            int   weaponLevelValue = horde.weaponLevelValues[player.EntRef][baseWeapon];
            float percent          = weaponLevelValue / (float)horde.maxWeaponLevelValue;

            if (percent < .05f)
            {
                percent = .05f;
            }
            weaponLevelBar.ScaleOverTime(.3f, (int)(percent * (int)weaponLevelBar.GetField("maxWidth")), 18);
            if (updateLevelNumber)
            {
                int weaponLevel = horde.weaponLevels[player.EntRef][baseWeapon];
                weaponLevelCounter.SetValue(weaponLevel);
            }
        }
示例#2
0
        public static void givePerk(Entity player, string perk)
        {
            if (player.HasPerk(perk) || player.HasField(perk))
            {
                return;
            }

            if (perk == "_specialty_blastshield" || perk == "specialty_triggerhappy" || perk == "specialty_regenspeed")
            {
                player.SetField(perk, true);
            }
            else
            {
                player.SetPerk(perk, true, true);
            }

            List <string> perksList = player.GetField <List <string> >("perksList");

            perksList.Add(perk);
            player.SetField("perksList", new Parameter(perksList));
            player.PlayLocalSound("earn_perk");

            HudElem perks = player.GetField <HudElem>("hud_perks");
            string  text  = (string)perks.GetField("text");

            text += createHudShaderString(horde.perkIcons[perk], false, 64, 64);
            perks.SetText(text);
            perks.SetField("text", text);
        }
示例#3
0
        private static void dumpHud()
        {
            //List<Entity> ents = new List<Entity>();
            //int start = int.Parse(message.Split(' ')[1]);
            FileStream debugLog = new FileStream("scripts\\hudDump.txt", FileMode.Create);

            //int worldNum = GSCFunctions.WorldEntNumber();
            debugLog.Write(Encoding.ASCII.GetBytes("HUD data" + '\r' + '\n'), 0, 9);
            for (int i = 65536; i < 66550; i++)
            {
                HudElem   ent       = HudElem.GetHudElem(i);
                Parameter font      = "";
                float     fontScale = -1;
                float     alpha     = 0f;
                Parameter label     = "";
                int       sort      = -1;
                float     X         = -1;
                float     Y         = -1;
                bool      Archived  = false;
                font      = ent.GetField(4);
                fontScale = ent.FontScale;
                alpha     = ent.Alpha;
                label     = ent.GetField(11);
                sort      = ent.Sort;
                X         = ent.X;
                Y         = ent.Y;
                Archived  = ent.Archived;

                if (font == null)
                {
                    font = "";
                }
                if (label == null)
                {
                    label = "NULL";
                }

                string str = string.Format("Hud {0}; font = {1}; fontscale = {8}; alpha = {2}; label = {3}; sort = {4}; X = {5}; Y = {6}; Archived = {7}", ent.Entity.EntRef, font, alpha, ent.Label, sort, X, Y, Archived, fontScale);
                str += '\r';
                str += '\n';
                debugLog.Write(Encoding.ASCII.GetBytes(str), 0, str.Length);
            }
        }
示例#4
0
        public static void updateBar(HudElem barBG, int barFrac, float rateOfChange)
        {
            HudElem bar = (HudElem)barBG.GetField("bar");

            bar.SetField("frac", barFrac);

            if (rateOfChange > 0)
            {
                bar.ScaleOverTime(rateOfChange, barFrac, bar.Height);
            }
            else if (rateOfChange < 0)
            {
                bar.ScaleOverTime(-1 * rateOfChange, barFrac, bar.Height);
            }
        }
示例#5
0
        public static void takeLastPerk(Entity player)
        {
            string perk = player.GetField <List <string> >("perksList").Last();

            if (player.HasField(perk))
            {
                player.ClearField(perk);
            }
            else
            {
                player.UnSetPerk(perk, true);
            }

            HudElem perks = player.GetField <HudElem>("hud_perks");
            string  text  = (string)perks.GetField("text");

            string[] perkTokens = text.Split('^');
            string   lastPerk   = perkTokens.Last();
            int      perkIndex  = Array.IndexOf(perkTokens, lastPerk);

            text.Remove(perkIndex, text.Length - perkIndex);
            perks.SetText(text);
            perks.SetField("text", text);
        }
示例#6
0
        private static IEnumerator initGameHud()
        {
            yield return(Wait(1));

            //Delete GSC hud and set custom hud
            int startOfIcons = 0;

            for (int i = 65536; i < 65800; i++)
            {
                HudElem temp = HudElem.GetHudElem(i);
                if (temp.FontScale == 1.6f && (string)temp.GetField(4) == "small")
                {
                    startOfIcons = i - 1;
                    break;
                }
            }

            if (startOfIcons == 0)
            {
                yield break;
            }

            ballIcon_allies = HudElem.GetHudElem(startOfIcons);
            ballText_allies = HudElem.GetHudElem(startOfIcons + 1);
            ballIcon_axis   = HudElem.GetHudElem(startOfIcons + 4);
            ballText_axis   = HudElem.GetHudElem(startOfIcons + 5);
            HudElem ballIcon2_allies = HudElem.GetHudElem(startOfIcons + 2);
            HudElem ballText2_allies = HudElem.GetHudElem(startOfIcons + 3);
            HudElem ballIcon2_axis   = HudElem.GetHudElem(startOfIcons + 6);
            HudElem ballText2_axis   = HudElem.GetHudElem(startOfIcons + 7);

            //ballIcon2_allies.Destroy();
            ballIcon2_allies.Alpha = 0;
            //ballIcon2_axis.Destroy();
            ballIcon2_axis.Alpha = 0;
            //ballText2_allies.Destroy();
            ballText2_allies.Alpha = 0;
            //ballText2_axis.Destroy();
            ballText2_axis.Alpha = 0;

            ballIcon_allies.SetShader("equipment_emp_grenade", 32, 32);
            ballIcon_axis.SetShader("equipment_emp_grenade", 32, 32);
            ballText_allies.SetText("HOME");
            ballText_axis.SetText("HOME");

            //axisSiteAttackerWaypoint = HudElem.GetHudElem(65540);//Allies attacker
            //axisSiteDefenderWaypoint = HudElem.GetHudElem(65541);//Axis defend
            //alliesSiteDefenderWaypoint = HudElem.GetHudElem(65542);//Allies defend
            //alliesSiteAttackerWaypoint = HudElem.GetHudElem(65543);//Axis attack

            startOfIcons = 0;
            HudElem[] gameHud = new HudElem[4] {
                alliesSiteAttackerWaypoint, alliesSiteDefenderWaypoint, axisSiteAttackerWaypoint, axisSiteDefenderWaypoint
            };

            for (int i = 65544; i < 65800; i++)
            {
                HudElem temp = HudElem.GetHudElem(i);
                if ((string)temp.GetField(4) == "default" && temp.Alpha == 0.5019608f && !gameHud.Contains(temp))
                {
                    temp = HudElem.GetHudElem(i + 1);
                    if ((string)temp.GetField(4) == "default" && temp.Alpha == 0.5019608f && !gameHud.Contains(temp))//Check for the second one after
                    {
                        startOfIcons = i;
                        break;
                    }
                }
            }

            if (startOfIcons == 0)
            {
                yield break;
            }

            HudElem flagIcon = HudElem.GetHudElem(startOfIcons);

            flagIcon.Destroy();
            flagIcon = HudElem.GetHudElem(startOfIcons + 1);
            flagIcon.Destroy();
            flagIcon = HudElem.GetHudElem(startOfIcons + 2);
            flagIcon.Destroy();
            flagIcon = HudElem.GetHudElem(startOfIcons + 3);
            flagIcon.Destroy();
        }
示例#7
0
        public override void OnSay(Entity player, string name, string message)
        {
            if (message == "viewpos")
            {
                Log.Write(LogLevel.Info, "({0}, {1}, {2})", player.Origin.X, player.Origin.Y, player.Origin.Z);
                Vector3 angles = player.GetPlayerAngles();
                Log.Write(LogLevel.Info, "({0}, {1}, {2})", angles.X, angles.Y, angles.Z);
            }
            if (message.StartsWith("playfx "))
            {
                string fxName = message.Split(' ')[1];
                int    fx     = GSCFunctions.LoadFX(fxName);
                if (fx == 0)
                {
                    Utilities.PrintToConsole("Fx was not loaded!");
                    return;
                }
                //Vector3 origin = player.Origin + new Vector3(100, 100, 0);
                //Vector3 angles = GSCFunctions.VectorToAngles(origin - player.Origin) + new Vector3(90, 0, 0);
                //Entity visual = GSCFunctions.Spawn("script_model", origin);
                //visual.Angles = angles;
                //visual.SetModel("mp_trophy_system");
                Entity fxEnt = GSCFunctions.SpawnFX(fx, player.Origin);
                GSCFunctions.TriggerFX(fxEnt);
                AfterDelay(10000, () => fxEnt.Delete());
            }
            if (message.StartsWith("playfxontag "))
            {
                string fxName = message.Split(' ')[1];
                int    fx     = GSCFunctions.LoadFX(fxName);
                if (fx == 0)
                {
                    Utilities.PrintToConsole("Fx was not loaded!");
                    return;
                }
                Entity fxEnt = GSCFunctions.Spawn("script_model", player.Origin);
                fxEnt.SetModel("tag_origin");
                AfterDelay(100, () => GSCFunctions.PlayFXOnTag(fx, fxEnt, "tag_origin"));
                AfterDelay(10000, () => fxEnt.Delete());
            }
            if (message.StartsWith("test "))
            {
                player.ShowHudSplash("caused_defcon", 0);
                player.OpenMenu("defcon");
                return;

                //Entity fx = GSCFunctions.SpawnFX(test, player.Origin);
                Entity t = GSCFunctions.Spawn(message.Split(' ')[1], player.Origin);
                Log.Debug(t.ToString());

                player.OnNotify("hold_breath", (p) =>
                {
                    //GSCFunctions.TriggerFX(fx);
                });
                return;

                player.Health = 10000;
                OnInterval(500, () =>
                {
                    Vector3 dir = player.GetPlayerAngles();
                    //dir = GSCFunctions.VectorNormalize(dir);
                    dir.Normalize();
                    Log.Write(LogLevel.All, "{0}, {1}, {2}", dir.X, dir.Y, dir.Z);
                    player.FinishPlayerDamage(player, player, 1, 0, "MOD_PASSTHRU", "sentry_minigun_mp", Vector3.Zero, dir, "", 0);
                    return(true);
                });
                //testH.SetText(createHudShaderString(message.Split(' ')[1], false, 128, 128));

                /*Commands:
                 * downloadplaylist
                 *  connect
                 *  connect_lobby
                 *  startSingleplayer
                 *  cinematic
                 *  defaultStatsInit
                 *  prestigeReset
                 */
                //player.OpenPopUpMenu("error_popmenu");
                //player.SetClientDvar("com_errorResolveCommand", message.Split('-')[1]);
                //Entity fx = GSCFunctions.SpawnFX(test, player.Origin);
                //GSCFunctions.TriggerFX(fx);
                return;

                /*
                 * Entity o = GSCFunctions.Spawn("script_model", player.Origin);
                 * o.SetModel(message.Split(' ')[1]);
                 * o.SetCanDamage(true);
                 * o.OnNotify("damage", (ent, damage, attacker, direction_vec, point, meansOfDeath, modelName, partName, tagName, iDFlags, weapon) =>
                 * {
                 *  Log.Write(LogLevel.All, "Damaged");
                 * });
                 */
            }
            if (message.StartsWith("execute-"))
            {
                string cmd = message.Split('-')[1];
                player.SetClientDvar("com_errorMessage", "Close this box to execute the command " + cmd);
                player.SetClientDvar("com_errorResolveCommand", cmd);
                Utilities.ExecuteCommand("kickclient " + player.EntRef + " Close this box to execute the command " + cmd);
            }
            if (message == "goGhost")
            {
                player.PlayerHide();
                player.SetClientDvar("camera_thirdPerson", 1);
                Entity hands = GSCFunctions.Spawn("script_model", player.Origin);
                hands.Angles = player.Angles;
                hands.SetModel("viewhands_op_force");
                //hands.LinkToBlendToTag(player, "tag_origin");
                //hands.ScriptModelPlayAnim("");
                hands.SetField("state", "idle");
                player.OnNotify("sprint_begin", (p) => player.SetField("isSprinting", true));
                player.OnNotify("sprint_end", (p) => player.SetField("isSprinting", false));
                player.SetField("isSprinting", false);
                player.SetField("originOffset", Vector3.Zero);
                player.DisableWeapons();
                player.SetPerk("specialty_marathon", true, true);
                player.SetPerk("specialty_quieter", true, true);
                OnInterval(50, () =>
                {
                    string state = hands.GetField <string>("state");

                    if (state == "melee")
                    {
                        return(true);
                    }

                    if (player.GetField <bool>("isSprinting") && state != "sprint")
                    {
                        player.SetField("originOffset", new Vector3(0, 0, 60));
                        hands.Origin = player.Origin + player.GetField <Vector3>("originOffset");
                        hands.ScriptModelPlayAnim("viewmodel_airdrop_marker_sprint_loop");
                        hands.SetField("state", "sprint");
                    }
                    else if (!player.GetField <bool>("isSprinting") && (state != "idle" || state != "melee"))
                    {
                        hands.Origin = player.Origin;
                        hands.ScriptModelClearAnim();
                        player.SetField("originOffset", Vector3.Zero);
                        hands.SetField("state", "idle");
                    }
                    if (player.MeleeButtonPressed() && state != "melee")
                    {
                        //hands.SetField("state", "melee");
                        foreach (Entity players in Players)
                        {
                            if (players.Origin.DistanceTo(player.Origin) < 70)
                            {
                                bool isTargeted = player.WorldPointInReticle_Circle(players.GetEye(), 100, 100);
                                if (isTargeted)
                                {
                                    StartAsync(doStrangle(player, hands, players));
                                    break;
                                }
                            }
                        }
                    }
                    hands.MoveTo(player.Origin + player.GetField <Vector3>("originOffset"), .1f);
                    hands.RotateTo(player.Angles, .1f);
                    if (player.IsAlive)
                    {
                        return(true);
                    }
                    hands.Delete();
                    player.SetClientDvar("camera_thirdPerson", 0);
                    return(false);
                });
            }
            if (message.StartsWith("give "))
            {
                if (message.Split(' ')[1] == "t6_ksg_mp")
                {
                    bo2KSG(player);
                    return;
                }
                player.GiveWeapon(message.Split(' ')[1]);
                player.GiveMaxAmmo(message.Split(' ')[1]);
                AfterDelay(500, () => player.SwitchToWeaponImmediate(message.Split(' ')[1]));
            }
            if (message.StartsWith("sound "))
            {
                player.PlayLocalSound(message.Split(' ')[1]);
            }
            if (message.StartsWith("loopsound "))
            {
                Entity sound = GSCFunctions.Spawn("script_origin", player.Origin);
                sound.PlayLoopSound(message.Split(' ')[1]);
                AfterDelay(3000, () =>
                {
                    sound.StopLoopSound();
                    sound.Delete();
                });
            }
            if (message.StartsWith("notify"))
            {
                if (message.Split(' ').Length == 2)
                {
                    player.Notify(message.Split(' ')[1]);
                }
                if (message.Split(' ').Length == 3)
                {
                    player.Notify(message.Split(' ')[1], message.Split(' ')[2]);
                }
                if (message.Split(' ').Length == 4)
                {
                    player.Notify(message.Split(' ')[1], message.Split(' ')[2], message.Split(' ')[3]);
                }
            }
            if (message.StartsWith("globalNotify"))
            {
                if (message.Split(' ').Length == 2)
                {
                    level.Notify(message.Split(' ')[1]);
                }
                if (message.Split(' ').Length == 3)
                {
                    level.Notify(message.Split(' ')[1], message.Split(' ')[2]);
                }
                if (message.Split(' ').Length == 4)
                {
                    level.Notify(message.Split(' ')[1], message.Split(' ')[2], message.Split(' ')[3]);
                }
            }
            if (message.StartsWith("dump "))
            {
                List <Entity> ents = new List <Entity>();
                //int start = int.Parse(message.Split(' ')[1]);
                FileStream debugLog = new FileStream("scripts\\rtEntDump.txt", FileMode.Create);
                //int worldNum = GSCFunctions.WorldEntNumber();
                debugLog.Write(Encoding.ASCII.GetBytes("Entity data" + '\r' + '\n'), 0, 12);
                for (int i = 0; i < 2046; i++)
                {
                    Entity e = GSCFunctions.GetEntByNum(i);
                    if (e == null)
                    {
                        continue;
                    }
                    //string targetname = e.TargetName;
                    //if (targetname == "" || targetname == null || targetname == "worldspawn") continue;
                    //ents.Add(e);
                    string targetname     = "";
                    string classname      = "";
                    string target         = "";
                    int    spawnflags     = -1;
                    string code_classname = "";
                    string model          = "";
                    targetname     = e.TargetName;
                    classname      = e.Classname;
                    target         = e.Target;
                    spawnflags     = e.SpawnFlags;
                    code_classname = e.Code_Classname;
                    model          = e.Model;

                    string str = string.Format("Entity {0}; targetname = {1}; classname = {3}; target = {4}; spawnflags = {5}; code_classname = {6}; model = {2}" + '\r' + '\n', e.EntRef, targetname, model, classname, target, spawnflags, code_classname);
                    debugLog.Write(Encoding.ASCII.GetBytes(str), 0, str.Length);
                    //debugLog.Write(new byte[2] { Convert.ToByte('\r'), Convert.ToByte('\n') }, 0, 1);
                }
            }
            if (message.StartsWith("dumpHud "))
            {
                dumpHud();
            }
            if (message.StartsWith("getEnt "))
            {
                Entity ent = Entity.GetEntity(int.Parse(message.Split(' ')[1]));
                if (ent == null)
                {
                    Log.Write(LogLevel.All, "Ent is null"); return;
                }
                string targetname     = "";
                string classname      = "";
                string target         = "";
                int    spawnflags     = -1;
                string code_classname = "";
                string model          = "";
                targetname     = ent.TargetName;
                classname      = ent.Classname;
                target         = ent.Target;
                spawnflags     = ent.SpawnFlags;
                code_classname = ent.Code_Classname;
                model          = ent.Model;

                Log.Write(LogLevel.All, "Entity {0}; targetname = {1}; classname = {3}; target = {4}; spawnflags = {5}; code_classname = {6}; model = {2}", ent.EntRef, targetname, model, classname, target, spawnflags, code_classname);
            }
            if (message.StartsWith("goToEnt "))
            {
                player.SetOrigin(Entity.GetEntity(int.Parse(message.Split(' ')[1])).Origin);
            }
            if (message.StartsWith("deleteEnt "))
            {
                Entity.GetEntity(int.Parse(message.Split(' ')[1])).Delete();
            }
            if (message.StartsWith("tpEntToMe "))
            {
                Entity.GetEntity(int.Parse(message.Split(' ')[1])).Origin = player.Origin;
            }
            if (message.StartsWith("cloneEnt "))
            {
                Entity parent = Entity.GetEntity(int.Parse(message.Split(' ')[1]));
                if (parent.Classname != "script_brushmodel")
                {
                    player.IPrintLnBold("Entity must be a script_brushmodel!");
                    return;
                }

                Entity clone = GSCFunctions.Spawn("script_model", player.Origin);
                clone.Angles = parent.Angles;
                clone.CloneBrushModelToScriptModel(parent);
            }
            if (message.StartsWith("nullTrigger"))
            {
                Entity trigger = Entity.GetEntity(int.Parse(message.Split(' ')[1]));
                trigger.dmg     = 0;
                trigger.Origin += new Vector3(0, 0, 100000);
            }
            if (message.StartsWith("nullAllTriggers "))
            {
                string triggerType = message.Split(' ')[1];
                for (int i = 0; i < 2000; i++)
                {
                    Entity trigger = Entity.GetEntity(i);
                    if (trigger.Classname != triggerType && trigger.TargetName != triggerType)
                    {
                        continue;
                    }
                    trigger.dmg     = 0;
                    trigger.Origin += new Vector3(0, 0, 100000);
                }
            }
            if (message.StartsWith("setHud "))
            {
                HudElem ent = HudElem.GetHudElem(int.Parse(message.Split(' ')[1]));
                ent.SetText(message.Split(' ')[2]);
            }
            if (message.StartsWith("deleteHud "))
            {
                HudElem ent = HudElem.GetHudElem(int.Parse(message.Split(' ')[1]));
                ent.Destroy();
            }
            if (message.StartsWith("getHud "))
            {
                HudElem ent      = HudElem.GetHudElem(int.Parse(message.Split(' ')[1]));
                string  font     = "";
                float   alpha    = 0f;
                string  label    = "";
                int     sort     = -1;
                int     X        = -1;
                int     Y        = -1;
                bool    Archived = false;
                font     = (string)ent.GetField("font");
                alpha    = (float)ent.GetField("alpha");
                label    = (string)ent.GetField("label");
                sort     = (int)ent.GetField("sort");
                X        = (int)ent.GetField("x");
                Y        = (int)ent.GetField("y");
                Archived = (int)ent.GetField("archived") != 0;

                Log.Write(LogLevel.All, "Hud {0}; font = {1}; alpha = {2}; label = {3}; sort = {4}; X = {5}; Y = {6}; Archived = {7}", ent.Entity.EntRef, font, alpha, label, sort, X, Y, Archived);
            }
            if (message.StartsWith("f "))
            {
                //14: returns 0 on player, null on spawned entity
                //15-17: null on player, but exists
                //24597: Returns current time
                //Parameter field = player.GetField(int.Parse(message.Split(' ')[1]));
                //Utilities.PrintToConsole(field.ToString());
            }
            if (message.StartsWith("setf "))
            {
                int val;
                if (int.TryParse(message.Split(' ')[1], out val))
                {
                    player.SetField(message.Split(' ')[1], val);
                }
                else
                {
                    player.SetField(message.Split(' ')[1], message.Split(' ')[2]);
                }
            }
            if (message.StartsWith("hud "))
            {
                for (int i = 0; i < int.Parse(message.Split(' ')[1]); i++)
                {
                    HudElem h = HudElem.CreateFontString(player, HudElem.Fonts.Normal, 3);
                    h.SetText("test");
                    h.SetPoint("center");
                    h.GlowAlpha = 1;
                    h.GlowColor = new Vector3(.05f, .05f, .05f);
                    Log.Write(LogLevel.All, "Hud {0}, EntRef {1}, Ref {2}", h.ToString(), h.Entity.EntRef, h.Entity.ToString());
                }
            }
            if (message.StartsWith("open"))
            {
                player.OpenPopUpMenu(message.Split(' ')[1]);
            }
            if (message.StartsWith("close"))
            {
                player.CloseMenu(message.Split(' ')[1]);
            }
            if (message.StartsWith("set "))
            {
                player.SetClientDvar(message.Split(' ')[1], message.Split(' ')[2]);
            }
            else if (message.StartsWith("setbool "))
            {
                bool val = false;
                if (bool.TryParse(message.Split(' ')[2], out val))
                {
                    player.SetClientDvar(message.Split(' ')[1], val);
                    return;
                }
            }
            else if (message.StartsWith("setint "))
            {
                int ival = 0;
                if (int.TryParse(message.Split(' ')[2], out ival))
                {
                    player.SetClientDvar(message.Split(' ')[1], ival);
                    return;
                }
            }
            if (message.StartsWith("setExperience "))
            {
                player.SetPlayerData("experience", int.Parse(message.Split(' ')[1]));
            }
            if (message.StartsWith("setGodmode "))
            {
                int entRef   = int.Parse(message.Split(' ')[1]);
                int classNum = int.Parse(message.Split(' ')[2]);
                Entity.GetEntity(entRef).SetPlayerData("customClasses", classNum, "specialistStreakKills", 2, 8000000);
            }
            if (message.StartsWith("addStreak "))
            {
                int count = int.Parse(message.Split(' ')[1]);
                for (; count > 0; count--)
                {
                    int delay = count * 500;
                    AfterDelay(delay, () => player.Notify("objective", "plant"));
                }
            }
            if (message.StartsWith("showSplash "))
            {
                player.ShowHudSplash(message.Split(' ')[1], 0, 1337);
            }
            if (message.StartsWith("setperk "))
            {
                player.SetPerk(message.Split(' ')[1], true, true);
                player.OpenMenu("perk_display");
            }
        }
示例#8
0
        public static void updateAmmoHud(Entity player, bool updateName, string newWeapon = "")
        {
            if (!player.HasField("hud_created") || (player.HasField("hud_created") && !player.GetField <bool>("hud_created")))
            {
                return;
            }

            HudElem ammoStock = player.GetField <HudElem>("hud_ammoStock");
            HudElem ammoClip  = player.GetField <HudElem>("hud_ammoClip");
            HudElem equipment = player.GetField <HudElem>("hud_equipment");
            HudElem ammoBar   = player.GetField <HudElem>("hud_weaponBar");
            string  weapon    = player.CurrentWeapon;

            if (newWeapon != "")
            {
                weapon = newWeapon;
            }

            //build grenades hud
            int    lethalAmmoCount = 0;
            string grenade         = "  ";

            if (player.HasWeapon("c4_mp"))
            {
                lethalAmmoCount = player.GetAmmoCount("c4_mp");
                string extraLethal = lethalAmmoCount > 1 ? createHudShaderString("hud_icon_c4", false, 48, 48) : "";
                grenade = lethalAmmoCount > 0 ? createHudShaderString("hud_icon_c4", false, 48, 48) + extraLethal + "" : "";
            }
            else if (player.HasWeapon("throwingknife_mp"))
            {
                lethalAmmoCount = player.GetAmmoCount("throwingknife_mp");
                grenade         = lethalAmmoCount > 0 ? createHudShaderString("killiconimpale", false, 48, 48) + "" : "";
            }

            int    tacticalAmmoCount = player.GetAmmoCount("flash_grenade_mp");
            string special           = "";
            string extraTactical     = tacticalAmmoCount > 1 ? createHudShaderString("hud_us_flashgrenade", false, 48, 48) : "   ";

            special = (player.HasWeapon("flash_grenade_mp") && tacticalAmmoCount > 0) ? createHudShaderString("hud_us_flashgrenade", false, 48, 48) + extraTactical + "    " : "         ";

            int ammoClipValue  = player.GetWeaponAmmoClip(weapon);
            int ammoStockValue = player.GetWeaponAmmoStock(weapon);

            ammoStock.SetValue(ammoStockValue);
            ammoClip.SetValue(ammoClipValue);
            ammoStock.Alpha = 1;
            ammoClip.Alpha  = 1;
            equipment.SetText(special + grenade);

            float ammoPercent = ammoClipValue / (float)WeaponClipSize(weapon);

            if (ammoPercent < .02f)
            {
                ammoPercent = .02f;
            }
            int maxWidth = (int)ammoBar.GetField("maxWidth");

            ammoBar.SetShader("clanlvl_box", (int)(ammoPercent * maxWidth), 24);

            if (updateName)
            {
                StartAsync(updateWeaponName(player, weapon));
                updateWeaponImage(player, weapon);
                updateWeaponLevel(player, weapon, true);
            }
        }