Well-met Posted March 27, 2019 Share Posted March 27, 2019 greetings I've been wanting to design a weapon and so far it's going well. However I'm looking to use the pushback code which can be seen on YOTP weapon signs that sends players and pigs flying around on hit. I believe this is the same state that's used in Forge by boarilla and bosses? I would like this affect to only affect other players and pigmen, as I would guess only these two can be knocked around because they have the necessary anims. SGwilson.lua reports 3 states used for this - knockback, knockback_pist, knockback_landed State{ name = "knockback", tags = { "busy", "nopredict", "nomorph", "nodangle" }, onenter = function(inst, data) ClearStatusAilments(inst) ForceStopHeavyLifting(inst) inst.components.rider:ActualDismount() inst.components.locomotor:Stop() inst:ClearBufferedAction() inst.AnimState:PlayAnimation("bucked") if data ~= nil then if data.propsmashed then local item = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) local pos if item ~= nil then pos = inst:GetPosition() pos.y = TUNING.KNOCKBACK_DROP_ITEM_HEIGHT_HIGH local dropped = inst.components.inventory:DropItem(item, true, true, pos) if dropped ~= nil then dropped:PushEvent("knockbackdropped", { owner = inst, knocker = data.knocker, delayinteraction = TUNING.KNOCKBACK_DELAY_INTERACTION_HIGH, delayplayerinteraction = TUNING.KNOCKBACK_DELAY_PLAYER_INTERACTION_HIGH }) end end if item == nil or not item:HasTag("propweapon") then item = inst.components.inventory:FindItem(IsMinigameItem) if item ~= nil then pos = pos or inst:GetPosition() pos.y = TUNING.KNOCKBACK_DROP_ITEM_HEIGHT_LOW item = inst.components.inventory:DropItem(item, false, true, pos) if item ~= nil then item:PushEvent("knockbackdropped", { owner = inst, knocker = data.knocker, delayinteraction = TUNING.KNOCKBACK_DELAY_INTERACTION_LOW, delayplayerinteraction = TUNING.KNOCKBACK_DELAY_PLAYER_INTERACTION_LOW }) end end end end if data.radius ~= nil and data.knocker ~= nil and data.knocker:IsValid() then local x, y, z = data.knocker.Transform:GetWorldPosition() local distsq = inst:GetDistanceSqToPoint(x, y, z) local rangesq = data.radius * data.radius local rot = inst.Transform:GetRotation() local rot1 = distsq > 0 and inst:GetAngleToPoint(x, y, z) or data.knocker.Transform:GetRotation() + 180 local drot = math.abs(rot - rot1) while drot > 180 do drot = math.abs(drot - 360) end local k = distsq < rangesq and .3 * distsq / rangesq - 1 or -.7 inst.sg.statemem.speed = (data.strengthmult or 1) * 12 * k inst.sg.statemem.dspeed = 0 if drot > 90 then inst.sg.statemem.reverse = true inst.Transform:SetRotation(rot1 + 180) inst.Physics:SetMotorVel(-inst.sg.statemem.speed, 0, 0) else inst.Transform:SetRotation(rot1) inst.Physics:SetMotorVel(inst.sg.statemem.speed, 0, 0) end end end end, onupdate = function(inst) if inst.sg.statemem.speed ~= nil then inst.sg.statemem.speed = inst.sg.statemem.speed + inst.sg.statemem.dspeed if inst.sg.statemem.speed < 0 then inst.sg.statemem.dspeed = inst.sg.statemem.dspeed + .075 inst.Physics:SetMotorVel(inst.sg.statemem.reverse and -inst.sg.statemem.speed or inst.sg.statemem.speed, 0, 0) else inst.sg.statemem.speed = nil inst.sg.statemem.dspeed = nil inst.Physics:Stop() end end end, timeline = { TimeEvent(8 * FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/movement/bodyfall_dirt") end), }, events = { EventHandler("animover", function(inst) if inst.AnimState:AnimDone() then inst.sg:GoToState("knockback_pst") end end), }, onexit = function(inst) if inst.sg.statemem.speed ~= nil then inst.Physics:Stop() end end, }, State{ name = "knockback_pst", tags = { "knockback", "busy", "nomorph", "nodangle" }, onenter = function(inst) inst.AnimState:PlayAnimation("buck_pst") end, timeline = { TimeEvent(27 * FRAMES, function(inst) inst.sg:RemoveStateTag("knockback") inst.sg:RemoveStateTag("busy") inst.sg:RemoveStateTag("nomorph") end), }, events = { EventHandler("animover", function(inst) if inst.AnimState:AnimDone() then inst.sg:GoToState("idle") end end), }, }, State{ name = "knockbacklanded", tags = { "knockback", "busy", "nopredict", "nomorph" }, onenter = function(inst, data) ClearStatusAilments(inst) ForceStopHeavyLifting(inst) inst.components.rider:ActualDismount() inst.components.locomotor:Stop() inst:ClearBufferedAction() inst.AnimState:PlayAnimation("hit_spike_heavy") if data ~= nil then if data.propsmashed then local item = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS) local pos if item ~= nil then pos = inst:GetPosition() pos.y = TUNING.KNOCKBACK_DROP_ITEM_HEIGHT_LOW local dropped = inst.components.inventory:DropItem(item, true, true, pos) if dropped ~= nil then dropped:PushEvent("knockbackdropped", { owner = inst, knocker = data.knocker, delayinteraction = TUNING.KNOCKBACK_DELAY_INTERACTION_LOW, delayplayerinteraction = TUNING.KNOCKBACK_DELAY_PLAYER_INTERACTION_LOW }) end end if item == nil or not item:HasTag("propweapon") then item = inst.components.inventory:FindItem(IsMinigameItem) if item ~= nil then if pos == nil then pos = inst:GetPosition() pos.y = TUNING.KNOCKBACK_DROP_ITEM_HEIGHT_LOW end item = inst.components.inventory:DropItem(item, false, true, pos) if item ~= nil then item:PushEvent("knockbackdropped", { owner = inst, knocker = data.knocker, delayinteraction = TUNING.KNOCKBACK_DELAY_INTERACTION_LOW, delayplayerinteraction = TUNING.KNOCKBACK_DELAY_PLAYER_INTERACTION_LOW }) end end end end if data.radius ~= nil and data.knocker ~= nil and data.knocker:IsValid() then local x, y, z = data.knocker.Transform:GetWorldPosition() local distsq = inst:GetDistanceSqToPoint(x, y, z) local rangesq = data.radius * data.radius local rot = inst.Transform:GetRotation() local rot1 = distsq > 0 and inst:GetAngleToPoint(x, y, z) or data.knocker.Transform:GetRotation() + 180 local drot = math.abs(rot - rot1) while drot > 180 do drot = math.abs(drot - 360) end local k = distsq < rangesq and .3 * distsq / rangesq - 1 or -.7 inst.sg.statemem.speed = (data.strengthmult or 1) * 8 * k inst.sg.statemem.dspeed = 0 if drot > 90 then inst.sg.statemem.reverse = true inst.Transform:SetRotation(rot1 + 180) inst.Physics:SetMotorVel(-inst.sg.statemem.speed, 0, 0) else inst.Transform:SetRotation(rot1) inst.Physics:SetMotorVel(inst.sg.statemem.speed, 0, 0) end end end inst.sg:SetTimeout(11 * FRAMES) end, onupdate = function(inst) if inst.sg.statemem.speed ~= nil then inst.sg.statemem.speed = inst.sg.statemem.speed + inst.sg.statemem.dspeed if inst.sg.statemem.speed < 0 then inst.sg.statemem.dspeed = inst.sg.statemem.dspeed + .075 inst.Physics:SetMotorVel(inst.sg.statemem.reverse and -inst.sg.statemem.speed or inst.sg.statemem.speed, 0, 0) else inst.sg.statemem.speed = nil inst.sg.statemem.dspeed = nil inst.Physics:Stop() end end end, timeline = { TimeEvent(9 * FRAMES, function(inst) inst.SoundEmitter:PlaySound("dontstarve/movement/bodyfall_dirt") end), }, ontimeout = function(inst) inst.sg:GoToState("idle", true) end, onexit = function(inst) if inst.sg.statemem.speed ~= nil then inst.Physics:Stop() end end, }, I believe I'd have to use components.weapon:OnAttack but I'm kinda lost here. Link to comment https://forums.kleientertainment.com/forums/topic/104219-knockback-on-hit/ Share on other sites More sharing options...
Well-met Posted March 29, 2019 Author Share Posted March 29, 2019 Got what I needed from Leonardo Coxington https://steamcommunity.com/sharedfiles/filedetails/?id=1179982849 just check how their boarrior does it and edit it from there Link to comment https://forums.kleientertainment.com/forums/topic/104219-knockback-on-hit/#findComment-1170882 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