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

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


 1
 2一八九.避魔圈(按键盘F9键在地上画避魔圈,任何生物靠近都将被弹开,再按F9键取消
 3
 4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/player_common.lua文件,在inst:AddComponent("playeractionpicker")的下一行插入以下内容:
 5
 6TheInput:AddKeyUpHandler(KEY_F9, function()
 7	if not inst:HasTag("havelifebuoy") then
 8	   inst:AddTag("havelifebuoy")
 9	   inst.components.locomotor:Stop()
10	   inst.AnimState:PlayAnimation("give")
11	   inst.components.health:DoDelta(-10)
12	   GetPlayer().components.playercontroller:ShakeCamera(inst, "FULL", 0.7, 0.02, .5, 40)
13	   GetPlayer().SoundEmitter:PlaySound("dontstarve_DLC001/creatures/glommer/foot_ground")
14	   SpawnPrefab("groundpoundring_fx").Transform:SetPosition(inst.Transform:GetWorldPosition())
15	   SpawnPrefab("tauntfire_fx").Transform:SetPosition(inst.Transform:GetWorldPosition())
16	   inst:DoTaskInTime(0.5, function() 
17		   local pt = inst:GetPosition()
18		   local lifebuoy = SpawnPrefab("firesuppressor_placer")
19		   lifebuoy.Transform:SetPosition(pt.x, 0, pt.z)
20		   lifebuoy.AnimState:SetOrientation( ANIM_ORIENTATION.OnGround )
21		   lifebuoy.AnimState:SetLayer( LAYER_BACKGROUND )
22		   lifebuoy.AnimState:SetSortOrder( 1 )
23		   lifebuoy.Transform:SetScale(1.1, 1.1, 1.1)
24		   lifebuoy.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
25		   lifebuoy.AnimState:SetMultColour(255/255,0/255,0/255,1)
26		   lifebuoy.persists = false
27		   lifebuoy:DoPeriodicTask(0.3, function()
28			   local pos = Vector3(lifebuoy.Transform:GetWorldPosition())
29			   local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 10)
30			   for k,v in pairs(ents) do
31				   if v.components.health and v.components.combat and not v.components.health:IsDead() and not v:HasTag("player") and not v:HasTag("wall") then
32					  GetPlayer().SoundEmitter:PlaySound("dontstarve/creatures/eyeballturret/shotexplo")
33					  SpawnPrefab("explode_small").Transform:SetPosition(v.Transform:GetWorldPosition())
34					  v.components.health:DoDelta(-200)
35					  local pt1 = lifebuoy:GetPosition()
36					  local pt2 = v:GetPosition()
37					  v.Transform:SetPosition((pt2.x-pt1.x)*1.5+pt2.x, 0, (pt2.z-pt1.z)*1.5+pt2.z)
38				   end
39			   end
40		   end )
41		   lifebuoy:AddTag("NOCLICK")
42		   lifebuoy:AddTag("lifebuoy")
43	   end )
44	else
45	   inst:RemoveTag("havelifebuoy")
46	   inst.components.locomotor:Stop()
47	   inst.AnimState:PlayAnimation("give")
48	   GetPlayer().SoundEmitter:PlaySound("dontstarve_DLC001/creatures/glommer/foot_ground")
49	   SpawnPrefab("tauntfire_fx").Transform:SetPosition(inst.Transform:GetWorldPosition())
50	   local pos = Vector3(inst.Transform:GetWorldPosition())
51	   local ents = TheSim:FindEntities(pos.x,pos.y,pos.z, 3000)
52	   for k,v in pairs(ents) do
53		   if v:HasTag("lifebuoy") then
54			  v:Remove()
55		   end
56	   end
57	end
58end )
59
60	即可按键盘F9键在地上画避魔圈,主角站在圈中,任何生物靠近都将被弹开,并杀伤其生命值,再次按键盘F9键收掉避魔圈。避魔圈是一种血魔法,每画一次,主角将消耗10点生命,在生命值较低时,请勿施法