Neu7ral Posted May 12, 2016 Share Posted May 12, 2016 (edited) So, I'm making an amulet, when on being hit, you have a chance of stunlocking enemies (like the ruins crown hat chances of trigger a shield) in a radius and damaging them, And, pretty Idk how to do that, someone has an idea? Edited May 12, 2016 by Neutral_Steve Link to comment https://forums.kleientertainment.com/forums/topic/67213-i-require-assistance/ Share on other sites More sharing options...
DarkXero Posted May 12, 2016 Share Posted May 12, 2016 2 hours ago, Neutral_Steve said: So, I'm making an amulet, when on being hit, you have a chance of stunlocking enemies (like the ruins crown hat chances of trigger a shield) in a radius and damaging them, And, pretty Idk how to do that, someone has an idea? Like this? specialamulet.lua: local assets = { Asset("ANIM", "anim/amulets.zip"), Asset("ANIM", "anim/torso_amulets.zip"), } local STUN_CHANCE = 0.5 local STUN_DURATION = 5 local STUN_RANGE = 15 local STUN_DAMAGE = 34 local YES_TAGS = {"_combat"} local NO_TAGS = {"player", "shadow", "shadowminion"} local function AfterStun(enemy) if enemy and enemy:IsValid() then enemy:RestartBrain() end end local function stun_fn(owner, data) local attacker = data and data.attacker if attacker and math.random() < STUN_CHANCE then local x, y, z = owner.Transform:GetWorldPosition() local ents = TheSim:FindEntities(x, y, z, STUN_RANGE, YES_TAGS, NO_TAGS) for i, v in ipairs(ents) do if v.sg and v.sg:HasState("hit") and v.components.health and not v.components.health:IsDead() and not v.sg:HasStateTag("transform") and not v.sg:HasStateTag("nointerrupt") and not v.sg:HasStateTag("frozen") then v.components.combat:GetAttacked(owner, STUN_DAMAGE) v.sg:GoToState("hit") if v.components.locomotor then v.components.locomotor:Stop() end v:StopBrain() v:DoTaskInTime(STUN_DURATION, AfterStun) end end end end local function onequip_blue(inst, owner) owner.AnimState:OverrideSymbol("swap_body", "torso_amulets", "blueamulet") inst:ListenForEvent("attacked", stun_fn, owner) end local function onunequip_blue(inst, owner) owner.AnimState:ClearOverrideSymbol("swap_body") inst:RemoveEventCallback("attacked", stun_fn, owner) end local function blue() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("amulets") inst.AnimState:SetBuild("amulets") inst.AnimState:PlayAnimation("blueamulet") inst.foleysound = "dontstarve/movement/foley/jewlery" inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inspectable") inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.BODY inst.components.equippable:SetOnEquip(onequip_blue) inst.components.equippable:SetOnUnequip(onunequip_blue) inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "blueamulet" return inst end STRINGS.NAMES.SPECIALAMULET = "Weird Amulet" STRINGS.CHARACTERS.GENERIC.DESCRIBE.SPECIALAMULET = "Chilly!" return Prefab("specialamulet", blue, assets) Link to comment https://forums.kleientertainment.com/forums/topic/67213-i-require-assistance/#findComment-770650 Share on other sites More sharing options...
Neu7ral Posted May 12, 2016 Author Share Posted May 12, 2016 Yes! @DarkXero you're great! thank you! Link to comment https://forums.kleientertainment.com/forums/topic/67213-i-require-assistance/#findComment-770659 Share on other sites More sharing options...
Neu7ral Posted June 22, 2016 Author Share Posted June 22, 2016 Calling for help again. How do I make consume uses, I mean, finite uses. I tried but I got nothing but crashes Link to comment https://forums.kleientertainment.com/forums/topic/67213-i-require-assistance/#findComment-786859 Share on other sites More sharing options...
Aquaterion Posted June 22, 2016 Share Posted June 22, 2016 --in the blue function: inst:AddComponent("finiteuses") inst.components.finiteuses:SetMaxUses(10) inst.components.finiteuses:SetUses(10) --in the stun_fn function: local amulet = owner.components.inventory:GetEquippedItem(EQUIPSLOTS.BODY) if amulet and amulet.components.finiteuses then amulet.components.finiteuses:Use(1) end Link to comment https://forums.kleientertainment.com/forums/topic/67213-i-require-assistance/#findComment-786861 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