It should work for every production. I am making from a normal hotel to a RP, so I have no use for this Thanks !I dont see how this benefits the hotel but good release. You have some bright ideas and thats what I like about. Ermm Im not sure this will work for every production, correct me if I am wrong.
That sounds 100% correct. Any errors? I don't think I left out any code.So correct me if I'm wrong.
First I added the code under the Habbo Class inside of Habbo.cs.
Then I changed the code in Item,cs to the new one you created.
After I created a file in the User command folder called rigdiceCommand.CS and made sure to change the namespace to users.
Finally, I added command_rigdice in my db.
Now, upon a successful build and testing it out it works, somewhat. Command functions, prints out the messages and all, but when rolling the dice it does not stop.
Did I miss something, thanks for the heads up!
Okay, thank you for this information.The command I set does work.
typing :rig <name> <rig order> appears with the message saying the players dice will be rig, blah.
When said player goes to roll, it just keeps rolling.
No it does not worth with out rigging as well. It causes all dice to break.
public static string[] RandomizeStrings(string[] arr)
{
List<KeyValuePair<int, string>> list = new List<KeyValuePair<int, string>>();
// Add all strings from array
// Add new random int each time
foreach (string s in arr)
{
list.Add(new KeyValuePair<int, string>(_random.Next(), s));
}
// Sort the list by the random number
var sorted = from item in list
orderby item.Key
select item;
// Allocate new string array
string[] result = new string[arr.Length];
// Copy values to array
int index = 0;
foreach (KeyValuePair<int, string> pair in sorted)
{
result[index] = pair.Value;
index++;
}
// Return copied array
return result;
}
No you just have to add the command part that points to the command in the commandManager.cs file?I did exactly what you guided, and debugged it via studios, got no errors, still whenever I type :rig or :rigdice, nothing happens and I did add it to the DB as :command_rig + :command_rigdice, does the command.cs file has to match something? like RigDiceCommand.cs or rigdiceCommand.cs?
If you havent mentioned commandManager.cs then thats probably where I got confusedNo you just have to add the command part that points to the command in the commandManager.cs file?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Plus.HabboHotel.GameClients;
using Plus.HabboHotel.Rooms;
using Plus.HabboHotel.Rooms.Chat.Commands;
namespace Plus.HabboHotel.Roleplay.Commands.Builder
{
internal sealed class RigDiceCommand : IChatCommand
{
public string PermissionRequired => "command_rigdice";
public string Parameters => "%username% %sequence%";
public string Description => "Set predetermined dice outcome(s) without any randomization.";
public void Execute(GameClient session, Room room, string[] Params)
{
if (Params.Length == 1)
{
session.SendWhisper("Syntax error! Usage: :rigdice <username> <sequence (0-6, 0-6..)>");
return;
}
// contemplating whether values should be stored in the RoomUser.
GameClient target = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]);
if (target == null)
{
session.SendWhisper("Couldn't find user " + Params[1] + " in this room!");
return;
}
// to be used by trusted staff, or convert to array and limit values.
string input = String.Concat(Params.Skip(2).ToArray()).Replace(" ", string.Empty);
// pre-allocated memory list configured for 5 insertions.
List<uint> sequence = new List<uint>(5);
foreach (string element in input.Split(','))
{
uint number;
if (!uint.TryParse(element, out number))
{
session.SendWhisper(element + " isn't a valid positive integer.");
return;
}
if (number > 6)
{
session.SendWhisper("Sequence cannot contain numbers greater than 6!");
return;
}
sequence.Add(number);
}
if (target.GetHabbo().DiceSequence != null)
{
// add the new sequence to the end of the old sequence (remove if not wanted).
lock (target.GetHabbo().DiceSequence)
{
List<uint> copySequence = new List<uint>(target.GetHabbo().DiceSequence.Count + sequence.Count);
copySequence.AddRange(target.GetHabbo().DiceSequence);
copySequence.AddRange(sequence);
target.GetHabbo().DiceSequence = copySequence;
}
session.SendWhisper("Added to " + target.GetHabbo().Username + "'s current dice sequence.");
return;
}
target.GetHabbo().DiceSequence = sequence;
// notify the caller that we're finished.
session.SendWhisper("Created " + target.GetHabbo().Username + "'s dice sequence.");
}
}
}
public List<uint> DiceSequence;
string[] numbers = new string[] { "1", "2", "3", "4", "5", "6" };
if (ExtraData == "-1")
{
User = GetRoom().GetRoomUserManager().GetRoomUserByHabbo(InteractingUser);
if (User.GetClient().GetHabbo().DiceSequence != null)
{
ExtraData = User.GetClient().GetHabbo().DiceSequence[0].ToString();
User.GetClient().GetHabbo().DiceSequence.RemoveAt(0);
// properly dispose of the DiceSequence list.
if (!User.GetClient().GetHabbo().DiceSequence.Any())
User.GetClient().GetHabbo().DiceSequence = null;
}
else
{
ExtraData = RandomizeStrings(numbers)[0];
}
}
UpdateState();
I refactored this a bit.
RigDiceCommand.cs
Code:using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Plus.HabboHotel.GameClients; using Plus.HabboHotel.Rooms; using Plus.HabboHotel.Rooms.Chat.Commands; namespace Plus.HabboHotel.Roleplay.Commands.Builder { internal sealed class RigDiceCommand : IChatCommand { public string PermissionRequired => "command_rigdice"; public string Parameters => "%username% %sequence%"; public string Description => "Set predetermined dice outcome(s) without any randomization."; public void Execute(GameClient session, Room room, string[] Params) { if (Params.Length == 1) { session.SendWhisper("Syntax error! Usage: :rigdice <username> <sequence (0-6, 0-6..)>"); return; } // contemplating whether values should be stored in the RoomUser. GameClient target = PlusEnvironment.GetGame().GetClientManager().GetClientByUsername(Params[1]); if (target == null) { session.SendWhisper("Couldn't find user " + Params[1] + " in this room!"); return; } // to be used by trusted staff, or convert to array and limit values. string input = String.Concat(Params.Skip(2).ToArray()).Replace(" ", string.Empty); // pre-allocated memory list configured for 5 insertions. List<uint> sequence = new List<uint>(5); foreach (string element in input.Split(',')) { uint number; if (!uint.TryParse(element, out number)) { session.SendWhisper(element + " isn't a valid positive integer."); return; } if (number > 6) { session.SendWhisper("Sequence cannot contain numbers greater than 6!"); return; } sequence.Add(number); } if (target.GetHabbo().DiceSequence != null) { // add the new sequence to the end of the old sequence (remove if not wanted). lock (target.GetHabbo().DiceSequence) { List<uint> copySequence = new List<uint>(target.GetHabbo().DiceSequence.Count + sequence.Count); copySequence.AddRange(target.GetHabbo().DiceSequence); copySequence.AddRange(sequence); target.GetHabbo().DiceSequence = copySequence; } session.SendWhisper("Added to " + target.GetHabbo().Username + "'s current dice sequence."); return; } target.GetHabbo().DiceSequence = sequence; // notify the caller that we're finished. session.SendWhisper("Created " + target.GetHabbo().Username + "'s dice sequence."); } } }
Habbo.cs (Habbo class, I added under the "Just random fun stuff" comment)
Code:public List<uint> DiceSequence;
My InteractionType.DICE case code
Code:string[] numbers = new string[] { "1", "2", "3", "4", "5", "6" }; if (ExtraData == "-1") { User = GetRoom().GetRoomUserManager().GetRoomUserByHabbo(InteractingUser); if (User.GetClient().GetHabbo().DiceSequence != null) { ExtraData = User.GetClient().GetHabbo().DiceSequence[0].ToString(); User.GetClient().GetHabbo().DiceSequence.RemoveAt(0); // properly dispose of the DiceSequence list. if (!User.GetClient().GetHabbo().DiceSequence.Any()) User.GetClient().GetHabbo().DiceSequence = null; } else { ExtraData = RandomizeStrings(numbers)[0]; } } UpdateState();