ServUO Version
Publish 57
Ultima Expansion
Endless Journey
So I am working on the name properties of an item, the shrink item specifically, and am trying to figure out a way to modify this list so it only shows skills greater than 0 so I don't have to make a million if statements for each skill.. so for example "If m_PetWrestling > 0" show "Wrestling {0}", so on and so forth.

C#:
list.Add(1060660, "Combat Skills\tWrestling {0}, Tactics {1}, Anatomy {2}, Poisoning {3}", m_PetWrestling, m_PetTactics, m_PetAnatomy, m_PetPoisoning);
 
From Soulstone, cause typing code on a phone is annoying

Screenshot_20220506-202621_Chrome.jpg
The rest would probably be best to use a StringBuilder within the for loop
 
Last edited:
Reference:
C#:
using System.Linq;
C#:
string skills = string.Join("\n", from.Skills.Where(skill => skill.Value > 0).Select(skill => $"{skill.Name}: {skill.Value:F1}"));

list.Add(1060660, $"Combat Skills\t\n{skills}");

Which can be adapted for the original request as;
C#:
using System.Linq;
using System.Collections.Generic;
C#:
Dictionary<string, double> skillValues = new Dictionary<string, double>
{
    { "Wrestling", m_PetWrestling },
    { "Tactics", m_PetTactics },
    { "Anatomy", m_PetAnatomy },
    { "Poisoning", m_PetPoisoning },
};

string skills = string.Join("\n", skillValues.Where(skill => skill.Value > 0).Select(skill => $"{skill.Key}: {skill.Value:F1}"));

list.Add(1060660, $"Combat Skills\t\n{skills}");

Which should produce:
Code:
Combat Skills
Wrestling: 100.1
Tactics: 10.0
Anatomy: 99.9
Poisoning: 119.9

Note that \n is used to trick the client into line-breaking the entries.

Not sure if this is more or less cumbersome than the if-chain you wanted to avoid tbh;
C#:
using System.Text;
C#:
StringBuilder skills = new StringBuilder();

if (m_PetWrestling > 0)
{
    skills.AppendLine($"Wrestling: {m_PetWrestling:F1}");
}

if (m_PetTactics > 0)
{
    skills.AppendLine($"Tactics: {m_PetTactics:F1}");
}

if (m_PetAnatomy > 0)
{
    skills.AppendLine($"Anatomy: {m_PetAnatomy:F1}");
}

if (m_PetPoisoning > 0)
{
    skills.AppendLine($"Poisoning: {m_PetPoisoning:F1}");
}

list.Add(1060660, $"Combat Skills\t\n{skills}");

You can probably just remove all the m_SkillValue fields from the ShrinkItem in the end, and directly reference the existing pet's Skills property (in line with the first example that uses from.Skills).
 
I should add, that if you use Vita-Nex' ExtendedOPL, you can avoid things like crashing the client due to arguments being too long (a creature with every skill > 0 for example).

C#:
using System.Linq;
using VitaNex.Network;
C#:
using (ExtendedOPL opl = new ExtendedOPL(list))
{
    opl.Add("Combat Skills");

    Skills skills = from.Skills;

    opl.AddRange(skills.Where(skill => skill.Value > 0).Select(skill => $"{skill.Name}: {skill.Value:F1}"));
}

No need to provide any cliloc# and you can add up to 65 custom lines by default :)
 
Reference:
C#:
using System.Linq;
C#:
string skills = string.Join("\n", from.Skills.Where(skill => skill.Value > 0).Select(skill => $"{skill.Name}: {skill.Value:F1}"));

list.Add(1060660, $"Combat Skills\t\n{skills}");

Which can be adapted for the original request as;
C#:
using System.Linq;
using System.Collections.Generic;
C#:
Dictionary<string, double> skillValues = new Dictionary<string, double>
{
    { "Wrestling", m_PetWrestling },
    { "Tactics", m_PetTactics },
    { "Anatomy", m_PetAnatomy },
    { "Poisoning", m_PetPoisoning },
};

string skills = string.Join("\n", skillValues.Where(skill => skill.Value > 0).Select(skill => $"{skill.Key}: {skill.Value:F1}"));

list.Add(1060660, $"Combat Skills\t\n{skills}");

Which should produce:
Code:
Combat Skills
Wrestling: 100.1
Tactics: 10.0
Anatomy: 99.9
Poisoning: 119.9

Note that \n is used to trick the client into line-breaking the entries.

Not sure if this is more or less cumbersome than the if-chain you wanted to avoid tbh;
C#:
using System.Text;
C#:
StringBuilder skills = new StringBuilder();

if (m_PetWrestling > 0)
{
    skills.AppendLine($"Wrestling: {m_PetWrestling:F1}");
}

if (m_PetTactics > 0)
{
    skills.AppendLine($"Tactics: {m_PetTactics:F1}");
}

if (m_PetAnatomy > 0)
{
    skills.AppendLine($"Anatomy: {m_PetAnatomy:F1}");
}

if (m_PetPoisoning > 0)
{
    skills.AppendLine($"Poisoning: {m_PetPoisoning:F1}");
}

list.Add(1060660, $"Combat Skills\t\n{skills}");

You can probably just remove all the m_SkillValue fields from the ShrinkItem in the end, and directly reference the existing pet's Skills property (in line with the first example that uses from.Skills).
String interpolation won't work for pub 57 though correct?
 
Back