Nipi Posted May 10, 2017 Share Posted May 10, 2017 (edited) Hello! I was trying to work on a perk for my character that would allow her to gain sanity when she's near other players... However, I can't seem to find a way to distinguish other players from my modded character. Code is in the spoiler: Spoiler local function sanityfn(inst) local x,y,z = inst.Transform:GetWorldPosition() local delta = 0 local ents = TheSim:FindEntities(x,y,z, 20, {"player"}) for k,v in pairs(ents) do local bonus_sanity = TUNING.SANITYAURA_LARGE local distsq = math.max(inst:GetDistanceSqToInst(v),1) delta = delta + bonus_sanity/distsq end return delta end inst.components.sanity.custom_rate_fn = sanityfn So basically my problem is that she is gaining sanity near others BUT it's also counting herself as an 'other' and that's not what I want. I want her to gain sanity only when she's near someone else rather than it counting herself as a sanity gain. Edited May 10, 2017 by Nipi Link to comment Share on other sites More sharing options...
DarkXero Posted May 10, 2017 Share Posted May 10, 2017 local function sanityfn(inst) local x, y, z = inst.Transform:GetWorldPosition() local delta = 0 local ents = TheSim:FindEntities(x, y, z, 20, {"player"}) for k, v in pairs(ents) do if v ~= inst then local bonus_sanity = TUNING.SANITYAURA_LARGE local distsq = math.max(inst:GetDistanceSqToInst(v), 1) delta = delta + bonus_sanity / distsq end end return delta end -- master_postinit inst.components.sanity.custom_rate_fn = sanityfn Link to comment Share on other sites More sharing options...
Nipi Posted May 11, 2017 Author Share Posted May 11, 2017 @DarkXero It worked thank you so much! Link to comment Share on other sites More sharing options...
AkaiNight Posted May 20, 2017 Share Posted May 20, 2017 On 11.05.2017 at 2:22 AM, DarkXero said: local function sanityfn(inst) local x, y, z = inst.Transform:GetWorldPosition() local delta = 0 local ents = TheSim:FindEntities(x, y, z, 20, {"player"}) for k, v in pairs(ents) do if v ~= inst then local bonus_sanity = TUNING.SANITYAURA_LARGE local distsq = math.max(inst:GetDistanceSqToInst(v), 1) delta = delta + bonus_sanity / distsq end end return delta end -- master_postinit inst.components.sanity.custom_rate_fn = sanityfn is it possible to make it fo other players? I mean when they near you they gain sanity or walk and attack speed? Is it possible to make a code like this? Link to comment Share on other sites More sharing options...
Lumina Posted May 20, 2017 Share Posted May 20, 2017 Yes, this is possible. For players gaining sanity near you, you have to give your character a sanity aura. inst:AddComponent("sanityaura") -- Make your character give off sanity. inst.components.sanityaura.aura = -TUNING.SANITYAURA_LARGE -- Instead of LARGE you can use, TINY, SMALL, MED, or HUGE. Removing the - will make players gain sanity from your character instead. Something like this i think. Never tested it myself. Link to comment Share on other sites More sharing options...
DarkXero Posted May 20, 2017 Share Posted May 20, 2017 52 minutes ago, AkaiNight said: is it possible to make it fo other players? I mean when they near you they gain sanity or walk local AURA_RADIUS = 15 local SANITY_BONUS = GLOBAL.TUNING.DAPPERNESS_MED local SPEED_MULTIPLIER = 1.25 local COMBAT_MULTIPLIER = 1.25 local AURA_NAME = "akaimodaura" local function UpdateAuras(inst) for i, v in ipairs(GLOBAL.AllPlayers) do if v ~= inst then local prev = v[AURA_NAME] or false local activate = v:IsNear(inst, AURA_RADIUS) if prev ~= activate then if activate then v.components.sanity.dapperness = v.components.sanity.dapperness + SANITY_BONUS v.components.locomotor:SetExternalSpeedMultiplier(inst, "superspeed", SPEED_MULTIPLIER) v.components.combat.damagemultiplier = (v.components.combat.damagemultiplier or 1) * COMBAT_MULTIPLIER else v.components.sanity.dapperness = v.components.sanity.dapperness - SANITY_BONUS v.components.locomotor:RemoveExternalSpeedMultiplier(inst, "superspeed") v.components.combat.damagemultiplier = v.components.combat.damagemultiplier / COMBAT_MULTIPLIER end end v[AURA_NAME] = activate end end end AddPrefabPostInit("wilson", function(inst) if GLOBAL.TheWorld.ismastersim then inst:DoPeriodicTask(2, UpdateAuras) end end) Here's a convenient package. Sanity, walk speed, and damage aura. You put it in modmain and you change "wilson" to the prefab your character is. 53 minutes ago, AkaiNight said: attack speed Forget it. Link to comment Share on other sites More sharing options...
AkaiNight Posted May 21, 2017 Share Posted May 21, 2017 14 hours ago, DarkXero said: local AURA_RADIUS = 15 local SANITY_BONUS = GLOBAL.TUNING.DAPPERNESS_MED local SPEED_MULTIPLIER = 1.25 local COMBAT_MULTIPLIER = 1.25 local AURA_NAME = "akaimodaura" local function UpdateAuras(inst) for i, v in ipairs(GLOBAL.AllPlayers) do if v ~= inst then local prev = v[AURA_NAME] or false local activate = v:IsNear(inst, AURA_RADIUS) if prev ~= activate then if activate then v.components.sanity.dapperness = v.components.sanity.dapperness + SANITY_BONUS v.components.locomotor:SetExternalSpeedMultiplier(inst, "superspeed", SPEED_MULTIPLIER) v.components.combat.damagemultiplier = (v.components.combat.damagemultiplier or 1) * COMBAT_MULTIPLIER else v.components.sanity.dapperness = v.components.sanity.dapperness - SANITY_BONUS v.components.locomotor:RemoveExternalSpeedMultiplier(inst, "superspeed") v.components.combat.damagemultiplier = v.components.combat.damagemultiplier / COMBAT_MULTIPLIER end end v[AURA_NAME] = activate end end end AddPrefabPostInit("wilson", function(inst) if GLOBAL.TheWorld.ismastersim then inst:DoPeriodicTask(2, UpdateAuras) end end) Here's a convenient package. Sanity, walk speed, and damage aura. You put it in modmain and you change "wilson" to the prefab your character is. Forget it. thanks a lot for code Link to comment Share on other sites More sharing options...
AkaiNight Posted May 21, 2017 Share Posted May 21, 2017 15 hours ago, Lumina said: Yes, this is possible. For players gaining sanity near you, you have to give your character a sanity aura. inst:AddComponent("sanityaura") -- Make your character give off sanity. inst.components.sanityaura.aura = -TUNING.SANITYAURA_LARGE -- Instead of LARGE you can use, TINY, SMALL, MED, or HUGE. Removing the - will make players gain sanity from your character instead. Something like this i think. Never tested it myself. thanks a lot Link to comment Share on other sites More sharing options...
AkaiNight Posted May 22, 2017 Share Posted May 22, 2017 (edited) On 11.05.2017 at 2:22 AM, DarkXero said: local function sanityfn(inst) local x, y, z = inst.Transform:GetWorldPosition() local delta = 0 local ents = TheSim:FindEntities(x, y, z, 20, {"player"}) for k, v in pairs(ents) do if v ~= inst then local bonus_sanity = TUNING.SANITYAURA_LARGE local distsq = math.max(inst:GetDistanceSqToInst(v), 1) delta = delta + bonus_sanity / distsq end end return delta end -- master_postinit inst.components.sanity.custom_rate_fn = sanityfn for this code if i chance player with critter_kitten is that work (i mean when kittykit around will i gain sanity?) and how much sanity will i gain per minunte can i edit this like 5 sanity per min? Or can i make it lose sanity like 7 per min? Edited May 22, 2017 by AkaiNight Link to comment Share on other sites More sharing options...
Lumina Posted May 22, 2017 Share Posted May 22, 2017 I don't know for the critter_kitten part, but you could change value of sanity, just change TUNING.SANITYAURA_LARGE By something else like the one suggested in my post. Do -TUNING.SANITYAURA_LARGE for negative aura Link to comment Share on other sites More sharing options...
AkaiNight Posted May 22, 2017 Share Posted May 22, 2017 1 minute ago, Lumina said: I don't know for the critter_kitten part, but you could change value of sanity, just change TUNING.SANITYAURA_LARGE By something else like the one suggested in my post. Do -TUNING.SANITYAURA_LARGE for negative aura thanks agai Link to comment 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