private static string GetNameString( Item item, bool useOnlyLabelNumber )
{
string name = ( useOnlyLabelNumber ? null : item.Name );
/*if ( item != null && name == null )
name = Server.Localize.Localizer.Get( item.LabelNumber );*/
return name;
}

Is there some other words I need besides Localize.Localizer to make this work with runuo 2.5 ? The script works with it commented out but the original name doesn't show on the items.
 
That GetNameString method is probably not even needed at all tbh, with my edit you dont need the useOnlyLabelNumber argument anymore and that can be removed if you want.
 
Replace all lines in between { and } with that one line :)
Thanks for helping, now I get unexpected character ' " ' and preprocessor directives must appear at the first non-whitespace character on a line
[doublepost=1520357777][/doublepost]Here's the whole script if it could help



Code:
// Class: NameRandomizer
// File: NameRandomizer.cs
// By: SHAMBAMPOW
// Inspired by: Nockar (and his Script Support question)
// Date: 7/21/2012
// Purpose: Use this to apply a random prefix to valid items.
// Example: Rather than "Katana", it would show "Zues's Magical Katana"
// RunUO: 2.1+ (below versions would probably just require minor edits to command system usage)
// Methods: GiveRandomName( item ) and PotentiallyGiveRandomName( item, chance )
// Commands: [RandomName and [RandomPrefix

using System;
using Server;
using Server.Items;
namespace Server.Items
{
    public class NameRandomizer
    {
        public const double RandomChanceToApplyNamePrefixes = 0.005;    // 0.5%
   
        #region RandomizeName Command
        public static void Initialize()
        {
          Server.Commands.CommandSystem.Register( "RandomName", AccessLevel.GameMaster, new Server.Commands.CommandEventHandler( RandomizeName_OnCommand ) );
          Server.Commands.CommandSystem.Register( "RandomPrefix", AccessLevel.GameMaster, new Server.Commands.CommandEventHandler( AddRandomNamePrefix_OnCommand ) );
        }       
       
        [Usage( "RandomName" )]
        [Description( "Apply a random name prefix to an armor, weapon, clothing, jewel, talisman, quiver, or instrument - using the LabelNumber of that item." )]
        public static void RandomizeName_OnCommand( Server.Commands.CommandEventArgs e )
        {
            bool userandomname = false;
           
            Mobile from = e.Mobile;
            from.LocalOverheadMessage( Server.Network.MessageType.Regular, 0x1150, true, "Target the item you wish to randomize the name of...");
            from.Target = new RandomizeNameTarget( userandomname );
        }
       
        [Usage( "RandomPrefix" )]
        [Description( "Applies a random name prefix to an armor, weapon, clothing, jewel, talisman, quiver, or instrument - using the current name of that item." )]
        public static void AddRandomNamePrefix_OnCommand( Server.Commands.CommandEventArgs e )
        {
            bool userandomname = true;
           
            Mobile from = e.Mobile;
            from.LocalOverheadMessage( Server.Network.MessageType.Regular, 0x1150, true, "Target the item you wish to randomize the name of...");
            from.Target = new RandomizeNameTarget( userandomname );
        }
      
        private class RandomizeNameTarget : Server.Targeting.Target
        {
            private bool UseCurrentName;
           
            public RandomizeNameTarget( bool useCurrentName ) : base( -1, true, Server.Targeting.TargetFlags.None )
            {
                UseCurrentName = useCurrentName;
            }
              
            protected override void OnTarget( Mobile from, object o )
            {
                if( o is Item )
                {
                    if( o is BaseWeapon || o is BaseArmor || o is BaseJewel || o is BaseClothing || o is BaseTalisman || o is BaseQuiver || o is BaseInstrument )
                    {
                        NameRandomizer.GiveRandomName( (Item)o, !UseCurrentName );
                       
                        if( !UseCurrentName )
                            from.SendMessage( "You randomize the entire name." );
                        else from.SendMessage( "You randomize the name prefix." );
                    }
                    else
                    {
                        from.SendMessage( "Valid targets include weapons, armor, jewelry, clothing, talismans, quivers, and instruments." );
                    }
                }
            }
        }
        #endregion
       
        private static string[] names = new string[]{ "", "Zeus", "Plato", "Zenon", "Zoro", "Hercules", "Ramses", "Ramos", "Thor", "Hercules", "Mars", "Fabio", "Cupid", "Jude", "Pluto", "Hermes",
                                                        "Aphrodite", "Apollo", "Ares", "Artemis", "Athena", "Demeter", "Dionysus", "Hades", "Hephaestus", "Hera", "Hestia", "Poseidon", "Zeus", "Aether",
                                                        "Ananke", "Erebus", "Gaia", "Hemera", "Chaos", "Chronos", "Nesoi", "Nyx", "Uranus", "Ourea", "Phanes", "Pontus", "Tartarus", "Thalassa", "Hyperion",
                                                        "Lapetus", "Coeus", "Crius", "Cronos", "Mnemosyne", "Oceanus", "Phoebe", "Rhea", "Tethys", "Theia", "Themis", "Asteria", "Astraeus", "Atlas", "Aura",
                                                        "Dione", "Eos", "Epimetheus", "Eurybia", "Eurynome", "Helios", "Clymene", "Lelantos", "Leto", "Menoetius", "Metis", "Ophion", "Pallas", "Perses",
                                                        "Prometheus", "Selene", "Styx", "Janus", "Jupiter", "Saturn", "Genius", "Mercury", "Apollo", "Mars", "Vulcan", "Neptune", "Sol", "Orcus", "Liber",
                                                        "Tellus", "Ceres", "Juno", "Luna", "Diana", "Minerva", "Venus", "Vesta", "Feronia", "Minerva", "Novensides", "Pales", "Salus", "Fortune", "Fons",
                                                        "Fides", "Ops", "Flora", "Vediovis", "Summanus", "Larunda", "Terminus", "Quirinus", "Vortumnus", "Lares", "Diana", "Luncina" };
       
        private static string[] adjectives = new string[] { "", "Glorious", "Tremendous", "Treasured", "Fabled", "Lost", "Adorned", "Missing", "Sacred", "Mighty", "Mystical", "Magic",
                                                            "Crippled", "Ruined", "Valued", "Glorious", "Fabulous", "Wonderful", "Wonderous", "Telling", "Spiritual", "Valuable", "Worthy", "Worthless",
                                                            "Forgotten", "Misplaced", "Reclaimed", "Powerful", "Feared", "Horrific", "Famed", "Esteemed", "Noble", "Holy", "Mystifying", "Boasted", "Honored",
                                                            "Precious"    };
       
        /* Example usage of GiveRandomName( Item item ):
        * NameRandomizer.GiveRandomName( newlyconstructeditem );    // Gives a random name 100% of the time
        */
        public static void GiveRandomName( Item item, bool useLabelNumberOnly )
        {
            if( item == null || item.Deleted ) return; // null check
           
            if( !( item is BaseArmor || item is BaseJewel || item is BaseWeapon || item is BaseClothing || item is BaseTalisman || item is BaseQuiver || item is BaseInstrument ) )
                return;    // this prevents things like scrolls, gems, etc from being renamed in the lootpack.
          
            string currentName = NameRandomizer.GetNameString( item, useLabelNumberOnly);    // returns weapons current name (Name property if it exist, else the string translation of the item's LabelNumber)
          
            string personName = NameRandomizer.GetRandomPersonName();
            string adjective = NameRandomizer.GetRandomAdjective();
          
            if( ( personName + adjective ).Equals( "" ) )
            {
                if( Utility.RandomBool() )
                {
                    personName = names[Utility.RandomMinMax( 1, names.Length )];
                }
                else
                {
                    adjective = adjectives[Utility.RandomMinMax( 1, adjectives.Length )];
                }
            }
          
            item.Name = String.Format( "{0}{1}{2}", String.Format( "{0}{1}", personName, String.IsNullOrEmpty( personName ) ? "" : "'s " ), String.Format( "{0}{1}", adjective, String.IsNullOrEmpty( adjective ) ? "" : " " ), currentName );    // add a 's and a space if the name isn't empty
        }
       
        /* Example usage of GiveRandomName( Item item ):
        * NameRandomizer.GiveRandomName( newlyconstructeditem );    // Gives a random name 100% of the time
        */
        public static void GiveRandomName( Item item )
        {
            NameRandomizer.GiveRandomName( item, true );
        }
        // private classes, cannot be called from outside - used only within GiveRandomName.
        private static string GetRandomPersonName()
        {
            return names[Utility.Random( names.Length )];
        }
        // private classes, cannot be called from outside - used only within GiveRandomName.
        private static string GetRandomAdjective()
        {
            return adjectives[Utility.Random( adjectives.Length )];
        }
      
        /* Example usage of PotentiallyRandomizeName( Item item ):
        * NameRandomizer.PotentiallyRandomizeName( newlyconstructeditem );    // Gives a random name 0.05% of the time.
        */
        public static void PotentiallyRandomizeName( Item item )
        {
            NameRandomizer.PotentiallyRandomizeName( item, RandomChanceToApplyNamePrefixes );    // default 0.5% chance
        }
       
        public static void PotentiallyRandomizeName( Item item, double chance )
        {
            NameRandomizer.PotentiallyRandomizeName( item, chance, true );
        }
      
         //Example usage of PotentiallyRandomizeName( Item item, double chance ):
         //NameRandomizer.PotentiallyRandomizeName( newlyconstructeditem, 0.01 );    // Gives a random name 1% of the time.
       
        public static void PotentiallyRandomizeName( Item item, double chance, bool useLabelNumber )
        {
            if( Utility.RandomDouble() < chance )
            {
                NameRandomizer.GiveRandomName( item, useLabelNumber );
            }
        }
       
        private static string GetNameString( Item item )
        {
            return NameRandomizer.GetNameString( item, false );
        }

        // UseOnlyLabelNumber means that it will get the name strictly based upon either a) the overridden LabelNumber (artifacts, etc) or b) the item's current ItemID.
        private static string GetNameString(Item item, bool useOnlyLabelNumber)
        {
            string name = (useOnlyLabelNumber ? null : item.Name);

            /*if ( item != null && name == null )
            name = Server.Localize.Localizer.Get( item.LabelNumber );*/

            return name;
        }

    }
}
 
Are you sure that's the version of the script that's giving you the error for preprocessor directives?
I don't see you put in the line of code that Voxpire provided
 
Yes I tried the edit from Voxpire, and got the preprocessor error with it. But I posted the original script, with the localize.Localizer that was giving me the original error. Which (I think) was a "doesn't recognize" error.... not sure now though because I'm old and forget things LOL. I was originally thinking that my version (2.5), just wouldn't recognize those localize words and that there may be some thing else to put there. The end of that script is where the errors are coming from. Thanks for any help you can give me! :)
 
This is the last time I'll bump this. I still need a fix if any one can help. The original error is " the type or namespace localize doesn't exist in server (are you missing an assembly reference)" or some thing close to that.
 
Last edited:
OK! well, that almost worked! lol I did your edit and typed it in myself and no error. But, instead of the items name it gives me a number. So I tested it on a katana, and it came out "Crius's Holy #1025119" instead of Crius's Holy Katana. This is the closest I've been though. Thanks for helping.

eta- 5119 is the item number of the katana if I item id it with GM.
 
It's displaying the number instead of converting it to the proper name because the full name (including prefix) does not start with the #number.

IE - If you didn't have the "Crius's Holy " prefix, it would display the proper name.

This will likely require a core mod to AddNameProperty so that it uses a different cliloc to add the name, other than "~1_AMOUNT ~ ~1_ITEM~". You may need to use one of the "~1_VAL~ ~2_VAL~ ~3_VAL~" clilocs and format them as such; "<amount>\t<prefix>\t<name>"
 
Thanks for trying to help! :) I am not great at C# but I get what you mean, pretty much. My question now is, as far as I know this script worked as intended for runuo 2.1 I think. So is there no way to just fix the localize. localizer error and have it work on runuo 2.5?
 
Back