Community Forum

Scripting help needed

Forum Overview >> Scripting

CategoryScripting
Created15.04.2022 19:00


Pieter H (PGHTJE) 15.04.2022 19:00
I can script in LUA but have problems with the internal specific game commands/functions/variables

cant see the difference between game commands and user created commands/variables/functions in existed scripts
so i cant get all the pices out that i need, i was looking in the towingchain.lua for my pices but cant find the right ones

and i have read many documentations on this website but cant find my way out, its more like a needle in a haystack to find your way in the docs an tutorials thats why i wanna ask someone to help me out with the last pices marked below with ???

Project data:
im making a SPMT (Self Propelled Modular Transporter)
each SPMT is marked/registered as a vehicle and i can drive them in game one by one but not together as one

all the ingame xml things working great
and i can connect so many SPMT's as i would together
but only 1 vehicle where i sit in give engine power right now

i show you a snipset from my XML about the attach between the SPMT's thats relevant for the scripting part

<!-- XML settings (all the SEC connecting to the PRIM is working by attachableRegister.lua and attachableTowBar.lua) --->
<attacherJoints>
<attacherJoint node="LengthAttacherPrim" jointType="trailer" lowerRotLimit="10 50 50" lowerTransLimit="0 0 0" upperRotRotationOffset="0" allowsJointLimitMovement="false">
<schema position="1 0" rotation="0" invertX="true" />
</attacherJoint>
<attacherJoint node="LengthAttacherSec" jointType="hookLift" lowerRotLimit="0 0 0" upperRotationOffset="0" allowsJointLimitMovement="false" canTurnOnImplement="false">
<schema position="1 0" rotation="0" invertX="false"/>
<objectChange node="ConnectPin" translationActive="-0.25 0 0" translationInactive="0 0 0"/>
<objectChange node="BoltsFront" visibilityActive="true" visibilityInactive="false" />
</attacherJoint>

<attacherJoint node="SideAttacherLeftPrim" jointType="trailer" lowerRotLimit="10 50 50" lowerTransLimit="0 0 0" upperRotRotationOffset="0" allowsJointLimitMovement="false">
<schema position="1 0" rotation="0" invertX="true" />
<objectChange node="SideAttacherLeftSec" translationActive="0 -2 0" translationInactive="0 0 0"/>
</attacherJoint>
<attacherJoint node="SideAttacherLeftSec" jointType="hookLift" lowerRotLimit="0 0 0" upperRotationOffset="0" allowsJointLimitMovement="false" canTurnOnImplement="false">
<schema position="1 0" rotation="0" invertX="false"/>
<objectChange node="SideSupportLeft" visibilityActive="true" visibilityInactive="false" />
</attacherJoint>

<attacherJoint node="SideAttacherRightPrim" jointType="trailer" lowerRotLimit="10 50 50" lowerTransLimit="0 0 0" upperRotRotationOffset="0" allowsJointLimitMovement="false">
<schema position="1 0" rotation="0" invertX="true" />
<objectChange node="SideAttacherRightSec" translationActive="0 -2 0" translationInactive="0 0 0"/>
</attacherJoint>
<attacherJoint node="SideAttacherRightSec" jointType="hookLift" lowerRotLimit="0 0 0" upperRotationOffset="0" allowsJointLimitMovement="false" canTurnOnImplement="false">
<schema position="1 0" rotation="0" invertX="false"/>
<objectChange node="SideSupportRight" visibilityActive="true" visibilityInactive="false" />
</attacherJoint>

<sounds>
<attach template="ATTACH_01" />
<hydraulic template="DEFAULT_HYDRAULIC_SOUND" />
</sounds>
</attacherJoints>
<!-- end of my pice of XML --->

i need a script that does the following thing:

When you are sitting in the scripted MAIN OBJECT behind the SPMT(in the big box) marked as vehicle
he need to tell all unscripted attached SPMT childs [by xml attacherJoints] to do the same things as he self
engine start/engine stop
drive forward/drive backward
steer left/steer right

this is what i got on the LUA scripting part until now:

function SeriePowered:onUpdate(dt, isActiveForInput, isActiveForInputIgnoreSelection, isSelected)
if self.spec_enterable.isEntered then
local FORWARD_BACKWARD, LEFT_RIGHT = 0

if self.spec_drivable.axisForward ~= nil and self.spec_drivable.axisForward ~= 0 then
FORWARD_BACKWARD = self.spec_drivable.axisForward
end

if self.spec_drivable.axisSide ~= nil and self.spec_drivable.axisSide ~= 0 then
LEFT_RIGHT = self.spec_drivable.axisSide
end

for ATTACHED_OBJECT_ID in pairs(???) do --(loop through attached childs)
if self.spec_motorized.isMotorStarted and not ATTACHED_OBJECT_ID.spec_motorized.isMotorStarted then
ATTACHED_OBJECT_ID:startMotor(false)
elseif not self.spec_motorized.isMotorStarted and ATTACHED_OBJECT_ID.spec_motorized.isMotorStarted then
ATTACHED_OBJECT_ID:stopMotor(false)
end

if FORWARD_BACKWARD ~= 0 or LEFT_RIGHT ~= 0 then
Drivable.updateVehiclePhysics(ATTACHED_OBJECT_ID, FORWARD_BACKWARD, LEFT_RIGHT, BRAKE, dt)
end
end
end
end

Pieter H (PGHTJE) 16.04.2022 17:43
Problem solved


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