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

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


  1
  2二二三.我是神龙(按键盘L键主角变身神龙,能吐火,再按L键变回人
  3
  4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/player_common.lua文件,在inst:AddComponent("playercontroller")的下一行插入以下内容:
  5
  6TheInput:AddKeyUpHandler(KEY_L, function()
  7	if not inst:HasTag("dragon") then
  8	   if inst.components.inventory:Has("goldnugget", 30) then
  9		  inst.components.inventory:ConsumeByName("goldnugget", 30)
 10		  inst.components.locomotor:Stop()
 11		  inst.components.playercontroller:Enable(false)
 12		  inst.AnimState:PlayAnimation("idle_shiver_pre")
 13		  inst.AnimState:PushAnimation("idle_shiver_loop")
 14		  inst.AnimState:PushAnimation("idle_shiver_pst", false)
 15		  inst:DoTaskInTime(1, function() 
 16			  inst:AddTag("dragon")
 17			  inst.AnimState:SetBank("krampus")
 18			  inst.AnimState:SetBuild("krampus_build")
 19			  inst:SetStateGraph("SGkrampus")
 20			  inst.AnimState:PlayAnimation("idle", true)
 21			  inst.AnimState:Hide("SACK")
 22			  inst.AnimState:Show("ARM")
 23			  inst.Transform:SetScale(1.8,1.8,1.8)
 24			  shadow:SetSize( 6, 3.5 )
 25			  local light = inst.entity:AddLight()
 26			  light:SetIntensity(.8)
 27			  light:SetRadius(20)
 28			  light:SetFalloff(.6)
 29			  light:Enable(true)
 30			  light:SetColour(255/255, 0/255, 0/255)
 31			  inst.components.locomotor.walkspeed = 10
 32			  inst.components.locomotor.runspeed = 15
 33			  local pos = GetPlayer():GetPosition()
 34			  GetSeasonManager():DoLightningStrike(pos)
 35			  inst.components.health:SetInvincible(true)
 36			  inst.components.hunger:Pause()
 37			  inst.components.combat:SetDefaultDamage(500)
 38			  inst.components.combat.hiteffectsymbol = "krampus_torso"
 39			  local pearl = SpawnPrefab("dragonfruit")
 40			  pearl.entity:AddSoundEmitter()
 41			  RemovePhysicsColliders(pearl)
 42			  pearl:AddTag("projectile")
 43			  pearl:AddTag("pearl")
 44			  pearl:RemoveComponent("edible")
 45			  pearl:RemoveComponent("stackable")
 46			  pearl:RemoveComponent("tradable")
 47			  pearl:RemoveComponent("perishable")
 48			  pearl:RemoveComponent("cookable")
 49			  pearl:RemoveComponent("bait")
 50			  pearl:RemoveComponent("plantable")
 51			  pearl:RemoveComponent("burnable")
 52			  pearl:RemoveComponent("propagator")
 53			  pearl:AddComponent("burnable")
 54			  pearl.components.burnable:SetFXLevel(3)
 55			  pearl.components.burnable:AddBurnFX("character_fire", Vector3(0,0,0) )
 56			  pearl:AddComponent("weapon")
 57			  pearl.components.weapon:SetDamage(500)
 58			  pearl.components.weapon:SetRange(20, 25)
 59			  pearl:AddComponent("equippable")
 60			  pearl.components.equippable.equipslot = EQUIPSLOTS.HANDS
 61			  pearl.components.equippable:SetOnEquip(function(pearl)
 62				  pearl.components.burnable:Extinguish()
 63			  end )
 64			  pearl:AddComponent("projectile")
 65			  pearl.components.projectile:SetSpeed(50)
 66			  pearl.components.projectile:SetOnHitFn(function(pearl, owner, target)
 67				  inst.SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
 68				  SpawnPrefab("collapse_small").Transform:SetPosition(target.Transform:GetWorldPosition())
 69				  SpawnPrefab("explode_small").Transform:SetPosition(target.Transform:GetWorldPosition())
 70				  inst.components.playercontroller:ShakeCamera(inst, "FULL", 0.2, 0.02, .5, 40)
 71				  if target.components.burnable then
 72					 target.components.burnable:Ignite()
 73				  end
 74				  owner.components.inventory:Equip(pearl)
 75			  end )
 76			  pearl.components.projectile:SetOnMissFn(function(pearl, owner)
 77				  owner.components.inventory:Equip(pearl)
 78			  end )
 79			  pearl:ListenForEvent("onthrown", function(pearl)
 80				  local pt = pearl:GetPosition()
 81				  pearl.Transform:SetPosition(pt.x, 2, pt.z)
 82				  pearl.SoundEmitter:PlaySound("dontstarve/common/blackpowder_explo")
 83				  pearl.components.burnable:Ignite(true)
 84			  end )
 85			  inst.components.inventory:Equip(pearl)
 86			  inst.components.temperature:SetTemp(20)
 87			  inst.components.playercontroller:Enable(true)
 88		  end )
 89		end
 90	else
 91		inst.components.locomotor:Stop()
 92		inst.components.playercontroller:Enable(false)
 93		inst.AnimState:PlayAnimation("taunt")
 94		inst:DoTaskInTime(1, function()
 95			inst:RemoveTag("dragon")
 96			inst.AnimState:SetBank("wilson")
 97			inst.AnimState:SetBuild(name)
 98			inst:SetStateGraph("SGwilson")
 99			inst.AnimState:PlayAnimation("idle")
100			inst.Transform:SetScale(1,1,1)
101			shadow:SetSize( 1.3, .6 )
102			inst.Light:Enable(false)
103			inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
104			inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
105			local pos = GetPlayer():GetPosition()
106			GetSeasonManager():DoLightningStrike(pos)
107			inst.components.health:SetInvincible(false)
108			inst.components.hunger:Resume()
109			inst.components.combat:SetDefaultDamage(TUNING.UNARMED_DAMAGE)
110			inst.components.combat.hiteffectsymbol = "torso"
111			local pos0 = Vector3(inst.Transform:GetWorldPosition())
112			local ents = TheSim:FindEntities(pos0.x,pos0.y,pos0.z, 3000)
113			for k,v in pairs(ents) do
114				if v:HasTag("pearl") then
115				   v:Remove()
116				end
117			end
118			inst.components.temperature:SetTemp(nil)
119			inst.components.playercontroller:Enable(true)
120		end )
121	end
122end )
123
124	即可在身上有30个黄金时,按键盘L键,主角随即变身神龙,将消耗30个黄金,身上黄金数不足时不会变身。变身神龙后,自动装备龙果,对敌人按鼠标左键,可发射龙果火球,如果卸载龙果,则改为近身格斗(按Ctrl + 鼠标左键攻击,或按住F键反击),防止点燃附近植物。神龙可夜视,不会饥饿,且锁血,对地上的物品点鼠标左键可捡起。想要变回主角时,再次按键盘L键即可,龙果将消失