bala1412

Member
ServUO Version
Publish 57
Ultima Expansion
Endless Journey
There are items in BaseLight, like lanterns and torches, that light up the area around a mobile when equipped. What I want is an item that can illuminate the area around a mobile as if it were equipped, even when it's in the mobile's bag, instead of being equipped. I'm curious if it's possible to create an item that uses LightType.Circle300 to illuminate the range when it exists in the bag
 
Possible : But there is no restricting light on players, thus imo using light is mute as most players are overriding the game to be light always! For years people have wanted to impose the dark nights etc etc ... Not stopping you, just adding my 2 cents!
 
Possible : But there is no restricting light on players, thus imo using light is mute as most players are overriding the game to be light always! For years people have wanted to impose the dark nights etc etc ... Not stopping you, just adding my 2 cents!
Thank you for your response. But I want to play the game individually using the lighting system, rather than using the system to keep the player bright at all times. So the system I'm building is very dark at night and it's not easy to enjoy the adventure at night without the lights. So what I want is to be able to use the lighting lights to take the adventure at night. I'm going to ask for help on how to create a lighting item that lights up inside the player's bag, like when you're holding a torch or lantern.
 
Ah, I see what you're attempting, traveler. You desire to create an item that can light up the area around a mobile, not just when equipped, but when present within a mobile's inventory. Normally, light sources like lanterns or torches only cast light when equipped, which is dictated by their interaction with the Equip logic in BaseLight.

For this task, we must re-imagine how the LightType.Circle300 interacts with the world, even while residing in the bag. To accomplish this, we'll likely need to modify the OnAdded and OnRemoved event handlers of the item and have the light continuously follow the mobile while the item is present in their pack.

Thought Process​

  1. BaseLight Inheritance: The item you're describing is similar to items that inherit from BaseLight. We will use that base to make it react even while in the backpack.
  2. Mobile's Light Property: We'll need to override the typical behavior where the light only activates upon equipping. Instead, we will bind the light's activation to whether the item is within the mobile's inventory.
  3. Events for Inventory Change: We'll employ event handlers such as OnAdded and OnRemoved to trigger the light's activation or deactivation based on the item’s presence in the mobile's bag.

Next Steps​

  1. Create a custom item that inherits from BaseLight.
  2. Implement logic in OnAdded to activate the light when placed in the mobile's backpack.
  3. Implement logic in OnRemoved to deactivate the light when removed from the mobile's backpack.
  4. Ensure the light updates dynamically so that if the mobile dies, the light will turn off appropriately.

Code Draft​

Here's a basic structure for such an item:


Copy code

using Server;
using Server.Items;
using Server.Mobiles;

namespace Scripts.Items
{
public class IlluminatingItem : BaseLight
{
public override LightType Light => LightType.Circle300;

[Constructable]
public IlluminatingItem() : base(0xA22) // Assuming a lantern as the base item
{
Movable = true;
Weight = 2.0;
Light = LightType.Circle300;
}

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

public override void OnAdded(object parent)
{
base.OnAdded(parent);

if (parent is Mobile m)
{
// Activate light if in the mobile's backpack
if (IsInBackpackOf(m))
{
m.Light = LightType.Circle300;
}
}
}

public override void OnRemoved(object parent)
{
base.OnRemoved(parent);

if (parent is Mobile m)
{
// Deactivate light when item is removed from backpack
m.Light = LightType.None;
}
}

private bool IsInBackpackOf(Mobile m)
{
return RootParent == m && m.Backpack != null && m.Backpack.Items.Contains(this);
}

public override void OnDelete()
{
// Ensure light turns off when the item is deleted
if (RootParent is Mobile m)
{
m.Light = LightType.None;
}

base.OnDelete();
}

public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // Version
}

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

 
Ah, I see what you're attempting, traveler. You desire to create an item that can light up the area around a mobile, not just when equipped, but when present within a mobile's inventory. Normally, light sources like lanterns or torches only cast light when equipped, which is dictated by their interaction with the Equip logic in BaseLight.

For this task, we must re-imagine how the LightType.Circle300 interacts with the world, even while residing in the bag. To accomplish this, we'll likely need to modify the OnAdded and OnRemoved event handlers of the item and have the light continuously follow the mobile while the item is present in their pack.

Thought Process​

  1. BaseLight Inheritance: The item you're describing is similar to items that inherit from BaseLight. We will use that base to make it react even while in the backpack.
  2. Mobile's Light Property: We'll need to override the typical behavior where the light only activates upon equipping. Instead, we will bind the light's activation to whether the item is within the mobile's inventory.
  3. Events for Inventory Change: We'll employ event handlers such as OnAdded and OnRemoved to trigger the light's activation or deactivation based on the item’s presence in the mobile's bag.

Next Steps​

  1. Create a custom item that inherits from BaseLight.
  2. Implement logic in OnAdded to activate the light when placed in the mobile's backpack.
  3. Implement logic in OnRemoved to deactivate the light when removed from the mobile's backpack.
  4. Ensure the light updates dynamically so that if the mobile dies, the light will turn off appropriately.

Code Draft​

Here's a basic structure for such an item:


Copy code

using Server;
using Server.Items;
using Server.Mobiles;

namespace Scripts.Items
{
public class IlluminatingItem : BaseLight
{
public override LightType Light => LightType.Circle300;

[Constructable]
public IlluminatingItem() : base(0xA22) // Assuming a lantern as the base item
{
Movable = true;
Weight = 2.0;
Light = LightType.Circle300;
}

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

public override void OnAdded(object parent)
{
base.OnAdded(parent);

if (parent is Mobile m)
{
// Activate light if in the mobile's backpack
if (IsInBackpackOf(m))
{
m.Light = LightType.Circle300;
}
}
}

public override void OnRemoved(object parent)
{
base.OnRemoved(parent);

if (parent is Mobile m)
{
// Deactivate light when item is removed from backpack
m.Light = LightType.None;
}
}

private bool IsInBackpackOf(Mobile m)
{
return RootParent == m && m.Backpack != null && m.Backpack.Items.Contains(this);
}

public override void OnDelete()
{
// Ensure light turns off when the item is deleted
if (RootParent is Mobile m)
{
m.Light = LightType.None;
}

base.OnDelete();
}

public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // Version
}

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

Thank you for your response. I'll apply what you've told me to make it! Thank you for the great advice!
 
Back