mitty2

Member
Guys basically this script works great. What I'm trying to do is give it a value of 1 once it is constructed, so I can add it to my vendor stone. Right now the only way to add in game obviously is to type [add LevelUpScroll 1 Ive tried quite a few things but it doesn't show up ingame, when you buy off stone. because it has no value on creation, till you give it one.
Here is part of the code im stuck on...

C#:
using System;
using Server.Network;
using Server.Prompts;
using Server.Mobiles;
using Server.Misc;
using Server.Items;
using Server.Gumps;
using Server.Targeting;
using Server.Targets;
namespace Server.Items
{
public class LevelUpScroll : Item
{
private int m_Value;
[CommandProperty(AccessLevel.GameMaster)]
public int Value
{
get
{
return m_Value;
}
set
{
m_Value = value;
}
}
[Constructable]
public LevelUpScroll (int value) : base(0x14F0)
{
Weight = 1.0;
Hue = 0x64;
m_Value = value;
}
public override void AddNameProperty(ObjectPropertyList list)
{
list.Add("an Item Level Deed (+{0} max levels)", m_Value);
}
public override void OnSingleClick(Mobile from)
{
base.LabelTo(from, "an Item Level Deed (+{0} max levels)", m_Value);
}
public LevelUpScroll(Serial serial) : base(serial)
{
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write((int)0); // version
//Version 0
writer.Write((int)m_Value);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
switch (version)
{
case 0:
{
m_Value = reader.ReadInt();
break;
}
}
}
public override void OnDoubleClick(Mobile from)
{
if (!IsChildOf(from.Backpack))
{
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
return;
}
else
{
from.SendMessage("Which item would you like to level up?");
from.Target = new LevelItemTarget(this); // Call our target
}
}
}
public class LevelItemTarget : Target
{
private LevelUpScroll m_Scroll;
public LevelItemTarget(LevelUpScroll scroll) : base(-1, false, TargetFlags.None)
{
this.m_Scroll = scroll;
}
 
I would try adding a second [Constructable] section just above the existing one, kind of like this:

Code:
        [Constructable]
        public LevelUpScroll() : this(1)
        {
        }

This section gets called if you add the item without specifying a value such as with the vendor stone, assigning it 1 automatically.
 
a newer c# way to do it is initialize the constructor value

public LevelUpScroll (int value = 1) : base(0x14F0)

does exactly the same thing as falkor's code but I prefer this method
 

Active Shards

Donations

Total amount
$0.00
Goal
$1,000.00
Back