Jump to content

Recommended Posts

Hello, I have a question.

So, like the title says is there a way to call upon a character's gender? I tried...

if v.CHARACTER_GENDERS.MALE then
v.components.health:DoDelta(-99999)
end

But it just crashed the game saying "attempt to index field 'CHARACTER_GENDERS' (a nil value)".. So, if someone knows if this's even possible that would be great :D! If it isn't possible that's fine too :).

Thanks for reading my problem, have a great day/night :D!

Edited by SuperDavid

I tried something like this

inst:ListenForEvent("onattackother", function(inst, data)
local gender = GetGenderStrings(inst.char)

if data.target:HasTag("player") and inst.components.sanity:IsSane() then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_HITPLAYER"))
inst.components.sanity:DoDelta(-10)


if gender == "MALE" then
target.components.health:DoDelta(-9999)
end

elseif data.target:HasTag("player") and not inst.components.sanity:IsSane() then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_HITPLAYER"))
end
end)

and it didn't do anything? Maybe I did it wrong? And thanks for helping DarkKingBoo :D!

I made a mistake, try data.char instead. Also added a print, check your log to see if it came up as DEFAULT. If not then change MALE to whatever that says (assuming its not nil).

inst:ListenForEvent("onattackother", function(inst, data)
local gender = GetGenderStrings(data.char)

print(gender) --Lets see if it comes up as "DEFAULT". If it did, that means it didn't work!

if data.target:HasTag("player") and inst.components.sanity:IsSane() then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_HITPLAYER"))
inst.components.sanity:DoDelta(-10)


if gender == "MALE" then
target.components.health:DoDelta(-9999)
end

elseif data.target:HasTag("player") and not inst.components.sanity:IsSane() then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_HITPLAYER"))
end
end)
3 minutes ago, DarkKingBoo said:

I made a mistake, try data.char instead. Also added a print, check your log to see if it came up as DEFAULT. If not then change MALE to whatever that says (assuming its not nil).


inst:ListenForEvent("onattackother", function(inst, data)
local gender = GetGenderStrings(data.char)

print(gender) --Lets see if it comes up as "DEFAULT". If it did, that means it didn't work!

if data.target:HasTag("player") and inst.components.sanity:IsSane() then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_HITPLAYER"))
inst.components.sanity:DoDelta(-10)


if gender == "MALE" then
target.components.health:DoDelta(-9999)
end

elseif data.target:HasTag("player") and not inst.components.sanity:IsSane() then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_HITPLAYER"))
end
end)

In my log it came up as "DEFAULT" so what should I do?

9 minutes ago, DarkKingBoo said:

Try data.target or data.other.

By that you meant instead of

local gender = GetGenderStrings(data.char)

I do

local gender = GetGenderStrings(data.other)

or

local gender = GetGenderStrings(data.target)

I tried those both right now & they didn't do anything, sorry to bother you so much :)..

4 minutes ago, DarkKingBoo said:

Thats okay, I did some tests. Its data.prefab.

I tried this & it still didn't work :shock:?

inst:ListenForEvent("onattackother", function(inst, data)
local gender = GetGenderStrings(data.prefab)

print(gender) --Lets see if it comes up as "DEFAULT". If it did, that means it didn't work!

if data.target:HasTag("player") and inst.components.sanity:IsSane() then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_HITPLAYER"))
inst.components.sanity:DoDelta(-10)


if gender == "MALE" then
target.components.health:DoDelta(-9999)
end

elseif data.target:HasTag("player") and not inst.components.sanity:IsSane() then
inst.components.talker:Say(GetString(inst, "ANNOUNCE_HITPLAYER"))
end
end)

 

Ok so lets do it the same way I tested it. Lets try hitotherfn.

I was able to get Wilson's gender through this.

--place this somewhere above master_postinit
local function onhitother(inst, data)
local gender = GetGenderStrings(data.prefab)

print(gender) --Lets see if it comes up as "DEFAULT". If it did, that means it didn't work!

if gender == "MALE" then
data.components.health:DoDelta(-9999)
end

end


--place this somewhere inside master_postinit.
inst.components.combat.onhitotherfn = onhitother
2 minutes ago, DarkKingBoo said:

Ok so lets do it the same way I tested it. Lets try hitotherfn.

I was able to get Wilson's gender through this.

This worked :D!! Thanks so much DarkKingBoo, i'll be sure to credit you for this.

Also, can

inst.components.combat.onhitotherfn = onhitother

be replaced with?

inst:ListenForEvent("onattackother", onhitother)

Again, thanks so much :D!

No unfortunately, 

inst.components.combat.onhitotherfn

Is what made the difference. Its usually more reliable in terms of reading/affecting the target which 

inst:ListenForEvent("onattackother", onhitother)

Doesn't seem to do it at all. I don't know the exact reason why though.

Edit: Also call me Leonardo Coxington, DarkKingBoo is my slave name.

Edited by DarkKingBoo

That's fine, thanks so much for your help DarkKingBoo :D!

If I can just ask 1 more question is do you maybe know where I could find all the genders? Then I know which genders I can use?

EDIT: Okay, Sir Leonardo Coxington  :)!

Edited by SuperDavid

Found in Don't Starve Together/data/scripts/constants.lua

	CHARACTER_GENDERS = 
{
    FEMALE = {
        "willow",
        "wendy",
        "wickerbottom",
        "wathgrithr",
    },
    MALE = {
        "wilson",
        "woodie",
        "waxwell",
        "wolfgang",
        "wes",
        "webber",
    },
    ROBOT = {
        "wx78",
        "pyro",
    },
    NEUTRAL = {}, --empty, for modders to add to
    PLURAL = {}, --empty, for modders to add to
}
	 
	

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...