嘿咻嘿咻,大家好啊!作为一个超级可爱的女士玩家,我想和大家分享一下有关饥荒这一酷炫游戏里面的一个小秘密:怎样撰写清理扫帚代码!玩家清楚吗?这一超有价值的编码能够帮助玩家维持基地干净整洁,让饥荒全球变得更加美好哦!
我们应该开启饥荒的开发环境,如何合成图勒棒这样我们才能逐渐编写程序呢。在文本编辑器中创建一个新文件,然后输入下列编码:
```
local function onClean(inst, target)
if target:HasTag("messy") then
target:RemoveTag("messy")
end
end
local function onUse(inst)
local x, y, z = inst.Transform:GetWorldPosition()
local range = 3
local ents = TheSim:FindEntities(x, y, z, range, { "messy" })
for i, target in ipairs(ents) do
onClean(inst, target)
end
end
local function fn()
local inst = CreateEntity()
inst.entity:AddTransform()
inst:AddComponent("playeractionpicker")
inst.components.playeractionpicker:AddAction(ACTIONS.SWEEP, "Use")
inst:AddTag("cleaner")
inst:AddTag("tool")
inst:AddComponent("tool")
inst.components.tool:SetAction(ACTIONS.SWEEP)
inst.components.tool:SetCanAttack(false)
inst:AddComponent("equippable")
inst.components.equippable:SetOnEquip(function() end)
inst.components.equippable:SetOnUnequip(function() end)
inst:AddComponent("inspectable")
inst:AddComponent("inventoryitem")
inst.components.inventoryitem.imagename = "clean_sweep"
inst.components.inventoryitem.atlasname = "images/inventoryimages/clean_sweep.xml"
inst:AddComponent("finiteuses")
inst.components.finiteuses:SetMaxUses(TUNING.CLEAN_SWEEP_USES)
inst.components.finiteuses:SetUses(TUNING.CLEAN_SWEEP_USES)
inst.components.finiteuses:SetOnFinished(function(inst) inst:Remove() end)
inst:AddComponent("weapon")
inst.components.weapon:SetDamage(0)
inst.components.weapon:SetRange(0)
inst.components.weapon:SetProjectile(nil)
inst:AddComponent("useableitem")
inst.components.useableitem:SetOnUseFn(onUse)
return inst
end
return Prefab("clean_sweep", fn)
```
棒极了!大家已成功撰写了清理扫帚代码!如今,我们只需保存文件,随后在游戏里建立清理扫帚物品就可以。
没多久,在饥荒的世界里,我们将要可以使用清理扫帚来维持基地干净整洁和美观。一扫就可清除所有的脏乱差,让这个世界变得更加美好!
希望大家能够喜欢这个小小的程序编写秘笈。记牢,手机游戏世界里的编程是这般有趣和有效。让我们一起享有编程的快乐吧!