help with using gender as a variable

Discussions on various DOL development features

Moderator: Support Team

help with using gender as a variable

Postby bluraven » Thu Apr 19, 2007 10:12 pm

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 :(
Last edited by bluraven on Thu Apr 19, 2007 10:19 pm, edited 1 time in total.
bluraven
Support Team
 
Posts: 1484
Joined: Mon Mar 19, 2007 8:18 am
Location: Las Vegas, NV

Postby Overdriven » Thu Apr 19, 2007 10:18 pm

player.Gender might just work, try that. First guess looking at it.
Overdriven
Inactive Staff Member
 
Posts: 1736
Joined: Wed Sep 07, 2005 8:49 pm
Website: http://www.jasonbenedetti.co.uk
Location: Surrey, UK.

Postby bluraven » Thu Apr 19, 2007 10:22 pm

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
bluraven
Support Team
 
Posts: 1484
Joined: Mon Mar 19, 2007 8:18 am
Location: Las Vegas, NV

Postby Batlas » Fri Apr 20, 2007 2:22 am

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.
[22:29] <Arms> someones having sex upstairs -.-
[22:30] <Arms> bbl

[21:16] <Angie> do /me
[21:16] <Batlas> roflmao
[21:16] <Dalaaji> haha
[21:16] <Batlas> wow that came out bad
[21:16] <Angie> wow
[21:16] <Angie> that so came out bad
Batlas
Support Team
 
Posts: 1707
Joined: Sun Mar 21, 2004 3:11 am

Postby bluraven » Fri Apr 20, 2007 4:40 am

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
bluraven
Support Team
 
Posts: 1484
Joined: Mon Mar 19, 2007 8:18 am
Location: Las Vegas, NV

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

Postby bluraven » Fri Apr 20, 2007 7:13 am

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.
bluraven
Support Team
 
Posts: 1484
Joined: Mon Mar 19, 2007 8:18 am
Location: Las Vegas, NV

Postby bluraven » Fri Apr 20, 2007 10:19 am

Incase anyone else would like my revised auto.cs script, I've posted it in the User Files section. Sharing is caring! :D
bluraven
Support Team
 
Posts: 1484
Joined: Mon Mar 19, 2007 8:18 am
Location: Las Vegas, NV


Return to “%s” DOL Development Discussion

Who is online

Users browsing this forum: No registered users and 0 guests