Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Server Development
Habbo Retros
Habbo Q&A
[Help] Hospital Bot For HabboRP'S [Help]
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Jerry" data-source="post: 294828" data-attributes="member: 35321"><p>[SPOILER]</p><p>using System;</p><p></p><p>using Reality.Game.Rooms;</p><p>using Reality.Specialized;</p><p></p><p>using System.Collections.Generic;</p><p>using System.Collections.ObjectModel;</p><p>using Reality.Game.Pathfinding;</p><p>using Reality.Game.Misc;</p><p>using Reality.Util;</p><p>using Reality.Game.Sessions;</p><p>using Reality.Storage;</p><p>using Reality.Communication.Outgoing;</p><p></p><p>namespace Reality.Game.Bots.Behavior</p><p>{</p><p> public class HospitalBot : IBotBehavior</p><p> {</p><p> private Bot mSelfBot;</p><p> private RoomActor mSelfActor;</p><p> private bool mNeedsRotation;</p><p></p><p> private int mNextSpeechAttempt;</p><p> private int mNextMovementAttempt;</p><p> private int remindSpeech;</p><p></p><p> private int mServingItemId;</p><p> private uint mServingActorId;</p><p> private bool mMovingToServePos;</p><p> private Vector2 mActorServePos;</p><p></p><p> public bool InRoom</p><p> {</p><p> get</p><p> {</p><p> return (mSelfActor != null);</p><p> }</p><p> }</p><p></p><p> public override void Initialize(Bot BotReference)</p><p> {</p><p> mSelfBot = BotReference;</p><p> }</p><p></p><p> public override void OnSelfEnterRoom(RoomInstance Instance)</p><p> {</p><p> mSelfActor = Instance.GetActorByReferenceId(mSelfBot.Id, RoomActorType.AiBot);</p><p></p><p> if (mSelfActor == null)</p><p> {</p><p> return;</p><p> }</p><p></p><p> mNeedsRotation = false;</p><p> mNextSpeechAttempt = RandomGenerator.GetNext(20, 255);</p><p> mNextMovementAttempt = RandomGenerator.GetNext(20, 255);</p><p> mServingItemId = 0;</p><p> mServingActorId = 0;</p><p> mMovingToServePos = false;</p><p> mActorServePos = null;</p><p></p><p> if (mSelfBot.Rotation >= 0)</p><p> {</p><p> mSelfActor.BodyRotation = mSelfBot.Rotation;</p><p> mSelfActor.HeadRotation = mSelfBot.Rotation;</p><p> }</p><p> }</p><p></p><p> public override void OnSelfLeaveRoom(RoomInstance Instance)</p><p> {</p><p> if (mSelfActor == null)</p><p> {</p><p> return;</p><p> }</p><p></p><p> mSelfActor = null;</p><p> }</p><p></p><p> public override void OnUserChat(RoomInstance Instance, RoomActor Actor, string MessageText, bool Shout)</p><p> {</p><p> try</p><p> { </p><p> Session Session = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Actor.Name));</p><p></p><p> if (MessageText.ToLower().Contains("heal"))</p><p> {</p><p> if (Session.CharacterInfo.Dead != 1)</p><p> {</p><p> if (Session.CharacterInfo.Health < 100)</p><p> {</p><p> Session.CharacterInfo.beingHealedSeconds = 60;</p><p> Session.CharacterInfo.beingHealed = true;</p><p></p><p> mSelfActor.Chat("*Treats " + Session.CharacterInfo.Username + " for major wounds*", true, true);</p><p> Session.CharacterInfo.poisoned = false;</p><p> }</p><p> else if(Session.CharacterInfo.Health >= 100)</p><p> {</p><p> Session.SendData(RoomChatComposer.Compose(Actor.Id, "Your health is already full!", 0, ChatType.Whisper));</p><p> return;</p><p> }</p><p> }</p><p></p><p> else</p><p> {</p><p> using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())</p><p> {</p><p> RealityEMU.Game.Roleplay.RPMisc.releaseFromHosp(Session, Instance);</p><p> } </p><p></p><p> mSelfActor.Chat("*Discharges " + Session.CharacterInfo.Username + "' from the hospital*", true, true);</p><p> Instance.BroadcastMessage(UserInfoUpdateComposer.Compose(Actor.Id, Session.CharacterInfo.Figure, Session.CharacterInfo.Gender, Session.CharacterInfo.Motto, Session.CharacterInfo.Score));</p><p> }</p><p> }</p><p></p><p> }</p><p> catch (Exception e) { Console.WriteLine(e.ToString()); }</p><p> </p><p> }</p><p></p><p> public override void OnUserEnter(RoomInstance Instance, RoomActor Actor)</p><p> {</p><p> mSelfActor.Chat("Welcome to the hospital " + Actor.Name + ". If you need a heal just ask!");</p><p></p><p> if (mSelfActor == null || Actor.Type == RoomActorType.AiBot)</p><p> {</p><p> return;</p><p> }</p><p></p><p> if (mSelfBot.Effect > 0)</p><p> {</p><p> mSelfActor.ApplyEffect(mSelfBot.Effect);</p><p> }</p><p> }</p><p></p><p> public override void OnUserLeave(RoomInstance Instance, RoomActor Actor)</p><p> {</p><p> if (mSelfActor == null || Actor.Type == RoomActorType.AiBot)</p><p> {</p><p> return;</p><p> }</p><p> }</p><p></p><p> public override void PerformUpdate(RoomInstance Instance)</p><p> {</p><p> if (mNextSpeechAttempt <= 0)</p><p> {</p><p> string Message = BotManager.GetRandomSpeechForBotDefinition(mSelfBot.DefinitionId);</p><p></p><p> if (Message != null && Message.Length > 0)</p><p> {</p><p> mSelfActor.Chat(Message);</p><p> }</p><p></p><p> mNextSpeechAttempt = RandomGenerator.GetNext(0, 255);</p><p> }</p><p> else</p><p> {</p><p> mNextSpeechAttempt--;</p><p> }</p><p> if (mSelfActor != null)</p><p> {</p><p> //!mSelfActor.IsMoving && mNextMovementAttempt <= 0</p><p> if (mNextMovementAttempt <= 0)</p><p> {</p><p> switch (mSelfBot.WalkMode)</p><p> {</p><p> default:</p><p> case BotWalkMode.STAND:</p><p></p><p> break;</p><p></p><p> case BotWalkMode.F<img src="https://cdn.devbest.com/data/assets/smilies/REE.png" srcset="https://cdn.devbest.com/data/assets/smilies/REE.png 1x, https://cdn.devbest.com/data/assets/smilies/REE-2x.png 2x" class="smilie" loading="lazy" alt="REE" title="REE REE" data-shortname="REE" />ROAM:</p><p> </p><p> Vector2 position = new Vector2(RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeX - 1),</p><p> RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeY - 1));</p><p> mSelfActor.MoveTo(position);</p><p> </p><p> break;</p><p></p><p> case BotWalkMode.SPECIFIED_RANGE:</p><p></p><p> ReadOnlyCollection<Vector2> Possibilites = mSelfBot.PredefinedPositions;</p><p> mSelfActor.MoveTo(Possibilites[RandomGenerator.GetNext(0, (Possibilites.Count - 1))]);</p><p> break;</p><p> }</p><p></p><p> mNextMovementAttempt = 5;</p><p> mNeedsRotation = true;</p><p> // mSelfActor.Chat("lol");</p><p> }</p><p> else</p><p> {</p><p> mNextMovementAttempt--;</p><p></p><p> if (mNextMovementAttempt > 5)</p><p> {</p><p> mNextMovementAttempt = 5;</p><p> }</p><p> //mSelfActor.Chat(mNextMovementAttempt + "-");</p><p> if (!mSelfActor.IsMoving)</p><p> {</p><p> if (mMovingToServePos)</p><p> {</p><p> mMovingToServePos = false;</p><p> mSelfActor.CarryItem(mServingItemId);</p><p> mSelfActor.MoveTo(mActorServePos);</p><p> }</p><p> else if (mServingItemId > 0)</p><p> {</p><p> mSelfActor.CarryItem(0);</p><p></p><p> RoomActor TargetActor = Instance.GetActor(mServingActorId);</p><p></p><p> if (TargetActor != null)</p><p> {</p><p> TargetActor.CarryItem(mServingItemId);</p><p></p><p> int NewRot = Rotation.Calculate(mActorServePos, TargetActor.Position.GetVector2());</p><p></p><p> mSelfActor.HeadRotation = NewRot;</p><p> mSelfActor.BodyRotation = NewRot;</p><p> mNeedsRotation = true;</p><p></p><p> mSelfActor.UpdateNeeded = true;</p><p> }</p><p></p><p> mServingItemId = 0;</p><p> }</p><p> else if (mNeedsRotation && mSelfBot.Rotation >= 0)</p><p> {</p><p> mSelfActor.BodyRotation = mSelfBot.Rotation;</p><p> mSelfActor.HeadRotation = mSelfBot.Rotation;</p><p> mNeedsRotation = false;</p><p> }</p><p> }</p><p> }</p><p></p><p> if (remindSpeech <= 0)</p><p> {</p><p> mSelfActor.Chat("If you need a heal just ask!");</p><p> remindSpeech = 100;</p><p> }</p><p> else</p><p> {</p><p> remindSpeech--;</p><p> }</p><p> }</p><p> }</p><p> }</p><p>}</p><p>[/SPOILER]</p></blockquote><p></p>
[QUOTE="Jerry, post: 294828, member: 35321"] [SPOILER] using System; using Reality.Game.Rooms; using Reality.Specialized; using System.Collections.Generic; using System.Collections.ObjectModel; using Reality.Game.Pathfinding; using Reality.Game.Misc; using Reality.Util; using Reality.Game.Sessions; using Reality.Storage; using Reality.Communication.Outgoing; namespace Reality.Game.Bots.Behavior { public class HospitalBot : IBotBehavior { private Bot mSelfBot; private RoomActor mSelfActor; private bool mNeedsRotation; private int mNextSpeechAttempt; private int mNextMovementAttempt; private int remindSpeech; private int mServingItemId; private uint mServingActorId; private bool mMovingToServePos; private Vector2 mActorServePos; public bool InRoom { get { return (mSelfActor != null); } } public override void Initialize(Bot BotReference) { mSelfBot = BotReference; } public override void OnSelfEnterRoom(RoomInstance Instance) { mSelfActor = Instance.GetActorByReferenceId(mSelfBot.Id, RoomActorType.AiBot); if (mSelfActor == null) { return; } mNeedsRotation = false; mNextSpeechAttempt = RandomGenerator.GetNext(20, 255); mNextMovementAttempt = RandomGenerator.GetNext(20, 255); mServingItemId = 0; mServingActorId = 0; mMovingToServePos = false; mActorServePos = null; if (mSelfBot.Rotation >= 0) { mSelfActor.BodyRotation = mSelfBot.Rotation; mSelfActor.HeadRotation = mSelfBot.Rotation; } } public override void OnSelfLeaveRoom(RoomInstance Instance) { if (mSelfActor == null) { return; } mSelfActor = null; } public override void OnUserChat(RoomInstance Instance, RoomActor Actor, string MessageText, bool Shout) { try { Session Session = SessionManager.GetSessionByCharacterId(CharacterResolverCache.GetUidFromName(Actor.Name)); if (MessageText.ToLower().Contains("heal")) { if (Session.CharacterInfo.Dead != 1) { if (Session.CharacterInfo.Health < 100) { Session.CharacterInfo.beingHealedSeconds = 60; Session.CharacterInfo.beingHealed = true; mSelfActor.Chat("*Treats " + Session.CharacterInfo.Username + " for major wounds*", true, true); Session.CharacterInfo.poisoned = false; } else if(Session.CharacterInfo.Health >= 100) { Session.SendData(RoomChatComposer.Compose(Actor.Id, "Your health is already full!", 0, ChatType.Whisper)); return; } } else { using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient()) { RealityEMU.Game.Roleplay.RPMisc.releaseFromHosp(Session, Instance); } mSelfActor.Chat("*Discharges " + Session.CharacterInfo.Username + "' from the hospital*", true, true); Instance.BroadcastMessage(UserInfoUpdateComposer.Compose(Actor.Id, Session.CharacterInfo.Figure, Session.CharacterInfo.Gender, Session.CharacterInfo.Motto, Session.CharacterInfo.Score)); } } } catch (Exception e) { Console.WriteLine(e.ToString()); } } public override void OnUserEnter(RoomInstance Instance, RoomActor Actor) { mSelfActor.Chat("Welcome to the hospital " + Actor.Name + ". If you need a heal just ask!"); if (mSelfActor == null || Actor.Type == RoomActorType.AiBot) { return; } if (mSelfBot.Effect > 0) { mSelfActor.ApplyEffect(mSelfBot.Effect); } } public override void OnUserLeave(RoomInstance Instance, RoomActor Actor) { if (mSelfActor == null || Actor.Type == RoomActorType.AiBot) { return; } } public override void PerformUpdate(RoomInstance Instance) { if (mNextSpeechAttempt <= 0) { string Message = BotManager.GetRandomSpeechForBotDefinition(mSelfBot.DefinitionId); if (Message != null && Message.Length > 0) { mSelfActor.Chat(Message); } mNextSpeechAttempt = RandomGenerator.GetNext(0, 255); } else { mNextSpeechAttempt--; } if (mSelfActor != null) { //!mSelfActor.IsMoving && mNextMovementAttempt <= 0 if (mNextMovementAttempt <= 0) { switch (mSelfBot.WalkMode) { default: case BotWalkMode.STAND: break; case BotWalkMode.FREEROAM: Vector2 position = new Vector2(RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeX - 1), RandomGenerator.GetNext(0, Instance.Model.Heightmap.SizeY - 1)); mSelfActor.MoveTo(position); break; case BotWalkMode.SPECIFIED_RANGE: ReadOnlyCollection<Vector2> Possibilites = mSelfBot.PredefinedPositions; mSelfActor.MoveTo(Possibilites[RandomGenerator.GetNext(0, (Possibilites.Count - 1))]); break; } mNextMovementAttempt = 5; mNeedsRotation = true; // mSelfActor.Chat("lol"); } else { mNextMovementAttempt--; if (mNextMovementAttempt > 5) { mNextMovementAttempt = 5; } //mSelfActor.Chat(mNextMovementAttempt + "-"); if (!mSelfActor.IsMoving) { if (mMovingToServePos) { mMovingToServePos = false; mSelfActor.CarryItem(mServingItemId); mSelfActor.MoveTo(mActorServePos); } else if (mServingItemId > 0) { mSelfActor.CarryItem(0); RoomActor TargetActor = Instance.GetActor(mServingActorId); if (TargetActor != null) { TargetActor.CarryItem(mServingItemId); int NewRot = Rotation.Calculate(mActorServePos, TargetActor.Position.GetVector2()); mSelfActor.HeadRotation = NewRot; mSelfActor.BodyRotation = NewRot; mNeedsRotation = true; mSelfActor.UpdateNeeded = true; } mServingItemId = 0; } else if (mNeedsRotation && mSelfBot.Rotation >= 0) { mSelfActor.BodyRotation = mSelfBot.Rotation; mSelfActor.HeadRotation = mSelfBot.Rotation; mNeedsRotation = false; } } } if (remindSpeech <= 0) { mSelfActor.Chat("If you need a heal just ask!"); remindSpeech = 100; } else { remindSpeech--; } } } } } [/SPOILER] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Q&A
[Help] Hospital Bot For HabboRP'S [Help]
Top