Page 1 of 1

help with using gender as a variable

PostPosted: Thu Apr 19, 2007 10:12 pm
by bluraven
I'm working with the auto.cs trainer script and trying to make it so that Valkyries can only be female. I tried this code that I thought should work:
Code: Select all
if ((player.RaceName == "Norseman") && (player.PlayerCharacter.Gender == 0)) player.Out.SendMessage("Additionally, you can also choose to become a [Valkyrie].", eChatType.CT_Say, eChatLoc.CL_PopupWindow);
and
Code: Select all
case "Valkyrie":
if (((player.RaceName == "Norseman") || (player.RaceName == "Frostalf")) && (player.CharacterClass.ID == 35) && (player.PlayerCharacter.Gender == 0))
PromotePlayer(player, (int)eCharacterClass.Valkyrie, "Arise, " + player.Name + ", and know that you are no longer a simple " + player.CharacterClass.BaseName + ". You are now a Valkyrie");
But I get this error:
[15:03:04,591] Script compilation failed because:
[15:03:04,591] The name 'PlayerCharacter' does not exist in the current context
[15:03:04,591] c:\DOLsource\release\scripts\customnpc\Auto.CS Line:536 Col:142

I'm still very new to scripting and I understand that apparently before I can use player.PlayerCharacter.Gender, the script needs to know where it can find that, and I am not sure what I am missing to tell it where to look for it. I thought the "using" statements on the top of the file were for that? Or do I need some sort of public bool int Player.Character.gender line or something to tell it what kind of info the variable stores?

I've looked in the valkyrie trainer script and it uses player.PlayerCharacter.Gender. So I am lost :(

PostPosted: Thu Apr 19, 2007 10:18 pm
by Overdriven
player.Gender might just work, try that. First guess looking at it.

PostPosted: Thu Apr 19, 2007 10:22 pm
by bluraven
If I change it to player.Gender I get this error instead:
Code: Select all
[15:22:21,612] Script compilation failed because:
[15:22:21,612] 'DOL.GS.GamePlayer' does not contain a definition for 'Gender'
[15:22:21,612] c:\DOLsource\release\scripts\customnpc\Auto.CS Line:107 Col:76
GamePlayer.cs uses PlayerCharacter.Gender, so I try that and get this error:
Code: Select all
[15:26:33,661] Script compilation failed because:
[15:26:33,661] The name 'PlayerCharacter' does not exist in the current context
[15:26:33,677] c:\DOLsource\release\scripts\customnpc\Auto.CS Line:107 Col:69

PostPosted: Fri Apr 20, 2007 2:22 am
by Batlas
Find where PlayerCharacter is defined inside of GamePlayer see if it is set as public or private.. Also if you look at the constructor of GamePlayer it will show you how Gender is defined.

PostPosted: Fri Apr 20, 2007 4:40 am
by bluraven
Thanks guys for all your help so far. I looked in GamePlayer.cs and it looks like PlayerCharacter is public.
Code: Select all
public Character PlayerCharacter
{
get { return m_character; }
}
So I looked up what a constructor is and if I understand it correctly, Gameplayer.cs does not seem to have a contructor that defines gender. :(

I found this in character.cs:
Code: Select all
/// <summary>
/// Male or female character
/// </summary>
[DataElement(AllowDbNull = false)]
public int Gender
{
get
{
return m_gender;
}
set
{
Dirty = true;
m_gender = value;
}
}
So is it correct to assume gender is defined here instead? If so, how do I get my auto.cs script to understand that character.cs is where to find the veriable gender?

When I use Character.Gender instead I get this new error:
[22:46:58,109] Script compilation failed because:
[22:46:58,109] An object reference is required for the nonstatic field, method,
or property 'DOL.Database.Character.Gender.get'
[22:46:58,109] c:\DOLsource\release\scripts\customnpc\Auto.CS Line:108 Col:69

It's working now but I don't know why! lol

PostPosted: Fri Apr 20, 2007 7:13 am
by bluraven
Ok so, after fussing with this gender crap for the better part of an hour, I got it working but I don't know why or how, it does not make sense. I used player.PlayerCharacter.Gender == 1 and it compiled. It should have complained The name 'PlayerCharacter' does not exist in the current context, like it did before. I have no explanation as to now why all of a sudden it's perfectlly happy to accept player.PlayerCharacter.Gender. It makes absolutely no sense whatsoever, but it worked! woot :D And it successfully offers me to become a Valkyrie if I talk to the trainer as a female, and doesn't allow a male to become one. I have no clue why it took it this time but I guess I shouldn't question a miracle, lol.

PostPosted: Fri Apr 20, 2007 10:19 am
by bluraven
Incase anyone else would like my revised auto.cs script, I've posted it in the User Files section. Sharing is caring! :D