Community Forum

Front loader Mouse and Gamepad controls?

Forum Overview >> Scripting

CategoryScripting
Created18.11.2010 08:53


Knut Are Nybo (Unknown) 18.11.2010 08:54
I am editing a mod to get controls like the original tractor with front loader in LS2011 but im stuck with this in the frontloader.LUA file:

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

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

function Frontloader:update(dt)
if self.frontloaderJointDesc ~= nil then
self.frontloaderJointDesc.moveDirection1 = 0;
self.frontloaderJointDesc.moveDirection2 = 0;
self.frontloaderJointInvalid = false;
end;
if self:getIsActiveForInput() then
if self.frontloaderJointDesc ~= nil then
if InputBinding.isPressed(InputBinding.FRONTLOADER_ARM_POS) then
self.frontloaderJointDesc.moveDirection1 = self.frontloaderJointDesc.moveDirection1+1;
end;
if InputBinding.isPressed(InputBinding.FRONTLOADER_ARM_NEG) then
self.frontloaderJointDesc.moveDirection1 = self.frontloaderJointDesc.moveDirection1-1;
end;
if InputBinding.isPressed(InputBinding.FRONTLOADER_TILT_POS) then
self.frontloaderJointDesc.moveDirection2 = self.frontloaderJointDesc.moveDirection2+1;
end;
if InputBinding.isPressed(InputBinding.FRONTLOADER_TILT_NEG) then
self.frontloaderJointDesc.moveDirection2 = self.frontloaderJointDesc.moveDirection2-1;
end;
end;
end;
if self:getIsActive() then
if self.frontloaderJointDesc ~= nil then
local charSets = {self.frontloaderJointDesc.animCharSet1, self.frontloaderJointDesc.animCharSet2};
local moveDirections = {self.frontloaderJointDesc.moveDirection1, self.frontloaderJointDesc.moveDirection2};
local speedScales = {self.frontloaderJointDesc.speedScale1, self.frontloaderJointDesc.speedScale2};
local durations = {self.frontloaderJointDesc.animDuration1, self.frontloaderJointDesc.animDuration2};
if moveDirections[2] == 0 then
moveDirections[2] = -moveDirections[1];
speedScales[2] = self.frontloaderJointDesc.compensationSpeedScale;
end;
for i=1, 2 do
local charSet = charSets[i];
if charSet ~= 0 then
local speedScale = nil;
local playUp = false;
local playDown = false;
if moveDirections[i] > 0.1 then
speedScale = speedScales[i];
playUp = true;
elseif moveDirections[i] < -0.1 then
speedScale = -speedScales[i];
playDown = true;
end;
if speedScale ~= nil then
local animTrackTime = getAnimTrackTime(charSet, 0);
if speedScale > 0 then
if animTrackTime < 0.0 then
setAnimTrackTime(charSet, 0, 0.0);
elseif animTrackTime > durations[i] then
playUp = false;
playDown = false;
end;
else
if animTrackTime > durations[i] then
setAnimTrackTime(charSet, 0, durations[i]);
elseif animTrackTime < 0.0 then
playUp = false;
playDown = false;
end;
end;
setAnimTrackSpeedScale(charSet, 0, speedScale);
enableAnimTrack(charSet, 0);
self.frontloaderJointInvalid = true;
else
disableAnimTrack(charSet, 0);
end;

Frontloader.updateHydraulicSound(self, 1, i, playUp);
Frontloader.updateHydraulicSound(self, 2, i, playDown);
end;
end;
end;
end;

end;

function Frontloader:draw()
end;

function Frontloader:onDetach()
if self.deactivateOnDetach then
Frontloader.onDeactivate(self);
end;
end;

function Frontloader:onLeave()
if self.deactivateOnLeave then
Frontloader.onDeactivate(self);
end;
end;

function Frontloader:onDeactivate()
for i=1, 2 do
Frontloader.updateHydraulicSound(self, 1, i, false);
Frontloader.updateHydraulicSound(self, 2, i, false);
end;
if self.frontloaderJointDesc ~= nil then
if self.frontloaderJointDesc.animCharSet1 ~= 0 then
disableAnimTrack(self.frontloaderJointDesc.animCharSet1, 0);
end;
if self.frontloaderJointDesc.animCharSet2 ~= 0 then
disableAnimTrack(self.frontloaderJointDesc.animCharSet2, 0);
end;
end;
end;

function Frontloader:validateAttacherJoint(implement, jointDesc, dt)
return false;
end;

-- dirIndex: 1 = up, 2 = down
-- posIndex: 1 = arm, 2 = tilt





Any way to make it a axis or mouse event instead of the FRONTLOADER_TILT_POS/FRONTLOADER_TILT_NEG (example)

Stefan Geiger - GIANTS Software 20.11.2010 15:52
You should check out the cylindered specialization, which implements the mouse control stuff for the frontloader in the game.

You can fully control which mouse axes are used to move which part in the vehicle xml.

The code of the cylindered spec. is available here:
http://ls-mods.de/scriptDocumentation.php?lua_file=vehicles/specializations/Cylindered

The code which does the mouse axis handling start at line 444.

Knut Are Nybo (Unknown) 23.11.2010 02:02
Thanks for that, solved my problem 1 step further:

Log entry caused by the mod so far:
Lua: Error running function: mouseEvent
D:/code/lsim2011/build/finalbin/dataS/scripts/vehicles/specializations/Cylindered.lua(115) : stack overflow
Lua: Error running function: mouseEvent
D:/code/lsim2011/build/finalbin/dataS/scripts/vehicles/specializations/Cylindered.lua(115) : stack overflow
Lua: Error running function: mouseEvent

And so on
the mod file looks like this (I send this because it was after altering this it happens):

<mouseControls>
<mouseControl iconFilename="$dataS2/menu/mouseControlsHelp/dafs_arm1.png" mouseButton="LEFT" mouseAxis="Y" axis="AXIS_FRONTLOADER_ARM" />
<mouseControl iconFilename="$dataS2/menu/mouseControlsHelp/dafs_tool.png" mouseButton="LEFT" mouseAxis="X" axis="AXIS_FRONTLOADER_TOOL" />
</mouseControls>

<movingTools>
<movingTool index="35" attacherJointIndices="2" componentJointIndex="0" anchorActor="0" rotSpeed="30" rotAcceleration="120" rotMax="5" rotMin="-80" axis="AXIS_FRONTLOADER_ARM" invertAxis="true" mouseAxis="AXIS_FRONTLOADER_ARM" invertMouseAxis="true" speedFactor="0.4">
<dependentPart index="0>35|3" />
</movingTool>
<movingTool index="35|1" attacherJointIndices="2" anchorActor="0" rotSpeed="100" rotAcceleration="120" rotMax="145" rotMin="5" axis="AXIS_FRONTLOADER_TOOL" invertAxis="false" mouseAxis="AXIS_FRONTLOADER_TOOL" invertMouseAxis="false" speedFactor="0.6">
<dependentPart index="0>35|1|0" />
</movingTool>
</movingTools>

<movingParts>
<!-- arm cylinder -->
<movingPart index="0>35|3" referencePoint="0>36" referenceFrame="0>36">
<translatingPart index="0>35|3|0" />
</movingPart>


<!-- main hinge -->
<movingPart index="0>35|1" referencePoint="0>35|1|0" localReferencePoint="0>35|1|0" referenceFrame="0>35|1|0">
<dependentPart index="0>35|1|0" />
<dependentPart index="0>35|2" />
</movingPart>

<!-- tool cylinder -->
<movingPart index="0>35|2" referencePoint="0>35|1|0" referenceFrame="0>35">
<translatingPart index="0>35|2|0" />
</movingPart>
</movingParts>

<frontloader jointIndex="35|0" jointType="frontloader" animationClip1="armClipSource" rootNode1="35" speedScale1="-1" animationClip2="tiltClipSource" rootNode2="35|1" speedScale2="2" compensationSpeedScale="0.6" />


I'm guessing the problem is in there somewhere but I guess I looked myself blind on it.

Stefan Geiger - GIANTS Software 30.11.2010 11:06
One problem is that you have both a moving tool with index="0>35|1" as well as a moving part with the same index.
You should remove the moving part, if you want this part to be controlled by the player.

A second problem is, that you have dependentPart with 0>35|1|0, but there is no movingPart with this index.

Knut Are Nybo (Unknown) 02.12.2010 08:09
Well that solved it :) thnx m8 now its available to be used with no errors :)


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