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

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


 1
 2二二四.我是龙卷风(按键盘U键主角变身龙卷风,掠过之处尽毁,敌人靠近会被冻伤,再按U键变回人
 3
 4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/player_common.lua文件,在inst:AddComponent("playercontroller")的下一行插入以下内容:
 5
 6TheInput:AddKeyUpHandler(KEY_U, function()
 7	if not inst:HasTag("windman") then
 8	   inst.components.locomotor:Stop()
 9	   inst.components.playercontroller:Enable(false)
10	   inst.AnimState:PlayAnimation("idle_shiver_pre")
11	   inst.AnimState:PushAnimation("idle_shiver_loop")
12	   inst.AnimState:PushAnimation("idle_shiver_pst", false)
13	   GetPlayer().SoundEmitter:PlaySound("dontstarve_DLC001/creatures/glommer/foot_ground")
14	   inst:DoTaskInTime(0.3, function() 
15		   inst:AddTag("windman")
16		   inst.AnimState:SetBank("tornado")
17		   inst.AnimState:SetBuild("tornado")
18		   inst:SetStateGraph("SGtornado")
19		   inst.AnimState:PlayAnimation("tornado_pre")
20		   inst.AnimState:PushAnimation("tornado_loop")
21		   inst.Transform:SetScale(1.8,1.8,1.8)
22		   local light = inst.entity:AddLight()
23		   light:SetIntensity(.8)
24		   light:SetRadius(10)
25		   light:SetFalloff(.6)
26		   light:Enable(true)
27		   light:SetColour(255/255,255/255,255/255)
28		   inst.components.locomotor.walkspeed = 20
29		   inst.components.locomotor.runspeed = 30
30		   inst.components.health:SetInvincible(true)
31		   inst.components.hunger:Pause()
32		   inst.components.temperature:SetTemp(20)
33		   inst.Physics:SetCollisionCallback(function(inst, other)
34			   if other and other.components.health and other.components.combat then
35				  if other.components.combat.target == GetPlayer() or GetPlayer().components.combat.target == other or other:HasTag("monster") then
36					 other.components.health:DoDelta(-100)
37					 if other.components.freezable then
38						other.components.freezable:AddColdness(10)
39						other.components.freezable:SpawnShatterFX()
40					 end
41				  end
42			   end
43			   if other and other.components.workable and other.components.workable.workleft > 0 then
44				  GetPlayer().SoundEmitter:PlaySound("dontstarve_DLC001/creatures/glommer/foot_ground")
45				  other.components.workable:Destroy(inst)
46			   end
47		   end )
48		   inst.components.playercontroller:Enable(true)
49	   end )
50	else
51		inst.components.locomotor:Stop()
52		inst.components.playercontroller:Enable(false)
53		GetPlayer().SoundEmitter:PlaySound("dontstarve_DLC001/creatures/glommer/foot_ground")
54		inst.AnimState:PlayAnimation("tornado_pst")
55		inst:DoTaskInTime(0.3, function()
56			inst:RemoveTag("windman")
57			inst.AnimState:SetBank("wilson")
58			inst.AnimState:SetBuild(name)
59			inst:SetStateGraph("SGwilson")
60			inst.AnimState:PlayAnimation("idle")
61			inst.Transform:SetScale(1,1,1)
62			inst.Light:Enable(false)
63			inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
64			inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
65			inst.components.health:SetInvincible(false)
66			inst.components.hunger:Resume()
67			inst.components.temperature:SetTemp(nil)
68			inst.Physics:SetCollisionCallback( nil )
69			inst.components.playercontroller:Enable(true)
70		end )
71	end
72end )
73
74	即可按键盘U键,主角变身龙卷风,掠过之处一切建筑、植物尽毁,敌人靠近将被冻伤。龙卷风可夜视,不会饥饿,且锁血,去席卷大陆吧。再次按键盘U键可变回人