Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

Giano

Slippery items drop Chance

Recommended Posts

Giano    1

Hello everyone! 

Does anyone know where is the data located for the item drop chance when Slippery? I mean when a tool or weapon is wet and it slips out of character's hands. 

I just want to increase the drop chance of Slippery items. 

I checked some files but I can't find the data in any of them.  

Thanks 

Share this post


Link to post
Share on other sites
Ultroman    619

All items equipped in the hand-slot become slippery when wet (there may be exceptions, though). Unless I'm missing something, there is no such thing as "Slippery items". Also, where do these "slippery items" you're talking about drop from? If a hand-slot item drops in a monster while it's raining, it'll be/get wet. What exactly are you looking to do?

Share this post


Link to post
Share on other sites
Giano    1

Thanks for the reply. I knew all of that, but when the tool or weapon in the hand slot becomes Slippery (after becoming wet) sometimes it will "drop" itself on the ground. It will literally slips out of the character's hand randomly. 

I just want to increase this random drop when the item is Slippery (wet) 

Share this post


Link to post
Share on other sites
bizziboi    1,929

Hmmm, glancing at the code, It happens from the OnWork function in player_common.lua, but it seems some gymnastics may be needed to tweak that.

Share this post


Link to post
Share on other sites
Giano    1

Thanks a lot, I forgot to check that. I will try to fiddle with it. Hopefully is the right one. Not very good at this kind of gymnastics

Share this post


Link to post
Share on other sites
Ultroman    619

EDIT: I misunderstood the OP. This code will make the player character never have tools or weapons slip from their hands!

NOTE: This approach does NOT work for DST, since it doesn't use the "notslippery" tag.

Well, the places in which it drops slippery weapons and tools, it does this sort of check

if not weapon:HasTag("notslippery") then
	DropItem(inst, data.target, weapon)
	--Lock out from picking up for a while?
end

So, we can listen for the "equip" event, which is pushed like this

self.inst:PushEvent("equip", {item=item, eslot=eslot})

Check whether the eslot is EQUIPSLOT.HANDS, and if it is, you add the tag and a little variable letting us know that we edited the item:

inst:ListenForEvent("equip", function(inst, data)
	if data.eslot == EQUIPSLOT.HANDS then
		local item = data.item
		if not item:HasTag("notslippery") then
			item.ieditedthisitem = true
			item:AddTag("notslippery")
		end
	end
end)

We do the same for the "unequip" event, which is pushed like this:

self.inst:PushEvent("unequip", {item=item, eslot=equipslot, slip = slip})

So, we can listen for the unequip event, where you reset the weapon if we edited it when it was equipped:

inst:ListenForEvent("unequip", function(inst, data)
	if item.ieditedthisitem then
		item:RemoveTag("notslippery")
		item.ieditedthisitem = nil
	end
end)

 

Share this post


Link to post
Share on other sites
Giano    1

Thanks ultroman the tacoman! (love your mods by the way). I'm trying to make the rain a bit more unforgiving so that the Slippery chance is much higher than the default one. I will see if I manage somehow 

Share this post


Link to post
Share on other sites
Ultroman    619
15 hours ago, Giano said:

Thanks ultroman the tacoman! (love your mods by the way).

Thank you! :) That means a lot!

15 hours ago, Giano said:

I'm trying to make the rain a bit more unforgiving so that the Slippery chance is much higher than the default one. I will see if I manage somehow 

Oh, woops. I completely misunderstood what you wanted, then. Now that I read it again, I don't know how I got the idea that you wanted to remove the slipperyness.

I mean...you COULD always make your own extra function which drops the item, when the "working" event is triggered. Basically copy the game code, make sure to check that the item is still being held, and then do another RNG check.

This code is basically a copy of the original game code, but I renamed the functions to clarify that we won't be overwriting anything. Since OnWork also calls the local function DropItem, I had to copy that one, as well. This means, that if Klei updates the game and changes this part of the code, then you should also make the same changes in your mod. Just a heads-up. Since we're not overwriting anything, your mod probably won't break, but keep an eye on it. 

Anyway, this means that with this code, you give the player DOUBLE the chance of the item slipping from their hands. You can change the easing however you want to change that.

Put this in your character prefab Lua file. Make sure to put that last line into the postinit function, usually named fn().

local function MyDropItem(inst, target, item)
	inst.components.inventory:Unequip(EQUIPSLOTS.HANDS, true)
	inst.components.inventory:DropItem(item)
	if item.Physics then
		local x, y, z = item:GetPosition():Get()
		y = .3
		item.Physics:Teleport(x,y,z)

		local hp = target:GetPosition()
		local pt = inst:GetPosition()
		local vel = (hp - pt):GetNormalized()
		local speed = 3 + (math.random() * 2)
		local angle = -math.atan2(vel.z, vel.x) + (math.random() * 20 - 10) * DEGREES
		item.Physics:SetVel(math.cos(angle) * speed, 10, math.sin(angle) * speed)
		inst.components.talker:Say(GetString(inst.prefab, "ANNOUNCE_TOOL_SLIP"))
	end
end

local function MyOnWork(inst, data)
	--Tool slip.
	local m = inst.components.moisture

	if m:GetSegs() < 4 then
		return
	end

	local mm = GetWorld().components.moisturemanager
	local tool = inst.components.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
	if tool and mm:IsEntityWet(tool) and math.random() < easing.inSine(m:GetMoisture(), 0, 0.15, m.moistureclamp.max)  then
		if not tool:HasTag("notslippery") then
			MyDropItem(inst, data.target, tool)
		end
	end
end

-- then in your character prefab fn()
inst:ListenForEvent("working", MyOnWork)

 

Share this post


Link to post
Share on other sites
Giano    1

Sorry for my ignorance but I find hard to see which line of code you mean that should be DOUBLE the drop chance. I thought it was this one 

if tool and mm:IsEntityWet(tool) and math.random() < easing.inSine(m:GetMoisture(), 0, 0.15, m.moistureclamp.max)

But it is exactly the same as the original... 

Share this post


Link to post
Share on other sites
Ultroman    619
1 hour ago, zetake said:

Maybe that's the point...

2 same function = 2x chance...

Exactly. The original function runs as it usually does, and your code runs immediately after it, and since it's currently the same values, that makes it effectively double the chance of the item slipping out of your character's hands.

Share this post


Link to post
Share on other sites