Jump to content

Recommended Posts

I've managed to add woodie's weremoose's tackle/charge mechanic to my character. It works fine but if the character charges then it will charge forever if it doesnt hit anything. Im pretty sure I've added every code thats involved with the charging so I really have no idea what im missing thats responsible for making the charge stop. This is all the tackle code in my character's prefab. What does it need to make it stop charging after a few seconds?

local function ChargeRightClickPicker(inst, target, pos)
	return target ~= inst
		and (	(	target ~= nil and
					target:HasTag("walkingplank") and
					inst:HasTag("on_walkable_plank") and
					inst.components.playeractionpicker:SortActionList({ ACTIONS.ABANDON_SHIP }, target, nil)
				)
				or
				(	not inst.components.playercontroller.isclientcontrollerattached and
					inst.components.playeractionpicker:SortActionList({ ACTIONS.TACKLE }, target or pos, nil)
				)
			)
		or nil
end

local function ChargePointSpecialActions(inst, pos, useitem, right)
    return right and inst.components.playercontroller:IsEnabled() and { ACTIONS.TACKLE } or {}
end

local function Empty()
end

local function ReticuleTargetFn(inst)
    return Vector3(inst.entity:LocalToWorldSpace(1.5, 0, 0))
end

local function ReticuleUpdatePositionFn(inst, pos, reticule, ease, smoothing, dt)
    local x, y, z = inst.Transform:GetWorldPosition()
    reticule.Transform:SetPosition(x, 0, z)
    local rot = -math.atan2(pos.z - z, pos.x - x) / DEGREES
    if ease and dt ~= nil then
        local rot0 = reticule.Transform:GetRotation()
        local drot = rot - rot0
        rot = Lerp((drot > 180 and rot0 + 360) or (drot < -180 and rot0 - 360) or rot0, rot, dt * smoothing)
    end
    reticule.Transform:SetRotation(rot)
end

local function EnableReticule(inst, enable)
    if enable then
        if inst.components.reticule == nil then
            inst:AddComponent("reticule")
            inst.components.reticule.reticuleprefab = "reticuleline2"
            inst.components.reticule.targetfn = ReticuleTargetFn
            inst.components.reticule.updatepositionfn = ReticuleUpdatePositionFn
            inst.components.reticule.ease = true
            if inst.components.playercontroller ~= nil and inst == ThePlayer then
                inst.components.playercontroller:RefreshReticule()
            end
        end
    elseif inst.components.reticule ~= nil then
        inst:RemoveComponent("reticule")
        if inst.components.playercontroller ~= nil and inst == ThePlayer then
            inst.components.playercontroller:RefreshReticule()
        end
    end
end

local function SetSpecialActions(inst)
    inst.ActionStringOverride = nil
        if inst.components.playercontroller ~= nil then
            inst.components.playercontroller.actionbuttonoverride = Empty
        end
        if inst.components.playeractionpicker ~= nil then
            inst.components.playeractionpicker.rightclickoverride = ChargeRightClickPicker
            inst.components.playeractionpicker.pointspecialactionsfn = ChargePointSpecialActions
        end
        EnableReticule(inst, true)
    end

local function onbecamehuman(inst)
	inst.components.combat:SetDefaultDamage(TUNING.WEREMOOSE_DAMAGE)
    inst.components.combat.bonusdamagefn = nil
	SetSpecialActions(inst)
end

local function OnTackleStart(inst)
    if inst.sg.currentstate.name == "tackle_pre" then
        inst.sg.statemem.tackling = true
        inst.sg:GoToState("tackle_start")
        return true
    end
end

local function OnTackleCollide(inst, other)
    local x, y, z = inst.Transform:GetWorldPosition()
    local x1, y1, z1 = other.Transform:GetWorldPosition()
    local r = other:GetPhysicsRadius(.5)
    r = r / (r + 1)
    SpawnPrefab("round_puff_fx_hi").Transform:SetPosition(x1 + (x - x1) * r, 0, z1 + (z - z1) * r)
    inst.SoundEmitter:PlaySound("dontstarve/characters/woodie/moose/bounce")
    ShakeAllCameras(CAMERASHAKE.FULL, .6, .025, .4, other, 20)
    if inst.components.grogginess ~= nil then
        inst.components.grogginess:MaximizeGrogginess()
    end
end

local function OnTackleTrample(inst, other)
    SpawnPrefab((other:HasTag("largecreature") or other:HasTag("epic")) and "round_puff_fx_lg" or "round_puff_fx_sm").Transform:SetPosition(other.Transform:GetWorldPosition())
end

local master_postinit = function(inst)
  	inst:AddComponent("tackler")
        inst.components.tackler:SetOnStartTackleFn(OnTackleStart)
        inst.components.tackler:SetDistance(.5)
        inst.components.tackler:SetRadius(.75)
        inst.components.tackler:SetStructureDamageMultiplier(1)
        inst.components.tackler:AddWorkAction(ACTIONS.CHOP, 4)
        inst.components.tackler:AddWorkAction(ACTIONS.MINE, 2)
        inst.components.tackler:AddWorkAction(ACTIONS.HAMMER, 1)
        inst.components.tackler:SetOnCollideFn(OnTackleCollide)
        inst.components.tackler:SetOnTrampleFn(OnTackleTrample)
        inst.components.tackler:SetEdgeDistance(5)
  end

 

Edited by VenusVapor

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...