HelpHow does the killAll command work?

Posts 1–10 of 10 · Page 1 of 1
How does the killAll command work?
How does the '/killAll' command work? How are objects assigned the 'enemy' attribute other than using the XML tag?

Basically can someone explain what this code does?

Code:
 
    class KillAll : Command
    {
        public KillAll() : base("killAll", Ranks.Admin)
        {
        }
        
        protected override bool Process(Player player, RealmTime time, string[] args)
        {
            var iterations = 0;
            var lastKilled = -1;
            var killed = 0;

            var mobName = args.Aggregate((s, a) => string.Concat(s, " ", a));
            while (killed != lastKilled)
            {
                lastKilled = killed;
                foreach (var i in player.Owner.Enemies.Values.Where(e =>
                    e.ObjectDesc?.ObjectId != null && e.ObjectDesc.ObjectId.ContainsIgnoreCase(mobName)))
                {
                    i.Death(time);
                    killed++;
                }
                if (++iterations >= 5)
                    break;
            }

            player.SendInfo($"{killed} enemy killed!");
            return true;
        }
    }
I am interested because the object in nexus called 'mb shopkeeper1' is deemed an enemy and is therefore removed when entering '/killAll'. I want to try and remove this.
Quote Originally Posted by FlashFlyyy View Post
How does the '/killAll' command work? How are objects assigned the 'enemy' attribute other than using the XML tag?

Basically can someone explain what this code does?

Code:
 
    class KillAll : Command
    {
        public KillAll() : base("killAll", Ranks.Admin)
        {
        }
        
        protected override bool Process(Player player, RealmTime time, string[] args)
        {
            var iterations = 0;
            var lastKilled = -1;
            var killed = 0;

            var mobName = args.Aggregate((s, a) => string.Concat(s, " ", a));
            while (killed != lastKilled)
            {
                lastKilled = killed;
                foreach (var i in player.Owner.Enemies.Values.Where(e =>
                    e.ObjectDesc?.ObjectId != null && e.ObjectDesc.ObjectId.ContainsIgnoreCase(mobName)))
                {
                    i.Death(time);
                    killed++;
                }
                if (++iterations >= 5)
                    break;
            }

            player.SendInfo($"{killed} enemy killed!");
            return true;
        }
    }
I am interested because the object in nexus called 'mb shopkeeper1' is deemed an enemy and is therefore removed when entering '/killAll'. I want to try and remove this.
The Killall command inherits form the base class Command.cs. When the command is called using the proper structure, the string is then combined to form a proper name if the name contains more than one word. It gets every entity entance in the players current world, check to see if the name matches the one specified. And for every enemy killed it increases the killed integer by one. After it's done looping through the foreach loop and meeting max iterations , it notifies the player of how much they've killed. Then returns true.
Quote Originally Posted by TooGoodAtCoding3039 View Post
check to see if the name matches the one specified
What do you mean by this?

It considers all entity instances in the player's current world, however how does it distinguish that an object is an enemy?
Could you give an example with data?
Quote Originally Posted by FlashFlyyy View Post
What do you mean by this?

It considers all entity instances in the player's current world, however how does it distinguish that an object is an enemy?
Could you give an example with data?
It checks if any x enemies matches the name you specified in when you initiate your command. /killall medusa, result: killed 999 (meaning there where 999 medusa in your world instance.)

And yes I'd assume it distinguishes regular objects from enemies, unless who ever made the enemies dictionary is a retard.
Objects can possess an enemy tag, it's usually under the object type "Character". You don't need the enemy tag for a nexus shop merchant.
Quote Originally Posted by Invader_Zim View Post
Objects can possess an enemy tag, it's usually under the object type "Character". You don't need the enemy tag for a nexus shop merchant.
No no lol. I know the way to make an enemy is to use the tag. But what I am saying is that the /killAll command removes the object (for example) 'mb shopkeep1' from nexus as it is deemed an enemy even when there is no enemy tag in its XML. I go in nexus and type /killAll and the mystery box wizard, some flies on the outside, the alchemist orbs, the rabbits, etc. are all removed and it says '121 enemies killed' even though they aren't enemies! I thought it had something to do with the 'statusimmune' tag but it's not.

Screen gifs:
https://gyazo.com/bfb3991a1c2711369a1375076bf5448f
https://gyazo.com/85d5f75a7bbd967c5782c737125c1947
Read:
Code:
                foreach (var i in player.Owner.Enemies.Values.Where(e =>
                    e.ObjectDesc?.ObjectId != null && e.ObjectDesc.ObjectId.ContainsIgnoreCase(mobName)))
Quote Originally Posted by DevilRotMG View Post
Read:
Code:
                foreach (var i in player.Owner.Enemies.Values.Where(e =>
                    e.ObjectDesc?.ObjectId != null && e.ObjectDesc.ObjectId.ContainsIgnoreCase(mobName)))
Ye, that's why I made it bold lol. But fine I will google parts of it and hopefully it will make sense -_-
I only started learning c# 2 weeks ago. I know it's some sort of list comprehension. But how is 'mobName' assigned its value? What are the variables 's' and 'a'?

EDIT: OHHHHHH, it's because I put no argument... that's why it killed everything

EDIT2: this doesn't help with the fact that some objects in nexus are effected by poison

EDIT3: is there a 'check_if_object_has_defense_tag' function somewhere? xD

EDIT4: fixed

Thanks to all!
Quote Originally Posted by FlashFlyyy View Post
Ye, that's why I made it bold lol. But fine I will google parts of it and hopefully it will make sense -_-
I only started learning c# 2 weeks ago. I know it's some sort of list comprehension. But how is 'mobName' assigned its value? What are the variables 's' and 'a'?

EDIT: OHHHHHH, it's because I put no argument... that's why it killed everything

EDIT2: this doesn't help with the fact that some objects in nexus are effected by poison

EDIT3: is there a 'check_if_object_has_defense_tag' function somewhere? xD

EDIT4: fixed

Thanks to all!
Very simple, just need to spend sometime and read, xD
@Nyaro @Luverdark solved.
Posts 1–10 of 10 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Need help?