Jump to content

Poisoned mushrooms


Recommended Posts

1 hour ago, makar5000 said:

I'm trying to make mod, that makes so mushrooms while eaten gives some grogginess to player, but I don't know how to make it. Can some1 help? I'll give some skins.

I can't easily access it but you sound look at functions like 'oneaten' in overal the 'eat' and there is a inst.components.groggyness:AddGroggyness( ) or something, to find the eat  stuff you might want to look into some game prefabs, if I were to guess, if you find something related to food.

sorry if I am not being straight foward here, I am not on my pc to check right now ;w;

Link to comment
Share on other sites

So, you want your character get groggy for like 5-10 seconds after eating a raw or cooked mushroom? If so then you would put this code in your mod's "modmain.lua" , hope it works for you :)!

Spoiler

AddPlayerPostInit(function(inst, data)
   inst:ListenForEvent("oneat", function(inst, data) 
      if data.food.prefab == "red_cap" and not inst:HasTag("groggy") then -- Raw Red Cap
	     inst:AddTag("groggy")
		 inst.components.locomotor:SetExternalSpeedMultiplier(inst, "groggy_penalty", .75) -- You can change it to a lower number to make even slower.
	     inst:DoTaskInTime(5, function() inst:RemoveTag("groggy") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "groggy_penalty") end) -- You can change "5" to a shorter or longer number then stays groggy longer.
      elseif data.food.prefab == "red_cap_cooked" and not inst:HasTag("groggy") then -- Cooked Red Cap
	     inst:AddTag("groggy")
		 inst.components.locomotor:SetExternalSpeedMultiplier(inst, "groggy_penalty", .75)
	     inst:DoTaskInTime(5, function() inst:RemoveTag("groggy") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "groggy_penalty") end)
	  elseif data.food.prefab == "green_cap" and not inst:HasTag("groggy") then -- Green Cap
	     inst:AddTag("groggy")
		 inst.components.locomotor:SetExternalSpeedMultiplier(inst, "groggy_penalty", .75)
	     inst:DoTaskInTime(5, function() inst:RemoveTag("groggy") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "groggy_penalty") end)
	  elseif data.food.prefab == "green_cap_cooked" and not inst:HasTag("groggy") then -- Cooked Green Cap
	     inst:AddTag("groggy")
		 inst.components.locomotor:SetExternalSpeedMultiplier(inst, "groggy_penalty", .75)
	     inst:DoTaskInTime(5, function() inst:RemoveTag("groggy") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "groggy_penalty") end)
	  elseif data.food.prefab == "blue_cap" and not inst:HasTag("groggy") then -- Blue Cap
	     inst:AddTag("groggy")
		 inst.components.locomotor:SetExternalSpeedMultiplier(inst, "groggy_penalty", .75)
	     inst:DoTaskInTime(5, function() inst:RemoveTag("groggy") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "groggy_penalty") end)
	  elseif data.food.prefab == "blue_cap_cooked" and not inst:HasTag("groggy") then -- Cooked Blue Cap
	     inst:AddTag("groggy")
		 inst.components.locomotor:SetExternalSpeedMultiplier(inst, "groggy_penalty", .75)
	     inst:DoTaskInTime(5, function() inst:RemoveTag("groggy") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "groggy_penalty") end)
      end
   end)
end)

 

 

Edited by SuperDavid
Link to comment
Share on other sites

@SuperDavid:
I guess this code would work, but I think it is better to use the already existing "grogginess" component, instead of simulating it with changing the speed and such things ;)
So simply use something like:
 

if player.components.grogginess then -- usually every character already has the grogginess component, set in "player_common.lua"
    player.components.grogginess:AddGrogginess(grogginess, knockoutduration) -- put some values here
end



And instead of modding every character, you could also mod the mushrooms itself... not sure what the better way would be. And don't know out of the box what function in mushroom is called when mushroom is eaten and if you can add stuff there, or only overwrite... so maybe it is really better to mod characters.

 

Edited by Serpens
Link to comment
Share on other sites

@makar5000 Never mind the other code I gave, I think this one would be better so use it instead :)!

You put it in your mod is "modmain.lua"

Spoiler

local function Make_Groggy(inst)
   local random_grog_strengh = math.random(1,3)
   inst:AddTag("groggy")
   
   if random_grog_strengh == 1 then
      inst.components.locomotor:SetExternalSpeedMultiplier(inst, "groggy_penalty", .65)
      inst:DoTaskInTime(7.5, function() inst:RemoveTag("groggy") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "groggy_penalty") end)
   elseif random_grog_strengh == 2 then
      inst.components.locomotor:SetExternalSpeedMultiplier(inst, "groggy_penalty", .75)
      inst:DoTaskInTime(5, function() inst:RemoveTag("groggy") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "groggy_penalty") end)
   elseif random_grog_strengh == 3 then
      inst.components.locomotor:SetExternalSpeedMultiplier(inst, "groggy_penalty", .85)
      inst:DoTaskInTime(2.5, function() inst:RemoveTag("groggy") inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "groggy_penalty") end)
   end

end

AddPlayerPostInit(function(inst, data)

   inst:ListenForEvent("oneat", function(inst, data)
   
      if not data.food.prefab == "red_cap" or not data.food.prefab == "red_cap_cooked" or not data.food.prefab == "green_cap" or not data.food.prefab == "green_cap_cooked" or not data.food.prefab == "blue_cap" or not data.food.prefab == "blue_cap_cooked" or inst:HasTag("groggy") then
         return
      end
   
      if data.food.prefab == "red_cap" or data.food.prefab == "red_cap_cooked" or data.food.prefab == "green_cap" or data.food.prefab == "green_cap_cooked" or data.food.prefab == "blue_cap" or data.food.prefab == "blue_cap_cooked" and not inst:HasTag("groggy") then
         Make_Groggy(inst)
      end
   end)
   
end)

 

What it does is whenever a character eats a mushroom if they're not already groggy they will become groggy for either 2.5 sec, 5 sec or 7.5 sec, so it's less boring & more fun that way, I think :D!

Edited by SuperDavid
Link to comment
Share on other sites

My version of the code using @Serpens suggestion and a 'random' factor from @SuperDavid's latest reply.

local grogginess =
{
	2.5,
	5,
	7.5,
}

local function oneat(inst)
	inst.components.grogginess:AddGrogginess(grogginess[math.random(1,3)])
end

local foods =
{
	['blue_cap'] = true,
	['blue_cap_cooked'] = true,
	['green_cap'] = true,
	['green_cap_cooked'] = true,
	['red_cap'] = true,
	['red_cap_cooked'] = true,
}

AddPlayerPostInit(function(inst, data)
	inst:ListenForEvent("oneat", function(inst, data)
		if foods[data.food.prefab] and not inst:HasTag('groggy') then
			oneat(inst)
		end
	end)
end)

This can also be expanded by adding by adding new prefabs to the foods table.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...