Sign in to follow this  
fixerhere

Need some help with my mod

Recommended Posts

fixerhere    1

I'm probably so close to finishing my character mod but still there is one thing I want to do but don't understand

I want evil flowers to be like normal flowers (having same food stats, having same aura and when picking up getting +5 sanity)

On the other hand i want normal flowers to be like evil flowers (having food stats like evil flowers, having negative aura, when picking up -5 sanity)
 

So is it even possible that my character would be only affected?

Share this post


Link to post
Share on other sites
thomas4846    859
local function CalcSanityAura(inst, observer)
    return (observer.prefab == "character_name" and 
	       inst.prefab == "flower_evil") and 0 or
		   (observer.prefab == "character_name" and
           inst.prefab == "flower") and -TUNING.SANITYAURA_SMALL or	   
		   inst.components.sanityaura.aura
end

local function FlowerButPlanted (inst)
if not GLOBAL.TheWorld.ismastersim then
    return inst
end

if not inst.components.sanityaura then
   inst:AddComponent("sanityaura")
end
   inst.components.sanityaura.aurafn = CalcSanityAura

if inst.components.pickable then
inst._onpickedfn = inst.components.pickable.onpickedfn

inst.components.pickable.onpickedfn = function(inst, picker, loot)
print(picker)			
if picker and picker.prefab == "character_name" then
   --code 
    if picker.components.sanity ~= nil and inst.prefab == "flower_evil" then
       picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
	elseif picker.components.sanity ~= nil and inst.prefab == "flower" then
	   picker.components.sanity:DoDelta(-TUNING.SANITY_TINY)
    end
	else inst._onpickedfn(inst, picker, loot)
   end
   --else inst._onpickedfn(inst, picker)
   inst:Remove()
  end
 end
end

AddPrefabPostInit("flower_evil", FlowerButPlanted)
AddPrefabPostInit("flower", FlowerButPlanted)

This should cover the code for:
>sanity aura
>picking sanity delta

this should work but i haven't tested it yet

But basically I've or should've replaced the functions components for the flowers specifically 
but this may not work well with mods that change the flowers as well 

please tell me if my code doesn't work with the log 

in modmain btw

me explaining for no reason

self.onpickedfn(self.inst, picker, loot)

this is the function in the pick able component, we have 3 parameters :
(self.inst,
picker,
loot)


we still use this function but we change it to only apply to our character but we save the original function for others
for the code we're gonna use we only use the first 2 

--1) saving the origina function 
inst._onpickedfn = inst.components.pickable.onpickedfn

inst.components.pickable.onpickedfn = function(inst, picker)
--2) function 
if  picker.prefab == "character_name" then 
--3) code specific for character 
else inst._onpickedfn(inst, picker)
--4) other characters
end
end

1) we first save the original function as:
>inst._onpickedfn 

2) but then replace it with our own:
>inst.components.pickable.onpickedfn = function(inst, picker)

3) Add an if .. else statement to make sure the code only applies to the custom charaacter:
>if  picker.prefab == "character_name" then

4) If the character is not yours then it should re-introduce the original function that we saved:
>else inst._onpickedfn(inst,picker) 

 

function Combat:GetAttacked(attacker, damage, weapon, stimuli)
--orignal code 

inst.components.combat.GetAttacked = function(self,attacker, damage, weapon, stimuli)
--from my code

I think sometimes you might need to add parameter "self" for some functions because idk but i think it's referenced in the originals code's function
image.png.08272914dafa399ed1c09a293edeeb54.png
bt dubs if anyone knows there's a link explaining this can you send it me so i can just link it next time

Edited by thomas4846
I oofed up

Share this post


Link to post
Share on other sites
thomas4846    859
local function CalcSanityAura(inst, observer)
    return (observer.prefab == "wilson" and 
	       inst.prefab == "flower_evil") and 0 or
		   (observer.prefab == "wilson" and
           inst.prefab == "flower") and -TUNING.SANITYAURA_SMALL or	   
		   inst.components.sanityaura.aura
end

local function FlowerButPlanted (inst)
if not GLOBAL.TheWorld.ismastersim then
    return inst
end

if not inst.components.sanityaura then
   inst:AddComponent("sanityaura")
end
   inst.components.sanityaura.aurafn = CalcSanityAura

if inst.components.pickable then
inst._onpickedfn = inst.components.pickable.onpickedfn

inst.components.pickable.onpickedfn = function(inst, picker, loot)
print(picker)			
if picker and picker.prefab == "wilson" then
   --code 
    if picker.components.sanity ~= nil and inst.prefab == "flower_evil" then
       picker.components.sanity:DoDelta(TUNING.SANITY_TINY)
	elseif picker.components.sanity ~= nil and inst.prefab == "flower" then
	   picker.components.sanity:DoDelta(-TUNING.SANITY_TINY)
    end
	else inst._onpickedfn(inst, picker, loot)
   end
   --else inst._onpickedfn(inst, picker)
   inst:Remove()
  end
 end
end

AddPrefabPostInit("flower_evil", FlowerButPlanted)
AddPrefabPostInit("flower", FlowerButPlanted)

@fixerhere

Okay sorry but i've changed the names to wilson but jsut change it to your characters and we'll all be dandy

The problems:
>functions were after addprefabpostinit
>else was too far down
>calculate aura didn't make normal flowers bad
>didn't remove flowers

this should be fixed now I'm gonna replace the original code

Edited by thomas4846

Share this post


Link to post
Share on other sites
fixerhere    1

Everything works well I mean there is a graphical bug it says that when picking up evil flower it gives -5 sanity (don't worry it gives +5 sanity) other than that everything works well now I only need to change food stat values for flower and evil flower

Share this post


Link to post
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
Sign in to follow this