--@name susp builder --@author loh kakoito --@shared if SERVER then --Settings local elasticConst = 15000 local elasticDamp = 2000 local baseMass = 700 local wheelMass = 65 local suspenionArm = 300 local wheelModel = "models/sprops/trans/wheel_b/t_wheel30.mdl" --######## wire.adjustInputs( {'E1', 'E2', 'E3', 'E4'}, {'entity', 'entity', 'entity', 'entity'} ) local e1 = wire.ports.E1 local e2 = wire.ports.E2 local e3 = wire.ports.E3 local e4 = wire.ports.E4 local base = chip():isWeldedTo() base:setAngles(Angle(0,90,0)) base:setMass(baseMass) local errorSound = "buttons/button10.wav" local hintSound = "buttons/button15.wav" local plates = {} hook.add('ClientInitialized', 'init', function(Player) if Player == owner() then net.start("info") net.writeEntity(base) net.writeString(wheelModel) net.send(Player) timer.create("plateCheck", 1, 0, CheckSteerPlates) end end) function SendClientNotification (message, type, duration) net.start('send_client_notification') net.writeInt(type, 8) net.writeFloat(duration) net.writeString(message) net.send() sounds.create(chip(), type == NOTIFY.HINT and hintSound or errorSound):play() end function CheckSteerPlates() e1 = wire.ports.E1 e2 = wire.ports.E2 e3 = wire.ports.E3 e4 = wire.ports.E4 if e1:isValid() and e2:isValid() and e3:isValid() and e4:isValid() then plates = {e1, e2, e3, e4} timer.stop("plateCheck") print("Arrows to move it") print("Enter to send settings and spawn") SendClientNotification('Arrows to move it', NOTIFY.HINT, 5) else print("Connect steering plates") SendClientNotification('Connect steering plates', NOTIFY.ERROR, 5) end end local Positions = {} local Angles = {} function Build() for i = 1, 4 do plates[i]:setAngles(base:getAngles()) local wheel = prop.create(Positions[i], Angles[i], wheelModel, true) wheel:setMass(wheelMass) wheel:enableSphere(true) constraint.rope(i, wheel, base, nil, nil, Vector(0), base:worldToLocal(wheel:localToWorld(Vector(suspenionArm,-suspenionArm,0))), nil, nil, nil, nil, nil, true) constraint.rope(i, wheel, base, nil, nil, Vector(0), base:worldToLocal(wheel:localToWorld(Vector(-suspenionArm,-suspenionArm,0))), nil, nil, nil, nil, nil, true) constraint.ballsocketadv(wheel, plates[i], nil, nil, Vector(0), Vector(0), nil, nil, Vector(-180, -0.1, -0.1), Vector(180, 0.1, 0.1), Vector(0), true, true) constraint.ballsocketadv(plates[i], wheel, nil, nil, Vector(0), Vector(0), nil, nil, Vector(-180, 0.1, 0.1), Vector(180, -0.1, -0.1), Vector(0), true, true) constraint.elastic(i, wheel, base, nil, nil, Vector(0), base:worldToLocal(wheel:localToWorld(Vector(0,0,0))), elasticConst, elasticDamp, nil, nil, true) constraint.elastic(i, wheel, base, nil, nil, Vector(0), base:worldToLocal(wheel:localToWorld(Vector(0,0,0))), elasticConst, 100, nil, nil, true) end SendClientNotification("Use 'Make Spherical' tool on the wheels then dupe and delete the chip", NOTIFY.HINT, 15) print("Use 'Make Spherical' tool on the wheels then dupe and delete the chip") end net.receive("settings", function() for i = 1, 4 do Positions[i] = net.readVector() Angles[i] = net.readAngle() end Build() end) end if CLIENT and player() == owner() then local Fwd = 0 local Bck = 0 local Lft = 0 local Rgh = 0 local Ctrl = 0 local Enter = 0 local Alternative = 0 hook.add('inputPressed', 'KeyPress', function(key) if key == KEY.UPARROW then Fwd = 1 elseif key == KEY.DOWNARROW then Bck = 1 elseif key == KEY.LEFTARROW then Lft = 1 elseif key == KEY.RIGHTARROW then Rgh = 1 elseif key == KEY.CTRL then Ctrl = 1 elseif key == KEY.ENTER then Enter = 1 elseif key == KEY.SHIFT then Alternative = 1 end end) hook.add('inputReleased', 'KeyRelease', function(key) if key == KEY.UPARROW then Fwd = 0 elseif key == KEY.DOWNARROW then Bck = 0 elseif key == KEY.LEFTARROW then Lft = 0 elseif key == KEY.RIGHTARROW then Rgh = 0 elseif key == KEY.CTRL then Ctrl = 0 elseif key == KEY.ENTER then Enter = 0 print(1) SendSettings() elseif key == KEY.SHIFT then Alternative = 0 end end) local wheelModel = "" local base local wheels = {} local ready = false local addPos = Vector(0) local addX = 0 local deadEnd = false local holoSpeed = 0.1 function Build() bHolo = holograms.create(base:getPos(), base:getAngles(), "models/holograms/hq_icosphere.mdl") bHolo:setColor(Color(255,0,0,100)) bHolo:setScale(Vector(0.2)) for i = 1, 4 do local LeftOrRight = i%2 == 0 and 1 or -1 local BackOrForw = i>2 and -1 or 1 wheels[i] = holograms.create(bHolo:localToWorld(Vector(50*BackOrForw,30*LeftOrRight,0)), Angle(0,90 * LeftOrRight,0), wheelModel) end end net.receive("info", function() net.readEntity(function(ent) base = ent end) wheelModel = net.readString() Build() end) net.receive('send_client_notification', function () local type = net.readInt(8) local duration = net.readFloat() local message = net.readString() notification.addLegacy(message, type, duration) end) function SendSettings() if #wheels > 0 and deadEnd == false then net.start("settings") for i = 1, 4 do net.writeVector(wheels[i]:getPos()) net.writeAngle(wheels[i]:getAngles()) end net.send() holograms.removeAll() end deadEnd = true end hook.add("think", "runtime", function() if #wheels > 0 and deadEnd == false then for i = 1, 4 do local LeftOrRight = i%2 == 0 and 1 or -1 local BackOrForw = i>2 and -1 or 1 if Alternative == 1 then addX = addX + (Fwd - Bck) * (Ctrl == 1 and holoSpeed / 10 or holoSpeed) else addPos = addPos + Vector(Fwd - Bck, Lft - Rgh, 0) * (Ctrl == 1 and holoSpeed / 10 or holoSpeed) addPos[2] = math.max(addPos[2], 0) addPos[1] = math.max(addPos[1], 0) end bHolo:setPos(base:localToWorld(Vector(addX,0,0))) wheels[i]:setPos(bHolo:localToWorld(Vector(addPos[1]*BackOrForw,addPos[2]*LeftOrRight,0))) end end end) end