LightbulbHow to use Behaviors and create custom enemies. [IN-DEPTH, BEGINNER]

Posts 1–12 of 12 · Page 1 of 1
How to use Behaviors and create custom enemies. [IN-DEPTH, BEGINNER]
THIS TUTORIAL IS FOR BEGINNERS. DON'T GO AROUND TELLING EVERYONE THAT YOU SHOULD KNOW HOW TO DO THIS.
I know tutorials on this have been made, but in my opinion, none are very informative or descriptive though that's not to say I guarantee this to be helpful.

A behavior is made up of a key component: The XML, meant for the purpose of describing what the enemy is: think about it as what a book looks like, rather than the contents of a book, and the behavior code, which is simply a series of C# constructors and properties. The XML interacts through the behavior, thus it is where you will find the stats for the enemy, such as HP, defense, and all the projectiles and their indexes.

Code:
   <Object type="0x0932" id="Oryx the Mad God 2">
      <DisplayId>Oryx the Mad God</DisplayId>
      <Enemy/>
      <Class>Character</Class>
      <Texture>
         <File>lofiChar16x16</File>
         <Index>0x54</Index>
      </Texture>
      <HitSound>monster/oryx_hit</HitSound>
      <DeathSound>monster/oryx_death</DeathSound>
      <Size>120</Size>
      <MaxHitPoints>75000</MaxHitPoints>
      <Defense>60</Defense>
      <Quest/>
      <God/>
      <Oryx/>
      <StasisImmune/>
      <Level>1</Level>
      <XpMult>1</XpMult>
      <NoArticle/>
      <Projectile id="0">
         <ObjectId>Fire Bolt</ObjectId>
         <Damage>135</Damage>
         <Speed>70</Speed>
         <LifetimeMS>2500</LifetimeMS>
      </Projectile>
      <Projectile id="1">
         <ObjectId>Green Star</ObjectId>
         <Damage>160</Damage>
         <Speed>70</Speed>
         <LifetimeMS>2500</LifetimeMS>
         <ConditionEffect duration="10">Slowed</ConditionEffect>
      </Projectile>
      <Projectile id="2">
         <ObjectId>Blade</ObjectId>
         <Damage>240</Damage>
         <Speed>100</Speed>
         <LifetimeMS>450</LifetimeMS>
      </Projectile>
      <Projectile id="3">
         <ObjectId>Purple Star</ObjectId>
         <Damage>160</Damage>
         <Speed>55</Speed>
         <LifetimeMS>3000</LifetimeMS>
         <ConditionEffect duration="5">Blind</ConditionEffect>
      </Projectile>
      <Projectile id="4">
         <ObjectId>Blue Star</ObjectId>
         <Damage>160</Damage>
         <Speed>105</Speed>
         <LifetimeMS>1200</LifetimeMS>
         <ConditionEffect duration="5">Confused</ConditionEffect>
      </Projectile>
      <Projectile id="5">
         <ObjectId>Grey Star</ObjectId>
         <Damage>160</Damage>
         <Speed>45</Speed>
         <LifetimeMS>3000</LifetimeMS>
         <ConditionEffect duration="3">Quiet</ConditionEffect>
      </Projectile>
      <Projectile id="6">
         <ObjectId>Red Star</ObjectId>
         <Damage>160</Damage>
         <Speed>55</Speed>
         <LifetimeMS>3000</LifetimeMS>
         <ArmorPiercing/>
      </Projectile>
      <Projectile id="13">
         <ObjectId>Dark Gray Spinner</ObjectId>
         <Speed>90</Speed>
         <Size>100</Size>
         <Damage>1</Damage>
         <LifetimeMS>1800</LifetimeMS>
         <ConditionEffect duration="20">Quiet</ConditionEffect>
         <MultiHit/>
      </Projectile>
      <Projectile id="14">
         <ObjectId>Gray Spinner</ObjectId>
         <Speed>90</Speed>
         <Size>100</Size>
         <Damage>1</Damage>
         <LifetimeMS>1800</LifetimeMS>
         <ConditionEffect duration="60">Weak</ConditionEffect>
         <MultiHit/>
      </Projectile>
   </Object>
I assume you know how the XML works, it should be fairly self-explanatory, much like behaviors themselves. If you need a reference, examine the XML code of "Oryx the Mad God 2". You use that ID in the C# code - when you create a behavior, you have to remember a few key things. 1: Make sure that you copy the 3 using statements located in all the other behavior files. Don't worry about regions, they're simply meant for organization purposes.

Code:
#region

using wServer.logic.behaviors;
using wServer.logic.loot;
using wServer.logic.transitions;

#endregion
Change the class to a partial class - assuming you don't, the compiler will not execute the behaviors properly. This essentially means the definitions are split when you use 'partial'.
Another thing you have to do is change the namespace from 'wServer.logic.db' to 'wServer.logic' - you'll get an error with loading your server if you do!

Next, add in your main enemy/enemies. Explaining what all of these do will take to long, though I highly suggest that you learn what a "lambda expression" and "class constructor" is in the future. You can enter the class definition by holding CTRL and clicking on it.

Code:
private _ Crystal = () => Behav()
            .Init("Mysterious Crystal",
                new State();
I like to use the crystal, since it holds examples of things pertinent to creating a behavior that wouldn't normally be found in another behavior, such as size, effects, spawning mobs, etc. Above, where you see .Init(""), the ID that you set in the XML is used. The name "Crystal" can be set to whatever the name of your class is.
(BehaviorDb._________.cs)

Inside State();, you add any special things that occur on the death of your enemy, such as a new setpiece(see Malphas), or dropping a portal, which we see in the Crystal behavior.
Next, you begin to interact with other states through transitions. A timedtransition refers to the amount of time in milliseconds before the next state occurs, which you set via referring states with different names, hence why you see weird names.

Code:
new State(
                    new DropPortalOnDeath("Deadwater Docks", 100),
                    new State("Idle",
                        new Taunt(0.1, "Break the crystal for great rewards..."),
                        new Taunt(0.1, "Help me..."),
                        new HpLessTransition(0.9999, "Instructions"),
                        new TimedTransition(10000, "Idle")
                        ),
                    new State("Instructions",
                        new Flash(0xffffffff, 2, 100),
                        new Taunt(0.8, "Fire upon this crystal with all your might for 5 seconds"),
                        new Taunt(0.8, "If your attacks are weak, the crystal magically heals"),
                        new Taunt(0.8, "Gather a large group to smash it open"),
                        new HpLessTransition(0.998, "Evaluation")
                        ),
And HpLessTransition as seen above refers to how much hp is needed to be depleted for it to continue to the next state. Remember that 1 = 100% HP. Thus, 0.998 = 99.8%!

Code:
new State("Daisy_attack",
                        new Prioritize(
                            new StayCloseToSpawn(0.3, 7),
                            new Wander(0.3)
                            ),
Hopefully, you're getting the hang of this. You should be able to see what's going on here; the enemy will move, but stay close to it's spawn point.

Code:
 new ConditionalEffect(ConditionEffectIndex.Invulnerable),
                            new Shoot(0, projectileIndex: 0, count: 4, shootAngle: 90, fixedAngle: 0, coolDown: 300),
Lastly is it's conditional effects and shots. The conditional effect can be changed to whatever you want, such as berserk, statsis, or armored. The new shoot looks a little complicated - but it's quite simple in usage. The projectileindex is simply a reference to the id of the shots you set in your XML! Make sure you don't go out of bounds, otherwise you'll get a bunch of errors in wServer.exe! It's zerobased - so it's common practice to start at 0, though you can theoretically use any number you like.

There you go. You're set to creating your own behaviors. I presume you'll be able to gather what states contain simply by looking at them. Remember to use other premade behaviors as reference if you're new.

I bid you the best of luck.

Oh, by the way; in case you wanted some explanations for the states, here you go.
http://www.mpgh.net/forum/showthread.php?t=1174922
A lot better than some of the tutorials, Good job!
Regions Aren't Only Used For Organized Purposes:/ (If You Have Any Thingy Out of The Regions That You Have (Which Is Almost Impossible)Then It Won't Work)

But then again its better than mine so no spot to complain
Quote Originally Posted by Demon View Post
Regions Aren't Only Used For Organized Purposes:/ (If You Have Any Thingy Out of The Regions That You Have (Which Is Almost Impossible)Then It Won't Work)

But then again its better than mine so no spot to complain
Are... Are you joking right now? Do you seriously not know what regions are? The whole purpose of the #region and #endregion directives to collapse and expand code so you are able to focus on different parts of the file. Removing the region, or carrying the using statements out of the region will do absolutely nothing. Either way, in your tutorial, you were criticized by many, including me, for omitting information and being unable to explain certain aspects of a behavior properly.
Quote Originally Posted by coolguy950 View Post
Are... Are you joking right now? Do you seriously not know what regions are? The whole purpose of the #region and #endregion directives to collapse and expand code so you are able to focus on different parts of the file. Removing the region, or carrying the using statements out of the region will do absolutely nothing. Either way, in your tutorial, you were criticized by many, including me, for omitting information and being unable to explain certain aspects of a behavior properly.
sorry about that i was just being stupid forgot that it does nothing...
Quote Originally Posted by Demon View Post
sorry about that i was just being stupid forgot that it does nothing...
It's fine <3
Quote Originally Posted by coolguy950 View Post
THIS TUTORIAL IS FOR BEGINNERS. DON'T GO AROUND TELLING EVERYONE THAT YOU SHOULD KNOW HOW TO DO THIS.
I know tutorials on this have been made, but in my opinion, none are very informative or descriptive though that's not to say I guarantee this to be helpful.

A behavior is made up of a key component: The XML, meant for the purpose of describing what the enemy is: think about it as what a book looks like, rather than the contents of a book, and the behavior code, which is simply a series of C# constructors and properties. The XML interacts through the behavior, thus it is where you will find the stats for the enemy, such as HP, defense, and all the projectiles and their indexes.

Code:
   <Object type="0x0932" id="Oryx the Mad God 2">
      <DisplayId>Oryx the Mad God</DisplayId>
      <Enemy/>
      <Class>Character</Class>
      <Texture>
         <File>lofiChar16x16</File>
         <Index>0x54</Index>
      </Texture>
      <HitSound>monster/oryx_hit</HitSound>
      <DeathSound>monster/oryx_death</DeathSound>
      <Size>120</Size>
      <MaxHitPoints>75000</MaxHitPoints>
      <Defense>60</Defense>
      <Quest/>
      <God/>
      <Oryx/>
      <StasisImmune/>
      <Level>1</Level>
      <XpMult>1</XpMult>
      <NoArticle/>
      <Projectile id="0">
         <ObjectId>Fire Bolt</ObjectId>
         <Damage>135</Damage>
         <Speed>70</Speed>
         <LifetimeMS>2500</LifetimeMS>
      </Projectile>
      <Projectile id="1">
         <ObjectId>Green Star</ObjectId>
         <Damage>160</Damage>
         <Speed>70</Speed>
         <LifetimeMS>2500</LifetimeMS>
         <ConditionEffect duration="10">Slowed</ConditionEffect>
      </Projectile>
      <Projectile id="2">
         <ObjectId>Blade</ObjectId>
         <Damage>240</Damage>
         <Speed>100</Speed>
         <LifetimeMS>450</LifetimeMS>
      </Projectile>
      <Projectile id="3">
         <ObjectId>Purple Star</ObjectId>
         <Damage>160</Damage>
         <Speed>55</Speed>
         <LifetimeMS>3000</LifetimeMS>
         <ConditionEffect duration="5">Blind</ConditionEffect>
      </Projectile>
      <Projectile id="4">
         <ObjectId>Blue Star</ObjectId>
         <Damage>160</Damage>
         <Speed>105</Speed>
         <LifetimeMS>1200</LifetimeMS>
         <ConditionEffect duration="5">Confused</ConditionEffect>
      </Projectile>
      <Projectile id="5">
         <ObjectId>Grey Star</ObjectId>
         <Damage>160</Damage>
         <Speed>45</Speed>
         <LifetimeMS>3000</LifetimeMS>
         <ConditionEffect duration="3">Quiet</ConditionEffect>
      </Projectile>
      <Projectile id="6">
         <ObjectId>Red Star</ObjectId>
         <Damage>160</Damage>
         <Speed>55</Speed>
         <LifetimeMS>3000</LifetimeMS>
         <ArmorPiercing/>
      </Projectile>
      <Projectile id="13">
         <ObjectId>Dark Gray Spinner</ObjectId>
         <Speed>90</Speed>
         <Size>100</Size>
         <Damage>1</Damage>
         <LifetimeMS>1800</LifetimeMS>
         <ConditionEffect duration="20">Quiet</ConditionEffect>
         <MultiHit/>
      </Projectile>
      <Projectile id="14">
         <ObjectId>Gray Spinner</ObjectId>
         <Speed>90</Speed>
         <Size>100</Size>
         <Damage>1</Damage>
         <LifetimeMS>1800</LifetimeMS>
         <ConditionEffect duration="60">Weak</ConditionEffect>
         <MultiHit/>
      </Projectile>
   </Object>
I assume you know how the XML works, it should be fairly self-explanatory, much like behaviors themselves. If you need a reference, examine the XML code of "Oryx the Mad God 2". You use that ID in the C# code - when you create a behavior, you have to remember a few key things. 1: Make sure that you copy the 3 using statements located in all the other behavior files. Don't worry about regions, they're simply meant for organization purposes.

Code:
#region

using wServer.logic.behaviors;
using wServer.logic.loot;
using wServer.logic.transitions;

#endregion
Change the class to a partial class - assuming you don't, the compiler will not execute the behaviors properly. This essentially means the definitions are split when you use 'partial'.
Another thing you have to do is change the namespace from 'wServer.logic.db' to 'wServer.logic' - you'll get an error with loading your server if you do!

Next, add in your main enemy/enemies. Explaining what all of these do will take to long, though I highly suggest that you learn what a "lambda expression" and "class constructor" is in the future. You can enter the class definition by holding CTRL and clicking on it.

Code:
private _ Crystal = () => Behav()
            .Init("Mysterious Crystal",
                new State();
I like to use the crystal, since it holds examples of things pertinent to creating a behavior that wouldn't normally be found in another behavior, such as size, effects, spawning mobs, etc. Above, where you see .Init(""), the ID that you set in the XML is used. The name "Crystal" can be set to whatever the name of your class is.
(BehaviorDb._________.cs)

Inside State();, you add any special things that occur on the death of your enemy, such as a new setpiece(see Malphas), or dropping a portal, which we see in the Crystal behavior.
Next, you begin to interact with other states through transitions. A timedtransition refers to the amount of time in milliseconds before the next state occurs, which you set via referring states with different names, hence why you see weird names.

Code:
new State(
                    new DropPortalOnDeath("Deadwater Docks", 100),
                    new State("Idle",
                        new Taunt(0.1, "Break the crystal for great rewards..."),
                        new Taunt(0.1, "Help me..."),
                        new HpLessTransition(0.9999, "Instructions"),
                        new TimedTransition(10000, "Idle")
                        ),
                    new State("Instructions",
                        new Flash(0xffffffff, 2, 100),
                        new Taunt(0.8, "Fire upon this crystal with all your might for 5 seconds"),
                        new Taunt(0.8, "If your attacks are weak, the crystal magically heals"),
                        new Taunt(0.8, "Gather a large group to smash it open"),
                        new HpLessTransition(0.998, "Evaluation")
                        ),
And HpLessTransition as seen above refers to how much hp is needed to be depleted for it to continue to the next state. Remember that 1 = 100% HP. Thus, 0.998 = 99.8%!

Code:
new State("Daisy_attack",
                        new Prioritize(
                            new StayCloseToSpawn(0.3, 7),
                            new Wander(0.3)
                            ),
Hopefully, you're getting the hang of this. You should be able to see what's going on here; the enemy will move, but stay close to it's spawn point.

Code:
 new ConditionalEffect(ConditionEffectIndex.Invulnerable),
                            new Shoot(0, projectileIndex: 0, count: 4, shootAngle: 90, fixedAngle: 0, coolDown: 300),
Lastly is it's conditional effects and shots. The conditional effect can be changed to whatever you want, such as berserk, statsis, or armored. The new shoot looks a little complicated - but it's quite simple in usage. The projectileindex is simply a reference to the id of the shots you set in your XML! Make sure you don't go out of bounds, otherwise you'll get a bunch of errors in wServer.exe! It's zerobased - so it's common practice to start at 0, though you can theoretically use any number you like.

There you go. You're set to creating your own behaviors. I presume you'll be able to gather what states contain simply by looking at them. Remember to use other premade behaviors as reference if you're new.

I bid you the best of luck.

Oh, by the way; in case you wanted some explanations for the states, here you go.
http://www.mpgh.net/forum/showthread.php?t=1174922
I did all of this and i ended up getting an error in wserver i was wondering what i did wrong?
Quote Originally Posted by Queshawn View Post
I did all of this and i ended up getting an error in wserver i was wondering what i did wrong?
Can you be more specific about the error?
Could u help me code the behavior of the puppets masters encore minions?
Quote Originally Posted by DarkBoodleli View Post
Could u help me code the behavior of the puppets masters encore minions?
Sorry for the late reply, but sure, as long as I can use them too.
Quote Originally Posted by coolguy950 View Post
Sorry for the late reply, but sure, as long as I can use them too.
you make it, therefor you can use them?????????
Quote Originally Posted by MikeRaarupBirk View Post
you make it, therefor you can use them?????????
::---DDDDDDD
Posts 1–12 of 12 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

Need help?