Jump to content

peaceful nightmare monsters


Recommended Posts

function NightmarecreaturePostInit(inst)

if GLOBAL.TheWorld.ismastersim then

local function retargetfn1(inst)

return FindEntity(inst, TUNING.SHADOWCREATURE_TARGET_DIST,

function(guy)

return inst.components.combat:CanTarget(guy) and not guy:HasTag("animsparrow")

end,

{ "playerghost" }

)

end

inst.components.combat:SetRetargetFunction(3, retargetfn1)

end

end

AddPrefabPostInit("nightmarecreature", NightmarecreaturePostInit)

Link to comment
Share on other sites

There is a first issue in the retarget function you wrote. You replaced the musttags from FindEntity function which was supposed to be "{ "player" }" and replaced it by "playerghost" and removed the notags.

It means that if your postinit was working, nightmare creatures would just attack ghost players.

 

But the main issue is that you add that function to "nightmarecreature" which is actually not a prefab. 

nightmarecreature.lua creates 2 separate prefabs : "crawlingnightmare" and "nightmarebeak"

 

Try to do a AddPrefabPostInit on these 2 prefabs instead (after correcting the FindEntity function to put back the proper musttags and notags).

 

If you have still issues, could you post your complete mod so I can just download it and try it out please?

Edited by ZupaleX
Link to comment
Share on other sites

Here is the fixed modmain.lua

Nightmare creatures will keep the same behavior toward any entity except your character, against who they will be peaceful.

 

I made it so it's more compatible with other mods which would affect the nightmare creatures.

 

I don't know what you want to do with the sanity widget and sanity of your character at all but I think you fucked up something. I may be able to help if you explain what you want to achieve.

modmain.lua

Link to comment
Share on other sites

Here is the fixed modmain.lua

Nightmare creatures will keep the same behavior toward any entity except your character, against who they will be peaceful.

 

I made it so it's more compatible with other mods which would affect the nightmare creatures.

 

I don't know what you want to do with the sanity widget and sanity of your character at all but I think you fucked up something. I may be able to help if you explain what you want to achieve.

 

I'm glad you decided to help me but still nothing happen. Don't work at all.

Link to comment
Share on other sites

What you wanted to do is working : Nightmare Creatures doesn't attack your character but attack other characters. I tested it out by spawning nightmare creatures next to the player when using your character or not.

 

If something else is not working this is an other issue that need to be addressed separatly.

What do you mean by "Don't work at all"?

Link to comment
Share on other sites

What I want to do is that when I'm insane my character should be not attacked by shadow monsters. Others are targeted as usual. When I attack them though, they become aggresive. But right now it doesnt work if I'm my character or any other, nightmare monsters still target everybody.

About sanity, my character has no sanity badge because his sanity scales with his beard

Link to comment
Share on other sites

local function MakeNeutral(inst)

if GLOBAL.TheWorld.ismastersim then

local _CanTarget = inst.components.combat.CanTarget

inst.components.combat.CanTarget = function(self, target)

local ret = _CanTarget(self, target)

if ret and target:HasTag("animsparrow") then

local playertarget = target.components.combat.target

local shadowtarget = playertarget and playertarget:HasTag("shadowcreature")

if not shadowtarget then

return false

end

end

return ret

end

end

end

AddPrefabPostInit("crawlinghorror", MakeNeutral)

AddPrefabPostInit("terrorbeak", MakeNeutral)

Link to comment
Share on other sites

That's doing the same that what is already in the modmain.lua currently (except for making the creature agressive whe, attacked by his character). The issue he is referring to must be something else.

Edited by ZupaleX
Link to comment
Share on other sites

Ahah, it's because I started from the lua file nightmarecreature.lua since that's what AnimSparrow was modifying... and this file indeed return 2 prefabs : "crawlingnightmare" and "nightmarebeak".

 

But it's not the prefab which are spawned when the sanity drop below the threshold, which are the prefabs created by shadowcreature.lua

 

This explain the mystery of why, when I was spawning these 2 prefabs it was working the targeting while AnimSparrow was claiming it was not, because I guess he was not popping them but trigerring their spawn by lowering the sanity.

 

Thanks for solving this mystery for me, I was really puzzled.

 

EDIT: btw, you know what's the use of nightmarecreature.lua and the 2 prefabs it returns which are totally similar to the shadow creatures? I am a bit lazy to search so if you already know... :-)

Edited by ZupaleX
Link to comment
Share on other sites

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
 Share

×
  • Create New...