local metadata = { "## Interface: 1.3.0.0PublicBeta1 1.3PublicBeta1", "## Title: FillablePalletSellTrigger2", "## Notes: Paletten verkauf mit FillTypes beschraenkung", "## Author: Marhu", "## Version: 1.0.0-23b", "## Date: 06.06.2015", "## Web: http://marhu.net" } local DebugEbene = 0; local function autor() for i=1,table.getn(metadata) do local _,n=string.find(metadata[i],"## Author: ");if n then return (string.sub (metadata[i], n+1)); end;end;end; local function name() for i=1,table.getn(metadata) do local _,n=string.find(metadata[i],"## Title: ");if n then return (string.sub (metadata[i], n+1)); end;end;end; local function version() for i=1,table.getn(metadata) do local _,n=string.find(metadata[i],"## Version: ");if n then return (string.sub (metadata[i], n+1)); end;end;end; local function support() for i=1,table.getn(metadata) do local _,n=string.find(metadata[i],"## Web: ");if n then return (string.sub (metadata[i], n+1)); end;end;end; local function Debug(printDebug,...) if printDebug <= DebugEbene then local text, TITLE, VERSION = "","","" for i = 1, select("#", ...) do if type(select(i, ...)) == "boolean" then text = text..(select(i, ...) and "true" or "false").." "; else text = text..tostring(select(i, ...) or "nil").." "; end; end print((name())..(version())..": "..text); end; end; FillablePalletSellTrigger2 = {} local FillablePalletSellTrigger2_mt = Class(FillablePalletSellTrigger2); function FillablePalletSellTrigger2.onCreate(id) g_currentMission:addNonUpdateable(FillablePalletSellTrigger2:new(id)); Debug(1,string.format("onCreate %s Id %s",getName(id),tostring(id))) end function FillablePalletSellTrigger2:new(nodeId) local self = {} setmetatable(self, FillablePalletSellTrigger2_mt) self.triggerId = nodeId addTrigger(nodeId, "triggerCallback", self) local fillTypesStr = getUserAttribute(nodeId, "fillTypes") local priceMultipliersString = getUserAttribute(nodeId, "priceMultipliers") if fillTypesStr ~= nil and fillTypesStr ~= "" then local fillTypes = Utils.splitString(" ", fillTypesStr) local multipliers = {}; if priceMultipliersString ~= nil and priceMultipliersString ~= "" then multipliers = Utils.splitString(" ", priceMultipliersString) end self.fillTypes = {} self.priceMultipliers = {} for k, v in pairs(fillTypes) do local fillType = Fillable.fillTypeNameToInt[v] if fillType ~= nil then self.fillTypes[fillType] = true; self.priceMultipliers[fillType] = tonumber((multipliers[k] or 1)) end end end return self end function FillablePalletSellTrigger2:delete() removeTrigger(self.triggerId) end function FillablePalletSellTrigger2:triggerCallback(triggerId, otherActorId, onEnter, onLeave, onStay, otherShapeId) if onEnter and otherActorId ~= 0 then local object = g_currentMission:getNodeObject(otherActorId) if object ~= nil and object:isa(FillablePallet) then Debug(1,string.format("triggerCallback %s Id %s",getName(otherActorId),tostring(otherActorId))) local fillType = object:getFillType() if self.fillTypes == nil or self.fillTypes[fillType] ~= nil then playSample(g_currentMission.cashRegistrySound, 1, 1, 0) if g_currentMission:getIsServer() then local difficultyMultiplier = 2^(3 - g_currentMission.missionStats.difficulty) local baseValue = object:getValue() local priceMultiplier = 1; if self.priceMultipliers ~= nil and self.priceMultipliers[fillType] ~= nil then priceMultiplier = self.priceMultipliers[fillType]; end; local price = baseValue*difficultyMultiplier*priceMultiplier; g_currentMission:addSharedMoney(price, "other") g_currentMission:addMoneyChange(price, FSBaseMission.MONEY_TYPE_SINGLE, true) object:delete() end end end end end g_onCreateUtil.addOnCreateFunction("FillablePalletSellTrigger2", FillablePalletSellTrigger2.onCreate); --- Log Info --- print("Script "..(name()).." v"..(version()).." by "..(autor()).." loaded! Support on "..(support()));