Habe folgendes Problem und zwar will ich den Betriebsstundenzähler in die Standardfahrzeuge einbauen. In Modfahrzeugen funktioniert er einwandfrei wen ich ihn von Hand einbaue, aber mit dem Script funktionierts nich. Weis aber jetz auch nich wo der Fehler liegt??
Hier einmal die lua zum hinzufügen:
[lua]SpecializationUtil.registerSpecialization("operatingHours", "operatingHours", g_currentModDirectory .. "operatingHours.lua")
function add_operatingHours()
for _, v in pairs(VehicleTypeUtil.vehicleTypes) do
if v ~= nil then
for i = 1, table.maxn(v.specializations) do
local vs = v.specializations[i];
if vs ~= nil and vs == SpecializationUtil.getSpecialization("steerable") then
if not SpecializationUtil.hasSpecialization(operatingHours, v.specializations) then
table.insert(v.specializations, SpecializationUtil.getSpecialization("operatingHours"));
print("adding operatingHours to: "..tostring(v.name))
end
end;
end;
end;
end;
end;
add_operatingHours();[/lua]
und hier die eig Betriebsstundenzähler lua:
[expander]
[lua]operatingHours = {};
function operatingHours.prerequisitesPresent(specializations)
return SpecializationUtil.hasSpecialization(Motorized, specializations);
end;
function operatingHours:load(xmlFile)
self.addOperatingTime = SpecializationUtil.callSpecializationsFunction("addOperatingTime");
self.operatingTime = 0;
self.ohX = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.operatingHours#posX"), 0.7613);
self.ohY = Utils.getNoNil(getXMLFloat(xmlFile, "vehicle.operatingHours#posY"), 0.1855);
self.yOffset = 0.01;
--self.ohOverlay = Overlay:new("hudOHOverlay", Utils.getFilename("operatingHours_hud.png", g_modsDirectory.."/ZZZ_operatingHours/"), self.ohX, self.ohY, 0.11855, 0.039525);
end;
function operatingHours:delete()
end;
function operatingHours:readStream(streamId, connection)
self:addOperatingTime(streamReadFloat32(streamId), true);
end;
function operatingHours:writeStream(streamId, connection)
streamWriteFloat32(streamId, self.operatingTime);
end;
function operatingHours:mouseEvent(posX, posY, isDown, isUp, button)
end;
function operatingHours:keyEvent(unicode, sym, modifier, isDown)
end;
function operatingHours:update(dt)
end;
function operatingHours:updateTick(dt)
if self:getIsActive() or self.isHired then
self:addOperatingTime(dt);
end;
end;
function operatingHours:draw()
local operatingHours = math.floor((self.operatingTime / 1000 / 60 / 60)*10) / 10;
local hours = math.floor(operatingHours);
local minutes = tostring(math.floor((operatingHours - hours)*10));
--self.ohOverlay:render();
setTextAlignment(RenderText.ALIGN_RIGHT);
setTextBold(true);
setTextColor(0.1,0.1,1,1);
renderText(self.ohX+0.062, self.ohY+self.yOffset, 0.022, tostring(hours) .. ".");
--setTextColor(0.95,0,0,1);
renderText(self.ohX+0.071, self.ohY+self.yOffset, 0.023, minutes);
renderText(self.ohX+0.08, self.ohY+self.yOffset, 0.023, "h");
setTextColor(1,1,1,1);
setTextAlignment(RenderText.ALIGN_LEFT);
end;
function operatingHours:addOperatingTime(addTime)
local time = math.max(Utils.getNoNil(addTime, 0), 0);
self.operatingTime = self.operatingTime + time;
if self.operatingTime > (99999.9 * 1000 * 60 * 60) then
self.operatingTime = 0;
end;
end;
function operatingHours:loadFromAttributesAndNodes(xmlFile, key, resetVehicles)
if not resetVehicles then
local operatingTime = Utils.getNoNil(getXMLFloat(xmlFile, key .. "#operatingTime"), self.operatingTime) * 1000;
self:addOperatingTime(operatingTime);
end;
return BaseMission.VEHICLE_LOAD_OK;
end;
function operatingHours:getSaveAttributesAndNodes(nodeIdent)
local attributes = 'operatingTime="' .. tostring((self.operatingTime / 1000)) ..'"';
return attributes, nil;
end;[/lua]
[/expander]