I hope I can explain this.
I have a script to replace spellbooks according to the skills the players have when they login. i.e. If bushido skill is > 25 they get a Book of Bushido and so on for all 5 spell books. This works just as I want.
I don't want new accounts/players to get these books even if their skill is high enough. The CharacterCreation.cs takes care of that.
Here is the problem. I use
public static void Initialize()
{
EventSink.Login += new LoginEventHandler( Give_Login );
}
to start the event.
I have tried to check for gametime > 5 minutes and check if !young go and give spellbooks. Neither of these checks work. I am guessing that during account creation and character creation, it is bypassing my EventSink.Login some how.
So here is my question. How else could I determine if this is a new account/character or older one so spellbooks in my new script only go to older accounts/characters?
Thanks. I hope this is understandable.
What exactly is happening that is a problem?
You dont want to give out the spellbooks during character creation so you dont give out the books in CharacterCreation.
You do want to check in your login handler for account age and hand it out then.
I sounds like you are doing these things already.
Is it not handing out the books in your login handler? If that is the case then post that and we can take a look.
It appears to me that the eventsink adds spellbooks to the new player before the new player is set to young.
Here is the code I have tried.
CODE |
public static void Initialize() { EventSink.Login += new LoginEventHandler( Give_Login ); }
private static void Give_Login( LoginEventArgs args ) { Mobile m = args.Mobile; bool value = DisplayMessage( m ); Account acct=(Account)m.Account; if ( !m.Young ) { if ( !value ) { m.AddToBackpack(new BagOfSpellbooks()); acct.SetTag( "books", "true" ); m.SendGump ( new TellGump( m )); } } } |
and this
CODE |
public static void Initialize() { EventSink.Login += new LoginEventHandler( Give_Login ); }
private static void Give_Login( LoginEventArgs args ) { Mobile m = args.Mobile; bool value = DisplayMessage( m ); Account acct=(Account)m.Account; TimeSpan JoinGameAge = TimeSpan.FromMinutes( 5.0 ); if ( pm.GameTime > JoinGameAge ) { if ( !value ) { m.AddToBackpack(new BagOfSpellbooks()); acct.SetTag( "books", "true" ); m.SendGump ( new TellGump( m )); } } } |
I Tried both of these checks and in either case it still gives new players the spellbook. It seems that this login event happens before either Young is set to true or GameTime is set. So maybe I need to check other than in EventSink.Login. My chain of events is wrong. I'm checking for player properties before they are set.
Sorry I explained badly in first post.
ah, ok. Now I understand.
but what is this line
CODE |
if ( pm.GameTime > JoinGameAge )
|
where do you define pm? GameTime should be initialized to zero when the new playermobile is created, so that should work if you have the pm assignment right.
Sorry the pm in this post was a typing error not a copy and paste. Actually it is m.GameTime
Sorry
I just tried this code with old and new players and it worked as expected.
CODE |
public static void Initialize() { EventSink.Login += new LoginEventHandler(Give_Login); }
private static void Give_Login(LoginEventArgs args) {
PlayerMobile pm = args.Mobile as PlayerMobile;
if (pm == null) return;
Account acct = (Account)pm.Account; TimeSpan JoinGameAge = TimeSpan.FromMinutes(5.0);
Console.WriteLine("GameTime for {0} is {1}", pm, pm.GameTime);
if (pm.GameTime > JoinGameAge) { Console.WriteLine("Player {0} is old enough",pm); } }
|
new players had basically zero game time, and old players were correctly identified as having enough game time to qualify.
I would try it again.
Thank you Arte. I am dumber than a bag of Smithy Hammers. I was changing the script on one server and testing on another. I have 4 servers running and am totally stupid at times. Thanks again for at least testing this for me and getting me to look closer.