RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Item Level requirements

MrBurston

Traveler
I want it so items (rare items) require a certain level.

Basically if i had a sword that requires level 100 how do i make it so you cant equip it unless you are level 100 or over?
 

Alyssa Dark

Sorceror
first thing I think of that references that is the baseweapon.cs where it sets requirements for CanEquip based on str, dex and int...

Code:
        public override bool CanEquip( Mobile from )
        {
            if ( !Ethics.Ethic.CheckEquip( from, this ) )
                return false;
 
            if( RequiredRace != null && from.Race != RequiredRace )
            {
                if( RequiredRace == Race.Elf )
                    from.SendLocalizedMessage( 1072203 ); // Only Elves may use this.
                else
                    from.SendMessage( "Only {0} may use this.", RequiredRace.PluralName );
 
                return false;
            }
            else if ( from.Dex < DexRequirement )
            {
                from.SendMessage( "You are not nimble enough to equip that." );
                return false;
            }
            else if ( from.Str < AOS.Scale( StrRequirement, 100 - GetLowerStatReq() ) )
            {
                from.SendLocalizedMessage( 500213 ); // You are not strong enough to equip that.
                return false;
            }
            else if ( from.Int < IntRequirement )
            {
                from.SendMessage( "You are not smart enough to equip that." );
                return false;
            }
            else if ( !from.CanBeginAction( typeof( BaseWeapon ) ) )
            {
                return false;
            }
            else
            {
                return base.CanEquip( from );
            }
        }

I would think that modifying that for your 'level' in the item script itself is where to start.
 

LFFPicard

Sorceror
I am no coder, but I would suggest looking at the script for a weapon or armor that says "Requires Mondains Legacy" on it and see if that gives some pointers.
 

ThatDudeJBob

Sorceror
This is what i got to work. Hope it helps

C#:
        public override bool CanEquip( Mobile from )
        {
            if ( from.Skills[SkillName.Swords].Base <= 50.0 )//Skills[SkillName.Swords].Base
            {
                from.SendMessage( "You are not skilled enough to equip that." );
                return false;
            }
            else
            {
                return base.CanEquip( from );
            }
        }
 

MrBurston

Traveler
OK i got the majority of it working but im getting an error on start up now (see attached image)

Even tho in playermobile there is this section.
Code:
public partial class PlayerMobile : Mobile, IHonorTarget
    {
    //Level System
        private int m_Level;
        private int m_MaxLevel;
        private int m_Exp;
        private int m_ToLevel;
        private int m_kxp;
        private int m_SKPoints;
        private int m_StatPoints;
   
   
        [CommandProperty(AccessLevel.GameMaster)]
        public int Level
        {
            get { return m_Level; }
            set { m_Level = value; InvalidateProperties(); }
        }
 

Attachments

  • error.jpg
    59.1 KB · Views: 4

m309

Squire
If you added the Level check into BaseWeapon, you probably didn't pass Mobile as a PlayerMobile, so its checking every Mobile. Unless you also have all the "Level" stuff in BaseCreature, or Mobile.cs for that matter - it will error out.

You need to pass your "if (Mobile.Level <= 99 )" or whatever check you used (we have no idea because you only posted a tiny bit of code that doesn't show where the error is from) as a PlayerMobile, not the base Mobile.
 

siran

Sorceror
Playermobile is a class that inherits from Mobile, which means all of the things defined in Mobile are also present in PlayerMobile. However, the reverse is not true. Things added to the PlayerMobile class, like your Level, are not present in the Mobile class. In BaseWeapon.cs, the OnEquip method receives a Mobile as it's argument. All of the extra stuff in PlayerMobile is not available unless you can cast the Mobile as a PlayerMobile, which is possible because of inheritance.

In your OnEquip method, add something like the following:
Code:
if (from.Player) // This makes sure you are only trying this when it IS a player, and not for every creature
{
    PlayerMobile pm = from as PlayerMobile; // This is the cast I'm talking about
    if (pm.Level < 100)
    {
        // Do you stuff
    }
}
 

pooka01

Sorceror
Code:
if (from is Playermobile)
{
 PlayerMobile pm = (PlayerMobile)from;
 if (from.Level < 100)
 {
  stuff
 }
}
A mobile can be "Player = true", so must avoid casting to playermobile if it's not one, it is better to check if from is a playermobile instead.
 

MrBurston

Traveler
throws up a similar error but for both "player" and "level" now...

ABOVE IS FIXED

ok ive got it so i can now use [set LevelRequirement 99 in game but when i add it to my script it get the attached error.


see below example.
Code:
public class FireScythe : BasePoleArm
    {
        public override int LevelRequirement{ get{ return 70; } }
 

Attachments

  • Untitled.png
    12.7 KB · Views: 2

pooka01

Sorceror
Code:
private int m_LevelRequirement;
public virtual int LevelRequirement{ get{ return 0; } }
 
[CommandProperty( AccessLevel.GameMaster )]
  public int LevelRequirement
  {
  get{ return m_LevelRequirement; }
  set{ m_LevelRequirement = value; InvalidateProperties(); }
  }

looks like that? (in baseweapon)
 

MrBurston

Traveler
private int m_LevelReq;
public virtual int ReqLevel{ get{ return 0; } }

[CommandProperty( AccessLevel.GameMaster )]
public int LevelRequirement
{
get{ return m_LevelReq; }
set{ m_LevelReq = value; InvalidateProperties(); }
}

I've also added on the baseweapon.sc and the weapon I'm trying to set the required level on.
 

Attachments

  • BaseWeapon.cs
    106 KB · Views: 1
  • FireScythe.cs
    1.6 KB · Views: 1

pooka01

Sorceror
public virtual int ReqLevel{ get{ return 0; } }

means you need

public override int ReqLevel{ get{ return #####; } }

in your new weapon file.
and not public override int LevelRequirement...
 

MrBurston

Traveler
Ok so i got it to load without any errors BUT! it does not set the level requirement when i create the weapon!

see attached image.
 

Attachments

  • Untitled.png
    289.5 KB · Views: 5

pooka01

Sorceror
post your baseweapon and the weapon file, that will make it easier to see what goes wrong at this point.
 

pooka01

Sorceror
So basically you set it in the props menu, (are you sure you are clicking on the right button to apply the change?), then it goes automatically to 0?
 

MrBurston

Traveler
This is what i do in game

[add firescythe

then i use

[props (on the fire scythe)

LevelRequirement is 0 when it should be 70
 
Top