THISTINYTHING Posted December 14, 2016 Share Posted December 14, 2016 Hate to be a bother yet again but I'm stuck. I have my item which is a microphone, but I can't seem to get it to play. I have it so it so you can hold it and it has the action button to Play. But it won't do anything. I have copied some code from the pan flute to do this, but I can't seem to get the play function to work because I don't know how to really write it and I'm honestly throwing random code in and seeing if it works. I think it's almost there but again the action just doesn't want to play. Here's the broken code. Spoiler local assets = { Asset("ANIM", "anim/microphone.zip"), Asset("ANIM", "anim/swap_microphone.zip"), Asset("ATLAS", "images/inventoryimages/microphone.xml"), Asset("IMAGE", "images/inventoryimages/microphone.tex"), } local function onequip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_microphone", "microphone") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") end local function onunequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") end local function onfinished(inst, owner) local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner if owner then local brokentool = SpawnPrefab("brokentool") brokentool.Transform:SetPosition(inst.Transform:GetWorldPosition() ) inst:Remove() end end local function HearMicrophone(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()) then if inst.components.sleeper ~= nil then inst.components.sleeper:AddSleepiness(10, TUNING.MICROPHONE_SLEEPTIME) elseif inst.components.grogginess ~= nil then inst.components.grogginess:AddGrogginess(10, TUNING.MICROPHONE_SLEEPTIME) else inst:PushEvent("knockedout") end end end local function fn() local inst = CreateEntity() local trans = inst.entity:AddTransform() local anim = inst.entity:AddAnimState() MakeInventoryPhysics(inst) inst.entity:AddNetwork() anim:SetBank("microphone") anim:SetBuild("microphone") anim:PlayAnimation("idle") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end --------- inst:AddComponent("instrument") inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "microphone" inst.components.inventoryitem.atlasname = "images/inventoryimages/microphone.xml" --------- inst:AddComponent("equippable") inst.components.equippable:SetOnEquip( onequip ) inst.components.equippable:SetOnUnequip( onunequip ) --------- inst.components.instrument.range = TUNING.MICROPHONE_SLEEPRANGE inst.components.instrument:SetOnHeardFn(HearMicrophone) inst:AddComponent("tool") inst.components.tool:SetAction(ACTIONS.PLAY) inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(100) inst.components.finiteuses:SetUses(100) inst.components.finiteuses:SetOnFinished(inst.Remove) inst.components.finiteuses:SetConsumption(ACTIONS.PLAY, 1) MakeHauntableLaunch(inst) return inst end return Prefab("common/inventory/microphone", fn, assets) Link to comment Share on other sites More sharing options...
Serpens Posted December 14, 2016 Share Posted December 14, 2016 didn't look at your code, but there was another thread about instruments and maybe it will help: Link to comment Share on other sites More sharing options...
Neu7ral Posted December 14, 2016 Share Posted December 14, 2016 (edited) Panflute code works with the flute tag inst:AddTag("flute") Equipable items that doesn't have weapon components is recomended to use this that for avoid a bug of characters doing punch instead of doing a swing. inst:AddTag("nopunch") both should put before if not TheWorld.ismastersim then return inst end Also, you'll have a new problem, since the instrument will show as a panflute when you play it, I know there's a way to change that, but I don't remember well. Edited December 14, 2016 by Neutral_Steve Edits, yay! 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