| Category | Scripting |
| Created | 01.10.2025 12:56 |
| John Smith (poofyswine) | 01.10.2025 12:56 |
|---|---|
| Why do these hooks not return the correct farm ID for FS25 they only ever return 0 function MoneyPause:handlePlayerFarmChange(player) if player == nil then return end local uid = player.userId or player.connectionId or tostring(player) local user = nil -- Manually search userManager for the matching user object if g_currentMission.userManager and g_currentMission.userManager.users then for _, u in pairs(g_currentMission.userManager.users) do if u.userId == player.userId then user = u break end end end local oldFarm = self.userLastFarm[uid] or 0 local newFarm = (user and user.farmId) or 0 print(string.format("[%s] Player farm changed - UID: %s | Old: %d -> New: %d", self.modName, uid, oldFarm, newFarm)) if oldFarm ~= newFarm then if oldFarm > 0 then self:_onPlayerLeftFarm(uid, oldFarm) end if newFarm > 0 then self:_onPlayerJoinedFarm(uid, newFarm) end self.userLastFarm[uid] = newFarm end end -- ==================================================================== -- JOIN/LEAVE HANDLERS -- ==================================================================== function MoneyPause:_onPlayerJoinedFarm(uid, farmId) farmId = tonumber(farmId) or 0 if farmId <= 0 then return end local prevCount = self.farmPlayerCounts[farmId] or 0 if prevCount == 0 then print(string.format("[%s] Farm %d was empty — restoring money", self.modName, farmId)) self:restoreFarmMoney(farmId) end self.farmPlayerCounts[farmId] = prevCount + 1 print(string.format("[%s] Player '%s' joined farm %d -> new count=%d", self.modName, uid, farmId, self.farmPlayerCounts[farmId])) end function MoneyPause:_onPlayerLeftFarm(uid, farmId) farmId = tonumber(farmId) or 0 if farmId <= 0 then return end local prevCount = self.farmPlayerCounts[farmId] or 1 local newCount = math.max(0, prevCount - 1) self.farmPlayerCounts[farmId] = newCount print(string.format("[%s] Player '%s' left farm %d -> new count=%d", self.modName, uid, farmId, newCount)) if newCount == 0 then print(string.format("[%s] Farm %d now empty — saving money", self.modName, farmId)) self:saveFarmMoney(farmId) end end |
|
Note: Log in to post. Create a new account here.