[Expression 2] Universal Engine

Discussion in 'Your Works' started by Locko1997, May 7, 2016.

  1. Locko1997

    Locko1997 Member
    Server Administrator

    Joined:
    Apr 15, 2016
    Messages:
    53
    Likes Received:
    10
    Hello! i finished my first iteration of universal engine!. This means that this engine works for every boat the same, as it adjusts the force applied according to the engine total mass.

    This is the first Iteration so it's a bit simple.

    1) Copy the Code
    2) Paste the code on Expression 2 tool
    3) Spawn it in the central prop of your ship ( Yes, that big prop that is on the middle of your boat were you welded all your crap to.)
    Remember, The Force will be applied on that prop only, so if your ship is unbalanced or the prop is not on the middle of the boat, it might cause deviations )
    4) Spawn a seat facing front ( It's important because the force will be applied in the forward direction of this seat )
    5) Link Pod[wirelink] to a Pod controler.
    6) Win

    Code:
    @name Universal_Engine
    @inputs Pod:wirelink Egp:wirelink
    @outputs Throttle Speed AngSpeed:angle
    @persist Props:array Entity:entity
    interval(100)
    
    W = Pod["W",number]
    S = Pod["S",number]
    D = Pod["D",number]
    A = Pod["A",number]
    Active = Pod["Active",number]
    Alt = Pod["Alt",number]
    R = Pod["Reload",number]
    F = Pod["Light",number]
    Mouse1 = Pod["Mouse1",number]
    Mouse2 = Pod["Mouse2",number]
    PodEntity = Pod["Entity",entity]
    
    MaxSpeed = 15
    Mult = 2
    
    
    if ( first() | dupefinished() ) {
      
          
        Props = entity():isWeldedTo():getConstraints()
        Entity = entity():isWeldedTo()
      
        function number entity:totalMass() {
            local Entities = This:getConstraints()
            local Mass = This:mass()
            for(I=1,Entities:count()) {Mass += Entities[I,entity]:mass()}
            return Mass
        }
      
        Egp:egpText(1,"",vec2(256,260)) # MPH text
        Egp:egpColor(1,vec(255,255,255))
        Egp:egpSize(1,30)
        Egp:egpPos(1,vec2(40,250))
      
      
    }
    # End of first or dupe finished
    
    
    if(Active){
      
        Egp:egpSetText(1,"Mph: " + round(Speed,0))
      
      
      
        if(W||S){Throttle+=(W-S)*1}
        if( Throttle>100 ){Throttle=100}
        elseif( Throttle<-30 ){Throttle=-30}
    }
    else{
      
        if(Throttle<=100 && Throttle>=-1 && Throttle !=0 ){Throttle-=2}
        elseif(Throttle<=1 && Throttle>=-30 && Throttle!=0){Throttle+=2}
    }
    
    For = PodEntity:forward()
    Pos = entity():pos()
    Vel = Entity:vel():length()
    Speed = toUnit("mph",Vel)
    AngSpeed = entity():angVel()
    Angle = ang(0, (A-D)*90, 0)
    
    if(Speed<MaxSpeed){
      
        Entity:applyForce( ( ( vec(100,100,0)*For*Throttle/100)* Mult - entity():vel()/2 ) * entity():totalMass())
    }
    else{ Entity:applyForce(-Entity:vel()) }
      
    if(A || D){Entity:applyAngForce( ( Angle*Mult*2 + Angle*Speed/2 )* entity():totalMass() ) }
    
    
    
    
    
     
    #1 Locko1997, May 7, 2016
    Last edited: May 16, 2016
    Altair likes this.
  2. Captain Barry

    Captain Barry Toby Larone
    Server Administrator

    Joined:
    Apr 22, 2016
    Messages:
    53
    Likes Received:
    10
    It produces and error when spawned for me. "Variable (Egp) does not exist at line 35, char 6"
     
  3. Locko1997

    Locko1997 Member
    Server Administrator

    Joined:
    Apr 15, 2016
    Messages:
    53
    Likes Received:
    10
    There, it should work now. Cant check right now so lemme know
     

Share This Page