Enderia Posted May 21, 2022 Share Posted May 21, 2022 I'm trying to add to custom food knock out effect, similar to the mandrake/mandrake soup but I can't find code needed. Help? Link to comment https://forums.kleientertainment.com/forums/topic/140396-adding-knock-out-effect-to-food/ Share on other sites More sharing options...
-LukaS- Posted May 21, 2022 Share Posted May 21, 2022 Here's the function that causes entities to fall asleep when eating a mandrake: local function doareasleep(inst, range, time) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, range, nil, SLEEPTARGETS_CANT_TAGS, SLEEPTARGETS_ONEOF_TAGS) local canpvp = not inst:HasTag("player") or TheNet:GetPVPEnabled() for i, v in ipairs(ents) do if (v == inst or canpvp or not v:HasTag("player")) and not (v.components.freezable ~= nil and v.components.freezable:IsFrozen()) and not (v.components.pinnable ~= nil and v.components.pinnable:IsStuck()) and not (v.components.fossilizable ~= nil and v.components.fossilizable:IsFossilized()) then local mount = v.components.rider ~= nil and v.components.rider:GetMount() or nil if mount ~= nil then mount:PushEvent("ridersleep", { sleepiness = 7, sleeptime = time + math.random() }) end if v:HasTag("player") then v:PushEvent("yawn", { grogginess = 4, knockoutduration = time + math.random() }) elseif v.components.sleeper ~= nil then v.components.sleeper:AddSleepiness(7, time + math.random()) elseif v.components.grogginess ~= nil then v.components.grogginess:AddGrogginess(4, time + math.random()) else v:PushEvent("knockedout") end end end end It's from mandrake_inactive.lua, line 21. Link to comment https://forums.kleientertainment.com/forums/topic/140396-adding-knock-out-effect-to-food/#findComment-1572116 Share on other sites More sharing options...
Enderia Posted May 21, 2022 Author Share Posted May 21, 2022 5 hours ago, -t- said: Here's the function that causes entities to fall asleep when eating a mandrake: local function doareasleep(inst, range, time) local x, y, z = inst.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, range, nil, SLEEPTARGETS_CANT_TAGS, SLEEPTARGETS_ONEOF_TAGS) local canpvp = not inst:HasTag("player") or TheNet:GetPVPEnabled() for i, v in ipairs(ents) do if (v == inst or canpvp or not v:HasTag("player")) and not (v.components.freezable ~= nil and v.components.freezable:IsFrozen()) and not (v.components.pinnable ~= nil and v.components.pinnable:IsStuck()) and not (v.components.fossilizable ~= nil and v.components.fossilizable:IsFossilized()) then local mount = v.components.rider ~= nil and v.components.rider:GetMount() or nil if mount ~= nil then mount:PushEvent("ridersleep", { sleepiness = 7, sleeptime = time + math.random() }) end if v:HasTag("player") then v:PushEvent("yawn", { grogginess = 4, knockoutduration = time + math.random() }) elseif v.components.sleeper ~= nil then v.components.sleeper:AddSleepiness(7, time + math.random()) elseif v.components.grogginess ~= nil then v.components.grogginess:AddGrogginess(4, time + math.random()) else v:PushEvent("knockedout") end end end end It's from mandrake_inactive.lua, line 21. That's the problem - I already tried this code and its not workin. No effect, just the usual health/sanity/hunger change. Link to comment https://forums.kleientertainment.com/forums/topic/140396-adding-knock-out-effect-to-food/#findComment-1572241 Share on other sites More sharing options...
Ziro2k Posted May 21, 2022 Share Posted May 21, 2022 @Enderia Can you post your relevant code so we can see how you're trying to implement it? Link to comment https://forums.kleientertainment.com/forums/topic/140396-adding-knock-out-effect-to-food/#findComment-1572256 Share on other sites More sharing options...
Enderia Posted May 22, 2022 Author Share Posted May 22, 2022 14 hours ago, Ziro2k said: @Enderia Can you post your relevant code so we can see how you're trying to implement it? I tried for few hours to the point where the original code wasn't even recognizable but it either had no effect or kept crashing. I don't know enough about LUA to get it to work, would appreciate any help on what I have to do with this piece of code. I just need it to work on one eater with no AoE. moondrops.lua Link to comment https://forums.kleientertainment.com/forums/topic/140396-adding-knock-out-effect-to-food/#findComment-1572382 Share on other sites More sharing options...
-LukaS- Posted May 22, 2022 Share Posted May 22, 2022 Try this: local function doareasleep(inst, eater, time) eater:PushEvent("yawn", { grogginess = 4, knockoutduration = time + math.random() }) end local function oneaten(inst, eater) eater:DoTaskInTime(0.5, function() doareasleep(inst, eater, TUNING.MANDRAKE_SLEEP_TIME) end) end Link to comment https://forums.kleientertainment.com/forums/topic/140396-adding-knock-out-effect-to-food/#findComment-1572399 Share on other sites More sharing options...
Enderia Posted May 22, 2022 Author Share Posted May 22, 2022 1 hour ago, -t- said: Try this: local function doareasleep(inst, eater, time) eater:PushEvent("yawn", { grogginess = 4, knockoutduration = time + math.random() }) end local function oneaten(inst, eater) eater:DoTaskInTime(0.5, function() doareasleep(inst, eater, TUNING.MANDRAKE_SLEEP_TIME) end) end Yessss!! It workes perfectly! Thank you so much!!! Link to comment https://forums.kleientertainment.com/forums/topic/140396-adding-knock-out-effect-to-food/#findComment-1572407 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now