Timer

08/02/2010 16:13 Zkiller110#1
I'm trying to make a timer on how often the /xp skill command can be used but i just cant seem to get it right here's my command
Code:
                        #region XP Skill

                        if (Cmd[0] == "/XP" || Cmd[0] == "/xp")
                        {
                            DateTime TillNext = DateTime.Now;
                            DateTime LastUse = GC.MyChar.LastXPCommand.AddMinutes(1);
                            TimeSpan TimeLeft = LastUse - TillNext;
                            if (GC.GM || GC.MyChar.VipLevel == 7)
                                if (DateTime.Now > GC.MyChar.LastXPCommand.AddMinutes(1))
                                {
                                    GC.MyChar.StatEff.Add(NewestCOServer.Game.StatusEffectEn.XPStart);
                                    GC.MyChar.Buffs.Add(new Game.Buff() { StEff = NewestCOServer.Game.StatusEffectEn.XPStart, Lasts = 20, Started = DateTime.Now, Eff = NewestCOServer.Features.SkillsClass.ExtraEffect.None });
                                }
                                else
                                    GC.LocalMessage(2000, "You must wait " + (TimeLeft.ToString ("mm:ss")) + " before useing /XP again.");
                            if (GC.PM)
                            {
                                GC.MyChar.StatEff.Add(NewestCOServer.Game.StatusEffectEn.XPStart);
                                GC.MyChar.Buffs.Add(new Game.Buff() { StEff = NewestCOServer.Game.StatusEffectEn.XPStart, Lasts = 20, Started = DateTime.Now, Eff = NewestCOServer.Features.SkillsClass.ExtraEffect.None });
                            }
                        }

                        #endregion
and i added public DateTime LastXPCommand = DateTime.Now; to character.cs :p any idea on fixing it
08/02/2010 17:25 pro4never#2
It's simple. Make a char value last used datetime then on login set it to datetime.now! So it initializes n login. In the cmd do


If(datetime.now > gc.mychar.lastxppuse.addminutes(1)
{
//turn on xp
gc.mychar.lastxpuse = datetime.now;
}

That's all there is to datetime checks. Compair it to current datetime using an if statement and if it passes be sure to reset the datetime to current time (or it can be spammed)
08/02/2010 17:36 Zkiller110#3
ok umm what about the if statement it wont start the with the if statement that i have on there now cause the datetime.now is the same as the gc.mychar.lastxpcommand is there a way i can get it to bypass the if statement for the first use of the command?
08/02/2010 17:57 Fish*#4
put:
DateTime TillNext = DateTime.Now;
DateTime LastUse = GC.MyChar.LastXPCommand.AddMinutes(1);
TimeSpan TimeLeft = LastUse - TillNext;

after the check.
I think.
08/02/2010 18:24 Zkiller110#5
i was messing around with it for a bit and here's what i got its just i can get the message to come up saying "you have to wait 00:38 seconds before using /xp again" and when i first use the command it jumps down to almost the last line of my chat.cs saying "your not a [PM]" -.-
Code:
                        #region XP Skill

                        if (Cmd[0] == "/XP" || Cmd[0] == "/xp")
                        {
                            DateTime TillNext = DateTime.Now;
                            DateTime LastUse = GC.MyChar.LastXPCommand.AddMinutes(1);
                            TimeSpan TimeLeft = LastUse - TillNext;
                            if (GC.GM || GC.MyChar.VipLevel == 7)
                            {
                                if (GC.MyChar.FirstXPCommandUsed == false)
                                {
                                    GC.MyChar.StatEff.Add(NewestCOServer.Game.StatusEffectEn.XPStart);
                                    GC.MyChar.Buffs.Add(new Game.Buff() { StEff = NewestCOServer.Game.StatusEffectEn.XPStart, Lasts = 20, Started = DateTime.Now, Eff = NewestCOServer.Features.SkillsClass.ExtraEffect.None });
                                    GC.MyChar.FirstXPCommandUsed = true;
                                }
                                else if (GC.MyChar.FirstXPCommandUsed == true && TillNext > LastUse)
                                {
                                    GC.MyChar.StatEff.Add(NewestCOServer.Game.StatusEffectEn.XPStart);
                                    GC.MyChar.Buffs.Add(new Game.Buff() { StEff = NewestCOServer.Game.StatusEffectEn.XPStart, Lasts = 20, Started = DateTime.Now, Eff = NewestCOServer.Features.SkillsClass.ExtraEffect.None });
                                    GC.MyChar.LastXPCommand = DateTime.Now;
                                }
                                else
                                    GC.LocalMessage(2000, "You must wait " + (TimeLeft.ToString("mm:ss")) + " before useing /XP again.");
                            }
                            if (GC.PM)
                            {
                                GC.MyChar.StatEff.Add(NewestCOServer.Game.StatusEffectEn.XPStart);
                                GC.MyChar.Buffs.Add(new Game.Buff() { StEff = NewestCOServer.Game.StatusEffectEn.XPStart, Lasts = 20, Started = DateTime.Now, Eff = NewestCOServer.Features.SkillsClass.ExtraEffect.None });
                            }
                        }

                        #endregion
08/02/2010 19:00 pro4never#6
>.< sooo much needless code. As i said you initialize it when you log in the character. Using 2 diff datetimes and all the other code is needless and tbh, messy.

Also.. you don't need to do the 2 diff /xp or /XP, simply do tolower to make the cmd lower case.


Srry on cell so i can't write the full code for you
08/02/2010 19:25 Zkiller110#7
Quote:
Originally Posted by pro4never View Post
>.< sooo much needless code. As i said you initialize it when you log in the character. Using 2 diff datetimes and all the other code is needless and tbh, messy.

Also.. you don't need to do the 2 diff /xp or /XP, simply do tolower to make the cmd lower case.


Srry on cell so i can't write the full code for you
ok i got it working the way i want now i got rid of all the "messy" code :p and added "public DateTime LastXPCommand = DateTime.Now.AddSeconds(-60);"
so i can use /xp command when i log in but that still didnt solve my problem with the
Code:
                                else
                                    GC.LocalMessage(2000, "You must wait " + (TimeLeft.ToString("mm:ss")) + " before useing /XP again.");
and it still say "your not a [PM]" when the command is first used
08/03/2010 02:19 -impulse-#8
PHP Code:
        #region XP Skill
        
if (Cmd[0].ToLower().Contains("xp"))
        {
            if (
GC.GM || GC.MyChar.VipLevel == 7)
            {
                if (
DateTime.Now GC.MyChar.LastXPCommand.AddMinutes(1))
                {
                    
DateTime.Now GC.MyChar.LastXPCommand DateTime.Now;
                    
GC.MyChar.StatEff.Add(NewestCOServer.Game.StatusEffectEn.XPStart);
                    
GC.MyChar.Buffs.Add(new Game.Buff() { StEff NewestCOServer.Game.StatusEffectEn.XPStartLasts 20Started DateTime.NowEff NewestCOServer.Features.SkillsClass.ExtraEffect.None });
                }
                else
                    
GC.LocalMessage(2000"You must wait 1 minute after every usage of " Cmd[0] + ". Please have patience.");
            }
            else if (
GC.PM)
            {
                
GC.MyChar.StatEff.Add(NewestCOServer.Game.StatusEffectEn.XPStart);
                
GC.MyChar.Buffs.Add(new Game.Buff() { StEff NewestCOServer.Game.StatusEffectEn.XPStartLasts 20Started DateTime.NowEff NewestCOServer.Features.SkillsClass.ExtraEffect.None });
            }
        }
        
#endregion 
08/03/2010 03:34 Zkiller110#9
Quote:
Originally Posted by -impulse- View Post
PHP Code:
        #region XP Skill
        
if (Cmd[0].ToLower().Contains("xp"))
        {
            if (
GC.GM || GC.MyChar.VipLevel == 7)
            {
                if (
DateTime.Now GC.MyChar.LastXPCommand.AddMinutes(1))
                {
                    
DateTime.Now GC.MyChar.LastXPCommand DateTime.Now;
                    
GC.MyChar.StatEff.Add(NewestCOServer.Game.StatusEffectEn.XPStart);
                    
GC.MyChar.Buffs.Add(new Game.Buff() { StEff NewestCOServer.Game.StatusEffectEn.XPStartLasts 20Started DateTime.NowEff NewestCOServer.Features.SkillsClass.ExtraEffect.None });
                }
                else
                    
GC.LocalMessage(2000"You must wait 1 minute after every usage of " Cmd[0] + ". Please have patience.");
            }
            else if (
GC.PM)
            {
                
GC.MyChar.StatEff.Add(NewestCOServer.Game.StatusEffectEn.XPStart);
                
GC.MyChar.Buffs.Add(new Game.Buff() { StEff NewestCOServer.Game.StatusEffectEn.XPStartLasts 20Started DateTime.NowEff NewestCOServer.Features.SkillsClass.ExtraEffect.None });
            }
        }
        
#endregion 
yours is good just it wont have a countdown for the time remains till you can use the next /xp command :p i've gotten my working now but thanks for the help
08/03/2010 16:41 pro4never#10
Quote:
Originally Posted by Zkiller110 View Post
yours is good just it wont have a countdown for the time remains till you can use the next /xp command :p i've gotten my working now but thanks for the help
Not quite sure what you mean... his looks to be perfect.

What 'time remains' are you talking about showing how long it is till you can use it again?

replace the
PHP Code:
else
                    
GC.LocalMessage(2000"You must wait 1 minute after every usage of " Cmd[0] + ". Please have patience."); 
with something that prints out how long until it can be used again by comparing the last used date time with the current datetime and then printing out how long you must wait
08/04/2010 17:58 Zkiller110#11
after you type /xp it starts xp command then if your type it again you get a message saying your must wait ___ amount of seconds before using command again i've already solved this and youll be able to see how it was done when i release commands i got got a few more to add, test and fix up before i release them