Community Forum

Need help to beginner

Forum Overview >> Scripting

CategoryScripting
Created01.01.2021 11:14


Darius Smitas (piluots) 01.01.2021 11:14
function AutomaticMilkSale:sellMilk(farmID)
g_currentMission:addMoney(self:canMilkSale(farmID) * g_currentMission.economyManager:getPricePerLiter(g_fillTypeManager:getFillTypeIndexByName("milk")), farmID, MoneyType.SOLD_MILK, true);
self:canMilkSale(farmID, true);
end;

This function is a part of an automatic milk sale script that sells milk automatically every midnight. Its works pretty fine but problem is with prices. As you see price is taken frtom economy manager as i understand from filltype.xml and is static. I need that price has to be taken from sell point on map. How i must change 3 line to achieve this.

Bilbo Beutlin (BBeutlin) 01.01.2021 16:22
Since there's no extra table for sellingsStations, you need to scan the table of unloadingStations until you get the right one.

----- example code -----
for _,station in pairs(g_currentMission.storageSystem.unloadingStations) do
-- check for valid sellingStation
if station.isSellingPoint ~= nil and station.isSellingPoint == true then
-- check for valid unload
if station:getIsFillAllowedFromFarm(g_currentMission.player.farmId) then
-- now you can check the station for a certain name
if station.stationName == "THIS_NAME" then
-- get index of fillType milk
local fillTypeIndex = g_fillTypeManager:getFillTypeIndexByName("milk");
-- check for accepted fillType
if station.acceptedFillTypes[fillTypeIndex] == true then
-- you get the price with
local price = station.fillTypePrices[fillTypeIndex];

Darius Smitas (piluots) 03.01.2021 22:44
Thanks for reply i understand wath to need to do but i am very bad i lua basics an don now how to end a function:
function AutomaticMilkSale:getMilkSale(milkPrice)
for _, station in pairs(g_currentMission.storageSystem.unloadingStations) do
if station.isSellingPoint ~= nil and station.isSellingPoint == true then
if station.stationName == "MyStationName'" then
local fillTypeIndex = g_currentMission.fillTypeManager:getFillTypeByName(g_fillTypeManager:getFillTypeIndexByName("milk"));
if station.acceptedFillTypes[fillTypeIndex] == true then
local milkPrice = (station.originalFillTypePrices[fillTypeIndex] + station.fillTypePriceRandomDelta[fillTypeIndex])
* station.priceMultipliers[fillTypeIndex] * EconomyManager.getPriceMultiplier();
end
end
end
end
end

as i understad this function must be called in mu formula above but always i am getting error that lua attemt aritmeric with nil. I understand that this function is bad but not figure out, I read almost all lua manual but nothing found beacouse very small amoun of info is in my native language
if some one could help complete this funtion il be very happy, Maybe need to put somewhere return or while i dont now :((( I absolutely raw in lua but is more interesting as i try new things

Darius Smitas (piluots) 04.01.2021 16:42
SOLVED


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