Announcement

Collapse
No announcement yet.

Need help getting a line of code to work!

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help getting a line of code to work!

    So im making a server designed for single player play, and im attempting to give clothing random resistances from 0-3% where 0 is not present.
    im not really a programmer but i have got this code to work before, but i had to apply it to every item resulting in much un-nessasary coding.

    what i would like is this line :

    Resistances.Energy (0 + ( 100 > Utility.Random 0 = (0,3)));

    //100% chance of 0-3 energy resistance

    to apply to the public abstract class base shirt rather than having to add it to every artical of clothing. However i cant get this line to work either way.
    does anyone know what i messed up here?

    also i found public override to be to messy and bulky, i would prefer to apply this like a "SetAttribute.ResistenceType.Enegry" type of way to the underlying base for clothing,. the goal is to make it as small as possible.

    p.s. my mouse broke :*(

    below is my attempt to get this code to work. iv also tried it in the int itemID Context aswell with no success.
    __________________________________________________ __________________________________________________ __________________

    using System;

    namespace Server.Items
    {
    public abstract class BaseShirt : BaseClothing
    {
    public BaseShirt( int itemID ) : this( itemID, 0 )
    {
    }

    public BaseShirt( int itemID, int hue ) : base( itemID, Layer.Shirt, hue )
    {
    Resistances.Energy (0 + ( 100 > Utility.Random 0 = (0, 3 )));
    }

    public BaseShirt( Serial serial ) : base( serial )
    {
    }


  • #2
    So iv been tinkering around and figured out my coding problem,

    Resistances.Energy (0 + ( 100 > Utility.Random 0 = (0,3)));

    Which was simply too many brackets.

    Resistances.Poison = 0 + Utility.RandomMinMax( 0, 3 );
    Resistances.Cold = 0 + Utility.RandomMinMax( 0, 3 );
    Resistances.Fire = 0 + Utility.RandomMinMax( 0, 3 );
    Resistances.Energy = 0 + Utility.RandomMinMax( 0, 3 );
    Resistances.Physical = 0 + Utility.RandomMinMax( 0, 3 );

    can also be written

    Resistances.Poison = (Utility.RandomMinMax( 0, 3 ));
    Resistances.Cold = (Utility.RandomMinMax( 0, 3 ));
    Resistances.Fire = (Utility.RandomMinMax( 0, 3 ));
    Resistances.Energy = (Utility.RandomMinMax( 0, 3 ));
    Resistances.Physical = (Utility.RandomMinMax( 0, 3 ));

    But I like being able to see the math, and the code is the same size but im left with another much harder to answer question,
    if there are multiple ways to write the same line, then how do I determine which of the lines is the most stable and hardware efficient?


    In this example the mods are added be for the item is constructed, There is no item id or defining variables.

    public override int BasePhysicalResistance{ get{ return 0; } }
    public override int BaseFireResistance{ get{ return 5; } }
    public override int BaseColdResistance{ get{ return 9; } }
    public override int BasePoisonResistance{ get{ return 5; } }
    public override int BaseEnergyResistance{ get{ return 5; } }


    In this section the mods are added after the construction and id of the item which is the easiest method iv found, but I imagin the code need to access more sub scripts to function.

    Resistances.Poison = 10;
    Resistances.Cold = 10;
    Resistances.Fire = 10;
    Resistances.Energy = 10;
    Resistances.Physical = 10;

    Resistances.Poison = 0 + Utility.RandomMinMax( 0, 2 );
    Resistances.Cold = 0 + Utility.RandomMinMax( 0, 2 );
    Resistances.Fire = 0 + Utility.RandomMinMax( 0, 2 );
    Resistances.Energy = 0 + Utility.RandomMinMax( 0, 2 );
    Resistances.Physical = 0 + Utility.RandomMinMax( -2, 2 );


    In this example Mods are added or modified in desterilize section, the actual mods not being relevant as this is from a copy/past list I made to show contextual use of code.

    public override void Deserialize(GenericReader reader)
    {
    base.Deserialize( reader );
    int version = reader.ReadInt();

    if ( version < 1 )
    {
    WeaponAttributes.SelfRepair = 0;
    ArmorAttributes.SelfRepair = 3;
    Attributes.Luck = 0;
    Attributes.AttackChance = 10;
    Attributes.NightSight = 1;
    SkillBonuses.SetValues( 0, Utility.RandomCombatSkill(), 10.0 );
    SkillBonuses.SetBonus( 1, 0 );
    }

    if ( version < 1 )
    {
    if ( Weight == 1.0 )
    Weight = 6.0;
    if ( Hue == 0x55A )
    Hue = 0x4F6;
    if ( Attributes.NightSight == 0 )
    Attributes.NightSight = 1;
    if ( ItemID == 0x13CB )
    ItemID = 0x13D2;
    if ( ArmorAttributes.SelfRepair == 0 )
    ArmorAttributes.SelfRepair = 1;

    PhysicalBonus = 0;
    EnergyBonus = 0;
    FireBonus = 0;
    ColdBonus = 0;
    PoisonBonus = 0;
    }
    }

    So which is most effective and least hardware consuming? iv gone through a lot of the scripts that come with runuo 2.6 (via github(Stack overflow is better)) and iv found a lot of variation in coding method and context for adding or modifying item attributes so there need to be something defining which method is best.

    Ill post all my lists somewhere...

    Comment

    Working...
    X