Jump to content

Recommended Posts

How would one go about adding functional character perks for a character mod? I'm looking to 

  1. Increase the amount of sanity picking flowers yields 
  2. Increase the amount of sanity damage being near shadows deals
  3. Eliminate the sanity damage penalty for using magic and magic items 

I've got so far

	--Perk: Flowers
local function onpickedfn(inst, picker)
    if picker and picker.components.sanity then
        picker.components.sanity:DoDelta(TUNING.SANITY_MED)
    end
	
	-- Perk: Sanity Perk for Magic
	inst.components.sanity.magic_drain_mult = 0
	
	-- Perk(disavantage): Sanity Drain from Shadows
	inst.components.sanity.shadowcreature_drain_mult = 3

all three of these are placed at the end of my characer.lua file in mod/scripts/prefabs and I'm fairly certain at least two of them are wrong. 

I've also found DST's tuning.lua but I'm not 100 percent sure what I'd be looking for in there, or if it's even where I'm supposed to be for this sort of thing. 

Any suggestions, or worthwhile tutorials for perks or tuning?

Much appreciated, 

Tib 

Link to comment
https://forums.kleientertainment.com/forums/topic/71280-character-perks/
Share on other sites

You mentioned that these are posted at the end of your character.lua. Where is that? inside of masterpostinit or outside of masterpostinit?

Maybe show us where this stuff is located in relation to everything else. Also are all of these not working?

24 minutes ago, DarkKingBoo said:

You mentioned that these are posted at the end of your character.lua. Where is that? inside of masterpostinit or outside of masterpostinit?

Maybe show us where this stuff is located in relation to everything else. Also are all of these not working?

It took me a moment to figure it out, but they're currently residing outside of the masterpostinit. 

I'd take a wild guess that's what crashed the mod. 

The code for the flowers I ripped right from the flowers prefab in the original DST files, but the other two were a little more... creative, and I'm concerned about the phrasing of "[aspect]_drain_mult" in regards to the phrasing, but I've just been getting crash errors before it even starts up. 

-- Perk: Sanity Perk for Magic
	inst.components.sanity.magic_drain_mult = 0
	
	-- Perk(disavantage): Sanity Drain from Shadows
	inst.components.sanity.shadowcreature_drain_mult = 3

These need to be inside of masterpostinit.

 

That function needs to be above at least the common_postinit, but you'll need to replace it anyways, since that function will crash since its a function that requires the prefab to be pickable, which will never be the case for players and this isn't want you want.

--I haven't tested this out yet. Remember that this goes above the common_postinit
local function onpickup (inst, data)
	if data.prefab == "flower" then
		inst.components.sanity:DoDelta(10, false)
	end
end

--put this in your masterpostinit
inst:ListenForEvent("onpickup", onpickup)

Pretty tired so I just made it on the fly, if it crashes let me know so I can correct it.

Edited by DarkKingBoo
On 31.10.2016 at 1:51 AM, DarkKingBoo said:

That function needs to be above at least the common_postinit, but you'll need to replace it anyways, since that function will crash since its a function that requires the prefab to be pickable, which will never be the case for players and this isn't want you want.


--I haven't tested this out yet. Remember that this goes above the common_postinit
local function onpickup (inst, data)
	if data.prefab == "flower" then
		inst.components.sanity:DoDelta(10, false)
	end
end

--put this in your masterpostinit
inst:ListenForEvent("onpickup", onpickup)

Pretty tired so I just made it on the fly, if it crashes let me know so I can correct it.

The error does not appear, but the number of restore sanity remained the same (5)
Fix this pls

Edited by Tezumoto

So I tried several different events that involved picking up items and couldn't get the prefab name. So instead of that method, use this one:

--Put this into your modmain.lua

AddPrefabPostInit("flower", function(inst)

local function OnPickedfn(inst, picker)
	 if picker and picker.components.sanity and picker.prefab ~= "\yourcharacternamehere" then
        picker.components.sanity:DoDelta(TUNING.SANITY_MED)
	elseif picker and picker.components.sanity and picker.prefab == "yourcharacternamehere" then
		picker.components.sanity:DoDelta(10, false)
    end
	
	if inst.animname == ROSE_NAME and picker.components.combat ~= nil then
        picker.components.combat:GetAttacked(inst, TUNING.ROSE_DAMAGE)
        picker:PushEvent("thorns")
    end

    GLOBAL.TheWorld:PushEvent("beginregrowth", inst)

    inst:Remove()	
end

inst.components.pickable.onpickedfn = OnPickedfn
end
)

If anyone wants to jumpin and tell me which event that will identify the prefab being picked or just have a better method, I would also appreciate it.

Edited by DarkKingBoo
1 hour ago, DarkKingBoo said:

So I tried several different events that involved picking up items and couldn't get the prefab name. So instead of that method, use this one:


--Put this into your modmain.lua

AddPrefabPostInit("flower", function(inst)

local function OnPickedfn(inst, picker)
	 if picker and picker.components.sanity and picker.prefab ~= "\yourcharacternamehere" then
        picker.components.sanity:DoDelta(TUNING.SANITY_MED)
	elseif picker and picker.components.sanity and picker.prefab == "yourcharacternamehere" then
		picker.components.sanity:DoDelta(10, false)
    end
	
	if inst.animname == ROSE_NAME and picker.components.combat ~= nil then
        picker.components.combat:GetAttacked(inst, TUNING.ROSE_DAMAGE)
        picker:PushEvent("thorns")
    end

    GLOBAL.TheWorld:PushEvent("beginregrowth", inst)

    inst:Remove()	
end

inst.components.pickable.onpickedfn = OnPickedfn
end
)

If anyone wants to jumpin and tell me which event that will identify the prefab being picked or just have a better method, I would also appreciate it.

Yes!!! This worked, instead of +5 sanity, it's +15 for picking flowers. 

You've been an absolute LIFE saver, Boo, thank you so much!! 

 

7 hours ago, DarkKingBoo said:

So I tried several different events that involved picking up items and couldn't get the prefab name. So instead of that method, use this one:


--Put this into your modmain.lua

AddPrefabPostInit("flower", function(inst)

local function OnPickedfn(inst, picker)
	 if picker and picker.components.sanity and picker.prefab ~= "\yourcharacternamehere" then
        picker.components.sanity:DoDelta(TUNING.SANITY_MED)
	elseif picker and picker.components.sanity and picker.prefab == "yourcharacternamehere" then
		picker.components.sanity:DoDelta(10, false)
    end
	
	if inst.animname == ROSE_NAME and picker.components.combat ~= nil then
        picker.components.combat:GetAttacked(inst, TUNING.ROSE_DAMAGE)
        picker:PushEvent("thorns")
    end

    GLOBAL.TheWorld:PushEvent("beginregrowth", inst)

    inst:Remove()	
end

inst.components.pickable.onpickedfn = OnPickedfn
end
)

If anyone wants to jumpin and tell me which event that will identify the prefab being picked or just have a better method, I would also appreciate it.

This works, but the recovery mind is not impossible to edit.
Always +15)

Edited by Tezumoto
2 hours ago, DarkKingBoo said:

Which character are you playing as, the mod character or someone else?

change the other line then:


picker.components.sanity:DoDelta(TUNING.SANITY_MED)

 

I have a problem.
For some reason, any character that picks up flower on the server receives +15 a mind.

AddPrefabPostInit("flower", function(inst)

local function OnPickedfn(inst, picker)
	 if picker and picker.components.sanity and picker.prefab ~= "\reisen" then
        picker.components.sanity:DoDelta(TUNING.SANITY_MED)
	elseif picker and picker.components.sanity and picker.prefab == "reisen" then
		picker.components.sanity:DoDelta(10, false)
    end
	
	if inst.animname == ROSE_NAME and picker.components.combat ~= nil then
        picker.components.combat:GetAttacked(inst, TUNING.ROSE_DAMAGE)
        picker:PushEvent("thorns")
    end

    GLOBAL.TheWorld:PushEvent("beginregrowth", inst)

    inst:Remove()	
end

inst.components.pickable.onpickedfn = OnPickedfn
end
)

I am using this code.
I put it in modmain.lua one character (reisen)

2 minutes ago, Tezumoto said:

I have a problem.
For some reason, any character that picks up flower on the server receives +15 a mind.

Add this code inside YOURCHARACTER.lua is common_postinit

inst:AddTag("reisen")

then change this

AddPrefabPostInit("flower", function(inst)

local function OnPickedfn(inst, picker)
	 if picker and picker.components.sanity and picker.prefab ~= "\reisen" then
        picker.components.sanity:DoDelta(TUNING.SANITY_MED)
	elseif picker and picker.components.sanity and picker.prefab == "reisen" then
		picker.components.sanity:DoDelta(10, false)
    end
	
	if inst.animname == ROSE_NAME and picker.components.combat ~= nil then
        picker.components.combat:GetAttacked(inst, TUNING.ROSE_DAMAGE)
        picker:PushEvent("thorns")
    end

    GLOBAL.TheWorld:PushEvent("beginregrowth", inst)

    inst:Remove()	
end

inst.components.pickable.onpickedfn = OnPickedfn
end
)

to this

AddPrefabPostInit("flower", function(inst)

local function OnPickedfn(inst, picker)
	 if picker and picker.components.sanity and picker:HasTag("reisen") then
        picker.components.sanity:DoDelta(15) -- change to sanity amount u want
	elseif picker and picker.components.sanity and not picker:HasTag("reisen") then
		picker.components.sanity:DoDelta(5)
    end
	
	if inst.animname == ROSE_NAME and picker.components.combat ~= nil then
        picker.components.combat:GetAttacked(inst, TUNING.ROSE_DAMAGE)
        picker:PushEvent("thorns")
    end

    GLOBAL.TheWorld:PushEvent("beginregrowth", inst)

    inst:Remove()	
end

inst.components.pickable.onpickedfn = OnPickedfn
end
)

with this any character that isn't reisen will only get 5 sanity from picking flowers but if the character is resien they will get 15 sanity

30 minutes ago, SuperDavid said:

Add this code inside YOURCHARACTER.lua is common_postinit


inst:AddTag("reisen")

to this


AddPrefabPostInit("flower", function(inst)

local function OnPickedfn(inst, picker)
	 if picker and picker.components.sanity and picker:HasTag("reisen") then
        picker.components.sanity:DoDelta(15) -- change to sanity amount u want
	elseif picker and picker.components.sanity and not picker:HasTag("reisen") then
		picker.components.sanity:DoDelta(5)
    end
	
	if inst.animname == ROSE_NAME and picker.components.combat ~= nil then
        picker.components.combat:GetAttacked(inst, TUNING.ROSE_DAMAGE)
        picker:PushEvent("thorns")
    end

    GLOBAL.TheWorld:PushEvent("beginregrowth", inst)

    inst:Remove()	
end

inst.components.pickable.onpickedfn = OnPickedfn
end
)

with this any character that isn't reisen will only get 5 sanity from picking flowers but if the character is resien they will get 15 sanity

Thank you for your advice, he helped me)

Edited by Tezumoto

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...