Community Forum

Update ownedFarmItems

Forum Overview >> Farming Simulator 19

CategoryFarming Simulator 19
Created10.01.2021 16:58

Christian (chmue) 10.01.2021 16:58
Hello everyone

I want to create a mod which enables players to sell vehicles to each other.

To test it, I changed the ownerFarmId to another farms id (for instance: g_currentMission.vehicles[1].ownerFarmId = 2).
The vehicle cannot be accessed by the original owner anymore. The new owner can access the vehicle. So the principle works.

When I open the garage menu in the store, the vehicle is still displayed in the original users garage. So I checked the owned farm items table (g_currentMission.shopController.ownedFarmItems) to find out that the vehicle is still in this table
To refresh the owned farm items table I either have to exit the game and reopen it, or join the other farm and then join the original farm again. Also when I buy a new vehicle the garage is being refreshed obviously.

I used the ConsoleHelper mod to find a function somewhere under g_currentMission.shopController which reloads the owned farm items table, but I didn't find one.
Do you know any function that does that refresh?

Thanks in advance for your help

Mike R*** (Vanguard) 11.01.2021 15:44
Cool idea, but unfortunately it's much more complicated than that. You need to handle a lot more than just changing the ownerFarmId (which you should be using the function :setOwnerFarmId(farmId) not just setting the value BTW). The vehicle is also in a number of other places, such as g_currentMission.ownedItems / leasedItems / attachables / shopMenu.shopController.ownedFarmItems etc etc etc. You also need to consider if the vehicle is attached to something else, currently controlled by someone, being used by a helper etc, and perhaps detach the vehicle or simply prevent items from being traded that are in that state. Also consider the vehicle is owned and not leased (vehicle:getPropertyState() == Vehicle.PROPERTY_STATE_OWNED)

Long story short, in a multiplayer environment, these all have to be synchronized. You'll need to create an event that would do the following:
(Not 100% sure and obviously not tested):
if g_currentMission.player.farmId == sellFromFarmId then
elseif g_currentMission.player.farmId == sellToFarmId
g_currentMission.shopMenu:updateGarageItems() <== I believe this is what you were looking for, but it only works if g_currentMission.ownedItems has already been updated via remove/addOwnedItem as above.

Good luck

Note: Log in to post. Create a new account here.