Jump to content

Stopping Item Transfer once the Weight Limit is reached and surpassed


Daevinski

Recommended Posts

I need to stop the item transfer from any container to the character's inventory once the inventory weight limit is reached and surpassed, but it can continue once the inventory have room. Similar to when a backpack is full and you can't add anything new, for example.

 

This is what I did so far:

 

stoptransfer = {}
stoptransfer.init = function()

    -- Stop Item Transfer if the Character's Inventory is full

    local player = getSpecificPlayer(0);
   
    if player:getInventoryWeight() > player:getMaxWeight() then

        -- Stop Transfer

    else

        -- Continue Transfer

    end

end

Events.OnRefreshInventoryWindowContainers.Add( stoptransfer.init );

 

EDIT: In this case I want to forbid only item transfer from world containers to the character's inventory. Be able to equip or drop things from the inventory or from containers inside the inventory should remain the same, with the encumbrance status as the only "penalty".

 

I believe this code is right, because I tested with AddItem and every time the weight limit was reached, an item was added to the inventory. But I'm not sure about what to put on "Stop" and "Continue" to control the transfer. I guess it's related to Timed Actions, but I'm not sure.

 

I looked online, I looked other mods... but I can't find a clear solution.

Edited by Daevinski
Link to comment
Share on other sites

Did you dig in the vanilla java & lua files to try to find the code relative to backpacks ? Because as it's the same feature you are looking for, maybe finding the code for backpacks would help you to figure it out for player inventory ?

Link to comment
Share on other sites

6 minutes ago, Asilar said:

Did you dig in the vanilla java & lua files to try to find the code relative to backpacks ? Because as it's the same feature you are looking for, maybe finding the code for backpacks would help you to figure it out for player inventory ?

 

Yes. I spent the whole day, yesterday, checking the game files and mods that maybe do something similar. The closest I got was with Timed Actions, but I only managed to disable item transfer at all, without an actual condition. lol

I think it's related to the inventory portion of the Timed Action system, because there is pieces that define source and destination containers, the player and the world, but I'm not sure how to write the correct function to achieve what I need.

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
×
×
  • Create New...