新手玩家

- 贡献度
- 0
- 金元
- 740
- 积分
- 14
- 精华
- 0
- 注册时间
- 2013-7-24
|
本帖最后由 fjguest 于 2014-2-27 20:14 编辑
根据易宁的修改,改了一下 二五0.智能播种机器人(将独奏乐器扔在地上自动种100棵香蕉树)的代码,让其更加简洁,并可以设定种植的横纵数量,以及横纵间距。播种时按列播种,每0.5秒播种一次。其中plantspacex为x轴的间距(也就是列与列之间的距离),plantspacez 为z轴的间距(一列中植物之间的距离),plantnumx为x轴植物数量(列数)plantnumz为z轴植物数量(行数)。这里设定的是种植20棵数(plantnumx*plantnumz)
local function ondropped(inst)
local player = GetPlayer()
local plantspacex = 3
local plantspacez = 2
local plantnumx = 5
local plantnumz = 4
if player.components.inventory:Has("goldnugget", 50) then
player.components.inventory:ConsumeByName("goldnugget", 50)
RemovePhysicsColliders(inst)
inst.name = "cave_banana_tree"
inst.components.inventoryitem.canbepickedup = false
for k = 1 ,plantnumx do
inst:DoTaskInTime(1+0.5*plantnumz*(k-1)+k-1, function()
inst.task = inst:DoPeriodicTask(0.5, function()
inst.Physics:SetMotorVelOverride((-1)^(k+1)*plantspacez,0,(-1)^(k+1)*plantspacez)
inst.Physics:ClearMotorVelOverride()
player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
SpawnPrefab(inst.name).Transform:SetPosition(inst.Transform:GetWorldPosition())
end)
end)
inst:DoTaskInTime(1+0.5*plantnumz*k+k-1, function()
if inst.task then inst.task:Cancel() inst.task = nil end
player.SoundEmitter:PlaySound("dontstarve/characters/wx78/levelup")
inst.Physics:SetMotorVelOverride(0-plantspacex,0,plantspacex)
inst.Physics:ClearMotorVelOverride()
end)
end
inst:DoTaskInTime(1+0.5*plantnumz*plantnumx+plantnumx, function()
inst.components.inventoryitem.canbepickedup = true
end)
end
end
inst:ListenForEvent("ondropped", ondropped)
|
|