Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @name Utility connector thing
- @inputs ToggleAttach ToggleExtend [Base]:entity
- @outputs Lock Locked Other_Base:entity Step LiftHeight LiftSpeed RopeDistance
- @outputs E2_pos:vector Find:entity [Force_Vec AxisPos]:vector Dist Sound Extend ExtendActive RopeLength SetLength
- #made by Pote
- LiftHeight = 12
- LiftSpeed = 1
- AxisPos = vec(-30, 0, 0) #local to e2, dont set it tiny values
- #[
- HOW TO USE:
- +- INPUTS ------------------------------------------------------------------------------------------+
- | ToggleAttach is a key to toggle the connector |
- | ToggleExtend is a key to raise or lower the tool |
- | Base is the baseplate of your vehicle |
- | |
- +- VEHICLE -----------------------------------------------------------------------------------------+
- | place this e2 wherever you want the vehicle connector to be (in lowered position) |
- | little arrow on the e2 needs to face forward |
- | the chip should be parented to Base (no constraints needed) |
- | |
- +- TOOL --------------------------------------------------------------------------------------------+
- | on your utility tool, at the position of the connector, place an e2 named 'Tool connector' |
- | it should be at the same angle as the vehicle e2 |
- | contents of this e2 can be anything, we only need its name to be Tool connector |
- | parent it to the base of the tool, then apply a nocollide constraint between it and the tool base |
- +---------------------------------------------------------------------------------------------------+
- # ah btw when the tool is frozen or physgunned something could explode
- ]#
- if( first() | dupefinished() )
- {
- enableConstraintUndo(0)
- }
- if( ~ToggleAttach & ToggleAttach )
- {
- Lock = !Lock
- soundPlay( 1, 1, "buttons/lightswitch2.wav" )
- }
- if( Lock )
- {
- E2_pos = entity():pos()
- findClearWhiteList()
- findExcludeEntity( entity() )
- findIncludeClass( "gmod_wire_expression2" )
- findInSphere( E2_pos, 72 )
- Find = findClosest( E2_pos )
- if( Find:getName() == "Tool connector" )
- {
- Other_Base = Find:isConstrainedTo()
- }
- else
- {
- Find = noentity()
- Lock = 0
- soundPlay( 2, 1, "buttons/button8.wav" )
- }
- }
- if(Locked)
- {
- switch(Step)
- {
- case 1,
- Other_Base:setAng(entity():angles() - Other_Base:toLocal(Find:angles()))
- Other_Base:setPos(entity():toWorld(Find:toLocal(Other_Base:pos())))
- break
- case 2,
- axis(Base, Base:toLocal(entity():toWorld(AxisPos)), Other_Base, vec(), 0, Base:toLocal(entity():toWorld(AxisPos+vec(0,1,0))))
- # id ent1 local pos to ent1 ent2 local pos to ent2 addlength w mat rigid
- #rope(1, Base, Base:toLocal(entity():toWorld(vec(0,0,LiftHeight))), Other_Base, Other_Base:toLocal(E2_pos), 0, 0, "", 0)
- #rope(2, Base, Base:toLocal(E2_pos), Other_Base, Other_Base:toLocal(E2_pos), LiftHeight, 0, "", 0)
- # id ent1 local pos to ent1 ent2 local pos to ent2 width
- hydraulic(323, Base, Base:toLocal(entity():toWorld(vec(0,0,LiftHeight*4))), Other_Base, Other_Base:toLocal(entity():toWorld(vec(-AxisPos:x(),0,0))), 0)
- break
- case 3,
- Other_Base:propFreeze(0)
- Base:propFreeze(0)
- ExtendActive = 1
- Extend = 1
- Base:constraintBreak( "weld", Other_Base )
- break
- }
- if(Step < 4)
- {
- interval(15)
- Step++
- }
- if(~ToggleExtend & ToggleExtend)
- {
- Extend = !Extend
- ExtendActive = 1
- Base:constraintBreak( "weld", Other_Base )
- }
- if(ExtendActive)
- {
- interval(15)
- RopeLength += clamp(LiftHeight*Extend - RopeLength, -LiftSpeed/10, LiftSpeed/10)
- SetLength = LiftHeight*4 - RopeLength*2
- Base:setLength(323, SetLength)
- if(Dist*Extend > LiftHeight*Extend | !RopeLength)
- {
- ExtendActive = 0
- }
- }
- elseif(Extend)
- {
- weld(Base, Other_Base)
- }
- }
- if( Lock )
- {
- Dist = E2_pos:distance( Find:pos() )
- if( Dist > 1 & !Locked )
- {
- interval(15)
- Force_Vec = ( E2_pos - Find:pos() ) * Other_Base:mass() * 10 / clamp(Dist + ( Find:vel() - Base:vel() ):length()/20, 1, 30)
- Other_Base:applyOffsetForce( Force_Vec + $Force_Vec * 5, Find:pos() )
- Base:applyOffsetForce( -( Force_Vec + $Force_Vec * 5), E2_pos )
- }
- elseif( !Locked )
- {
- Other_Base:propFreeze(1)
- Base:propFreeze(1)
- Locked = 1
- Step = 1
- soundPlay( 4, 1, "buttons/latchunlocked2.wav" )
- interval(15)
- }
- if( Sound )
- {
- Sound = 0
- soundPlay( 3, 1, "buttons/button9.wav" )
- }
- }
- else
- {
- Base:constraintBreak( "rope", Other_Base )
- Base:constraintBreak( "axis", Other_Base )
- Base:constraintBreak( "weld", Other_Base )
- Base:constraintBreak( "elastic", Other_Base )
- Locked = 0
- Sound = 1
- Step = 0
- RopeLength = 0
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement