anybody order a taxi?
it's really just a play test but if any1 wants to use it here's how
follows standard waypoints (edited to be circular)
not bad for now, may edit the stopping and starting at some point so it really slows down when you get out rather than a dead stop.
you need;
- a car that's set as a character (ischaracter = 1 in fpe, may also need to adjust the fixnewy = 180)
- set it's own name in the ifused field
- give it the taxi.lua script
- some way points to follow (the first 1 must be kinda under and infront of the car)
optional
- some road to drive on (dont forget to set these as forcesimpleobstacle = 3 in their fpe)
- a sound effect in slot 1
- an image of the dashboard in the folder "scriptbank\images\car" named "000.png"
--script by smallg
local input = "e"
local pressed = 0
local waypoint_angle = {}
local state = {}
local taxi_angle = {}
local turn_speed = {}
local taxi_speed = {}
local start_point = {}
local delay = 250
local top_speed = 1000
local brake_power = top_speed / 100
local accel = top_speed / 200
function taxi_init(e)
CharacterControlUnarmed(e)
ai_soldier_pathindex[e] = -1
state[e] = "wait"
turn_speed[e] = top_speed / 400
taxi_speed[e] = 0
LoadImages("car",0)
end
function taxi_main(e)
EntObjNo = g_Entity[e]['obj']
CollisionOff(e)
if state[e] == "wait" then
StopSound(e,1)
HideImage(0)
if GetTimer(e) > delay then
Show(e)
end
if GetPlayerDistance(e) < 300 then
PromptLocal(e,"press " .. input .. " to get in the taxi")
if g_InKey == input and pressed == 0 then
pressed = 1
state[e] = "taxi"
Hide(e)
end
end
elseif state[e] == "taxi" then
SetImageAlignment(0)
SetImagePosition(50,50)
ShowImage(0)
LoopSound(e,1)
if g_InKey == input and pressed == 0 then
SetRotation(e,0,g_PlayerAngY,0)
pressed = 1
state[e] = "wait"
--AIEntityGoToPosition(EntObjNo,g_Entity[e]['x'],g_Entity[e]['y'])
delay = GetTimer(e) + 500
end
Panel(44,66,60,75)
TextCenterOnX(51,71,1,"Taxi Speed = "..taxi_speed[e])
if ai_soldier_pathindex[e] == -1 then
ai_soldier_pathindex[e] = -2
PathIndex = -1
PathPointIndex = -1
pClosest = 99999
for pa = 1, AIGetTotalPaths(), 1 do
for po = 1 , AIGetPathCountPoints(pa), 1 do
pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po)
pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po)
pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ))
if pDist < pClosest and pDist < 100 then
pClosest = pDist
PathIndex = pa
PathPointIndex = po
end
end -- po
end -- pa
if PathIndex > -1 then
ai_soldier_pathindex[e] = PathIndex
ai_path_point_index[e] = PathPointIndex
if start_point[e] == nil then
start_point[e] = ai_path_point_index[e]
end
ai_path_point_direction[e] = 1
ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e])
end
end
if ai_soldier_pathindex[e] > -1 then
ai_patrol_x[e] = AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e])
ai_patrol_z[e] = AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e])
waypoint_angle[e] = RotateToPoint(e,ai_patrol_x[e],ai_patrol_z[e])
if taxi_angle[e] == nil then
taxi_angle[e] = waypoint_angle[e]
end
if waypoint_angle[e] < taxi_angle[e] - (turn_speed[e] * 2.1) or waypoint_angle[e] > taxi_angle[e] + (turn_speed[e] * 2.1) then
if taxi_angle[e] > 180 then
if waypoint_angle[e] > taxi_angle[e] - 180 and waypoint_angle[e] < taxi_angle[e] then
taxi_angle[e] = taxi_angle[e] - turn_speed[e]
else
taxi_angle[e] = taxi_angle[e] + turn_speed[e]
end
else
if waypoint_angle[e] < taxi_angle[e] + 180 and waypoint_angle[e] > taxi_angle[e] then
taxi_angle[e] = taxi_angle[e] + turn_speed[e]
else
taxi_angle[e] = taxi_angle[e] - turn_speed[e]
end
end
end
--keep angle within 0 ~ 360
if taxi_angle[e] < -taxi_angle[e] then
taxi_angle[e] = 360 + taxi_angle[e]
elseif taxi_angle[e] >= 365 then
taxi_angle[e] = taxi_angle[e] - 360
end
SetRotation(e,0,taxi_angle[e],0)
turn_speed[e] = top_speed / 400
tDistX = g_Entity[e]['x'] - ai_patrol_x[e]
tDistZ = g_Entity[e]['z'] - ai_patrol_z[e]
DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))
if DistFromPath < 100 then
turn_speed[e] = top_speed / 100
if taxi_speed[e] > top_speed * 0.25 then
taxi_speed[e] = taxi_speed[e] - (brake_power * 2)
else
taxi_speed[e] = taxi_speed[e] + accel
end
elseif DistFromPath < top_speed / 3 then
if taxi_speed[e] > top_speed * 0.5 then
taxi_speed[e] = taxi_speed[e] - brake_power
end
else
if taxi_speed[e] < top_speed then
taxi_speed[e] = taxi_speed[e] + accel
end
end
MoveForward(e,taxi_speed[e])
TransportToIfUsed(e)
if DistFromPath < 45 then
if ai_path_point_direction[e] == 1 then
ai_path_point_index[e] = ai_path_point_index[e] + 1
if ( ai_path_point_index[e] > ai_path_point_max[e] ) then
ai_path_point_index[e] = start_point[e]
ai_path_point_direction[e] = 1
end
else
ai_path_point_index[e] = ai_path_point_index[e] - 1
if ( ai_path_point_index[e] < 1 ) then
ai_path_point_index[e] = 2
ai_path_point_direction[e] = 1
end
end
end
end
if g_InKey ~= input then
pressed = 0
end
end
if g_InKey ~= input then
pressed = 0
end
end --main
function taxi_exit(e)
end
function RotateToEntity(e,v)
if g_Entity[e] ~= nil and g_Entity[e] ~= 0 and g_Entity[v] ~= nil and g_Entity[v] ~= 0 then
local x = g_Entity[v]['x'] - g_Entity[e]['x']
local z = g_Entity[v]['z'] - g_Entity[e]['z']
local angle = math.atan2(x,z)
angle = angle * (180.0 / math.pi)
if angle < 0 then
angle = 360 + angle
elseif angle > 360 then
angle = angle - 360
end
--SetRotation(e,0,angle,0)
return angle
end
end
function RotateToPoint(e,x,z)
if g_Entity[e] ~= nil and x > 0 and z > 0 then
local destx = x - g_Entity[e]['x']
local destz = z - g_Entity[e]['z']
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
--SetRotation(e,0,angle+180,0)
return angle
end
end
life\'s one big game
windows vista ultimate
i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11