Dear forum users! In compliance with the new European GDPR regulations, we'd just like to inform you that if you have an account, your email address is stored in our database. We do not share your information with third parties, and your email address and password are encrypted for security reasons.

New to the forum? Say hello in this topic! Also make sure to read the rules.

how to get a player gender?

Share questions, scripts and tutorials related to the ScriptAPI in SFD.
Forum rules
By using the forum you agree to the following rules.
Post Reply
User avatar
Astolfo
Fighter
Fighter
Posts: 13
Joined: Tue Jan 21, 2020 9:00 pm
Started SFD: I forgot

how to get a player gender?

Post by Astolfo » Sun Jan 17, 2021 2:10 pm

I need to make a script that determines the gender of the player and then executes the command. For example, if the player's gender is male, then he executes a command, if female, then executes another command.
0 x
Hello world

User avatar
Odex64
Superfighter
Superfighter
Posts: 172
Joined: Sat Jul 29, 2017 12:39 pm
Title: Content Creator
SFD Account: Odex64
Started SFD: PreAlpha
Location: Italy
Gender:
Age: 22

Post by Odex64 » Sun Jan 17, 2021 2:59 pm

Female skin and clothes end with "_fem" suffix. To check if a player is using a female or male skin, you can use the following code:

Code: Select all

public void ButtonPressed(TriggerArgs args)
{
    if (args.Sender is IPlayer)
    {
        IPlayer ply = (IPlayer)args.Sender;
        if (ply.GetProfile().Skin.Name.Split('_').Length > 1)
        {
            //female
        }
        else
        {
            //male
        }
    }
}
Let me know if it works; I haven't tested it.
2 x
Image

User avatar
Astolfo
Fighter
Fighter
Posts: 13
Joined: Tue Jan 21, 2020 9:00 pm
Started SFD: I forgot

Post by Astolfo » Sun Jan 17, 2021 3:32 pm

Odex64 wrote:
Sun Jan 17, 2021 2:59 pm
Let me know if it works; I haven't tested it.
Yes, that works, thank you!
0 x
Hello world

User avatar
Gurt
Lead Programmer
Lead Programmer
Posts: 1884
Joined: Sun Feb 28, 2016 3:22 pm
Title: Lead programmer
Started SFD: Made it!
Location: Sweden
Gender:
Age: 34

Post by Gurt » Sun Jan 17, 2021 11:06 pm

Or use the Gender property:
if (ply.GetProfile().Gender == Gender.Female)
{
// Female
} else {
// Male
}
0 x
Gurt

Post Reply