But is this also possible in multiplayer where you don't know were the buildings are placed since the player choose its position for hisself.
But off course! I already expected a question like this, that's why I made the following choices in my script example, so it helps you further adjust it:
- why did I not just use 2 seperate variables to store the amount of wares? Because storing them in an array makes it easier to manage many values, for more buildings!
- why did I not just make a 'fixed' array with a length of 2, but made a 'dynamic' array with an unknown length? So you can fill it with as many values as you need, for example if you do not know in advance how many values you want to put in it!
- why did I write things like 'TIMBER = 2'? Because it makes it easier to manage your script if you want to do this for multiple kinds of resources!
Now, I know that this doesn't help you any further, but I am not going to give you
the a solution straight away (Nederlands: de oplossing aan je voorkauwen

) because this will be excellent learning material! My suggestion to tackle this problem is as follows:
1 - you figured out
the essential trick a possible approach: storing the amount of wares into something and compare them with the actual amount. If the actual amount is bigger, move something to a storehouse and update your memory.
2 - you figured out how to do this for two predefined buildings, on two predefined locations; and to move it to a predefined storehouse at a predefined location.
3 - next step: change your script so that it works without telling it manually where your sawmill and tannery is (in my example). Think about how you could get the houseIDs! You need to understand two essential things for this: how to use a 'for loop' to search in an array, and how to use States.PlayerGetAllHouses.
4 - once you figure out step 3, it will probably be very easy for you to do the trick for an unknown number of sawmills, tanneries, or any other building, with other wares of your choice.
5 - when you know how to do this for any sort of building, for any ware, then you could extend it to make it work for any player!
6 - if you know how to make it work for any player, you could now try to manipulate your script so that it also moves wares to storehouses of your allies, just like you requested in your original question!
Step 3 is by far the most difficult. Do you need help on using for loops or searching arrays?