IC Grundeinstellung LUA

  • Hallo LS Freunde,


    ich habe ein Problem ich möchte Allrad via IC Steuern.


    So XML Einträge moddesc habe ich schon drin nun muss ich ja in der ICButten.lua sagen was der butten machen soll aber ich kann ihn ig nicht betätigen. die beschreibung im hilfefenster von ic habe ich aber der rest nicht



    hier mal der ausschnit aus der LUA


    function Button:doAction(noEventSend)
    if self.vehicle ~= nil then
    if self.event == "toggleMotorIgnition" then
    if self.vehicle.isMotorStarted then
    self.vehicle:invokeIgnition(false, noEventSend);
    else
    self.vehicle:invokeIgnition(true, noEventSend);
    end;
    end;
    if self.event == "toggleAllradV2" then
    if self.vehicle ~= nil then
    if self.vehicle.B3.wl then
    self.vehicle:setState("AllradV2", false);
    else
    self.vehicle:setState("AllradV2", true);
    end;
    end;
    if self.event == "toggleBeaconLights" then
    if self.vehicle ~= nil then
    if self.vehicle.beaconLightsActive then
    self.vehicle:setBeaconLightsVisibility(false);
    else
    self.vehicle:setBeaconLightsVisibility(true);
    end;
    end;
    end;
    end;
    end;
    end;

  • Hey,


    also als erstes solltest du die "Lua Quellcode"-Funktion nutzen, da es einfach bekannter und übersichtlicher aussieht.


    Zu deinem eigentlichen Problem hätte ich eine Frage. Was genau soll denn passieren, wenn du den Knopf gedrückt hast? Im Moment sieht es nämlich so aus, dass du das BELV3 ansprichst und somit nicht zu du deinem gewünschten Ergebnis kommst.


    Sofern es ein eigenständiges Script ist, bzw. das bereits bekannte, musst du mal schauen, ob es eine Funktion oder eine Variable gibt, die das Allrad ein- und ausschaltet.
    Diese müsstest du dann hier posten, damit man das IC dementsprechend abändern kann ;)


    MfG

  • Also der Butten soll Allrad an u. Allrad aus Können


    Allrad LUA
    [lua]
    --
    -- AllradV2
    -- Specialization for Allrad
    --
    -- by modelleicher
    -- http://www.schwabenmodding.bplaced.net
    -- MP Fähig!



    AllradV2 = {};


    function AllradV2.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(Motorized, specializations);
    end;


    function AllradV2:load(xmlFile)


    self.allradState = AllradV2.allradState;


    self.AllradV2Active = false;

    self.wellenCount = Utils.getNoNil(getXMLInt(xmlFile, "vehicle.Allradwellen.Wellen#count"), 0);
    self.Wellen = {}
    if self.wellenCount ~= 0 and self.wellenCount ~= nil then
    for i=1, self.wellenCount do
    local Welle = string.format("vehicle.Allradwellen.Welle%d", i)
    self.Wellen[i] = Utils.indexToObject(self.rootNode, getXMLString(xmlFile, Welle .. "#index"));
    end;
    end;
    self.hudAllradPosX = 0.65;
    self.hudAllradWidth = 0.08;
    self.hudAllradPosY = 0.13;
    self.hudAllradHeight = 0.08;
    self.infoPanelAllradONPath = Utils.getFilename("AllradON.png", self.baseDirectory);
    self.hudAllradONOverlay = Overlay:new("hudAllradOverlayON", self.infoPanelAllradONPath, self.hudAllradPosX, self.hudAllradPosY, self.hudAllradWidth, self.hudAllradHeight);
    self.infoPanelAllradOFFPath = Utils.getFilename("AllradOFF.png", self.baseDirectory);
    self.hudAllradOFFOverlay = Overlay:new("hudAllradOverlayOFF", self.infoPanelAllradOFFPath, self.hudAllradPosX, self.hudAllradPosY, self.hudAllradWidth, self.hudAllradHeight);


    self.showhudAllrad = false;


    end;


    function AllradV2:delete()
    if self.hudAllradONOverlay ~= nil or self.hudAllradOFFOverlay ~= nil then
    self.hudAllradONOverlay:delete();
    self.hudAllradOFFOverlay:delete();
    end;
    end;


    function AllradV2:readStream(streamId, connection)
    self:allradState(streamReadBool(streamId), true);
    end;


    function AllradV2:writeStream(streamId, connection)
    streamWriteBool(streamId, self.AllradV2Active);
    end;


    function AllradV2:mouseEvent(posX, posY, isDown, isUp, button)
    end;
    function AllradV2:keyEvent(unicode, sym, modifier, isDown)
    end;


    function AllradV2:allradState(state, noEventSend)
    AllradStateEvent.sendEvent(self, state, noEventSend);
    self.AllradV2Active = state;
    end;


    function AllradV2:update(dt)
    if self:getIsActiveForInput() then
    if InputBinding.hasEvent(InputBinding.AllradV2) then
    self.AllradV2Active = not self.AllradV2Active;
    end;
    end;
    if self:getIsActive() then
    if self.AllradV2Active == true then
    self.showhudAllrad = true;
    self.wheels[1].driveMode =2
    self.wheels[2].driveMode =2
    self.wheels[3].driveMode =2
    self.wheels[4].driveMode =2
    else
    self.showhudAllrad = false;
    self.wheels[1].driveMode =0
    self.wheels[2].driveMode =0
    self.wheels[3].driveMode =2
    self.wheels[4].driveMode =2
    end;
    if self.wellenCount ~= 0 and self.wellenCount ~= nil then
    local getRx, getRy, getRz = getRotation(self.wheels[3].repr);
    for i=1, self.wellenCount do
    setRotation(self.Wellen[i], 0, 0, getRx);
    end;
    end;
    end;
    end;


    function AllradV2:draw()
    if self.showhudAllrad == true then
    self.hudAllradONOverlay:render();
    g_currentMission:addHelpButtonText(g_i18n:getText("AllradOFF"), InputBinding.AllradV2);
    else
    g_currentMission:addHelpButtonText(g_i18n:getText("AllradON"), InputBinding.AllradV2);
    self.hudAllradOFFOverlay:render();
    end;
    end;


    AllradStateEvent = {};
    AllradStateEvent_mt = Class(AllradStateEvent, Event);


    InitEventClass(AllradStateEvent, "AllradStateEvent");


    function AllradStateEvent:emptyNew()
    local self = Event:new(AllradStateEvent_mt );
    self.className="AllradStateEvent";
    return self;
    end;


    function AllradStateEvent:new(vehicle, state)
    self.vehicle = vehicle;
    self.state = state;
    return self;
    end;


    function AllradStateEvent:readStream(streamId, connection)
    local id = streamReadInt32(streamId);
    self.state = streamReadBool(streamId);
    self.vehicle = networkGetObject(id);
    self:run(connection);
    end;


    function AllradStateEvent:writeStream(streamId, connection)
    streamWriteInt32(streamId, networkGetObjectId(self.vehicle));
    streamWriteBool(streamId, self.state );
    end;


    function AllradStateEvent:run(connection)
    self.vehicle:allradState(self.state, true);
    if not connection:getIsServer() then
    g_server:broadcastEvent(AllradStateEvent:new(self.vehicle, self.state), nil, connection, self.object);
    end;
    end;


    function AllradStateEvent.sendEvent(vehicle, state, noEventSend)
    if noEventSend == nil or noEventSend == false then
    if g_server ~= nil then
    g_server:broadcastEvent(AllradStateEvent:new(vehicle, state), nil, nil, vehicle);
    else
    g_client:getServerConnection():sendEvent(AllradStateEvent:new(vehicle, state));
    end;
    end;
    end;


    [/lua]



    ICbutten LUA



    [lua]--
    -- InteractiveButtons
    -- Specialization for an interactive control button
    --
    -- @author Manuel Leithner (SFM-Modding)
    -- @version v2.1
    -- @date 29/08/11
    -- @history: v1.0 - Initial version
    -- v2.0 - converted to ls2011
    -- v2.1 - improvements
    --


    InteractiveButtons = {};


    function InteractiveButtons.prerequisitesPresent(specializations)
    return SpecializationUtil.hasSpecialization(InteractiveControl, specializations);
    end;


    function InteractiveButtons:load(xmlFile)


    local i=0;
    while true do
    local buttonName = string.format("vehicle.interactiveComponents.buttons.button(%d)", i);
    if not hasXMLProperty(xmlFile, buttonName) then
    break;
    end;
    local name = Utils.getNoNil(g_i18n:getText(getXMLString(xmlFile, buttonName .. "#name")), "ERROR");
    local mark = Utils.indexToObject(self.components, getXMLString(xmlFile, buttonName .. "#mark"));
    local highlight = getChildAt(mark, 0);
    local size = Utils.getNoNil(getXMLFloat(xmlFile, buttonName .. "#size"), 0.1);
    local event = getXMLString(xmlFile, buttonName .. "#event");
    local onMessage = g_i18n:getText(Utils.getNoNil(getXMLString(xmlFile, buttonName .. "#onMessage"), "ic_button_on"));
    local offMessage = g_i18n:getText(Utils.getNoNil(getXMLString(xmlFile, buttonName .. "#offMessage") , "ic_button_off"));

    local button = Button:new(nil, highlight, name, mark, size, event, self, onMessage, offMessage, self.infoBar);


    table.insert(self.interactiveObjects, button);
    i = i + 1;
    end;
    end;


    function InteractiveButtons:delete()
    end;


    function InteractiveButtons:mouseEvent(posX, posY, isDown, isUp, button)
    end;


    function InteractiveButtons:keyEvent(unicode, sym, modifier, isDown)
    end;


    function InteractiveButtons:update(dt)
    end;


    function InteractiveButtons:draw()
    end;




    --
    -- Button Class
    -- Specifies an interactive Button
    --
    -- SFM-Modding
    -- @author Manuel Leithner
    -- @date 29/08/11
    --


    Button = {};


    function Button:new(node, highlight, name, mark, size, event, vehicle, onMessage, offMessage, infobar)


    local Button_mt = Class(Button, InteractiveComponentInterface);
    local instance = InteractiveComponentInterface:new(node, highlight, name, mark, size, onMessage, offMessage, infobar, Button_mt);


    instance.vehicle = vehicle;
    instance.event = event;

    return instance;
    end;


    function Button:delete()
    InteractiveComponentInterface.delete(self);
    end;


    function Button:mouseEvent(posX, posY, isDown, isUp, button)
    InteractiveComponentInterface.mouseEvent(self, posX, posY, isDown, isUp, button);
    end;


    function Button:keyEvent(unicode, sym, modifier, isDown)
    InteractiveComponentInterface.keyEvent(self, unicode, sym, modifier, isDown);
    end;


    function Button:update(dt)
    if self.vehicle ~= nil then
    if self.event == "toggleMotorIgnition" then
    self.isOpen = self.vehicle.isMotorStarted;
    end;
    end;
    InteractiveComponentInterface.update(self, dt);
    end;


    function Button:draw()
    InteractiveComponentInterface.draw(self);
    end;


    function Button:doAction(noEventSend)
    if self.vehicle ~= nil then
    if self.event == "toggleMotorIgnition" then
    if self.vehicle.isMotorStarted then
    self.vehicle:invokeIgnition(false, noEventSend);
    else
    self.vehicle:invokeIgnition(true, noEventSend);
    end;
    end;
    if self.event == "toggleAllradV2" then
    if self.vehicle ~= nil then
    if self.vehicle.B3.wl then
    self.vehicle:setState("AllradV2", false);
    else
    self.vehicle:setState("AllradV2", true);
    end;
    end;
    end;
    end;
    end;


    function Button:onEnter(dt)
    InteractiveComponentInterface.onEnter(self, dt);
    end;


    function Button:onExit(dt)
    InteractiveComponentInterface.onExit(self, dt);
    end;


    function Button:setActive()
    InteractiveComponentInterface.setActive(self, isActive);
    end;


    function Button:setVisible(isVisible)
    InteractiveComponentInterface.setVisible(self, isVisible);
    end;[/lua]

  • Moin..


    Tausch mal diese Zeilen:
    [lua] if self.event == "toggleAllradV2" then
    if self.vehicle ~= nil then
    if self.vehicle.B3.wl then
    self.vehicle:setState("AllradV2", false);
    else
    self.vehicle:setState("AllradV2", true);
    end;
    end;
    end;[/lua]


    gegen diese:


    [lua] if self.event == "toggleAllradV2" then
    if self.vehicle ~= nil then
    if self.vehicle.AllradV2.AllradV2Active then
    self.vehicle:allradState(false, false)
    else
    self.vehicle:allradState(true, false)
    end;
    end;
    end;[/lua]


    Sollte hoffentlich funktionieren.. Hab mich noch nie mit IC beschäftigt :D



    LG

  • Hm, ich würd mal den Quellcode der Buttons.lua wiefolgt abändern ;)


    [lua]


    function Button:doAction(noEventSend)
    if self.vehicle ~= nil then
    if self.event == "toggleMotorIgnition" then
    if self.vehicle.isMotorStarted then
    self.vehicle:invokeIgnition(false, noEventSend);
    else
    self.vehicle:invokeIgnition(true, noEventSend);
    end;
    end;
    if self.event == "toggleAllradV2" then
    if self.vehicle ~= nil then
    self.vehicle:allradState(not self.vehicle.AllradV2Active, false);
    end;
    end;
    end;
    end;


    [/lua]


    Edit:


    Modelleicher war schneller :D.


    MfG

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!