Don't Starve

Don't Starve

[Bulingbuling]不灵小姐似乎在绝赞遇难中
1.33版本自动萃取机不能接受自动流水线输入的可选处理方案
之前我在留言区断断续续发过一次,现在我才发现steam有这样一个讨论功能,可以发长文本,于是决定再发一次。我通过一点简单的代码修改解决了自动萃取器不能自动化输入的问题,仅做参考:
分析:通过游玩,我发现自动萃取器不能自动化无非就两个问题:(1).不能像传送带那样整齐地排列(2).不能接受自动机械臂的输入。依次解决就好了。
1.打开该mod下的scripts\prefabs\buling_item.lua文件,找到两个function: ronglu2itemfn和buling_chuansongdai_itemfn,将buling_chuansongdai_itemfn对应的函数块移动到ronglu2itemfn函数块的前面来; 然后修改ronglu2itemfn内的local inst = boxitem(inst)为local inst = buling_chuansongdai_itemfn(inst)
(这样就解决了第一个问题了,记得保存)

2.打开该mod下的scripts\prefabs\buling_item.lua文件,找到这个ronglufn2函数块,将其整体替换为下面的代码:
local function anglejiaozheng(angle)
if angle > 360 then
angle = angle - 360
elseif angle <= 0 then
angle = angle + 360
end
return angle
end
local function Onpick(item)
if item.buling_chuansongdai then
item.buling_chuansongdai:Cancel()
item.buling_chuansongdai = nil
end
end
local function OnGetItemFromPlayer(inst, giver, item)
if not inst.components.container.slots[1] or (inst.components.container.slots[1].stackable and item.components.stackable:StackSize() > 1 and inst.components.container.slots[1].prefab == item.prefab) then
inst.components.container:GiveItem(item, 1)

else
item.Transform:SetPosition(inst.Transform:GetWorldPosition())
inst:RemoveEventCallback("onpickup", Onpick, item)
if item.buling_chuansongdai then
item.buling_chuansongdai:Cancel()
item.buling_chuansongdai = nil
end
item:ListenForEvent("onpickup",Onpick,item)
item.buling_chuansongdai = item:DoTaskInTime(0.5,function()
local pos = inst:GetPosition()
local ents = TheSim:FindEntities(pos.x,0, pos.z, 1, nil, {"FX", "DECOR", "INLIMBO"})
for k,v in pairs(ents) do
local pt = Vector3(v.Transform:GetWorldPosition())
local p_angle = inst:GetAngleToPoint(pt:Get())
if p_angle <= 0 then
p_angle = p_angle + 360
elseif p_angle > 360 then
p_angle = p_angle - 360
end
if p_angle < 45 then p_angle = 0
elseif p_angle < 145 then p_angle = 90
elseif p_angle < 225 then p_angle = 180
elseif p_angle < 360 then p_angle = 270
end
if inst.angle == p_angle and v.angle and v~= inst then
v.components.trader:AcceptGift(inst,item)
break
elseif inst.prefab == "buling_jixiebi" and inst.angle == p_angle and v~= inst and v.components.container and not v.components.container:IsFull() then
v.components.container:GiveItem(item)
else
print(v,p_angle)
end
end
end)
end
end
local function buling_chuansongdai(inst)
local slotpos = {Vector3(0,0,0)}
local inst = CreateEntity()
inst.entity:AddTransform()
inst.entity:AddSoundEmitter()
inst.entity:AddAnimState()
--MakeObstaclePhysics(inst, .5)
inst:AddComponent("inspectable")
-- inst.AnimState:SetBank("buling_box")
-- inst.AnimState:SetBuild("buling_box")
-- inst.AnimState:PlayAnimation("chuansongdai")

inst.pos = Vector3(inst.Transform:GetWorldPosition())
inst.angle = anglejiaozheng(inst:GetAngleToPoint(inst.pos:Get()))
inst.Transform:SetRotation(inst.angle)
inst.beeritem = "buling_chuansongdai_item"
inst.components.inspectable.getstatus = function(inst,viewer)
inst.angle = math.floor(inst.angle + 90)
inst.angle = anglejiaozheng(inst.angle)
inst.Transform:SetRotation(inst.angle)
end
inst:AddComponent("trader")
inst.components.trader.onaccept = OnGetItemFromPlayer
inst.components.trader.deleteitemonaccept = false
local function onsave(inst, data)
data.angle = inst.angle
end
local function onload (inst, data)
if data.angle then
inst.angle = data.angle
inst.Transform:SetRotation(inst.angle)
end
end
inst.OnSave = onsave
inst.OnLoad = onload
return inst
end
local function ronglufn2()
local function removesockets(inst)
if inst.dizuo then
inst.dizuo:Remove()
end
end
local function itemtest(inst, item, slot)
if slot == 1 and shaozhibiao[item.prefab] ~= nil then
return true
end
if slot == 2 then
return true
end

end
local function duidie(inst,itemname)
local item2 = inst.components.container:GetItemInSlot(2)
if item2 and item2.prefab == itemname and (item2.components.stackable and not item2.components.stackable:IsFull()) then
item2.components.stackable:SetStackSize(item2.components.stackable.stacksize+1)
else
inst.components.container:GiveItem(SpawnPrefab(itemname), 2)
end
end
local function StopAutoOutput(inst)
if inst.task then
inst.autoflag = false
inst.task:Cancel()
inst.task = nil
end
end

local function StartAutoOutput(inst)
if inst.autoflag then
return
else
inst.autoflag = true
end
inst.task = inst:DoPeriodicTask(1,function()
if not inst.components.container.slots[2] then
StopAutoOutput(inst)
return
end
local pos = inst:GetPosition()
local ents = TheSim:FindEntities(pos.x,0, pos.z, 1.5, nil, {"FX", "DECOR", "INLIMBO"})
for k,v in pairs(ents) do
if v.prefab == "buling_jixiebi" then
v.components.trader:AcceptGift(inst, inst.components.container:GetItemInSlot(2))
break
end
end
end)
end
local function zidongcuiqu(inst)
local item = inst.components.container:GetItemInSlot(1)
if item then
if shaozhibiao[item.prefab] ~= nil then
if inst.components.beerpower.power >= 10 then
local replacement = shaozhibiao[item.prefab]
if replacement then
inst.components.container:ConsumeByName(item.prefab,1)
duidie(inst,replacement)
StartAutoOutput(inst)
inst.components.beerpower:UpBeer(10)
end
end
end
end
end

local function OnOpen(inst)
GetPlayer():PushEvent("OpenBuling_cuiqu")
end
local function OnClose(inst)
GetPlayer():PushEvent("CloseBuling_cuiqu")
end
local slotpos = {Vector3(-80,0,0),Vector3(80,0,0)}
local inst = CreateEntity()
inst = buling_chuansongdai(inst)
inst.autoflag = false
inst.task = nil
inst:ListenForEvent("itemget",function(inst) if inst.components.container.slots[2] then StartAutoOutput(inst) end end)
local trans = inst.entity:AddTransform()
local anim = inst.entity:AddAnimState()
local sound = inst.entity:AddSoundEmitter()
local shadow = inst.entity:AddDynamicShadow()
shadow:SetSize(2,0.75)
inst.Transform:SetScale(.4, .4, .4)
trans:SetFourFaced()
inst.AnimState:SetBuild("buling_ronglu")
inst.AnimState:SetBank("buling_ronglu")
inst.AnimState:PlayAnimation("idle")
inst:AddComponent("inspectable")
inst:AddComponent("beerpower")
inst.components.beerpower:SetNumber(2000)
inst.displaynamefn = get_name
inst:AddComponent("container")
inst.components.container:SetNumSlots(#slotpos)
inst.components.container.widgetslotpos = slotpos
inst.components.container.widgetanimbank = "ui_chest_3x3"
inst.components.container.widgetanimbuild = "ui_chest_3x3"
inst.components.container.widgetpos = Vector3(0,200,0)
inst.components.container.side_align_tip = 100
inst.components.container.itemtestfn = itemtest
inst.components.container.onopenfn = OnOpen
inst.components.container.onclosefn = OnClose
inst.beeritem = "buling_ronglu2_item"
inst:DoPeriodicTask(5,function()zidongcuiqu(inst)end)
inst:DoTaskInTime(0,function()
inst.dizuo = SpawnPrefab("buling_fx")
inst.dizuo.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )
inst.dizuo.AnimState:SetLayer( LAYER_BACKGROUND )
inst.dizuo.AnimState:SetSortOrder(2)
inst.dizuo.AnimState:SetBank("buling_box")
inst.dizuo.AnimState:SetBuild("buling_box")
inst.dizuo.AnimState:PlayAnimation("zidonghecheng")
inst.dizuo.Transform:SetPosition(inst.Transform:GetWorldPosition()) end)
inst:ListenForEvent("onremove", removesockets)
return inst
end
< >
Showing 1-1 of 1 comments
●ω<♥♪ 7 Mar, 2021 @ 4:07am 
第二步打错了一点,打开的文件应该是buling_box.lua,手误
< >
Showing 1-1 of 1 comments
Per page: 1530 50