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
Removebadge command
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="tyutu" data-source="post: 435843" data-attributes="member: 71974"><p>I made a command to remove badges, but I have a problem; the badge is only removed after the user</p><p>reenter in the Hotel. Does anyone know how to fix this? I remember that this command used to work perfectly in emulators: p</p><p></p><p><strong>RemovebadgeCommand</strong></p><p>[CODE]using System;</p><p>using System.Linq;</p><p>using System.Text;</p><p>using System.Collections.Generic;</p><p></p><p>using Plus.HabboHotel.GameClients;</p><p></p><p>namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator</p><p>{</p><p> class RemoveBadgeCommand : IChatCommand</p><p> {</p><p> public string PermissionRequired</p><p> {</p><p> get { return "command_remove_badge"; }</p><p> }</p><p></p><p> public string Parameters</p><p> {</p><p> get { return "%username% %badge%"; }</p><p> }</p><p></p><p> public string Description</p><p> {</p><p> get { return "Remove a badge from a player"; }</p><p> }</p><p></p><p> public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params)</p><p> {</p><p> if (Params.Length != 3)</p><p> {</p><p> Session.SendWhisper("Please enter a username and the code of the badge you want to remove!");</p><p> return;</p><p> }</p><p></p><p> GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);</p><p> if (TargetClient != null)</p><p> {</p><p> if (!TargetClient.GetHabbo().GetBadgeComponent().HasBadge(Params[2]))</p><p> {</p><p> TargetClient.GetHabbo().GetBadgeComponent().RemoveBadge(Params[2]);</p><p> if (TargetClient.GetHabbo().Id != Session.GetHabbo().Id)</p><p> TargetClient.SendNotification("You have had the badge " + Params[2] + " removed from you!");</p><p> else</p><p> Session.SendWhisper("You have succesfully removed the badge " + Params[2] + " from yourself!");</p><p> }</p><p> else</p><p> Session.SendWhisper("Oops, that user does not have that badge!");</p><p> return;</p><p> }</p><p> else</p><p> {</p><p> Session.SendWhisper("That user cannot be found!");</p><p> return;</p><p> }</p><p> }</p><p> }</p><p>}[/CODE]</p><p></p><p><strong>BadgeComponent</strong></p><p><strong>[CODE]using System.Collections.Generic;</strong></p><p><strong></strong></p><p><strong>using Plus.HabboHotel.GameClients;</strong></p><p><strong>using Plus.Communication.Packets.Outgoing.Inventory.Badges;</strong></p><p><strong>using Plus.Communication.Packets.Outgoing.Inventory.Furni;</strong></p><p><strong></strong></p><p><strong>using Plus.Database.Interfaces;</strong></p><p><strong>using Plus.HabboHotel.Badges;</strong></p><p><strong></strong></p><p><strong>namespace Plus.HabboHotel.Users.Badges</strong></p><p><strong>{</strong></p><p><strong> public class BadgeComponent</strong></p><p><strong> {</strong></p><p><strong> private readonly Habbo _player;</strong></p><p><strong> private readonly Dictionary<string, Badge> _badges;</strong></p><p><strong></strong></p><p><strong> public BadgeComponent(Habbo Player, UserData.UserData data)</strong></p><p><strong> {</strong></p><p><strong> _player = Player;</strong></p><p><strong> _badges = new Dictionary<string, Badge>();</strong></p><p><strong></strong></p><p><strong> foreach (Badge badge in data.badges)</strong></p><p><strong> {</strong></p><p><strong> BadgeDefinition BadgeDefinition = null;</strong></p><p><strong> if (!PlusEnvironment.GetGame().GetBadgeManager().TryGetBadge(badge.Code, out BadgeDefinition) || BadgeDefinition.RequiredRight.Length > 0 && !Player.GetPermissions().HasRight(BadgeDefinition.RequiredRight))</strong></p><p><strong> continue;</strong></p><p><strong></strong></p><p><strong> if (!_badges.ContainsKey(badge.Code))</strong></p><p><strong> _badges.Add(badge.Code, badge);</strong></p><p><strong> } </strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> public int Count</strong></p><p><strong> {</strong></p><p><strong> get { return _badges.Count; }</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> public int EquippedCount</strong></p><p><strong> {</strong></p><p><strong> get</strong></p><p><strong> {</strong></p><p><strong> int i = 0;</strong></p><p><strong></strong></p><p><strong> foreach (Badge badge in _badges.Values)</strong></p><p><strong> {</strong></p><p><strong> if (badge.Slot <= 0)</strong></p><p><strong> {</strong></p><p><strong> continue;</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> i++;</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> return i;</strong></p><p><strong> }</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> public ICollection<Badge> GetBadges()</strong></p><p><strong> {</strong></p><p><strong> return _badges.Values;</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> public Badge GetBadge(string badge)</strong></p><p><strong> {</strong></p><p><strong> if (_badges.ContainsKey(badge))</strong></p><p><strong> return _badges[badge];</strong></p><p><strong></strong></p><p><strong> return null;</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> public bool TryGetBadge(string code, out Badge badge)</strong></p><p><strong> {</strong></p><p><strong> return _badges.TryGetValue(code, out badge);</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> public bool HasBadge(string badge)</strong></p><p><strong> {</strong></p><p><strong> return _badges.ContainsKey(badge);</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> public void GiveBadge(string code, bool inDatabase, GameClient session)</strong></p><p><strong> {</strong></p><p><strong> if (HasBadge(code))</strong></p><p><strong> return;</strong></p><p><strong></strong></p><p><strong> BadgeDefinition badge = null;</strong></p><p><strong> if (!PlusEnvironment.GetGame().GetBadgeManager().TryGetBadge(code.ToUpper(), out badge) || badge.RequiredRight.Length > 0 && !session.GetHabbo().GetPermissions().HasRight(badge.RequiredRight))</strong></p><p><strong> return;</strong></p><p><strong></strong></p><p><strong> if (inDatabase)</strong></p><p><strong> {</strong></p><p><strong> using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())</strong></p><p><strong> {</strong></p><p><strong> dbClient.SetQuery("REPLACE INTO `user_badges` (`user_id`,`badge_id`,`badge_slot`) VALUES ('" + _player.Id + "', @badge, '" + 0 + "')");</strong></p><p><strong> dbClient.AddParameter("badge", code);</strong></p><p><strong> dbClient.RunQuery();</strong></p><p><strong> }</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> _badges.Add(code, new Badge(code, 0));</strong></p><p><strong></strong></p><p><strong> if (session != null)</strong></p><p><strong> {</strong></p><p><strong> session.SendPacket(new BadgesComposer(session));</strong></p><p><strong> session.SendPacket(new FurniListNotificationComposer(1, 4));</strong></p><p><strong> }</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> public void ResetSlots()</strong></p><p><strong> {</strong></p><p><strong> foreach (Badge Badge in _badges.Values)</strong></p><p><strong> {</strong></p><p><strong> Badge.Slot = 0;</strong></p><p><strong> }</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> public void RemoveBadge(string Badge)</strong></p><p><strong> {</strong></p><p><strong> if (!HasBadge(Badge))</strong></p><p><strong> {</strong></p><p><strong> return;</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())</strong></p><p><strong> {</strong></p><p><strong> dbClient.SetQuery("DELETE FROM user_badges WHERE badge_id = @badge AND user_id = " + _player.Id + " LIMIT 1");</strong></p><p><strong> dbClient.AddParameter("badge", Badge);</strong></p><p><strong> dbClient.RunQuery();</strong></p><p><strong> }</strong></p><p><strong></strong></p><p><strong> if (_badges.ContainsKey(Badge))</strong></p><p><strong> _badges.Remove(Badge);</strong></p><p><strong> }</strong></p><p><strong> }</strong></p><p><strong>}[/CODE]</strong></p><p><strong></strong></p></blockquote><p></p>
[QUOTE="tyutu, post: 435843, member: 71974"] I made a command to remove badges, but I have a problem; the badge is only removed after the user reenter in the Hotel. Does anyone know how to fix this? I remember that this command used to work perfectly in emulators: p [B]RemovebadgeCommand[/B] [CODE]using System; using System.Linq; using System.Text; using System.Collections.Generic; using Plus.HabboHotel.GameClients; namespace Plus.HabboHotel.Rooms.Chat.Commands.Moderator { class RemoveBadgeCommand : IChatCommand { public string PermissionRequired { get { return "command_remove_badge"; } } public string Parameters { get { return "%username% %badge%"; } } public string Description { get { return "Remove a badge from a player"; } } public void Execute(GameClients.GameClient Session, Rooms.Room Room, string[] Params) { if (Params.Length != 3) { Session.SendWhisper("Please enter a username and the code of the badge you want to remove!"); return; } GameClient TargetClient = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]); if (TargetClient != null) { if (!TargetClient.GetHabbo().GetBadgeComponent().HasBadge(Params[2])) { TargetClient.GetHabbo().GetBadgeComponent().RemoveBadge(Params[2]); if (TargetClient.GetHabbo().Id != Session.GetHabbo().Id) TargetClient.SendNotification("You have had the badge " + Params[2] + " removed from you!"); else Session.SendWhisper("You have succesfully removed the badge " + Params[2] + " from yourself!"); } else Session.SendWhisper("Oops, that user does not have that badge!"); return; } else { Session.SendWhisper("That user cannot be found!"); return; } } } }[/CODE] [B]BadgeComponent [CODE]using System.Collections.Generic; using Plus.HabboHotel.GameClients; using Plus.Communication.Packets.Outgoing.Inventory.Badges; using Plus.Communication.Packets.Outgoing.Inventory.Furni; using Plus.Database.Interfaces; using Plus.HabboHotel.Badges; namespace Plus.HabboHotel.Users.Badges { public class BadgeComponent { private readonly Habbo _player; private readonly Dictionary<string, Badge> _badges; public BadgeComponent(Habbo Player, UserData.UserData data) { _player = Player; _badges = new Dictionary<string, Badge>(); foreach (Badge badge in data.badges) { BadgeDefinition BadgeDefinition = null; if (!PlusEnvironment.GetGame().GetBadgeManager().TryGetBadge(badge.Code, out BadgeDefinition) || BadgeDefinition.RequiredRight.Length > 0 && !Player.GetPermissions().HasRight(BadgeDefinition.RequiredRight)) continue; if (!_badges.ContainsKey(badge.Code)) _badges.Add(badge.Code, badge); } } public int Count { get { return _badges.Count; } } public int EquippedCount { get { int i = 0; foreach (Badge badge in _badges.Values) { if (badge.Slot <= 0) { continue; } i++; } return i; } } public ICollection<Badge> GetBadges() { return _badges.Values; } public Badge GetBadge(string badge) { if (_badges.ContainsKey(badge)) return _badges[badge]; return null; } public bool TryGetBadge(string code, out Badge badge) { return _badges.TryGetValue(code, out badge); } public bool HasBadge(string badge) { return _badges.ContainsKey(badge); } public void GiveBadge(string code, bool inDatabase, GameClient session) { if (HasBadge(code)) return; BadgeDefinition badge = null; if (!PlusEnvironment.GetGame().GetBadgeManager().TryGetBadge(code.ToUpper(), out badge) || badge.RequiredRight.Length > 0 && !session.GetHabbo().GetPermissions().HasRight(badge.RequiredRight)) return; if (inDatabase) { using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("REPLACE INTO `user_badges` (`user_id`,`badge_id`,`badge_slot`) VALUES ('" + _player.Id + "', @badge, '" + 0 + "')"); dbClient.AddParameter("badge", code); dbClient.RunQuery(); } } _badges.Add(code, new Badge(code, 0)); if (session != null) { session.SendPacket(new BadgesComposer(session)); session.SendPacket(new FurniListNotificationComposer(1, 4)); } } public void ResetSlots() { foreach (Badge Badge in _badges.Values) { Badge.Slot = 0; } } public void RemoveBadge(string Badge) { if (!HasBadge(Badge)) { return; } using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor()) { dbClient.SetQuery("DELETE FROM user_badges WHERE badge_id = @badge AND user_id = " + _player.Id + " LIMIT 1"); dbClient.AddParameter("badge", Badge); dbClient.RunQuery(); } if (_badges.ContainsKey(Badge)) _badges.Remove(Badge); } } }[/CODE] [/B] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Server Development
Habbo Retros
Habbo Q&A
Removebadge command
Top