Jump to content

Recommended Posts

here, my prefab, can give a mod if needed

local assets={	Asset("ANIM", "anim/revolver.zip"),	Asset("ANIM", "anim/swap_revolver.zip"),	Asset("IMAGE", "images/inventoryimages/revolver.tex"),    Asset("ATLAS", "images/inventoryimages/revolver.xml"),    Asset("IMAGE", "images/inventoryimages/bullet.tex"),    Asset("ATLAS", "images/inventoryimages/bullet.xml"),}local function onequip(inst, owner)     owner.AnimState:OverrideSymbol("swap_object", "swap_revolver", "symbol0")    owner.AnimState:Show("ARM_carry")     owner.AnimState:Hide("ARM_normal")    inst.components.container:Open(owner)endlocal function onunequip(inst, owner)     owner.AnimState:Hide("ARM_carry")     owner.AnimState:Show("ARM_normal")     inst.components.container:Close(owner)endlocal function onattack(inst, attacker, target)    inst.SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")    if inst.components.container:Has("bullet", 1) then       inst.components.container:ConsumeByName("bullet", 1)    end    if Auto then    if inst.components.container:IsEmpty() then    if attacker.sg and not attacker.sg:HasStateTag("busy") then    attacker.AnimState:PlayAnimation("give")    end    inst:DoTaskInTime(0.5, function()    if attacker.components.inventory:Has("bullet", 1) then      inst.SoundEmitter:PlaySound("dontstarve/common/minerhatAddFuel")    attacker.components.inventory:ConsumeByName("bullet", 1)    inst.components.container:GiveItem(SpawnPrefab("bullet"))     end   end)  endend    if math.random() <= 0.2 then    if target.components.combat then     target.components.combat:GetAttacked(attacker, 20, nil, "revolver")    end    local pt = target:GetPosition()    attacker:StartThread(function()            for k = 1, 3 do                local blood = SpawnPrefab("splash")                blood.Transform:SetPosition(pt.x, 1.5, pt.z)                blood.AnimState:SetMultColour(255/255,0/255,0/255,1)                blood.Transform:SetScale(2, 2, 2)                Sleep(.1)            end        end)    endendlocal function onopen(inst)    inst.SoundEmitter:PlaySound("dontstarve/wilson/backpack_open", "open")endlocal function onclose(inst)    inst.SoundEmitter:PlaySound("dontstarve/wilson/backpack_close", "open")endlocal function itemtest(inst, item, slot)    return item.prefab == "bullet" endlocal slotpos = {}for y = 0, .5 do    --table.insert(slotpos, Vector3(-162, -y*75 + 114 ,0))    table.insert(slotpos, Vector3(-162 -448, -y*75 + 85 ,0))endlocal function rfn(Sim)	local inst = CreateEntity()	local trans = inst.entity:AddTransform()	local anim = inst.entity:AddAnimState()	inst.entity:AddSoundEmitter()    MakeInventoryPhysics(inst)        anim:SetBank("revolver")    anim:SetBuild("revolver")    anim:PlayAnimation("revolver")    inst.Transform:SetScale(.8, .8, .8)        inst:AddTag("sharp")    inst:AddComponent("container")    inst.components.container.itemtestfn = itemtest    inst.components.container:SetNumSlots(#slotpos)    inst.components.container.widgetslotpos = slotpos    inst.components.container.widgetpos = Vector3(0,-376,100)    inst.components.container.side_widget = true    inst.components.container.type = "equippable"    inst.components.container.onopenfn = onopen    inst.components.container.onclosefn = onclose    inst:AddComponent("weapon")    inst.components.weapon:SetDamage(36)    inst.components.weapon:SetRange(10, 12)    inst.components.weapon:SetOnAttack(onattack)    inst.components.weapon:SetProjectile("fire_projectile")    inst:AddComponent("inspectable")        inst:AddComponent("inventoryitem")    inst.components.inventoryitem.atlasname="images/inventoryimages/revolver.xml"        inst:AddComponent("equippable")    inst.components.equippable:SetOnEquip( onequip )    inst.components.equippable:SetOnUnequip( onunequip )    inst:DoPeriodicTask(.5, function()    if inst.components.equippable.isequipped then    local owner = inst.components.inventoryitem.owner    if not inst.components.container:Has("bullet", 1) then    if inst.components.weapon then    inst:RemoveComponent("weapon")    end    else    if not inst.components.weapon then    inst:AddComponent("weapon")    inst.components.weapon:SetDamage(36)    inst.components.weapon:SetRange(10, 12)    inst.components.weapon:SetOnAttack(onattack)    inst.components.weapon:SetProjectile("fire_projectile")    end   end  end end)    return instendlocal function OnIgniteFn(inst)    inst.SoundEmitter:PlaySound("dontstarve/common/blackpowder_fuse_LP", "hiss")    inst:DoTaskInTime(1.5, function() inst.Physics:SetMotorVelOverride(0,8,0) end)endlocal function OnExplodeFn(inst)    local pos = Vector3(inst.Transform:GetWorldPosition())    inst.SoundEmitter:KillSound("hiss")    inst.SoundEmitter:PlaySound("dontstarve/common/blackpowder_explo")    local explode = SpawnPrefab("explode_small")    local pos = inst:GetPosition()    explode.Transform:SetPosition(pos.x, pos.y, pos.z)    --local explode = PlayFX(pos,"explode", "explode", "small")    explode.AnimState:SetBloomEffectHandle( "shaders/anim.ksh" )    explode.AnimState:SetLightOverride(1)endlocal function bfn(Sim)    local inst = CreateEntity()    local trans = inst.entity:AddTransform()    local anim = inst.entity:AddAnimState()    inst.entity:AddSoundEmitter()    MakeInventoryPhysics(inst)        anim:SetBank("revolver")    anim:SetBuild("revolver")    anim:PlayAnimation("bullet")    --inst.Transform:SetScale(2, 2, 2)        inst:AddTag("sharp")    inst:AddComponent("inspectable")    inst:AddComponent("stackable")    inst.components.stackable.maxsize = 7    MakeSmallBurnable(inst, 3+math.random()*3)    MakeSmallPropagator(inst)        inst:AddComponent("explosive")    inst.components.explosive:SetOnExplodeFn(OnExplodeFn)    inst.components.explosive:SetOnIgniteFn(OnIgniteFn)    inst.components.explosive.explosivedamage = 25        inst:AddComponent("inventoryitem")    inst.components.inventoryitem.atlasname="images/inventoryimages/bullet.xml"    return instendreturn Prefab( "common/inventory/revolver", rfn, assets),       Prefab( "common/inventory/bullet", bfn, assets)

@OdyseyFBI, great, another thing I'm unfamiliar with x)... If I can't help you I hope someone else will...

 

Shouldn't you have this 

    if inst.components.container ~= nil then        inst.components.container:Open(owner)    end

Instead of only this

    inst.components.container:Open(owner)

? (And likewise for when the container closes)

 

I think it's that kind of problem, because what I understand from the error is that the game doesn't quite fully recognize the container. But I could be mistaken (again, I'm very unfamiliar with this ^^')

 

Hope you'll figure it out!

 

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...