代码来源于“易宁”大佬的分享,仅供学习,不要直接复制粘贴。

原帖链接:http://bbs.3dmgame.com/thread-3859071-1-1.html



二六八.喷气虫座骑(用夏日背心种喷气虫座骑,左键点虫可骑乘,右键点主角可下来,给草让它原地等待)

	用MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/trunkvest.lua文件,在inst.AnimState:SetBuild("armor_trunkvest_summer")的下一行插入以下内容:

local function OnDeploy (inst, pt)
	local jet = SpawnPrefab("trunkvest_summer")
	jet.Transform:SetPosition(pt.x, pt.y, pt.z)
	jet.AnimState:SetBank("glommer")
	jet.AnimState:SetBuild("glommer")
	jet.AnimState:PlayAnimation("idle_loop")
	jet.Transform:SetFourFaced()
	jet.entity:AddSoundEmitter()
	local shadow = jet.entity:AddDynamicShadow()
	shadow:SetSize( 2, .75 )
	local minimap = jet.entity:AddMiniMapEntity()
	minimap:SetIcon("glommer.png")
	jet:AddComponent("named")
	jet.components.named:SetName("Glommer")
	jet:RemoveComponent("inventoryitem")
	jet:RemoveComponent("equippable")
	jet:RemoveComponent("insulator")
	jet:RemoveComponent("fueled")
	jet:RemoveComponent("waterproofer")
	jet:RemoveComponent("deployable")
	jet:AddComponent("knownlocations")
	jet:AddComponent("follower")
	jet.components.follower:SetLeader(GetPlayer())
	jet:AddComponent("lootdropper")
	jet:AddComponent("health")
	jet.components.health:SetMaxHealth(2000)
	jet:AddComponent("combat")
	jet:AddComponent("locomotor")
	jet.components.locomotor.walkspeed = 15
	jet:SetStateGraph("SGglommer")
	local brain = require "brains/chesterbrain"
	jet:SetBrain(brain)
	jet:AddComponent("trader")
	jet.components.trader:SetAcceptTest(function(jet, item)
		if not jet:HasTag("driving") then
		   if item.prefab == "cutgrass" then
			  return true
		   end
		end
		return false
	end )
	jet.components.trader.onaccept = function(jet, giver, item)
		jet.components.health:DoDelta(2000)
		if not jet:HasTag("stophere") then
		   jet:AddTag("stophere")
		   jet.components.locomotor:Stop()
		   jet:SetBrain(nil)
		   jet.components.follower:SetLeader(nil)
		else
		   jet:RemoveTag("stophere")
		   local brain = require "brains/chesterbrain"
		   jet:SetBrain(brain)
		   jet:RestartBrain()
		   jet.components.follower:SetLeader(GetPlayer())
		end
	end
	jet.components.inspectable.getstatus = function()
		if not jet:HasTag("driving") then
		   jet:AddTag("driving")
		   jet:RemoveTag("stophere")
		   jet.components.locomotor:Stop()
		   local shadow = jet.entity:AddDynamicShadow()
		   shadow:SetSize( 0, 0 )
		   jet.Physics:SetActive(false)
		   jet:SetStateGraph("SGshadowwaxwell")
		   jet:SetBrain(nil)
		   jet.components.follower:SetLeader(nil)
		   jet.AnimState:SetBank("wilson")
		   if GetPlayer().prefab == "wilson" then jet.AnimState:SetBuild("wilson") end
		   if GetPlayer().prefab == "wendy" then jet.AnimState:SetBuild("wendy") end
		   if GetPlayer().prefab == "wes" then jet.AnimState:SetBuild("wes") end
		   if GetPlayer().prefab == "wickerbottom" then jet.AnimState:SetBuild("wickerbottom") end
		   if GetPlayer().prefab == "willow" then jet.AnimState:SetBuild("willow") end
		   if GetPlayer().prefab == "wolfgang" then jet.AnimState:SetBuild("wolfgang") end
		   if GetPlayer().prefab == "wx78" then jet.AnimState:SetBuild("wx78") end
		   if GetPlayer().prefab == "woodie" then jet.AnimState:SetBuild("woodie") end
		   if GetPlayer().prefab == "waxwell" then jet.AnimState:SetBuild("waxwell") end
		   if GetPlayer().prefab == "wathgrithr" then jet.AnimState:SetBuild("wathgrithr") end
		   if GetPlayer().prefab == "webber" then jet.AnimState:SetBuild("webber") end
		   jet.AnimState:PlayAnimation("idle")
		   jet.AnimState:Hide("ARM_carry") 
		   jet.AnimState:Show("ARM_normal")
		   jet.Transform:SetRotation( 0 )
		   jet.task = jet:DoPeriodicTask(0.05, function(jet)
			   local pt1 = GetPlayer():GetPosition()
			   jet.Transform:SetPosition(pt1.x, 3.5, pt1.z)
			   jet.Transform:SetRotation(GetPlayer().Transform:GetRotation())
		   end )
		   GetPlayer().AnimState:SetBank("glommer")
		   GetPlayer().AnimState:SetBuild("glommer")
		   GetPlayer().AnimState:PlayAnimation("idle_loop")
		   GetPlayer():SetStateGraph("SGglommer")
		   local shadow = GetPlayer().entity:AddDynamicShadow()
		   shadow:SetSize( 2, .75 )
		   GetPlayer().components.locomotor.walkspeed = 25
		   GetPlayer().components.locomotor.runspeed = 25
		   GetPlayer().components.health:SetInvincible(true)
		   GetPlayer().components.hunger:Pause()
		   GetPlayer().components.temperature:SetTemp(20)
		   GetPlayer().components.playeractionpicker.leftclickoverride = function(target_ent, pos)
			   if GetPlayer().components.combat:CanTarget(target_ent) then
				  return GetPlayer().components.playeractionpicker:SortActionList({ACTIONS.LOOKAT}, target_ent, nil)
			   end
		   end
		else
		   jet:RemoveTag("driving")
		   local shadow = jet.entity:AddDynamicShadow()
		   shadow:SetSize( 2, .75 )
		   jet.Physics:SetActive(true)
		   jet.AnimState:SetBank("glommer")
		   jet.AnimState:SetBuild("glommer")
		   jet.AnimState:PlayAnimation("idle_loop")
		   jet:SetStateGraph("SGglommer")
		   local brain = require "brains/chesterbrain"
		   jet:SetBrain(brain)
		   jet:RestartBrain()
		   jet.components.follower:SetLeader(GetPlayer())
		   if jet.task then jet.task:Cancel() jet.task = nil end
		   local pt1 = GetPlayer():GetPosition()
		   jet.Transform:SetPosition(pt1.x, 0, pt1.z)
		   GetPlayer().AnimState:SetBank("wilson")
		   if GetPlayer().prefab == "wilson" then GetPlayer().AnimState:SetBuild("wilson") end
		   if GetPlayer().prefab == "wendy" then GetPlayer().AnimState:SetBuild("wendy") end
		   if GetPlayer().prefab == "wes" then GetPlayer().AnimState:SetBuild("wes") end
		   if GetPlayer().prefab == "wickerbottom" then GetPlayer().AnimState:SetBuild("wickerbottom") end
		   if GetPlayer().prefab == "willow" then GetPlayer().AnimState:SetBuild("willow") end
		   if GetPlayer().prefab == "wolfgang" then GetPlayer().AnimState:SetBuild("wolfgang") end
		   if GetPlayer().prefab == "wx78" then GetPlayer().AnimState:SetBuild("wx78") end
		   if GetPlayer().prefab == "woodie" then GetPlayer().AnimState:SetBuild("woodie") end
		   if GetPlayer().prefab == "waxwell" then GetPlayer().AnimState:SetBuild("waxwell") end
		   if GetPlayer().prefab == "wathgrithr" then GetPlayer().AnimState:SetBuild("wathgrithr") end
		   if GetPlayer().prefab == "webber" then GetPlayer().AnimState:SetBuild("webber") end
		   GetPlayer().AnimState:PlayAnimation("idle")
		   GetPlayer():SetStateGraph("SGwilson")
		   local shadow = GetPlayer().entity:AddDynamicShadow()
		   shadow:SetSize( 1.3, .6 )
		   GetPlayer().components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
		   GetPlayer().components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
		   GetPlayer().components.health:SetInvincible(false)
		   GetPlayer().components.hunger:Resume()
		   GetPlayer().components.temperature:SetTemp(nil)
		   GetPlayer().components.playeractionpicker.leftclickoverride = nil
		end
	end
	jet:AddTag("jets")
	inst:Remove()
end
	inst:AddComponent("deployable")
	inst.components.deployable.ondeploy = OnDeploy
local function onsave(inst, data)
	if inst:HasTag("jets") then
		data.jets = true
	end
	if inst:HasTag("stophere") then
		data.stophere = true
	end
end
local function onload(inst, data)
  if data and data.jets then
	inst.AnimState:SetBank("glommer")
	inst.AnimState:SetBuild("glommer")
	inst.AnimState:PlayAnimation("idle_loop")
	inst.Transform:SetFourFaced()
	inst.entity:AddSoundEmitter()
	local shadow = inst.entity:AddDynamicShadow()
	shadow:SetSize( 2, .75 )
	local minimap = inst.entity:AddMiniMapEntity()
	minimap:SetIcon("glommer.png")
	inst:AddComponent("named")
	inst.components.named:SetName("Glommer")
	inst:RemoveComponent("inventoryitem")
	inst:RemoveComponent("equippable")
	inst:RemoveComponent("insulator")
	inst:RemoveComponent("fueled")
	inst:RemoveComponent("waterproofer")
	inst:RemoveComponent("deployable")
	inst:AddComponent("knownlocations")
	inst:AddComponent("follower")
	inst.components.follower:SetLeader(GetPlayer())
	inst:AddComponent("lootdropper")
	inst:AddComponent("health")
	inst.components.health:SetMaxHealth(2000)
	inst:AddComponent("combat")
	inst:AddComponent("locomotor")
	inst.components.locomotor.walkspeed = 15
	inst:SetStateGraph("SGglommer")
	local brain = require "brains/chesterbrain"
	inst:SetBrain(brain)
	inst:AddComponent("trader")
	inst.components.trader:SetAcceptTest(function(inst, item)
		if not inst:HasTag("driving") then
		   if item.prefab == "cutgrass" then
			  return true
		   end
		end
		return false
	end )
	inst.components.trader.onaccept = function(inst, giver, item)
		inst.components.health:DoDelta(2000)
		if not inst:HasTag("stophere") then
		   inst:AddTag("stophere")
		   inst.components.locomotor:Stop()
		   inst:SetBrain(nil)
		   inst.components.follower:SetLeader(nil)
		else
		   inst:RemoveTag("stophere")
		   local brain = require "brains/chesterbrain"
		   inst:SetBrain(brain)
		   inst:RestartBrain()
		   inst.components.follower:SetLeader(GetPlayer())
		end
	end
	inst.components.inspectable.getstatus = function()
		if not inst:HasTag("driving") then
		   inst:AddTag("driving")
		   inst:RemoveTag("stophere")
		   inst.components.locomotor:Stop()
		   local shadow = inst.entity:AddDynamicShadow()
		   shadow:SetSize( 0, 0 )
		   inst.Physics:SetActive(false)
		   inst:SetStateGraph("SGshadowwaxwell")
		   inst:SetBrain(nil)
		   inst.components.follower:SetLeader(nil)
		   inst.AnimState:SetBank("wilson")
		   if GetPlayer().prefab == "wilson" then inst.AnimState:SetBuild("wilson") end
		   if GetPlayer().prefab == "wendy" then inst.AnimState:SetBuild("wendy") end
		   if GetPlayer().prefab == "wes" then inst.AnimState:SetBuild("wes") end
		   if GetPlayer().prefab == "wickerbottom" then inst.AnimState:SetBuild("wickerbottom") end
		   if GetPlayer().prefab == "willow" then inst.AnimState:SetBuild("willow") end
		   if GetPlayer().prefab == "wolfgang" then inst.AnimState:SetBuild("wolfgang") end
		   if GetPlayer().prefab == "wx78" then inst.AnimState:SetBuild("wx78") end
		   if GetPlayer().prefab == "woodie" then inst.AnimState:SetBuild("woodie") end
		   if GetPlayer().prefab == "waxwell" then inst.AnimState:SetBuild("waxwell") end
		   if GetPlayer().prefab == "wathgrithr" then inst.AnimState:SetBuild("wathgrithr") end
		   if GetPlayer().prefab == "webber" then inst.AnimState:SetBuild("webber") end
		   inst.AnimState:PlayAnimation("idle")
		   inst.AnimState:Hide("ARM_carry") 
		   inst.AnimState:Show("ARM_normal")
		   inst.Transform:SetRotation( 0 )
		   inst.task = inst:DoPeriodicTask(0.05, function(inst)
			   local pt1 = GetPlayer():GetPosition()
			   inst.Transform:SetPosition(pt1.x, 3.5, pt1.z)
			   inst.Transform:SetRotation(GetPlayer().Transform:GetRotation())
		   end )
		   GetPlayer().AnimState:SetBank("glommer")
		   GetPlayer().AnimState:SetBuild("glommer")
		   GetPlayer().AnimState:PlayAnimation("idle_loop")
		   GetPlayer():SetStateGraph("SGglommer")
		   local shadow = GetPlayer().entity:AddDynamicShadow()
		   shadow:SetSize( 2, .75 )
		   GetPlayer().components.locomotor.walkspeed = 25
		   GetPlayer().components.locomotor.runspeed = 25
		   GetPlayer().components.health:SetInvincible(true)
		   GetPlayer().components.hunger:Pause()
		   GetPlayer().components.temperature:SetTemp(20)
		   GetPlayer().components.playeractionpicker.leftclickoverride = function(target_ent, pos)
			   if GetPlayer().components.combat:CanTarget(target_ent) then
				  return GetPlayer().components.playeractionpicker:SortActionList({ACTIONS.LOOKAT}, target_ent, nil)
			   end
		   end
		else
		   inst:RemoveTag("driving")
		   local shadow = inst.entity:AddDynamicShadow()
		   shadow:SetSize( 2, .75 )
		   inst.Physics:SetActive(true)
		   inst.AnimState:SetBank("glommer")
		   inst.AnimState:SetBuild("glommer")
		   inst.AnimState:PlayAnimation("idle_loop")
		   inst:SetStateGraph("SGglommer")
		   local brain = require "brains/chesterbrain"
		   inst:SetBrain(brain)
		   inst:RestartBrain()
		   inst.components.follower:SetLeader(GetPlayer())
		   if inst.task then inst.task:Cancel() inst.task = nil end
		   local pt1 = GetPlayer():GetPosition()
		   inst.Transform:SetPosition(pt1.x, 0, pt1.z)
		   GetPlayer().AnimState:SetBank("wilson")
		   if GetPlayer().prefab == "wilson" then GetPlayer().AnimState:SetBuild("wilson") end
		   if GetPlayer().prefab == "wendy" then GetPlayer().AnimState:SetBuild("wendy") end
		   if GetPlayer().prefab == "wes" then GetPlayer().AnimState:SetBuild("wes") end
		   if GetPlayer().prefab == "wickerbottom" then GetPlayer().AnimState:SetBuild("wickerbottom") end
		   if GetPlayer().prefab == "willow" then GetPlayer().AnimState:SetBuild("willow") end
		   if GetPlayer().prefab == "wolfgang" then GetPlayer().AnimState:SetBuild("wolfgang") end
		   if GetPlayer().prefab == "wx78" then GetPlayer().AnimState:SetBuild("wx78") end
		   if GetPlayer().prefab == "woodie" then GetPlayer().AnimState:SetBuild("woodie") end
		   if GetPlayer().prefab == "waxwell" then GetPlayer().AnimState:SetBuild("waxwell") end
		   if GetPlayer().prefab == "wathgrithr" then GetPlayer().AnimState:SetBuild("wathgrithr") end
		   if GetPlayer().prefab == "webber" then GetPlayer().AnimState:SetBuild("webber") end
		   GetPlayer().AnimState:PlayAnimation("idle")
		   GetPlayer():SetStateGraph("SGwilson")
		   local shadow = GetPlayer().entity:AddDynamicShadow()
		   shadow:SetSize( 1.3, .6 )
		   GetPlayer().components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
		   GetPlayer().components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
		   GetPlayer().components.health:SetInvincible(false)
		   GetPlayer().components.hunger:Resume()
		   GetPlayer().components.temperature:SetTemp(nil)
		   GetPlayer().components.playeractionpicker.leftclickoverride = nil
		end
	end
	inst:AddTag("jets")
  end
  if data and data.stophere then
	 inst.components.locomotor:Stop()
	 inst:SetBrain(nil)
	 inst.components.follower:SetLeader(nil)
	 inst:AddTag("stophere")
  end
end
	inst.OnSave = onsave
	inst.OnLoad = onload

	即可用夏日背心种喷气虫座骑,对喷气虫点鼠标左键(手里不要拿武器)可骑乘,对主角按鼠标右键可下来。骑着喷气虫时无法战斗,但遭到攻击时不会受伤(敌人够不到你)。喷气虫会跟随你,喂它一根草(拿着草对它点鼠标左键)可让其停在原地,并同时补血,再给一根草可继续跟随。喷气虫座骑在小地图上显示为格罗门图标,不想要喷气虫座骑了,杀掉即可(按Ctrl + 鼠标左键攻击)。夏日背心在穿戴选项(画着帽子)下,用1个红色象鼻、8个蛛丝制造