pilot_angle = 35 pilot_range = 350 pressed = 0 state = {} speed = {} max_speed = {} accleration = {} max_reversing_speed = {} brake_power = {} reverse_accleration = {} seat_posx = {} seat_posy = {} seat_modi = {} drift_slow = {} turn_speed = {} max_turnspeed = {} max_height_gain = {} last_weapon = 0 local new_y = 0 local seatx = 0 local seatz = 0 local turning = 0 local turningx = 0 local gain_height = 0 function spaceship_init(e) state[e] = "landed" speed[e] = 0 max_speed[e] = 1000 --maximum speed (forwards) accleration[e] = 0.5 --how quickly you reach max speed (forwards) brake_power[e] = 2 --how quickly you stop max_reversing_speed[e] = 600 --maximum speed (backwards) reverse_accleration[e] = 0.25 --how quickly you reach max reverse speed max_height_gain[e] = 50 --how quickly you gain/lose height while aiming the nose (more tilt = more impact) turn_speed[e] = 0.3 --how quickly the ship starts to turn max_turnspeed[e] = 50 --maximum turning speed the ship can reach (low value = wide turns) seat_posx[e] = 260 --how far forward the seat is on the model seat_posy[e] = 80 --how high up the seat is on the model seat_modi[e] = 0.14 --adjusts how much the seat is moved while tilting (not 100% working) drift_slow[e] = 0.25 --allows for ship to slow down if not controlled end function spaceship_main(e) if state[e] == "landed" then if PlayerLooking(e,pilot_range,pilot_angle) == 1 then PromptLocal(e,"Pilot the ship? (e)") if g_KeyPressE == 1 and pressed == 0 then pressed = 1 last_weapon = g_PlayerGunID SetPlayerWeapons(0) turning = 0 new_seatpos = seat_posy[e] new_seatdist = seat_posx[e] state[e] = "flying" end end elseif state[e] == "flying" then Panel(0,0,50,12) TextCenterOnX(25,5,3,speed[e].." MPH") TextCenterOnX(25,10,3,g_Entity[e]['y'].."m above ground") if g_KeyPressW == 1 then if speed[e] < max_speed[e] then speed[e] = speed[e] + accleration[e] else speed[e] = max_speed[e] end elseif g_KeyPressS == 1 then if speed[e] > 0 then speed[e] = speed[e] - brake_power[e] elseif speed[e] > -max_reversing_speed[e] then speed[e] = speed[e] - reverse_accleration[e] elseif speed[e] < 0 then speed[e] = -max_reversing_speed[e] end elseif g_KeyPressC == 1 and speed[e] < max_speed[e]*0.1 and speed[e] > -max_reversing_speed[e]*0.1 then speed[e] = 0 else if speed[e] > 0 then speed[e] = speed[e] - drift_slow[e] elseif speed[e] < 0 then speed[e] = speed[e] + drift_slow[e] else speed[e] = 0 end end if speed[e] > 0 then if g_KeyPressA == 1 then turning = turning - (turn_speed[e]*(speed[e]/max_speed[e])) elseif g_KeyPressD == 1 then turning = turning + (turn_speed[e]*(speed[e]/max_speed[e])) else if turning > (turn_speed[e]/2) then turning = turning - (turn_speed[e]/2) elseif turning < (turn_speed[e]/2) then turning = turning + (turn_speed[e]/2) else turning = 0 end end elseif speed[e] < 0 then if g_KeyPressA == 1 then turning = turning - (turn_speed[e]*(speed[e]/max_reversing_speed[e])) elseif g_KeyPressD == 1 then turning = turning + (turn_speed[e]*(speed[e]/max_reversing_speed[e])) else if turning > (turn_speed[e]/2) then turning = turning - (turn_speed[e]/2) elseif turning < (turn_speed[e]/2) then turning = turning + (turn_speed[e]/2) else turning = 0 end end end if turning < -max_turnspeed[e] then turning = -max_turnspeed[e] elseif turning > max_turnspeed[e] then turning = max_turnspeed[e] end if speed[e] == 0 then turning = 0 end -- -40 = up -- +40 = down if g_KeyPressR == 1 then if g_Entity[e]['anglex'] > -40 then turningx = turningx-0.1 new_seatpos = new_seatpos+seat_modi[e] new_seatdist = new_seatdist-seat_modi[e] else turningx = 0 end --seat_posy[e] = seat_posy[e]+10 elseif GetScancode() == 16 then if g_Entity[e]['anglex'] < 40 then turningx = turningx+0.1 new_seatpos = new_seatpos-seat_modi[e] new_seatdist = new_seatdist+seat_modi[e] else turningx = 0 end --seat_posy[e] = seat_posy[e]-10 else if turningx > 1 then turningx = turningx-0.1 new_seatpos = new_seatpos+seat_modi[e] new_seatdist = new_seatdist+seat_modi[e] elseif turningx < -1 then turningx = turningx+0.1 new_seatpos = new_seatpos-seat_modi[e] new_seatdist = new_seatdist-seat_modi[e] else turningx = 0 end end if turningx > 10 then turningx = 10 elseif turningx < -10 then turningx = -10 end if g_Entity[e]['anglex'] < 0 then gain_height = 1 elseif g_Entity[e]['anglex'] > 0 then gain_height = -1 else gain_height = 0 end CollisionOff(e) RotateX(e,turningx) MoveForward(e,speed[e]) MoveUp(e,gain_height*(max_height_gain[e]*(math.abs(g_Entity[e]['anglex'])/31))) RotateY(e,turning) CollisionOn(e) new_y = math.rad(g_Entity[e]['angley']) seatx = g_Entity[e]['x'] + (math.sin(new_y) * new_seatdist) seatz = g_Entity[e]['z'] + (math.cos(new_y) * new_seatdist) SetFreezeAngle(g_Entity[e]['anglex'],g_Entity[e]['angley'],g_Entity[e]['anglez']) SetFreezePosition(seatx,g_Entity[e]['y']+new_seatpos,seatz) TransportToFreezePosition() if speed[e] == 0 and g_Entity[e]['y'] < GetTerrainHeight(g_Entity[e]['x'],g_Entity[e]['z'])+10 then TextCenterOnX(50,85,3,"Press E to get out") if g_KeyPressE == 1 and pressed == 0 then pressed = 1 SetPlayerWeapons(1) ChangePlayerWeaponID(last_weapon) CollisionOn(e) state[e] = "landed" end end end if g_KeyPressE == 0 then pressed = 0 end end function PlayerLooking(e,dis,v) if g_Entity[e] ~= nil then if dis == nil then dis = 3000 end if v == nil then v = 0.5 end if GetPlayerDistance(e) <= dis then local destx = g_Entity[e]['x'] - g_PlayerPosX local destz = g_Entity[e]['z'] - g_PlayerPosZ local angle = math.atan2(destx,destz) angle = angle * (180.0 / math.pi) if angle <= 0 then angle = 360 + angle elseif angle > 360 then angle = angle - 360 end while g_PlayerAngY < 0 or g_PlayerAngY > 360 do if g_PlayerAngY <= 0 then g_PlayerAngY = 360 + g_PlayerAngY elseif g_PlayerAngY > 360 then g_PlayerAngY = g_PlayerAngY - 360 end end local L = angle - v local R = angle + v if L <= 0 then L = 360 + L elseif L > 360 then L = L - 360 end if R <= 0 then R = 360 + R elseif R > 360 then R = R - 360 end if (L < R and math.abs(g_PlayerAngY) > L and math.abs(g_PlayerAngY) < R) then return 1 elseif (L > R and (math.abs(g_PlayerAngY) > L or math.abs(g_PlayerAngY) < R)) then return 1 else return 0 end else return 0 end end end