manualIgnition für alle Fahrzeuge inkl. Standardfahrzeuge

  • Servusla,


    habe letztens ein kleines Projekt aufgegriffen, an welches sich schon vor einiger Zeit der User "Donner" gewagt (allerdings nicht ganz fehlerfrei abgeschlossen) hatte.
    Es dreht sich um das manualIgnition-Skript von Templaer (multiplayer ready: Andreas Schneider, bugfixes: Mofa-Killer), welches automatisch in "alle" Fahrzeuge inklusive Standardfahrzeuge "installiert" werden soll.
    Soweit klappt alles wunderbar, das Skript wird in alle Mods die die Spezi "motorized" verwenden eingefügt.


    Allerdings möchte ich, dass das Skript nicht(!) in Fahrzeuge eingebunden wird, die das Skript manualIgnition o.ä. schon verbaut haben... bzw. die schon verbaute Spezi (eventl. ältere Version) aus dem Mod entfernen lassen. Denn wenn sie doppelt vorhanden ist, wird der Motor auf Knopfdruck ein- und gleichzeitig von der zweiten Spezi wieder ausgeschalten.


    Wie bei Courseplay, nutze ich folgende Zeilen um das Skript einzubinden:
    [lua]SpecializationUtil.registerSpecialization("manualIgnition", "manualIgnition", g_modsDirectory.."/zzz_manualMotorIgnition/manualIgnition.lua")



    print("--- manualIgnition - specialization for manual motor ignition ---");


    for k,v in pairs(VehicleTypeUtil.vehicleTypes) do
    if v~=nil then
    for a=1, table.maxn(v.specializations) do
    local s = v.specializations[a];
    if s ~= nil then
    if s == SpecializationUtil.getSpecialization("motorized") then
    print("adding manualIgnition to:"..tostring(v.name));
    table.insert(v.specializations, SpecializationUtil.getSpecialization("manualIgnition"));
    end;
    end;
    end;
    end;
    end;[/lua]


    Das Problem liegt nun darin, dass mit "SpecializationUtil.getSpecialization" an dieser Stelle anscheinend nur Standard-Spezies (hier "motorized") herausgepickt werden können. Dem Mod hinzugefügte Spezis wie z.B. "operatingHours" oder "manualIgnition" werden dadurch nicht erkannt... vielleicht werden sie nicht bzw. erst später in das table "v.specializations" eingefügt?


    Ein kleiner Test mit folgenden Zeilen soll das Problem verdeutlichen:


    [lua]SpecializationUtil.registerSpecialization("manualIgnition", "manualIgnition", g_modsDirectory.."/zzz_manualMotorIgnition/manualIgnition.lua")



    print("--- manualIgnition - specialization for manual motor ignition ---");


    for k,v in pairs(VehicleTypeUtil.vehicleTypes) do
    if v~=nil then
    for a=1, table.maxn(v.specializations) do
    local s = v.specializations[a];
    if s ~= nil then
    if s == SpecializationUtil.getSpecialization("motorized") then
    print(tostring(v.name)..": Specialization motorized is present !!!!!!!!!!");
    print("adding manualIgnition to:"..tostring(v.name));
    table.insert(v.specializations, SpecializationUtil.getSpecialization("manualIgnition"));
    end;
    if s == SpecializationUtil.getSpecialization("operatingHours") then
    print(tostring(v.name)..": Specialization operatingHours is present !!!!!!!!!!");
    end;
    if s == SpecializationUtil.getSpecialization("manualIgnition") then
    print(tostring(v.name)..": Specialization manualIgnition is present !!!!!!!!!!");
    end;
    if s == SpecializationUtil.getSpecialization("hirable") then
    print(tostring(v.name)..": Specialization hirable is present !!!!!!!!!!");
    end;
    end;
    end;
    end;
    end;[/lua]
    Wenn die Spezies motorized, operatingHours, manualIgnition und hirable in dem Fahrzeug vorhanden sind, werden die entsprechenden Zeilen beim Laden des Spiels in die Log.txt geschrieben. Der Mod ClaasAxion850v5.zip hat alle diese Spezies und folgendes steht nach dem Spielstart in meiner Log.txt:


    Zitat von Log.txt

    --- manualMotorIgnition - specialization for manual motor ignition ---
    ClaasAxion850v5.ClaasAxion850: Specialization motorized is present !!!!!!!!!!
    adding manualIgnition to:ClaasAxion850v5.ClaasAxion850
    ClaasAxion850v5.ClaasAxion850: Specialization hirable is present !!!!!!!!!!


    Da die beiden Sätze "ClaasAxion850v5.ClaasAxion850: Specialization operatingHours is present !!!!!!!!!!" und "ClaasAxion850v5.ClaasAxion850: Specialization manualIgnition is present !!!!!!!!!!" fehlen, kann ich mir das Problem nur so wie weiter oben genannt erklären.


    Kann das jemand bestätigen bzw. hat jemand von euch irgendeine Idee dazu?

  • Hi!


    Nur eine Vermutung. Hast du es mal mit dem hasSpecialization versucht?

    Code
    SpecializationUtil.hasSpecialization(ManualIgnition, specializations);


    Der geht aber glaube ich auf den Klassennamen, deshalb evtl. die andere Schreibweise beachten.

  • jup, SpecializationUtil.hasSpecialization hab ich auch schon in einigen Varianten ausprobiert... allerdings immer mit "v.specializations" anstatt nur "specializations"... werd diese Möglichkeit mal eben noch testen... Danke für den Tip ;)


    hmmm... mit specializations allein geht es an dieser Stelle nicht -> D:/code/lsim2011/build/finalbin/dataS/scripts/SpecializationUtil.lua(57) : bad argument #1 to 'pairs' (table expected, got nil)

  • Versuche es mal so:


    [lua]for k,v in pairs(VehicleTypeUtil.vehicleTypes) do
    if v~=nil then
    for a=1, table.maxn(v.specializations) do
    local s = v.specializations[a];
    if s ~= nil then
    if s == SpecializationUtil.getSpecialization("steerable") then
    if not SpecializationUtil.hasSpecialization(manualIgnition, v.specializations) then
    print("adding manualIgnition to:"..tostring(v.name));
    table.insert(v.specializations, SpecializationUtil.getSpecialization("manualIgnition"));
    end
    end;[/lua]

  • Mercí, hoffe ich habe deinen Hinweis nicht falsch verstanden, aber das Problem besteht auch mit "steerable" immernoch...


    Nochmal zum Verständnis: Das Einfügen der Spezi funktioniert ja einwandfrei.
    Mit
    [lua]if s == SpecializationUtil.getSpecialization("steerable") then [/lua]
    sowie mit
    [lua]if s == SpecializationUtil.getSpecialization("motorized") then [/lua].


    Das Problem ist, dass die in einen Mod hinzugefügten Spezies wie z.B. OperatingHours mit "SpecializationUtil.getSpecialization" bzw. "SpecializationUtil.hasSpecialization" anscheinend nicht erfaßt werden... ist vielleicht etwas komisch umschrieben, aber ich hoffe ihr wißt was ich meine.



    Hab es jetzt mal so ausprobiert:


    Das Skript und die Klasse habe ich mal in ManualMotorIgnition.lua und ManualMotorIgnition umbenannt, die Klasse beginnt jetzt also auch mit einem Großbuchstaben (laut Coding-Guideline).


    In der register.lua steht nun also folgendes:


    [lua]SpecializationUtil.registerSpecialization("manualMotorIgnition", "ManualMotorIgnition", g_modsDirectory.."/zzz_ManualMotorIgnition/ManualMotorIgnition.lua")



    print("--- ManualMotorIgnition - specialization for manual motor ignition ---");


    for k,v in pairs(VehicleTypeUtil.vehicleTypes) do
    if v~=nil then
    for a=1, table.maxn(v.specializations) do
    local s = v.specializations[a];
    if s ~= nil then
    if s == SpecializationUtil.getSpecialization("steerable") then --Wenn die Spezi mit dem Namen "steerable" dem vehicleType zugeordnet wurde, dann:
    print(tostring(v.name)..": Specialization steerable is present"); --wird dieser Satz in die Log.txt geschrieben
    print("adding manualIgnition to:"..tostring(v.name)); --wird dieser Satz in die Log.txt geschrieben
    table.insert(v.specializations, SpecializationUtil.getSpecialization("manualMotorIgnition")); --wird die Spezi mit dem Namen "manualMotorIgnition" zum den specializations des vehibleType hinzugefügt
    end;
    if s == SpecializationUtil.getSpecialization("operatingHours") then --Wenn die Spezi mit dem Namen "operatingHours" dem vehicleType zugeordnet wurde, dann:
    print(tostring(v.name)..": Specialization operatingHours is present !!!!!!!!!!"); --wird dieser Satz in die Log.txt geschrieben
    end;
    if s == SpecializationUtil.getSpecialization("OperatingHours") then -- das gleiche zur Vorsicht nochmal mit dem Namen der Klasse
    print(tostring(v.name)..": Specialization OperatingHours is present !!!!!!!!!!");
    end;
    if SpecializationUtil.hasSpecialization(OperatingHours, v.specializations) then -- Wenn die Spezi mit der Klasse "OperatingHours" vorhanden ist, dann:
    print(tostring(v.name)..": Specialization OperatingHours is present !!!!!!!!!!"); --wird dieser Satz in die Log.txt geschrieben
    end;
    if s == SpecializationUtil.getSpecialization("hirable") then --Wenn die Spezi mit dem Namen "hirable" dem vehicleType zugeordnet wurde, dann:
    print(tostring(v.name)..": Specialization hirable is present"); --wird dieser Satz in die Log.txt geschrieben
    end;
    end;
    end;
    end;
    end;[/lua]



    Im mods-Ordner habe ich den ClaasAxion850v5 (ClaasAxion850v5.zip), welcher auch die Spezi "OperatingHours" verbaut hat.
    Die Spezi "ManualMotorIgnition" wird nun korrekt in den Mod eingefügt und in die Log.txt werden folgende Zeilen geschrieben:


    Zitat von Log.txt

    --- ManualMotorIgnition - specialization for manual motor ignition ---
    ClaasAxion850v5.ClaasAxion850: Specialization steerable is present
    adding manualIgnition to:ClaasAxion850v5.ClaasAxion850
    ClaasAxion850v5.ClaasAxion850: Specialization hirable is present


    Wie man sieht, fehlen die Sätze mit "OperatingHours"!


    Warum, Wieso, Weshalb ist jetzt die Fage... habe ich irgendwo einen Denkfehler, oder geht es einfach nur nicht mit den hinzugefügten Spezies (also nicht Standard-Spezies)?

  • jup, da kommen wir der Sache schon näher... Danke für die Info!


    Mit
    [lua]if SpecializationUtil.hasSpecialization(ClaasAxion850v5.OperatingHours, v.specializations) then
    print(tostring(v.name)..": Specialization OperatingHours is present !!!!!!!!!!");
    end;[/lua]
    funktioniert es.


    Nun bräuchte ich nur noch für ClaasAxion850v5 sowas wie eine "allgemeine Variable", damit es automatisch für alle betreffenden Mods funktioniert... sonst müßten ja alle möglichen Mods in das Skript eingetragen werden... hoffe ihr versteht was ich meine.


    v.name gibt ja den Namen des vehicleTypes, wenn ich mich nicht irre...
    Gibt es da nicht sowas wie currentModDirectory oder so?... gleichmal Suchen gehen.

  • Ouumann hab ich mich schon gefreut!! ... aber leider möcht es nicht so wirklich funzeln :(


    Und der Grund ist höchstwahrscheinlich dieser:


    Zitat von Stefan Geiger - GIANTS Software 22.06.2009 12:24

    The problem is, that Utils.splitString internally uses string.find, which where "." has the special meaning of "any character". This means, Utils.splitString(".",...) splits at any character.
    ...


    http://gdn.giants-software.com…?categoryId=3&threadId=56




    Ausprobiert hab ich folgendes:


    [lua]SpecializationUtil.registerSpecialization("manualMotorIgnition", "ManualMotorIgnition", g_modsDirectory.."/zzz_ManualMotorIgnition/ManualMotorIgnition.lua")



    print("--- ManualMotorIgnition - specialization for manual motor ignition ---");


    for k,v in pairs(VehicleTypeUtil.vehicleTypes) do
    if v~=nil then

    local results = Utils.splitString(".", v.name);
    local _name = results[1];
    print("_name:".._name)

    for a=1, table.maxn(v.specializations) do
    local s = v.specializations[a];
    if s ~= nil then
    if s == SpecializationUtil.getSpecialization("steerable") then
    print(tostring(v.name)..": Specialization steerable is present");
    print("adding manualIgnition to:"..tostring(v.name));
    table.insert(v.specializations, SpecializationUtil.getSpecialization("manualMotorIgnition"));
    end;
    if SpecializationUtil.hasSpecialization(_name.OperatingHours, v.specializations) then
    print(tostring(v.name)..": Specialization OperatingHours is present !!!!!!!!!!");
    end;
    if s == SpecializationUtil.getSpecialization("hirable") then
    print(tostring(v.name)..": Specialization hirable is present");
    end;
    end;
    end;
    end;
    end;[/lua]


    mit dem Resultat:



    Das "_name:" hab ich mal davor gesetzt, weil sonst eine komplett leere Zeile in der Log angezeigt wird... local _name ist also anscheinend leer!
    EDIT: nicht nil, aber leer^^




    Um die obige Aussage von Stefan Geiger nochmal zu kontollieren, hab noch folgendes ausprobiert:


    [lua]SpecializationUtil.registerSpecialization("manualMotorIgnition", "ManualMotorIgnition", g_modsDirectory.."/zzz_ManualMotorIgnition/ManualMotorIgnition.lua")



    print("--- ManualMotorIgnition - specialization for manual motor ignition ---");


    for k,v in pairs(VehicleTypeUtil.vehicleTypes) do
    if v~=nil then

    local v_name_string = tostring(v.name)
    print(v_name_string)
    local pointlocation = string.find(v_name_string, ".")
    print(tostring(pointlocation))
    local _name = string.sub(v_name_string, 1, pointlocation)
    print(_name)

    for a=1, table.maxn(v.specializations) do
    local s = v.specializations[a];
    if s ~= nil then
    if s == SpecializationUtil.getSpecialization("steerable") then
    print(tostring(v.name)..": Specialization steerable is present");
    print("adding manualIgnition to:"..tostring(v.name));
    table.insert(v.specializations, SpecializationUtil.getSpecialization("manualMotorIgnition"));
    end;
    if SpecializationUtil.hasSpecialization(_name.OperatingHours, v.specializations) then
    print(tostring(v.name)..": Specialization OperatingHours is present !!!!!!!!!!");
    end;
    if s == SpecializationUtil.getSpecialization("hirable") then
    print(tostring(v.name)..": Specialization hirable is present");
    end;
    end;
    end;
    end;
    end;[/lua]


    Und siehe da:




    In dem Beitrag auf GDN schlägt Stefan eine alternative Funktion zu Utils.splitString vor... allerdings sieht es etwas kompilizierter aus. Könntet ihr euch das bitte mit anschauen?


    PS: Stefan meinte auch, dass er das Problem für die nächsten Versionen des LS beheben möchte... das war am 22.06.2009, also zu Zeiten des LS09. Theoretisch müßte es ja jetz im LS11 behoben sein...
    Nungut... auf zur function string:split(delimiter)^^

  • Hm, vielleicht brauchst du das garnicht soo kompliziert aufbauen. Ich weiß jetzt nicht genau wie sich der Wert der Variable v.name zusammensetzt, doch in deinen Test hast du immer "ClaasAxion850v5.ClaasAxion850" genannt...


    Ich habe das mal eben getestet...


    [lua]
    local originalString = v.name;
    if originalString ~= nil then
    local firstPointIndex = string.find(originalString, ".", nil, true);
    local firstStringPart = string.sub(originalString, 1, firstPointIndex-1)
    end;
    [/lua]


    ich habe das Ganze mit originalString = "ClaasAxion850v5.ClaasAxion850" getestet und als firstStringPart = "ClaasAxion850v5" ausgegeben bekommen.
    Sofern sich in v.name nur ein Punkt befindet, sollte es doch eigentlich funktionieren oder? :D


    MfG

  • EDIT: Ach hätt ich doch noch kurz auf deinen Beitrag gewartet, dann hätt ich mir die Schreiberei des folgenden Textes sparen können ;)
    Ich lass es trotzdem mal stehen, denn anscheinend funzt es noch nicht ganz:




    Oha... mir ist eben noch was wichtiges aufgefallen:


    Zitat von http://lua.gts-stolberg.de/string.php#string.find

    string.find (cString, cWas [, nAbWo [, lAuchFormatierung]])

    Diese Funktion sucht in cString nach cWas. Die Suche Beginnt bei nAbWo.
    Ist lAuchFormatierung true, dann werden Formatierungszeichen als einfacher Text behandelt. In dem Fall muss nAbWo auch angegeben werden.


    Also folgendes ausprobiert:


    [lua]local v_name_string = tostring(v.name)
    print(v_name_string)
    local point_location = string.find(v_name_string, ".", 1, true)
    print(tostring(point_location))
    if point_location ~= nil then
    local _name = string.sub(v_name_string, 1, point_location)
    print(_name)
    end;[/lua]


    und siehe da:


    Zitat von Log.txt

    ClaasAxion850v5.ClaasAxion850
    16
    ClaasAxion850v5.



    Jetz muß ja theoretisch nur noch der Punkt weg, also:


    [lua]local v_name_string = tostring(v.name)
    print(v_name_string)
    local point_location = string.find(v_name_string, ".", 1, true)
    print(tostring(point_location))
    if point_location ~= nil then
    local _name = string.sub(v_name_string, 1, point_location-1)
    print(_name)
    end;[/lua]


    Zitat von Log.txt

    ClaasAxion850v5.ClaasAxion850
    16
    ClaasAxion850v5


    Das Ganze dann folgendermaßen eingefügt:


    [lua]SpecializationUtil.registerSpecialization("manualMotorIgnition", "ManualMotorIgnition", g_modsDirectory.."/zzz_ManualMotorIgnition/ManualMotorIgnition.lua")



    print("--- ManualMotorIgnition - specialization for manual motor ignition ---");


    for k,v in pairs(VehicleTypeUtil.vehicleTypes) do
    if v~=nil then
    for a=1, table.maxn(v.specializations) do
    local s = v.specializations[a];
    if s ~= nil then
    if s == SpecializationUtil.getSpecialization("motorized") then
    print(tostring(v.name)..": Specialization motorized is present");
    print("adding manualIgnition to:"..tostring(v.name));
    table.insert(v.specializations, SpecializationUtil.getSpecialization("manualMotorIgnition"));

    local v_name_string = tostring(v.name)
    print(v_name_string)
    local point_location = string.find(v_name_string, ".", 1, true)
    print(tostring(point_location))
    if point_location ~= nil then
    local _name = string.sub(v_name_string, 1, point_location-1)
    print(_name)
    if SpecializationUtil.hasSpecialization(_name.OperatingHours, v.specializations) then
    print(tostring(v.name)..": Specialization OperatingHours is present !!!!!!!!!!");
    end;
    end;
    end;
    end;
    end;
    end;
    end;[/lua]


    ...die Problemlösung scheint in greifbarer Nähe... die Spannung steigt! Und?


    Zitat von Log.txt

    --- ManualMotorIgnition - specialization for manual motor ignition ---
    ClaasAxion850v5.ClaasAxion850: Specialization motorized is present
    adding manualIgnition to:ClaasAxion850v5.ClaasAxion850
    ClaasAxion850v5.ClaasAxion850
    16
    ClaasAxion850v5


    Aaaarrrrrrrggghhhhhhhh - es folgt ein herber Niederschlag! Der Satz "Specialization OperatingHours is present !!!!!!!!!!" möchte in der Log einfach nicht auftauchen... Schimpfwörter sowie sämtliche Schreibtischgegenstände fliegen durch die Luft! MannMannMann, ist das ein aufregender Sonntagvormittag ^^


    Nein *ScherzbeiSeiteschieb*, weit kann die Lösung ja nicht mehr sein. Irgendwas stimmt noch nicht mit SpecializationUtil.hasSpecialization(_name.OperatingHours, v.specializations) oder steht es einfach nur im Skript an falscher Stelle? Was meint ihr?

  • EDIT: OperatingHours ist nur als Beispiel für eine dem Mod hinzugefügte Spezi. Im Endeffekt soll an dieser Stelle dann "manualIgnition" bzw. andere Spezies mit dieser Funktion stehen, damit das mauelle Starten des Motors quasi nicht doppelt in einem Mod vorhanden ist und damit dann nicht einwandfrei funzt.



    Also an falscher Stelle scheint es nicht zu stehen. Ersetze ich das "SpecializationUtil.hasSpecialization(_name.OperatingHours, v.specializations)" durch SpecializationUtil.hasSpecialization(ClaasAxion850v5.OperatingHours, v.specializations) funktioniert es... der Satz "ClaasAxion850v5.ClaasAxion850: Specialization OperatingHours is present !!!!!!!!!!" wird in der Log angezeigt.


    Hat _name vielleicht das falsche Format? Aber was außer ein string soll denn da passen? Anscheinend sind wir auf dem Holzweg :(

  • ne, das liegt daran, dass _name ein string ist. Wir brauchen aber einen Table um auf die Specializations zugreifen zu können.


    Du kannst versuchen mal zu gucken, ob du über:


    local spec = SpecializationUtil.getSpecialization(_name.."OperatingHours");


    auf die kommst, da die function wohl mit strings umgehen kann, oder ob das auch direkt bei:


    SpecializationUtil.hasSpecialization(_name.."OperatingHours", v.specializations);


    geht :)

  • Hab jetz folgende Varianten erfolglos ausprobiert:


    [lua]SpecializationUtil.registerSpecialization("manualMotorIgnition", "ManualMotorIgnition", g_modsDirectory.."/zzz_ManualMotorIgnition/ManualMotorIgnition.lua")



    print("--- ManualMotorIgnition - specialization for manual motor ignition ---");


    for k,v in pairs(VehicleTypeUtil.vehicleTypes) do
    if v~=nil then
    for a=1, table.maxn(v.specializations) do
    local s = v.specializations[a];
    if s ~= nil then
    if s == SpecializationUtil.getSpecialization("motorized") then
    print(tostring(v.name)..": Specialization motorized is present");
    print("adding manualIgnition to:"..tostring(v.name));
    table.insert(v.specializations, SpecializationUtil.getSpecialization("manualMotorIgnition"));

    local v_name_string = v.name
    print(v_name_string)
    local point_location = string.find(v_name_string, ".", nil, true)
    print(tostring(point_location))
    if point_location ~= nil then
    local _name = string.sub(v_name_string, 1, point_location-1);
    print(_name)

    if SpecializationUtil.hasSpecialization(_name.."OperatingHours", v.specializations) then
    if SpecializationUtil.hasSpecialization(_name..".OperatingHours", v.specializations) then
    if SpecializationUtil.hasSpecialization(_name.."OperatingHours", v.specializations) then --ohne point_location-1, also der _name mit Punkt am Ende
    if s == SpecializationUtil.getSpecialization(_name.."OperatingHours") then
    if s == SpecializationUtil.getSpecialization(_name..".OperatingHours") then
    if s == SpecializationUtil.getSpecialization(_name.."OperatingHours") then --ohne point_location-1, also der _name mit Punkt am Ende

    if s == SpecializationUtil.getSpecialization(string.format("%sOperatingHours", _name)) then
    if s == SpecializationUtil.getSpecialization(string.format("%s.OperatingHours", _name)) then
    if s == SpecializationUtil.getSpecialization(string.format("%sOperatingHours", _name)) then --ohne point_location-1, also der _name mit Punkt am Ende
    print(tostring(v.name)..": Specialization OperatingHours is present !!!!!!!!!!");
    end;
    end;
    end;
    end;
    end;
    end;
    end;[/lua]


    Bei den Varianten mit SpecializationUtil.hasSpecialization wurden ja im Prinzip immer strings verwendet... sollten wir aus dem _name nicht irgendwie ein table machen?

  • Versuch mal, ob SpecializationUtil.hasSpecialization("ClaasAxion850v5.OperatingHours", v.specializations) funktioniert. Sollte, wenn man sich deine Versuchen ansieht, nicht funktionieren. Falls es also wie erwartet nicht funktioniert solltest du dir mal den Typ von ClaasAxion850v5.OperatingHours ausgeben lassen, also print(type(ClaasAxion850v5.OperatingHours)). Falls es sich dabei um einen String oder Number handelt solltest du dir mal deren Inhalt ausgeben lassen.

Jetzt mitmachen!

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