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

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



二五三.小病小灾(主角会感冒、食物中毒,吃曼德拉草可痊愈)

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

local function OnEat(inst, food)
	if food and food.prefab ~= "mandrake" then
		if math.random()<0.1 then
		   if not inst:HasTag("poisoning") and not inst:HasTag("fever") then
			  inst:AddTag("poisoning")
			  inst.AnimState:SetMultColour(0/255,255/255,0/255,1)
			  inst.components.health:DoDelta(-inst.components.health.maxhealth*.2)
			  inst.components.sanity:DoDelta(-inst.components.sanity.max*.5)
			  inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED*.3
			  inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*.3
			  inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD*5)
			  inst.poison = inst:DoPeriodicTask(10, function()
				  inst.components.hunger:DoDelta(-20)
				  inst.components.locomotor:Stop()
				  inst.AnimState:PlayAnimation("pickup")
				  SpawnPrefab("poop").Transform:SetPosition(inst.Transform:GetWorldPosition())
			   end )
		   end
		end
	end
	if food.prefab == "mandrake" then
		if inst:HasTag("poisoning") then inst:RemoveTag("poisoning") end
		if inst:HasTag("fever") then inst:RemoveTag("fever") end
		if inst.poison then inst.poison:Cancel() inst.poison = nil end
		if inst.fever then inst.fever:Cancel() inst.fever = nil end
		inst.AnimState:SetMultColour(255/255,255/255,255/255,1)
		inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
		inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
		inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD)
	end
end
	inst.components.eater:SetOnEatFn(OnEat)
local function OnDay(inst)
	if inst:HasTag("poisoning") then
	   inst:RemoveTag("poisoning")
	   inst.AnimState:SetMultColour(255/255,255/255,255/255,1)
	   inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
	   inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
	   inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD)
	   if inst.poison then inst.poison:Cancel() inst.poison = nil end
	end
	if not inst:HasTag("fever") then
	   if math.random()<0.1 then
		  inst:AddTag("fever")
		  inst.AnimState:SetMultColour(255/255,0/255,0/255,1)
		  inst.components.sanity:DoDelta(-inst.components.sanity.max*.5)
		  inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED*.3
		  inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*.3
		  inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD*5)
		  inst.fever = inst:DoPeriodicTask(15, function()
			  inst.components.health:DoDelta(-inst.components.health.maxhealth*.05)
			  inst.components.locomotor:Stop()
			  inst.AnimState:PlayAnimation("idle_shiver_pre")
			  inst.AnimState:PushAnimation("idle_shiver_loop")
			  inst.AnimState:PushAnimation("idle_shiver_pst", false)
		  end )
	   end
	else
	   inst:RemoveTag("fever")
	   inst.AnimState:SetMultColour(255/255,255/255,255/255,1)
	   inst.components.locomotor.walkspeed = TUNING.WILSON_WALK_SPEED
	   inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED
	   inst.components.combat:SetAttackPeriod(TUNING.WILSON_ATTACK_PERIOD)
	   if inst.fever then inst.fever:Cancel() inst.fever = nil end
	end
end
	inst:ListenForEvent( "daytime", function() OnDay(inst) end, GetWorld())

	即可让游戏有更加真实的体验,主角会感冒,浑身因发烧而呈红色,行动迟缓,生命值不断下降,如不注意补血,则有生命危险。另外,在吃食物时,也有一定概率发生食物中毒,浑身呈绿色,行动迟缓,且不断出现腹泻,饥饿值下降速度加快。无论感冒还是食物中毒,只要你抗过一天,基本都能痊愈,如果服用曼德拉草,则可立即痊愈。如果修改了“小诊所”,也可以给护士5个黄金治疗疾病。不要与“伍迪吃疯肉立即变海狸且随身物品不掉落”一同修改