Community Forum

Ponsse Scorpion Harvester Head

Forum Overview >> Scripting

CategoryScripting
Created17.03.2016 18:47


Stig Ove Ruud (Unknown) 17.03.2016 18:55
Hi. I found all scripts for Woodharvester, and was hoping to modify them a bit.
When selecting cut length for logs I would like to use 2 buttons. one for + and one for - step.
Orginal in game we need to cycle trough all steps to get the cut length we want.

I would allso like to delimb tree, and then press the cut button when I want to after that, as in an real machine.
It should allso be possible to run delimb in both directions so more buttons may be needed for this.

Is there ANY one out there understanding the scripts well enough to help me with this ??? It would be awesome !

I know many ppls on internet asked the same for a long time.

Scripts are:

Woodharvester.lua
WoodHarvesterCutTreeEvent.lua
WoodHarvesterOnCutTreeEvent.lua
WoodHarvesterOnDelimbTreeEvent.lua

Scripts can be downloaded from here: http://ls-mods.de/scriptDocumentation.php

Thanx !!!

Emil Drefers (Unknown) 18.03.2016 07:55
Hi,

basically that is no problem ;)

The 'length to be cutted' should be fairly easy to adjust.
Just create another inputBinding and adjust the 'cutLength' if the button was hit.

WoodHarvester:cutTree(length)
is used to move/delimb the trees through the head, if 'length' > 0
and it is used to cut the tree, if 'length' == 0

Maybe this little information can bring you forward?

You could take the original script and modify it to your desired behavior or try to overwrite only certain functions.
The first approach might be easier and better to handle.

Cheers,
Emil

Stig Ove Ruud (Unknown) 18.03.2016 23:55
Nice.. Problem is that I dont understand much of lua at all... How can I get the modified script to override the orginal one? I did my best to call it up in my mod modDesc.xml file but nothing happend


<extraSourceFiles>
<sourceFile filename="WoodHarvester.lua" />
</extraSourceFiles>

Emil Drefers (Unknown) 21.03.2016 07:45
Hi,

well that could wourk, but only under certain circumstances.

Probably it would make sense to find somebody who knows lua better?
Otherwise you might try to have a look at other mods and try to understand what ways of 'adding source code' are available and how they work, just to get into it and learn the basics ;)

Cheers,
Emil



Sven Hecht (Svenstihl2) 16.09.2018 04:19
Hello i need this scripte,
Woodharvester.lua
WoodHarvesterCutTreeEvent.lua
WoodHarvesterOnCutTreeEvent.lua
WoodHarvesterOnDelimbTreeEvent.lua for an attachable harvester head i cant get it running .. thanks for Help ;)

greetings Sven



William Beard (willbobber) 17.09.2018 18:17
This is a script that someone helped me to write that has altered the cut button. The ingame button is (a guess) B.
I needed the button to be what I wanted so he helped me write this. Its not the correct way of doing things he said but it works. it may get you going for now

WoodHarvester.load = Utils.appendedFunction(WoodHarvester.load, function (self)
local cutButtonStr = getXMLString(self.xmlFile, "vehicle.woodHarvester#cutButton")
if cutButtonStr ~= nil then
self.newCutBinding = InputBinding[cutButtonStr]
end
self.newCutBinding = Utils.getNoNil(self.newCutBinding, InputBinding.IMPLEMENT_EXTRA2)
end)

WoodHarvester.update = Utils.overwrittenFunction(WoodHarvester.update, function(self, superFunc, dt)
if self:getIsActive() then
-- Verify that the split shapes still exist (possible that someone has cut them)
if self.isServer then
local lostShape = false;
if self.attachedSplitShape ~= nil then
if not entityExists(self.attachedSplitShape) then
self.attachedSplitShape = nil;
self.attachedSplitShapeJointIndex = nil;
self.isAttachedSplitShapeMoving = false;
self.cutTimer = -1;
lostShape = true;
end
elseif self.curSplitShape ~= nil then
if not entityExists(self.curSplitShape) then
self.curSplitShape = nil;
lostShape = true;
end
end
if lostShape then
self:onCutTree(0);
if g_server ~= nil then
g_server:broadcastEvent(WoodHarvesterOnCutTreeEvent:new(self, 0), nil, nil, self);
end;
end;
end;
-- Check for input
if self:getIsActiveForInput(true) and self:getIsTurnedOn() then
if self.cutNode ~= nil then
if self.hasAttachedSplitShape then
if not self.isAttachedSplitShapeMoving and self:getAnimationTime(self.cutAnimation.name) == 1 then
if InputBinding.hasEvent(self.newCutBinding) then
self:cutTree(self.currentCutLength);
end
end
elseif self.curSplitShape ~= nil then
if InputBinding.hasEvent(self.newCutBinding) then
self:cutTree(0);
end
end
if InputBinding.hasEvent(InputBinding.IMPLEMENT_EXTRA3) then
if not self.isAttachedSplitShapeMoving then
self.currentCutLength = self.currentCutLength + self.cutLengthStep;
if self.currentCutLength > self.cutLengthMax+0.0001 then
self.currentCutLength = self.cutLengthMin;
end
if self.treeCutLengthHud ~= nil then
VehicleHudUtils.setHudValue(self, self.treeCutLengthHud, self.currentCutLength*100, 9999);
end;
end;
end
end;
end
--
if self.isServer and (self.attachedSplitShape ~= nil or self.curSplitShape ~= nil) then
if self.cutTimer > 0 then
if self.cutAnimation.name ~= nil then
if self:getAnimationTime(self.cutAnimation.name) > self.cutAnimation.cutTime then
self.cutTimer = 0;
end;
else
self.cutTimer = math.max(self.cutTimer - dt, 0);
end;
end;
local readyToCut = self.cutTimer == 0;
-- cut
if readyToCut then
self.cutTimer = -1;
local x,y,z = getWorldTranslation(self.cutNode);
local nx,ny,nz = localDirectionToWorld(self.cutNode, 1,0,0);
local yx,yy,yz = localDirectionToWorld(self.cutNode, 0,1,0);
local newTreeCut = false;
local currentSplitShape;
if self.attachedSplitShapeJointIndex ~= nil then
removeJoint(self.attachedSplitShapeJointIndex);
self.attachedSplitShapeJointIndex = nil;
currentSplitShape = self.attachedSplitShape;
self.attachedSplitShape = nil;
else
currentSplitShape = self.curSplitShape;
self.curSplitShape = nil;
newTreeCut = true;
end
-- remember split type name for later (achievement)
local splitTypeName = "";
local splitType = SplitUtil.splitTypes[getSplitType(currentSplitShape)];
if splitType ~= nil then
splitTypeName = splitType.name;
end;
if self.delimbOnCut then
local xD,yD,zD = getWorldTranslation(self.delimbNode);
local nxD,nyD,nzD = localDirectionToWorld(self.delimbNode, 1,0,0);
local yxD,yyD,yzD = localDirectionToWorld(self.delimbNode, 0,1,0);
local vx,vy,vz = x-xD,y-yD,z-zD;
local sizeX = Utils.vector3Length(vx,vy,vz);
removeSplitShapeAttachments(currentSplitShape, xD+vx*0.5,yD+vy*0.5,zD+vz*0.5, nxD,nyD,nzD, yxD,yyD,yzD, sizeX*0.7+self.delimbSizeX, self.delimbSizeY, self.delimbSizeZ);
end;
self.attachedSplitShape = nil;
self.curSplitShape = nil;
splitShape(currentSplitShape, x,y,z, nx,ny,nz, yx,yy,yz, self.cutSizeY, self.cutSizeZ, "woodHarvesterSplitShapeCallback", self);
if self.attachedSplitShape == nil then
self:onCutTree(0);
if g_server ~= nil then
g_server:broadcastEvent(WoodHarvesterOnCutTreeEvent:new(self, 0), nil, nil, self);
end;
else
if self.delimbOnCut then
local xD,yD,zD = getWorldTranslation(self.delimbNode);
local nxD,nyD,nzD = localDirectionToWorld(self.delimbNode, 1,0,0);
local yxD,yyD,yzD = localDirectionToWorld(self.delimbNode, 0,1,0);
local vx,vy,vz = x-xD,y-yD,z-zD;
local sizeX = Utils.vector3Length(vx,vy,vz);
removeSplitShapeAttachments(self.attachedSplitShape, xD+vx*3,yD+vy*3,zD+vz*3, nxD,nyD,nzD, yxD,yyD,yzD, sizeX*3+self.delimbSizeX, self.delimbSizeY, self.delimbSizeZ);
end;
end;
if newTreeCut then
-- increase tree cut counter for achievements
g_currentMission.missionStats:updateStats("cutTreeCount", 1);
-- update the types of trees cut so far (achievement)
if splitTypeName ~= "" then
g_currentMission.missionStats:updateTreeTypesCut(splitTypeName);
end;
end;
end;
-- delimb
if self.attachedSplitShape ~= nil and self.isAttachedSplitShapeMoving then
if self.delimbNode ~= nil then
local x,y,z = getWorldTranslation(self.delimbNode);
local nx,ny,nz = localDirectionToWorld(self.delimbNode, 1,0,0);
local yx,yy,yz = localDirectionToWorld(self.delimbNode, 0,1,0);
removeSplitShapeAttachments(self.attachedSplitShape, x,y,z, nx,ny,nz, yx,yy,yz, self.delimbSizeX, self.delimbSizeY, self.delimbSizeZ);
end
if self.cutNode ~= nil and self.attachedSplitShapeJointIndex ~= nil then
local x,y,z = getWorldTranslation(self.cutAttachReferenceNode);
local nx,ny,nz = localDirectionToWorld(self.cutAttachReferenceNode, 0,1,0);
local _, lengthRem = getSplitShapePlaneExtents(self.attachedSplitShape, x,y,z, nx,ny,nz);
if lengthRem == nil or lengthRem <= 0.1 then
-- end of tree
removeJoint(self.attachedSplitShapeJointIndex);
self.attachedSplitShapeJointIndex = nil;
self.attachedSplitShape = nil;
self:onDelimbTree(false);
if g_server ~= nil then
g_server:broadcastEvent(WoodHarvesterOnDelimbTreeEvent:new(self, false), nil, nil, self);
end;
self:onCutTree(0);
if g_server ~= nil then
g_server:broadcastEvent(WoodHarvesterOnCutTreeEvent:new(self, 0), nil, nil, self);
end;
else
self.attachedSplitShapeY = self.attachedSplitShapeY + self.cutAttachMoveSpeed*dt;
if self.attachedSplitShapeY >= self.attachedSplitShapeTargetY then
self.attachedSplitShapeY = self.attachedSplitShapeTargetY;
self:onDelimbTree(false);
if g_server ~= nil then
g_server:broadcastEvent(WoodHarvesterOnDelimbTreeEvent:new(self, false), nil, nil, self);
end;
end
if self.attachedSplitShapeJointIndex ~= nil then
local x,y,z = localToWorld(self.cutNode, 0.3,0,0);
local nx,ny,nz = localDirectionToWorld(self.cutNode, 1,0,0);
local yx,yy,yz = localDirectionToWorld(self.cutNode, 0,1,0);
local shape, minY, maxY, minZ, maxZ = findSplitShape(x,y,z, nx,ny,nz, yx,yy,yz, self.cutSizeY, self.cutSizeZ);
if shape == self.attachedSplitShape then
local treeCenterX,treeCenterY,treeCenterZ = localToWorld(self.cutNode, 0, (minY+maxY)*0.5, (minZ+maxZ)*0.5);
self.attachedSplitShapeX, _, self.attachedSplitShapeZ = worldToLocal(self.attachedSplitShape, treeCenterX,treeCenterY,treeCenterZ);
self:setLastTreeDiameter((maxY-minY + maxZ-minZ)*0.5);
end;
local x,y,z = localToWorld(self.attachedSplitShape, self.attachedSplitShapeX, self.attachedSplitShapeY, self.attachedSplitShapeZ);
setJointPosition(self.attachedSplitShapeJointIndex, 1, x,y,z);
end;
end
end
end;
end;
end;
-- PS and sound for cut and delimb
if self.isClient then
if self:getIsActive() then
-- cut
if self.cutAnimation.name ~= nil then
if self:getIsAnimationPlaying(self.cutAnimation.name) and self:getAnimationTime(self.cutAnimation.name) < self.cutAnimation.cutTime then
self.cutParticleSystemsActive = true;
for _,ps in pairs(self.cutParticleSystems) do
ParticleUtil.setEmittingState(ps, true);
end;
if self.harvesterSounds.cutSample ~= nil then
SoundUtil.play3DSample(self.harvesterSounds.cutSample);
end;
else
self.cutParticleSystemsActive = false;
for _,ps in pairs(self.cutParticleSystems) do
ParticleUtil.setEmittingState(ps, false);
end;
if self.harvesterSounds.cutSample ~= nil then
SoundUtil.stop3DSample(self.harvesterSounds.cutSample);
end;
end;
end;
-- delimb
if self.isAttachedSplitShapeMoving then
if #self.forwardingWheels > 0 then
local f = dt/1000;
for _,wheel in pairs(self.forwardingWheels) do
if wheel.node ~= nil then
rotate(wheel.node, wheel.rotSpeed[1]*f, wheel.rotSpeed[2]*f, wheel.rotSpeed[3]*f);
end;
end;
end;
if self.harvesterSounds.delimbSample ~= nil then
SoundUtil.play3DSample(self.harvesterSounds.delimbSample);
end;
for _,ps in pairs(self.delimbParticleSystems) do
self.delimbParticleSystemsActive = true;
ParticleUtil.setEmittingState(ps, true);
end;
else
if self.harvesterSounds.delimbSample then
SoundUtil.stop3DSample(self.harvesterSounds.delimbSample);
end;
for _,ps in pairs(self.delimbParticleSystems) do
ParticleUtil.setEmittingState(ps, false);
end;
end;
else -- turn all off, done in onDeactivateSounds()
end
end;
end)

WoodHarvester.draw = Utils.overwrittenFunction(WoodHarvester.draw, function(self, superFunc)
if self:getIsActiveForInput(true) and self:getIsTurnedOn() then
if self.cutNode ~= nil then
if self.hasAttachedSplitShape then
if not self.isAttachedSplitShapeMoving and self:getAnimationTime(self.cutAnimation.name) == 1 then
g_currentMission:addHelpButtonText(g_i18n:getText("action_woodHarvesterCut"), self.newCutBinding, nil, GS_PRIO_HIGH);
end
elseif self.curSplitShape ~= nil then
g_currentMission:addHelpButtonText(g_i18n:getText("action_woodHarvesterCut"), self.newCutBinding, nil, GS_PRIO_HIGH);
end
if not self.isAttachedSplitShapeMoving then
g_currentMission:addHelpButtonText(string.format(g_i18n:getText("action_woodHarvesterChangeCutLength"), string.format("%.1f",self.currentCutLength)), InputBinding.IMPLEMENT_EXTRA3, nil, GS_PRIO_NORMAL);
end;
if self.warnInvalidTreeRadius then
g_currentMission:showBlinkingWarning(g_i18n:getText("warning_treeTooThick"), 1000);
elseif self.warnInvalidTree then
g_currentMission:showBlinkingWarning(g_i18n:getText("warning_treeTypeNotSupported"), 1000);
end
end;
end
end)


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