OfficerLawless
Member
Below is a script for a Bow that on creation will be assigned 3x Random Combat Properties from the Predetermined list. Occasionally when the item is created it will only have 2 properties on it instead of 3. I suspect this is related to the line " while (property1 == property2) " which is to prevent property 1 and 2 from being the same. I think its likely that its only comming out with 2 instead of 3 properties because the random chance has generated the same property multiple times.
im stumped on how i can include the 3rd property to not duplicate. ive tried using multiple loop statements like
" while (property1 == property2) "
" while (property2 == property3) "
" while (property1 == property3) "
this method did not work ive also tried adding property into the loop " while (property1 == property2 ==Property3) "
For obvious reasons this did not work either.
Looking for some guidance as ive spent way to much time on this and i think my brain is just broken at this point.
How can i fix the loop to include Property3?
namespace Items
{
[Flipable(0x13B2, 0x13B1)]
public class RareBowOfRandom : BaseRanged
{
[Constructable]
public RareBowOfRandom()
: base(0x13B2)
{
Name = "Rare Bow Of Random";
Weight = 6.0;
Layer = Layer.TwoHanded;
Hue = 0x4f2;
// Assign 2 random combat properties with a value of 75
int property1 = Utility.Random(1, 17);
int property2 = Utility.Random(1, 17);
int property3 = Utility.Random(1, 17);
while (property1 == property2)
{
property2 = Utility.Random(1, 17);
}
SetRandomProperty(property1, 75);
SetRandomProperty(property2, 75);
SetRandomProperty(property3, 75);
}
public RareBowOfRandom(Serial serial)
: base(serial)
{
}
public override int EffectID => 0xF42;
public override Type AmmoType => typeof(Arrow);
public override Item Ammo => new Arrow();
public override WeaponAbility PrimaryAbility => WeaponAbility.ParalyzingBlow;
public override WeaponAbility SecondaryAbility => WeaponAbility.MortalStrike;
public override int StrengthReq => 30;
public override int MinDamage => 17;
public override int MaxDamage => 21;
public override float Speed => 4;
public override int DefMaxRange => 10;
public override int InitMinHits => 31;
public override int InitMaxHits => 60;
public override WeaponAnimation DefAnimation => WeaponAnimation.ShootBow;
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
private void SetRandomProperty(int index, int value)
{
switch (index)
{
case 1:
WeaponAttributes.HitLeechHits = value;
break;
case 2:
WeaponAttributes.HitLeechStam = value;
break;
case 3:
WeaponAttributes.HitLeechMana = value;
break;
case 4:
WeaponAttributes.HitLowerAttack = value;
break;
case 5:
WeaponAttributes.HitLowerDefend = value;
break;
case 6:
WeaponAttributes.HitMagicArrow = value;
break;
case 7:
WeaponAttributes.HitHarm = value;
break;
case 8:
WeaponAttributes.HitFireball = value;
break;
case 9:
WeaponAttributes.HitLightning = value;
break;
case 10:
WeaponAttributes.HitDispel = value;
break;
case 11:
WeaponAttributes.HitColdArea = value;
break;
case 12:
WeaponAttributes.HitFireArea = value;
break;
case 13:
WeaponAttributes.HitPoisonArea = value;
break;
case 14:
WeaponAttributes.HitEnergyArea = value;
break;
case 15:
WeaponAttributes.HitPhysicalArea = value;
break;
case 16:
WeaponAttributes.UseBestSkill = value;
break;
case 17:
WeaponAttributes.MageWeapon = value;
break;
}
}
}
}
}
im stumped on how i can include the 3rd property to not duplicate. ive tried using multiple loop statements like
" while (property1 == property2) "
" while (property2 == property3) "
" while (property1 == property3) "
this method did not work ive also tried adding property into the loop " while (property1 == property2 ==Property3) "
For obvious reasons this did not work either.
Looking for some guidance as ive spent way to much time on this and i think my brain is just broken at this point.
How can i fix the loop to include Property3?
namespace Items
{
[Flipable(0x13B2, 0x13B1)]
public class RareBowOfRandom : BaseRanged
{
[Constructable]
public RareBowOfRandom()
: base(0x13B2)
{
Name = "Rare Bow Of Random";
Weight = 6.0;
Layer = Layer.TwoHanded;
Hue = 0x4f2;
// Assign 2 random combat properties with a value of 75
int property1 = Utility.Random(1, 17);
int property2 = Utility.Random(1, 17);
int property3 = Utility.Random(1, 17);
while (property1 == property2)
{
property2 = Utility.Random(1, 17);
}
SetRandomProperty(property1, 75);
SetRandomProperty(property2, 75);
SetRandomProperty(property3, 75);
}
public RareBowOfRandom(Serial serial)
: base(serial)
{
}
public override int EffectID => 0xF42;
public override Type AmmoType => typeof(Arrow);
public override Item Ammo => new Arrow();
public override WeaponAbility PrimaryAbility => WeaponAbility.ParalyzingBlow;
public override WeaponAbility SecondaryAbility => WeaponAbility.MortalStrike;
public override int StrengthReq => 30;
public override int MinDamage => 17;
public override int MaxDamage => 21;
public override float Speed => 4;
public override int DefMaxRange => 10;
public override int InitMinHits => 31;
public override int InitMaxHits => 60;
public override WeaponAnimation DefAnimation => WeaponAnimation.ShootBow;
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
private void SetRandomProperty(int index, int value)
{
switch (index)
{
case 1:
WeaponAttributes.HitLeechHits = value;
break;
case 2:
WeaponAttributes.HitLeechStam = value;
break;
case 3:
WeaponAttributes.HitLeechMana = value;
break;
case 4:
WeaponAttributes.HitLowerAttack = value;
break;
case 5:
WeaponAttributes.HitLowerDefend = value;
break;
case 6:
WeaponAttributes.HitMagicArrow = value;
break;
case 7:
WeaponAttributes.HitHarm = value;
break;
case 8:
WeaponAttributes.HitFireball = value;
break;
case 9:
WeaponAttributes.HitLightning = value;
break;
case 10:
WeaponAttributes.HitDispel = value;
break;
case 11:
WeaponAttributes.HitColdArea = value;
break;
case 12:
WeaponAttributes.HitFireArea = value;
break;
case 13:
WeaponAttributes.HitPoisonArea = value;
break;
case 14:
WeaponAttributes.HitEnergyArea = value;
break;
case 15:
WeaponAttributes.HitPhysicalArea = value;
break;
case 16:
WeaponAttributes.UseBestSkill = value;
break;
case 17:
WeaponAttributes.MageWeapon = value;
break;
}
}
}
}
}
Last edited: