Scripten lernen und erste Versuche

Hier findet ihr archivierte Support Themen zu allen LS Versionen die vielleicht noch hilfreich sein könnten.
FrankenChris
Beiträge: 2
Registriert: Do Aug 27, 2015 7:26 pm

Scripten lernen und erste Versuche

Beitragvon FrankenChris » Do Aug 27, 2015 7:41 pm

Hi alle zusammen,

ich will mir ein bisschen das Scripten beibringen und habe auch schon hunderte Beiträge dazu gelesen, die Dokumentation auf ls-mods.de angeschaut, und die gdn Seite studiert... naja was soll ich sagen, obwohl ich ein wenig Grundkenntnisse im programmieren habe, tue ich mir bisher sehr schwer. Ich wollte jetzt mal einfach ein ganz einfaches Script in den LS15 einbauen. Da hab ich ein Video auf youtube gefunden, ich glaube sogar das steht mit euch in Zusammenhang. Ist wirklich gut gemacht! So lange Rede kurzer Sinn: Das Skript habe ich mir abgeschrieben:

Code: Alles auswählen

-- Ein Beispielkommentar zur LUA
-- Zum Beispiel eine Beschreibung was die LUA tut und wann und von wem sie geschrieben wurde

wheelScale = {};

function wheelScale.prerequisitesPresent(specializations)
    return true;
end;

function wheelScale:load(xmlFile)
   self.wheelToScaleLeft = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.wheelScale.wheelToScaleLeft#index"));
   self.wheelToScaleRight = Utils.indexToObject(self.components, getXMLString(xmlFile, "vehicle.wheelScale.wheelToScaleRight#index"));
   
   self.wheelScaleState = false;
end;
function wheelScale:delete()
end;
function wheelScale:mouseEvent(posX, posY, isDown, isUp, button)
end;
function wheelScale:keyEvent(unicode, sym, modifier, isDown)
end;
function wheelScale:update(dt)
   if self:getIsActiveForInput() then
      if InputBinding.hasEvent(InputBinding.TASTE_SCALE) then
         self.wheelScaleState = (not self.wheelScaleState);
      end;
      
      if self.wheelScaleState == true then
         setScale(self.wheelToScaleLeft, 2, 2, 2);
         setScale(self.wheelToScaleRight, 2, 2, 2);
      elseif self.wheelScaleState == false then
         setScale(self.wheelToScaleLeft, 1, 1, 1);
         setScale(self.wheelToScaleRight, 1, 1, 1);
      end;
   end;
end;
function wheelScale:updateTick(dt)
end;
function wheelScale:draw()   
end;



Das ganze habe ich natürlich auch in die modDesc eingebaut:

Code: Alles auswählen

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<modDesc descVersion="21">
    <author>My Name</author>
    <version>1.0</version>
    <title>
        <en>Sample Mod</en>
        <de>Beispiel Mod</de>
    </title>
    <description>
        <en>Sample mod description</en>
        <de>Beispiel Mod Beschreibung</de>
    </description>
    <iconFilename>store_buehrer6135A.png</iconFilename>
    <multiplayer supported="true"/>
   <specializations>
      <specialization name="wheelScale" className="wheelScale" filename="wheelScale.lua"/>
   </specializations>
   <vehicleTypes>
      <type name="manureBarrel" className="Vehicle" filename="$dataS/scripts/vehicles/Vehicle.lua">
         <specialization name="wheelScale"/>
      </type>
   </vehicleTypes>
   <inputBindings>
      <input name="TASTE_SCALE" key1="KEY_6" button=""/>
   </inputBindings>   
   <l10n>
      <text name="TASTE_SCALE">
         <de>Reifenbreite</de>
      </text>
   </l10n>
    <storeItems>
        <storeItem>
            <name>
                <de>Bührer 6135 - Beispiel Mod</de>
                <en>Buehrer 6135 - Sample Mod</en>
            </name>
            <rotation>0</rotation>
            <image active="store_buehrer6135A.png" brand="brand_buehrer.png"/>
            <price>65000</price>
            <dailyUpkeep>95</dailyUpkeep>
            <xmlFilename>buehrer6135A.xml</xmlFilename>
            <brand>Bührer</brand>
            <category>tractors</category>
            <specs>
                <power>135</power>
            </specs>
        </storeItem>
    </storeItems>
</modDesc>


Und die entsprechenden Einträge in der Fahrzeug.xml sind auch vorhanden:

Code: Alles auswählen

<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<vehicle type="tractor">
    <annotation>Copyright (C) GIANTS Software GmbH, All Rights Reserved.</annotation>
    <name>
        <en>Buehrer 6135 A</en>
        <de>Bührer 6135 A</de>
    </name>
    <filename>buehrer6135A.i3d</filename>

    <size width="3.5" length="6"/>

    <wheels autoRotateBackSpeed="2">
        <wheel rotSpeed="1" restLoad="1.3" repr="0>0" driveNode="0>0|0" radius="0.585" initialCompression="50" suspTravel="0.15" spring="25" damper="25" mass="0.099" hasTyreTracks="true" tyreTrackAtlasIndex="0" fenderNode="0>0|2" fenderRotMin="-29" />
        <wheel rotSpeed="1" restLoad="1.3" repr="0>1" driveNode="0>1|0" radius="0.585" initialCompression="50" suspTravel="0.15" spring="25" damper="25" mass="0.099" hasTyreTracks="true" tyreTrackAtlasIndex="0" fenderNode="0>1|2" fenderRotMax="29" />
        <wheel rotSpeed="0" restLoad="1.0" repr="0>2" radius="0.79" initialCompression="50" suspTravel="0.09" spring="35" damper="25" mass="0.16" hasTyreTracks="true" tyreTrackAtlasIndex="0"/>
        <wheel rotSpeed="0" restLoad="1.0" repr="0>3" radius="0.79" initialCompression="50" suspTravel="0.09" spring="35" damper="25" mass="0.16" hasTyreTracks="true" tyreTrackAtlasIndex="0"/>
    </wheels>
   
   <wheelScale>
      <wheelToScaleLeft index="0>0|0" />
      <wheelToScaleRight index="0>1|0" />
   </wheelScale>

    <dynamicallyLoadedParts>
        <dynamicallyLoadedPart node="0|1" linkNode="0>0|0" filename="$data/vehicles/wheels/trelleborg/trelleborgTM700_380_70R24.i3d" />
        <dynamicallyLoadedPart node="0|0" linkNode="0>1|0" filename="$data/vehicles/wheels/trelleborg/trelleborgTM700_380_70R24.i3d" />
        <dynamicallyLoadedPart node="0|1" linkNode="0>2"   filename="$data/vehicles/wheels/trelleborg/trelleborgTM700_520_70R34.i3d" />
        <dynamicallyLoadedPart node="0|0" linkNode="0>3"   filename="$data/vehicles/wheels/trelleborg/trelleborgTM700_520_70R34.i3d" />
    </dynamicallyLoadedParts>

    <ackermannSteering rotSpeed="60" rotMax="35" rotCenterWheel1="2" rotCenterWheel2="3" />

    <differentials>
        <differential torqueRatio="0.5" maxSpeedRatio="1.2" wheelIndex1="0" wheelIndex2="1" /> <!-- front left-right -->
        <differential torqueRatio="0.5" maxSpeedRatio="1.3" wheelIndex1="2" wheelIndex2="3" /> <!-- back left-right -->
        <differential torqueRatio="0.5" maxSpeedRatio="1.1" differentialIndex1="0" differentialIndex2="1" /> <!-- front-back -->
    </differentials>

    <motor torqueScale="0.598" minRpm="1000" maxRpm="2200" maxBackwardSpeed="15" brakeForce="2.5" lowBrakeForceScale="0.5" lowBrakeForceSpeedLimit="1" minForwardGearRatio="19.7" maxForwardGearRatio="130" minBackwardGearRatio="50" maxBackwardGearRatio="130">
        <torque normRpm="0.45" torque="0.9"/>
        <torque normRpm="0.5" torque="0.97"/>
        <torque normRpm="0.59" torque="1"/>
        <torque normRpm="0.72" torque="1"/>
        <torque normRpm="0.86" torque="0.88"/>
        <torque normRpm="1" torque="0.72"/>
    </motor>

    <fuelCapacity>120</fuelCapacity>
    <fuelUsage>13</fuelUsage>

    <cameras count="2">
        <camera1 index="4|0" rotatable="true" rotateNode="4" limit="true" useWorldXZRotation="true" rotMinX="-1.4" rotMaxX="1" transMin="4" transMax="35" >
            <raycastNode index="0>6"/>
            <raycastNode index="0>7"/>
        </camera1>
        <camera2 index="5" rotatable="true" limit="true" rotMinX="-1.1" rotMaxX="0.4" transMin="0" transMax="0" useMirror="true" isInside="true" />
    </cameras>

    <lights>
        <light realLight="0>9" decoration="0>28" lightType="0"/>
        <light realLight="0>10" decoration="0>29" lightType="1"/>
    </lights>

    <brakeLights>
        <brakeLight index="0>34" />
    </brakeLights>

    <beaconLights>
        <beaconLight index="0>30" speed="0.015" filename="$data/vehicles/shared/beaconLight02.i3d" />
    </beaconLights>

    <turnSignals>
        <turnSignalLeft index="0>35|0" />
        <turnSignalRight index="0>35|1" />
    </turnSignals>

    <mirrors>
        <mirror index="0>36|0" />
        <mirror index="0>36|1" />
        <mirror index="0>36|2" />
    </mirrors>

    <indoorHud>
        <fuel animName="fuelDisplay" />
        <rpm animName="rpmDisplay" />
    </indoorHud>
   
    <enterReferenceNode index="0>"/>
    <exitPoint index="0>8"/>

    <attacherJoints>
        <attacherJoint index="0>11|0|0" rotationNode="0>11" minRot="21 0 0" minRot2="-14 0 0" maxRot="6 0 0" rotationNode2="0>11|0" maxRot2="-6 0 0" maxTransLimit="0 0.5 0" maxRotLimit="0 0 20" moveTime="2.5" ptoOutputNode="0>20" ptoFilename="$data/vehicles/shared/powerTakeoff.i3d">
            <bottomArm rotationNode="0>12" translationNode="0>12|0" referenceNode="0>12|0|0" zScale="-1" />
            <topArm baseNode="0>13" filename="$data/vehicles/shared/upperLink.i3d" zScale="-1" />
        </attacherJoint>
        <attacherJoint index="0>16|0|0" rotationNode="0>16" minRot="-50 0 0" minRot2="41 0 0" maxRot="-18 0 0" rotationNode2="16|0" maxRot2="18 0 0" maxTransLimit="0 0.4 0" maxRotLimit="0 0 20" moveTime="2.5" ptoOutputNode="0>22" ptoFilename="$data/vehicles/shared/powerTakeoff.i3d">
            <bottomArm rotationNode="0>17" translationNode="17|0" referenceNode="17|0|0" zScale="1" />
            <topArm baseNode="0>18" filename="$data/vehicles/shared/upperLinkSmall.i3d" zScale="1" toggleVisibility="true" />
        </attacherJoint>
        <!-- trailer attacher -->
        <attacherJoint index="0>19|0" jointType="trailer" transNode="0>19" transMinYHeight="0.62" transMaxYHeight="1.1" maxRotLimit="10 80 80" minRotRotationOffset="0" allowsJointLimitMovement="false" ptoOutputNode="0>20" ptoFilename="$data/vehicles/shared/powerTakeoff.i3d"/>
        <attacherJoint index="0>21"   jointType="trailerLow" maxRotLimit="10 50 50" minRotRotationOffset="0" allowsJointLimitMovement="false" ptoOutputNode="0>20" ptoFilename="$data/vehicles/shared/powerTakeoff.i3d"/>
    </attacherJoints>

    <attacherJointLowerCombo duration="2">
        <attacherJoint index="2" time="0" />
        <attacherJoint index="1" time="1" />
        <attacherJoint index="3" time="1" />
        <attacherJoint index="4" time="1" />
    </attacherJointLowerCombo>

    <movingTools>
        <!-- attacher joint back bottom-->
        <movingTool index="0>12">
            <!-- cylinder 1 -->
            <dependentPart index="0>14" />
            <!-- cylinder 2 -->
            <dependentPart index="0>15" />
            <!-- lowerlink -->
            <dependentPart index="0>33" />
        </movingTool>

        <!-- attacher joint front bottom-->
        <movingTool index="0>17">
            <!-- cylinder -->
            <dependentPart index="0>31" />
        </movingTool>
    </movingTools>

    <movingParts>
        <!-- attacher joint back bottom cylinder 1 -->
        <movingPart index="0>14" referencePoint="0>15|1" referenceFrame="0>15|1" invertZ="true">
            <translatingPart index="0>14|0" />
        </movingPart>
        <!-- attacher joint back bottom cylinder 2 -->
        <movingPart index="0>15" referencePoint="0>12|0|1" localReferencePoint="0>15|2" referenceFrame="0>" invertZ="true">
            <dependentPart index="0>15|2" />
        </movingPart>
        <!-- attacher joint back bottom cylinder 2b -->
        <movingPart index="0>15|2" referencePoint="0>12|0|1" referenceFrame="0>15|0" invertZ="true" />
        <!-- attacher joint front bottom cylinder -->
        <movingPart index="0>31" referencePoint="0>17|0|1" referenceFrame="0>17|0|1">
            <dependentPart index="0>31|0" />
        </movingPart>
        <!-- lowerlink -->
        <movingPart index="0>33" referencePoint="0>12|0|2" referenceFrame="0>" invertZ="true" scaleZ="true" />
        <!-- steering -->
        <movingPart index="0>0|1" referencePoint="0>1|1" referenceFrame="0>" scaleZ="true" playSound="false" isActiveDirty="true" />
    </movingParts>

    <steering index="0>23|0" indoorRotation="540" outdoorRotation="45" />

    <animations>
        <animation name="fuelDisplay">
            <part node="0>36|3|1" startTime="0" endTime="1" startRot="0 0 0" endRot="0 -95 0" />
        </animation>
        <animation name="rpmDisplay">
            <part node="0>36|3|0" startTime="0" endTime="1" startRot="0 0 0" endRot="0 200 0" />
        </animation>
    </animations>
   
    <characterNode index="0>24|0" cameraMinDistance="2.0" filename="$dataS2/character/player/player.i3d" characterMesh="1" characterGloves="2" characterSkin="0" spineNode="0|0" leftArmIKChainId="leftArm" rightArmIKChainId="rightArm" spineRotation="180 0 104" >
        <ikChains>
            <ikChain id="rightFoot" target="0>24|1" targetOffset="0 0.1 0" alignToTarget="true" isDirtyOnLoad="true" >
                <node index="0|1" />
                <node index="0|1|0"     minRx="0" maxRx="0" minRy="-20" maxRy="20" minRz="0"   maxRz="90" />
                <node index="0|1|0|0"   minRx="0" maxRx="0" minRy="0"   maxRy="0"  minRz="270" maxRz="360" />
                <node index="0|1|0|0|0" />
            </ikChain>
            <ikChain id="leftFoot" target="0>24|2" targetOffset="0 0.1 0" alignToTarget="true" isDirtyOnLoad="true">
                <node index="0|2"     />
                <node index="0|2|0"     minRx="0" maxRx="0" minRy="-20" maxRy="20" minRz="0"   maxRz="90" />
                <node index="0|2|0|0"   minRx="0" maxRx="0" minRy="0"   maxRy="0"  minRz="270" maxRz="360" />
                <node index="0|2|0|0|0" />
            </ikChain>
            <ikChain id="rightArm" target="0>23|0|0" targetOffset="0.025 0.066 0" alignToTarget="true" isDirtyOnLoad="true">
                <node index="0|0|0|1" />
                <node index="0|0|0|1|0"   minRx="0" maxRx="0" minRy="-40" maxRy="90" minRz="0" maxRz="90" />
                <node index="0|0|0|1|0|0" minRx="0" maxRx="0" minRy="0" maxRy="0" minRz="7" maxRz="90" />
                <node index="0|0|0|1|0|0|0" />
                <rotationNode index="0|0|0|1|0|0|0|0" rotation="0 0 -60" />
                <rotationNode index="0|0|0|1|0|0|0|0|0" rotation="0 0 -60" />
                <rotationNode index="0|0|0|1|0|0|0|1" rotation="-90 20 -40" />
                <rotationNode index="0|0|0|1|0|0|0|1|0" rotation="0 0 -40" />
            </ikChain>
            <ikChain id="leftArm" target="0>23|0|1" targetOffset="-0.025 0.066 0" alignToTarget="true" isDirtyOnLoad="true">
                <node index="0|0|0|2" />
                <node index="0|0|0|2|0"   minRx="0" maxRx="0" minRy="-40" maxRy="90" minRz="0" maxRz="90" />
                <node index="0|0|0|2|0|0" minRx="0" maxRx="0" minRy="0" maxRy="0" minRz="7" maxRz="90" />
                <node index="0|0|0|2|0|0|0" />
                <rotationNode index="0|0|0|2|0|0|0|0" rotation="0 0 -60" />
                <rotationNode index="0|0|0|2|0|0|0|0|0" rotation="0 0 -60" />
                <rotationNode index="0|0|0|2|0|0|0|1" rotation="-90 20 -40" />
                <rotationNode index="0|0|0|2|0|0|0|1|0" rotation="0 0 -40" />
            </ikChain>
        </ikChains>
    </characterNode>

    <aiTrafficCollisionTrigger index="0>25" />

    <exhaustEffects>
        <exhaustEffect index="0>26" filename="$data/vehicles/particleAnimations/shared/exhaust.i3d" minRpmColor="0.9 0.9 0.9 0.05" maxRpmColor="0.9 0.9 0.9 0.2" minRpmScale="0.05" maxRpmScale="0.4" forwardXRotations="-250 0 250" forwardZRotations="0 0 0" steerXRotations="0 0 0" steerZRotations="120 0 -50" />
    </exhaustEffects>

    <motorStartDuration>2500</motorStartDuration>
    <attachSound file="$data/vehicles/shared/attach.wav" pitchOffset="1" />
    <motorStartSound file="buehrer6135_start.wav" pitchOffset="1" volume="1.25" />
    <motorSound file="buehrer6135_idle.wav" pitchOffset="1" pitchScale="0.02" pitchMax="1.55" volume="1.25" radius="50" innerRadius="20" />
    <motorSoundRun file="buehrer6135_run.wav" pitchOffset="0.45" pitchScale="0.026" pitchMax="1.35" volume="1.3" />
    <motorSoundRun2 file="$data/vehicles/shared/transmissionOld.wav" pitchOffset="0.65" volume="0.2" pitchMax="1.4" volumeMax="0.45"/>
    <motorStopSound file="buehrer6135_stop.wav" pitchOffset="1" volume="1.5" />
    <compressedAirSound file="$data/vehicles/shared/brakeOld.wav" pitchOffset="1" volume="2"/>
    <compressionSound file="$data/vehicles/shared/compressorWork.wav" pitchOffset="1" volume="1.5"/>

    <honkSound file="$dataS2/sounds/horn.wav" volume="1" radius="80" innerRadius="35" />

    <driveGroundParticleSystems>
        <driveGroundParticleSystem file="$data/vehicles/particleAnimations/shared/drivingParticleSystem.i3d" wheel="1" />
        <driveGroundParticleSystem file="$data/vehicles/particleAnimations/shared/drivingParticleSystem.i3d" wheel="2" />
        <driveGroundParticleSystem file="$data/vehicles/particleAnimations/shared/drivingParticleSystem.i3d" wheel="3" />
        <driveGroundParticleSystem file="$data/vehicles/particleAnimations/shared/drivingParticleSystem.i3d" wheel="4" />
    </driveGroundParticleSystems>

    <washable dirtDuration="50" washDuration="1" workMultiplier="4" />

    <components count="1">
        <component1 centerOfMass="0 0.8 0.4" solverIterationCount="10" />
    </components>

    <schemaOverlay file="$dataS2/menu/schemas/vehicleSchema.png" fileSelected="$dataS2/menu/schemas/vehicleSchemaSelected.png" width="0.5" height="0.5" attacherJointPosition="0.5 0">
        <attacherJoint position="1 0" rotation="0" invertX="false" />
        <attacherJoint position="0 0" rotation="0" invertX="true" />
        <attacherJoint position="1 0" rotation="0" invertX="false" />
        <attacherJoint position="1 0" rotation="0" invertX="false" />
    </schemaOverlay>

</vehicle>



So nun hab ich wie du siehst in der modDesc sogar noch einen Hilfetext hinterlegt. Wenn ich das Spiel und den Mod lade, passiert aber einfach gar nichts. Keine log Fehlermeldung... nichts... Ich kann den Mod zwar kaufen und Fahren, aber es ist weder der Hilfetext vorhanden, noch kann ich die Reifen scalieren...

Ich hoffe ihr könnt mir weiterhelfen... würde wirklich gern bisschen was übers Scripten lernen :) Vielleicht kann mir ja einer bisschen Nachhilfe geben.


Ich bedanke mich schonmal im Vorraus

FrankenChris
Beiträge: 2
Registriert: Do Aug 27, 2015 7:26 pm

Re: Scripten lernen und erste Versuche

Beitragvon FrankenChris » Do Aug 27, 2015 8:49 pm

Hab das ganze jetzt gerade im LS11 ausprobiert, da funktioniert alles... kann mir jemand weiter helfen?

Grüße

Benutzeravatar
modelleicher
Schwabenleiter
Schwabenleiter
Beiträge: 2371
Registriert: Mo Jun 28, 2010 2:04 pm

Re: Scripten lernen und erste Versuche

Beitragvon modelleicher » Sa Aug 29, 2015 7:53 am

Moin


Du hast vergessen den VehicleType einzutragen..

Zum einen brauchst du in der modDesc einen kompletten VehicleType sprich mit allen specializations die "tractor" normal hat + der wheelScale.. Und zum anderen muss dann in der XML der neue vehicleType eingetragen werden (anstatt "tractor" )

Hier sind die Standard VehicleTypes: http://forum.giants-software.com/viewto ... 27&t=69284

Also so:

Code: Alles auswählen

      <type name="BuehrerWheelScale" className="Vehicle" filename="$dataS/scripts/vehicles/Vehicle.lua">
        <specialization name="animatedVehicle" />
        <specialization name="motorized" />
        <specialization name="steerable" />
        <specialization name="drivable" />
        <specialization name="cylindered" />
        <specialization name="hirable" />
        <specialization name="aiTractor" />
        <specialization name="bunkerSiloCompacter" />
        <specialization name="honk" />
        <specialization name="indoorHud" />
        <specialization name="washable" />
        <specialization name="mountable" />
         <specialization name="wheelScale"/>
      </type>



Und in der XML dann logisch:
<vehicle type="tractor">
ändern in
<vehicle type="BuehrerWheelScale">




LG


Zurück zu „Support-Archiv“

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder und 1 Gast