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

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


 1
 2二五三.小病小灾(主角会感冒、食物中毒,吃曼德拉草可痊愈)
 3
 4	MT管理器打开游戏目录/assets/DLC0002/scripts/prefabs/player_common.lua文件,在inst:AddComponent("eater")的下一行插入以下内容:
 5
 6local function OnEat(inst, food)
 7	if food and food.prefab ~= "mandrake" then
 8		if math.random()<0.1 then
 9		   if not inst:HasTag("poisoning") and not inst:HasTag("fever") then
10			  inst:AddTag("poisoning")
11			  inst.AnimState:SetMultColour(0/255,255/255,0/255,1)
12			  inst.components.health:DoDelta(-inst.components.health.maxhealth*.2)
13			  inst.components.sanity:DoDelta(-inst.components.sanity.max*.5)
14			  inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED*.3
15			  inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*.3
16			  inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD*5)
17			  inst.poison = inst:DoPeriodicTask(10, function()
18				  inst.components.hunger:DoDelta(-20)
19				  inst.components.locomotor:Stop()
20				  inst.AnimState:PlayAnimation("pickup")
21				  SpawnPrefab("poop").Transform:SetPosition(inst.Transform:GetWorldPosition())
22			   end )
23		   end
24		end
25	end
26	if food.prefab == "mandrake" then
27		if inst:HasTag("poisoning") then inst:RemoveTag("poisoning") end
28		if inst:HasTag("fever") then inst:RemoveTag("fever") end
29		if inst.poison then inst.poison:Cancel() inst.poison = nil end
30		if inst.fever then inst.fever:Cancel() inst.fever = nil end
31		inst.AnimState:SetMultColour(255/255,255/255,255/255,1)
32		inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
33		inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
34		inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD)
35	end
36end
37	inst.components.eater:SetOnEatFn(OnEat)
38local function OnDay(inst)
39	if inst:HasTag("poisoning") then
40	   inst:RemoveTag("poisoning")
41	   inst.AnimState:SetMultColour(255/255,255/255,255/255,1)
42	   inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
43	   inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
44	   inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD)
45	   if inst.poison then inst.poison:Cancel() inst.poison = nil end
46	end
47	if not inst:HasTag("fever") then
48	   if math.random()<0.1 then
49		  inst:AddTag("fever")
50		  inst.AnimState:SetMultColour(255/255,0/255,0/255,1)
51		  inst.components.sanity:DoDelta(-inst.components.sanity.max*.5)
52		  inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED*.3
53		  inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*.3
54		  inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD*5)
55		  inst.fever = inst:DoPeriodicTask(15, function()
56			  inst.components.health:DoDelta(-inst.components.health.maxhealth*.05)
57			  inst.components.locomotor:Stop()
58			  inst.AnimState:PlayAnimation("idle_shiver_pre")
59			  inst.AnimState:PushAnimation("idle_shiver_loop")
60			  inst.AnimState:PushAnimation("idle_shiver_pst", false)
61		  end )
62	   end
63	else
64	   inst:RemoveTag("fever")
65	   inst.AnimState:SetMultColour(255/255,255/255,255/255,1)
66	   inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
67	   inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
68	   inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD)
69	   if inst.fever then inst.fever:Cancel() inst.fever = nil end
70	end
71end
72	inst:ListenForEvent( "daytime", function() OnDay(inst) end, GetWorld())
73
74	即可让游戏有更加真实的体验,主角会感冒,浑身因发烧而呈红色,行动迟缓,生命值不断下降,如不注意补血,则有生命危险。另外,在吃食物时,也有一定概率发生食物中毒,浑身呈绿色,行动迟缓,且不断出现腹泻,饥饿值下降速度加快。无论感冒还是食物中毒,只要你抗过一天,基本都能痊愈,如果服用曼德拉草,则可立即痊愈。如果修改了“小诊所”,也可以给护士5个黄金治疗疾病。不要与“伍迪吃疯肉立即变海狸且随身物品不掉落”一同修改