Jump to content

My whip refuses to show itself


Recommended Posts

Most things i extract with ktools comes with ease, except for this dang thing.

While it did extract succesfully(I used whip and swap_whip for extraction) my prefab file just refuses to work correctly.

Holding the whip is invisible, attacking with the whip uses the default whip sprites, the inventoryimage refuses to show in the inventory

Is it something I did wrong at extraction or is my lua file at fault here? 

(or if alternatively, if you guys have a spare whip.lua and exported whip files that actually work can you send it my way, thanks.)

Edit: Updated the file, now the inventoryimages work but me holding the weapon is invisible and still uses the default whip sprites when attacking. Im completely stump.

local assets =
{
    Asset("ANIM", "anim/ocsayakawhip.zip"),
    Asset("ANIM", "anim/swap_ocsayakawhip.zip"),
	
    Asset("ATLAS", "images/inventoryimages/ocsayakawhip.xml"),
    Asset("IMAGE", "images/inventoryimages/ocsayakawhip.tex"),
}

local function onequip(inst, owner)
    owner.AnimState:OverrideSymbol("swap_object", "ocsayakaswap_whip", "ocsayakaswap_whip")
    owner.AnimState:OverrideSymbol("ocsayakawhipline", "ocsayakaswap_whip", "ocsayakawhipline")
    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 supercrack(inst)
    local x,y,z = inst.Transform:GetWorldPosition()
    local ents = TheSim:FindEntities(x,y,z, TUNING.WHIP_SUPERCRACK_RANGE, { "_combat" }, { "player", "epic", "shadow", "shadowminion", "shadowchesspiece" })
    for i,v in ipairs(ents) do
        if v.components.combat:HasTarget() then
            v.components.combat:DropTarget()
            if v.sg ~= nil and v.sg:HasState("hit")
                and v.components.health ~= nil and not v.components.health:IsDead()
                and not v.sg:HasStateTag("transform")
                and not v.sg:HasStateTag("nointerrupt")
                and not v.sg:HasStateTag("frozen")
                --and not v.sg:HasStateTag("attack")
                --and not v.sg:HasStateTag("busy")
                then

                if v.components.sleeper ~= nil then
                    v.components.sleeper:WakeUp()
                end
                v.sg:GoToState("hit")
            end
        end
    end
end

local function onattack(inst, attacker, target)
    if target ~= nil and target:IsValid() then
        local chance =
            (target:HasTag("epic") and TUNING.WHIP_SUPERCRACK_EPIC_CHANCE) or
            (target:HasTag("monster") and TUNING.WHIP_SUPERCRACK_MONSTER_CHANCE) or
            TUNING.WHIP_SUPERCRACK_CREATURE_CHANCE

        local snap = SpawnPrefab("impact")

        local x, y, z = inst.Transform:GetWorldPosition()
        local x1, y1, z1 = target.Transform:GetWorldPosition()
        local angle = -math.atan2(z1 - z, x1 - x)
        snap.Transform:SetPosition(x1, y1, z1)
        snap.Transform:SetRotation(angle * RADIANS)

        --impact sounds normally play through comabt component on the target
        --ocsayakawhip has additional impact sounds logic, which we'll just add here

        if math.random() < chance then
            snap.Transform:SetScale(3, 3, 3)
            if target.SoundEmitter ~= nil then
                target.SoundEmitter:PlaySound("dontstarve/common/whip_large")
            end
            inst:DoTaskInTime(0, supercrack)
        elseif target.SoundEmitter ~= nil then
            target.SoundEmitter:PlaySound("dontstarve/common/whip_small")
        end
    end
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("ocsayakawhip")
    inst.AnimState:SetBuild("ocsayakawhip")
    inst.AnimState:PlayAnimation("idle")

    inst:AddTag("whip")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end
	
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "ocsayakawhip"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/ocsayakawhip.xml"

    inst:AddComponent("weapon")
    inst.components.weapon:SetDamage(40)
    inst.components.weapon:SetRange(TUNING.WHIP_RANGE * 1.25)
    inst.components.weapon:SetOnAttack(onattack)

    inst:AddComponent("finiteuses")
    inst.components.finiteuses:SetMaxUses(150)
    inst.components.finiteuses:SetUses(150)
    inst.components.finiteuses:SetOnFinished(inst.Remove)

    inst:AddComponent("inspectable")

    inst:AddComponent("equippable")
    inst.components.equippable:SetOnEquip(onequip)
    inst.components.equippable:SetOnUnequip(onunequip)

    MakeHauntableLaunch(inst)

    return inst
end

STRINGS.NAMES.OCSAYAKAWHIP = "Sayaka's Whip"
STRINGS.CHARACTERS.GENERIC.DESCRIBE.OCSAYAKAWHIP = "This will hurt."

return Prefab("ocsayakawhip", fn, assets)

 

Edited by rons0n
Link to comment
Share on other sites

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
 Share

×
  • Create New...