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!

Half Life Bow ( Self Delete Timer + Timer In Attributes List )

zerodowned

Sorceror
--- Just noticed this is causing a crash. I believe it's only if the player with the item isn't logged in when the timer runs out then it causes crash.
--- No fix for this is available at the moment.


What it is:

A bow that self deletes after specified time.
Timer countdown shows in weapon attributes list.
Timer begins countdown when it is equipped, does not stop or start over if it's unequipped.
Message sent to player when item deletes (meant to avoid player confusion when the item deletes).
halflifebow.jpg

Why?
This is my solution to giving players an over-powered item and making it so they can't keep it forever.

Note:
*** If you change the timer, be sure to do it for all three.

If you want the timer to show up at the bottom of the attributes list instead of under the name, find AddNameProperty (there's two of them) and change to GetProperties

Credits:
Murzin - Hearthstone script, majority of this script came from the Hearthstone, including the timer showing in the attributes list.
Peoharen - SelfDeletingItem script (part of the Mobile Abilities Package), self delete function after timer ends
Soteric - for help on Script Support boards - pointed out that I forgot to use ": base()" in the Constructable.
 

Attachments

  • Half Life Bow.cs
    4 KB · Views: 131

zerodowned

Sorceror
To avoid confusion, this is Half Life as in:

Half-life, abbreviated , is the period of time it takes for the amount of a substance undergoing decay to decrease by half. The name was originally used to describe a characteristic of unstable atoms (radioactive decay), but it may apply to any quantity which follows a set-rate decay.
Ref: http://en.wikipedia.org/wiki/Half-life

Not the game Half Life.
 

Gage Williams

Wanderer
Question... Does the bows life still go down even if not used? If you didnt want players to keep uber items you could just remove powder of fort right? although its a kewl script. +karma for u
 

Alyssa Dark

Sorceror
hi zerodowned :)
great idea, i'm curious about the timer too, does it start when its equipped or when looted if a mob drop, or crafted, etc? then does it stop if player unequips it?

Question... Does the bows life still go down even if not used? If you didnt want players to keep uber items you could just remove powder of fort right? although its a kewl script. +karma for u
think that would depend a lot on the items self repair and smith's skills doing repairs, items could be around for quite awhile, lol, even without powder of fort
 

Gage Williams

Wanderer
I mean zerodowned has a great idea.. I remember playing osi back in the day and people having the same weapons for years and armor ect... I agree with what hese trying to do but there are better ways to do it... plus take for example you find a badass luck wepon but you dont use your luck equip that much its just going to sit and decay without use... now if you were to take the self repair stat out and change how many max hits it takes away for every repair.. you could adjust it like that to fit your server. and doing it that way would allow for people to keep deco items/weps/armor and save a luck suit or pvp suit in a box without it decaying... But like i said ++ karma man its a good script maybe what i said can give ya some ideas
 

zerodowned

Sorceror
glad that you like it, don't have time to reply to everything but timer only starts when it's equipped, doesn't stop or start over if someone unequipps/re-equipps.
I had considered making the timer start when the item is created...and might make an alternative, but if you put this as loot on a mob, won't it sit in the mob's backpack ticking away? possibly decaying long before someone kills it.
although i guess you could just have it add to loot OnDeath instead
 

Gage Williams

Wanderer
so you mean as soon as i put it in my hand it starts the count down. and doesnt stop when un epuiped? Now see if that is correct then you should try and add a timer stop when un epuiped. if doing that then items with a higher timer could be sold for more gold ingame. There are tons of potential ideas you could try.. And you say its unstable atoms.. then it would be kewl to make the item explode when the timer is up too would kinda go hand in hand with unstable atoms... if you were to do this you could make this a major artie thats extremely powerfull but will eventually explode because its unstable lol would make an interesting quest.

One more thing... Im not at all criticizing your work I like the idea im just sayin with a bit more work it could be awesome
 

zerodowned

Sorceror
:) no need to worry. I was actually thinking of the explosion when the timer runs out. Found a script that already does it, as well as a script for the One Ring (LoTR) that slowly damages the person wearing it (radiation poisioning?)
as for the timer stopping when you take it off...it's a good idea, but it doesn't really fit in with the idea I had for the script.
Plus - I'm not a good scripter, and wouldn't really know where to begin on something like that.
I have a feeling that even after you take it off the timer stops counting, the sytem would continue to update the timer on the attributes list, even if it isn't changing.
 

gerbillo

Squire
great idea!
but one question, because i'm very noob,
how i change in hour ? 2160 hours is 3 months
i have try to mod but maxtimer is 59min. please help
tnx for all!!

this is my Losing try mod!
where i wrong?
tnx

Code:
/*
    script by zerodowned
    credits to: Murzin's Hearthstone script, Peoharen's SelfDeletingItem script (part of the Mobile Abilities Package), and Soteric for help on Script Support boards - pointed out that I forgot to use ": base()" in the Constructable.
 
    Info: If you change the timer on this make sure that the timer on Line 24, and 112, and 123 match.
*/
 
using System;
using Server;
using Server.Mobiles;
using Server.Items;
using Server.Regions;
 
namespace Server.Items
{
    public class HalfLifeBow : CompositeBow
    {
    public override int InitMinHits{ get{ return 255; } }
    public override int InitMaxHits{ get{ return 255; } }
     
 
        // Initiate the starting variables to be used
        private DateTime i_halflife;
        private static readonly TimeSpan delay = TimeSpan.FromHours( 2160 );
        private Timer halflifetimer;
        private Mobile m;
        private Item i;
 
        // Setup the GM access/viewable variables for the item
        [CommandProperty( AccessLevel.GameMaster )]
        public DateTime lastused
        {
            get{ return i_halflife; }
            set{ i_halflife = value; }
        }
 
     
        // starting the item itself
        [Constructable]
        public HalfLifeBow() : base()
        {
            Name = "Half Life Bow";
            Hue = 2711;
            Attributes.WeaponDamage = 40;
            Attributes.WeaponSpeed = 20;
            WeaponAttributes.HitLeechHits = 25;
        //  WeaponAttributes.HitLeechMana = 40;
        //  WeaponAttributes.HitFireball = 35;
        //  WeaponAttributes.SelfRepair = 5;
        //    Attributes.SpellChanneling = 1;
        //    Attributes.CastSpeed = 1;
        //    Attributes.Luck = 20;
        //    Attributes.RegenMana = 5;
            Attributes.SpellDamage = 15;
        }
     
        private void Expire()
        {
            if ( Deleted )
                return;
 
            Delete();
            m.SendMessage( "The bow turns to dust" );
        }
 
        // this controls the list you see when you mouse-over the item
        public override void AddNameProperty( ObjectPropertyList list )
        {
            // make sure the normal mouse-over props show up
            base.AddNameProperty( list );
 
            // initial variables for use only inside the property list
            TimeSpan timetouse = ( ( this.lastused + Server.Items.HalfLifeBow.delay) - DateTime.Now );
            string lisths;
 
            // determine the info the timer display shows
            if ( timetouse.Hours > 0 )
            {
                int Hou = timetouse.Hours;
                lisths = String.Format( "{0} Hours.", Hou.ToString() );
            }
            if ( timetouse.Minutes > 0 )
            {
                int min = timetouse.Minutes;
                lisths = String.Format( "{0} minutes.", min.ToString() );
            }
            else if ( timetouse.Seconds > 0 )
            {
                int sec = timetouse.Seconds;
                lisths = String.Format( "{0} seconds.", sec.ToString() );
            }
            else
            {
                lisths = ( "<BASEFONT COLOR=#00FF00>Dormant<BASEFONT COLOR=#FFFFFF>" ); //FFFFFF
            }
 
            // adding the timer to the property list
            list.Add( "<BASEFONT COLOR=#00FF00>Half Life Remaining: {0}<BASEFONT COLOR=#FFFFFF>", lisths ); //FFFFFF
 
            // because we do not want the server spamming updates, slow down how fast the mouse-over info refreshes
            Timer.DelayCall( TimeSpan.FromSeconds( 1.0 ), new TimerCallback( InvalidateProperties ) );
        }
 
        public override bool OnEquip( Mobile from )
        {
            i = this;
            m = from;
         
            if ( ( this.lastused + Server.Items.HalfLifeBow.delay ) > DateTime.Now ) //check if timer is already started
                {
                    return true;
                }
         
            else //start timer
            {
                this.lastused = DateTime.Now;
                halflifetimer = Timer.DelayCall( TimeSpan.FromHours( 2160 ), new TimerCallback( Expire ) );
                return true;
             
            }
        }
 
     
     
 
        public HalfLifeBow( Serial serial ) : base( serial )
        {
            Timer.DelayCall( TimeSpan.FromHours( 2160 ), new TimerCallback( Expire ) );
        }
 
        public override void Serialize( GenericWriter writer ) // generic info to write and save
        {
            base.Serialize( writer );
            writer.Write( (int) 0 );
            writer.Write( (DateTime)i_halflife );
        }
   
        public override void Deserialize(GenericReader reader) // make sure proper variables are read
        {
            base.Deserialize( reader );
            int version = reader.ReadInt();
            i_halflife = reader.ReadDateTime();
        }
 
    }
}
 

fwiffo

Sorceror
I think that it would be better for the good to use the ReadDeltaTime() in Deserialize and the same in serialize (WriteDeltaTime), and for a good reason too.

If your server changes the server time, eg. you turn forward your clock, and reaload the server, you actually loose time remaining, the same happens if you put a old save for whatever reason :)
 

zerodowned

Sorceror
gerbillo - I know you can just change FromHours to FromSeconds, Days...I"m not sure about Months but I don't see why it wouldn't work. Try it and see. TimeSpan.FromMonths( 3 );

but you can expect problems with your server until I can fix the crash error.

fwiffo - deltatime? interesting, I'll try that out. thank you :)
 

virus512

Sorceror
I use server version 2,2 build 4556.4015 I use mondain legacy client without patch I was test your HalfLifeBow and I had no crash. I just change timer to 2 minutes and test on Owner character. I 9x tested timer because I try to crash server.
Create HalfLifeBow test when Bow was equip I was online timer run out and no crash.
Create HalfLifeBow test when Bow was equip I was log out and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put into backpack I was online timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put into backpack I was log out and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put on the ground/floor I was online timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put on the ground/floor I was log out and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip I was log out and log in and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put into backpack I was log out and log in and wait until timer run out and no crash.
Create HalfLifeBow test when Bow was equip and unequip it and put on the ground/floor I was log out and log in and wait until timer run out and no crash.

sry for my english ;D I hope everybody can understand what do I try to write ;D

zerodowned plz tell me how to crash the server I will try to do it and no crash. Great work and thank you for this ;)
 

zerodowned

Sorceror
It's hard to say what caused the crash.
I only noticed it after I had been away from my computer for awhile with the server running.
I'll try it out over the weekend and see if I can get it to happen again.
 

virus512

Sorceror
I think that it would be better for the good to use the ReadDeltaTime() in Deserialize and the same in serialize (WriteDeltaTime), and for a good reason too.

If your server changes the server time, eg. you turn forward your clock, and reaload the server, you actually loose time remaining, the same happens if you put a old save for whatever reason :)

I tested it on 1 minute timer :

Create HalfLifeBow test when Bow was equip and timer started then I save the world by [save command, after it I was log out and turn off the server and wait 2 minutes more. When I turn on the server when compile scripts there was not any crash or errors or warnings. After it I log in my character and Bow was equip on character and not disapear, timer was reset and he not count down I was play for about 1 hour with Bow equip on me and timer didnt move (didnt start count). Timer has started after I unequip and equip my Bow.

Can I ask you (fwiffo and zerodowned) for help me and change the script ??

is it possible to change the script that he can count down after turn off and then turn on server from time that server was turn off or if it not possible, can we change the script that he can after turn off and then turn on the server starts count down when someone has bow equip on his character when server starts

I really need help.. Im not a scripter I can only understand simple change or cut and paste to make new items ;D I was trying to replace all datatime to deltatime in the script but it didnt work and I have some errors which is obscure for me ;D

thanks in advance;)
 
Top