TerriFried Posted December 25, 2021 Share Posted December 25, 2021 I am trying to make a mod where every time the character plays an item similar to the pan flute, they get struck by lightning. unfortunately, every attempt I have made to make this happen has either resulted in the game not starting the server, or the game crashing after doing the pan flute animation. I have code that should cause the player to get struck by lightning: inst.components.playerlightningtarget:DoStrike() And I have this for hopefully ignoring the players insolation and lack of moisture (Huge credit to @CarlZalph for help with this code) local ForceStrikeOn = function(inst) if inst.components.health and not (inst.components.health:IsDead() or inst.components.health:IsInvincible()) then local x, y, z = inst.Transform:GetWorldPosition() SpawnPrefab("lightning").Transform:SetPosition(x, y, z) local mult = TUNING.ELECTRIC_WET_DAMAGE_MULT * (inst.components.moisture and inst.components.moisture:GetMoisturePercent() or 0) local damage = TUNING.LIGHTNING_DAMAGE + mult * TUNING.LIGHTNING_DAMAGE inst.components.health:DoDelta(-damage, false, "lightning") if not inst.sg:HasStateTag("dead") then inst.sg:GoToState("electrocute") end end end Here is the code for the item basically straight from the pan flute code. I would assume that I would place this code under local function HearPanFlute(inst, musician, instrument), but I have no idea why it refuses to work. local assets = { Asset("ANIM", "anim/sigjam.zip"), Asset("ATLAS", "images/inventoryimages/sigjam.xml"), Asset("IMAGE", "images/inventoryimages/sigjam.tex"), } local function HearPanFlute(inst, musician, instrument) if inst ~= musician and (TheNet:GetPVPEnabled() or not inst:HasTag("player")) and not (inst.components.freezable ~= nil and inst.components.freezable:IsFrozen()) and not (inst.components.pinnable ~= nil and inst.components.pinnable:IsStuck()) and not (inst.components.fossilizable ~= nil and inst.components.fossilizable:IsFossilized()) then local mount = inst.components.rider ~= nil and inst.components.rider:GetMount() or nil if mount ~= nil then mount:PushEvent("ridersleep", { sleepiness = 10, sleeptime = TUNING.PANFLUTE_SLEEPTIME }) end if inst.components.sleeper ~= nil then inst.components.sleeper:AddSleepiness(10, TUNING.PANFLUTE_SLEEPTIME) elseif inst.components.grogginess ~= nil then inst.components.grogginess:AddGrogginess(10, TUNING.PANFLUTE_SLEEPTIME) else inst:PushEvent("knockedout") end end end local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst:AddTag("sigjam") inst.AnimState:SetBank("pan_flute") inst.AnimState:SetBuild("sigjam") inst.AnimState:PlayAnimation("idle") if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/sigjam.xml" inst.components.inventoryitem.cangoincontainer = true inst.components.inventoryitem.onputininventoryfn = function(inst, player) local owner = inst.components.inventoryitem:GetGrandOwner() if owner.components.inventory and owner.prefab ~= "absynth" then inst:DoTaskInTime(0.1, function() player.components.inventory:DropItem(inst) player.components.talker:Say("I guess only holograms can use this?") end) end end --tool (from tool component) added to pristine state for optimization inst:AddTag("tool") MakeInventoryFloatable(inst, "small", 0.05, 0.8) inst.AnimState:AddOverrideBuild("sigjam") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("instrument") inst.components.instrument.range = TUNING.PANFLUTE_SLEEPRANGE inst.components.instrument:SetOnHeardFn(HearPanFlute) inst:AddComponent("tool") inst.components.tool:SetAction(ACTIONS.PLAY) inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "sigjam" inst.components.inventoryitem.atlasname = "images/inventoryimages/sigjam.xml" MakeHauntableLaunch(inst) inst:ListenForEvent("floater_startfloating", function(inst) inst.AnimState:PlayAnimation("float") end) inst:ListenForEvent("floater_stopfloating", function(inst) inst.AnimState:PlayAnimation("idle") end) return inst end return Prefab("common/inventory/sigjam", fn, assets) I will attach the .lua file, and any help or explanation would be incredibly appreciated! sigjam.lua Link to comment https://forums.kleientertainment.com/forums/topic/136498-adding-additional-function-to-playing-pan-flute/ 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