NPC taxi script

Dear devs,

I’m looking for a simple script that would allows players to call a taxi if no taxi players are online.

-The player could call a taxi with his smartphone or with a chat cmd
-A taxi spawn with a NPC/Ped as driver 50 meters away and come pick up the player
-The player has to put a marker on the map, pay and the taxi go there.
-The taxi disappear 100 meters away from the player

Its like the native Taxi function of GTA5.

I’ve some coding skills but not enought to do it alone. This script has to be an open source github project.

Regards, kisses, peace

6 Likes

Just replying so I can watch this. Great idea

should not be to hard sounds a good idea I may look into coding this :slight_smile:

2 Likes

You’d have to make it so that an NPC that drives a taxi actually SPAWNS when the player calls one.

I’d try and look for a “base” script that allows interactions with NPC’s. I think maybe this one?:

But again; That doesn’t “bring” the NPC to you, Rather you must go up to them.
I hope this helped you generate some ideas as to how you can make this script a reality!

I already got a test version working were you can spawn cab it come to you and you can take a ride still in testing stages like i says but TomTom has it once am happy that its as best as it can be I will release it

some screenshots: https://imgur.com/a/OByRx

3 Likes

Hey, i have exactly smth like this, i was working on making an AI ambulance script, and if you’d like to have the code i can give it out to ya, so you can edit it, not working on that anymore :man_shrugging:

1 Like

yea send me that ice always like to check out other codes :slight_smile:

Its a bit messy, but it should work xD, in one hour ill be at the pc so i can send you it :stuck_out_tongue:

1 Like

oo ill not use it but ill read code best way to learn :slight_smile:

@wpgn Here’s an example on getting the taxi meters working and some audio stuff.

https://github.com/throwarray/gtav-rendertarget/tree/master/taxihud
https://pastebin.com/kg684cRz

1 Like

ok cheers ill take a look

-- variables --
ambulance=GetHashKey('ambulance')

paramedic=GetHashKey("S_M_M_Paramedic_01")

nearesthospital=nil

-- spawning events --

RegisterNetEvent('EMS:Spawn')
RegisterNetEvent('Coroner:Spawn')

-- report progress events --

RegisterNetEvent('EMS:Half')
RegisterNetEvent('Coroner:Half')
RegisterNetEvent('EMS:Arrived')
RegisterNetEvent('Coroner:Arrived')

-- spawning events handlers --

AddEventHandler('EMS:Spawn', function(target)
    Citizen.CreateThread(function()
        
    local pc = GetEntityCoords(target)
    RequestModel(ambulance)
	RequestModel(paramedic)
	
	while not HasModelLoaded(ambulance) and RequestModel(paramedic) do
		RequestModel(ambulance)
		RequestModel(paramedic)
		Citizen.Wait(0)
	end
    local offset=GetOffsetFromEntityInWorldCoords(PlayerPedId(), 50, 50, 0)
    local heading, spawn = GetNthClosestVehicleNodeFavourDirection(offset.x, offset.y, offset.z, pc.x, pc.y, pc.z, 50, 1, 0x40400000, 0)
    print('spawn point found!')
    local vehicle = CreateVehicle(ambulance, spawn.x, spawn.y, spawn.z, heading, true, false)
    
    created_ped = CreatePed(5, paramedic , spawn.x +2 , spawn.y+ 2, spawn.z+1, heading, true, true)
    SetEntityAsMissionEntity(created_ped, false, false)
    SetEntityAsMissionEntity(vehicle, false, false)

    AddBlipForEntity(created_ped)
    SetVehicleSiren(vehicle, true)
    LoadAllPathNodes(true)
    while not AreAllNavmeshRegionsLoaded() do
        Wait(1)
    end
    TaskEnterVehicle(created_ped, vehicle, 1000, -1, 20, 1, 0)
    while GetIsTaskActive(created_ped, 160) do
    Wait(1)
    end
    TaskVehicleDriveToCoordLongrange(created_ped, vehicle, pc.x, pc.y, pc.z, 15.0, 1074004284, 2.0)
    local arrived = false
    while not arrived do
	Citizen.Wait(0)
        local coords = GetEntityCoords(created_ped, true)
    local distance=Vdist(coords.x, coords.y, coords.z, pc.x, pc.y, pc.z)
    if distance < 25.0 then
    break
    end
    end
    print('arrived')
	local pheading, parking = GetNthClosestVehicleNodeFavourDirection(pc.x, pc.y, pc.z, pc.x, pc.y, pc.z, 10, 1, 0x40400000, 0)
    TaskVehiclePark(created_ped, vehicle, parking.x, parking.y, parking.z, pheading, 1, 60.0, 1)
    while GetEntitySpeed(vehicle)>0 do
        Wait(1)
    end  
    ClearPedTasks(created_ped)
      TaskLeaveVehicle(created_ped, vehicle, 0)
      while IsPedInAnyVehicle(created_ped, false) do
        Wait(1)
    end
	print('exited veh')
	ClearPedTasks(created_ped)     
    TaskGoToEntity(created_ped, target, -1, 4.0, 100, 1073741824, 0)

    while not arrived do
        Citizen.Wait(0)
            local coords = GetEntityCoords(created_ped, true)
        local distance=Vdist(coords.x, coords.y, coords.z, pc.x, pc.y, pc.z)
        if distance < 2.0 then
            print('arrived to target... kneeling...')
        break
        end
        end
    TaskStartScenarioInPlace(created_ped, 'CODE_HUMAN_MEDIC_KNEEL', 0, true)
    while IsPedActiveInScenario(created_ped) do
        Wait(1)
    end
    print("we're done here!")
end)
    
end)


-- command --
RegisterCommand("ems", function()
    
  
    local target = GetClosestSuitablePed()
    if target~=nil then
    TriggerEvent('EMS:Spawn', target)
    else
        print('no peds found :^/')
    end

end, false)


-- useful functions --


function table_to_string(tbl)
    local result = "{"
    for k, v in pairs(tbl) do
        -- Check the key type (ignore any numerical keys - assume its an array)
        if type(k) == "string" then
            result = result.."[\""..k.."\"]".."="
        end

        -- Check the value type
        if type(v) == "table" then
            result = result..table_to_string(v)
        elseif type(v) == "boolean" then
            result = result..tostring(v)
        else
            result = result.."\""..v.."\""
        end
        result = result..","
    end
    -- Remove leading commas from the result
    if result ~= "" then
        result = result:sub(1, result:len()-1)
    end
    return result.."}"
end
function GetPositionInfrontOfEntity(ped, scalar)
    target= nil
    entity = GetEntity(ped)
    right, forward, up, pos = GetEntityMatrix(entity)
    return pos + forward * scalar
  end
  function GetClosestSuitablePed()
		local handle, p = FindFirstPed()
		local success
		target=nil
    repeat
        success, p = FindNextPed(handle)
           local pos = GetEntityCoords(p)
         local distance = Vdist(pos.x, pos.y, pos.z, GetEntityCoords(PlayerPedId(), true).x, GetEntityCoords(PlayerPedId(), true).y, GetEntityCoords(PlayerPedId(), true).z)
         
         
                             
                             if distance <= 4 and p  ~= GetPlayerPed(-1) then
                                target=p
                                
                                break
                                 end
                               
                        
                   
    until not success
    return target
end

it’s a client_script obviously. it’s also incomplete xD
oh yeah, i forgot to mention some people who helped me :stuck_out_tongue:
@Syntasu for the GetPositionInfrontOfEntity function
@d0p3t for the GetClosestSuitablePed function

3 Likes

More audio stuff mostly…

-- Driver
model = GetHashKey("a_m_y_stlat_01");
voice = "A_M_M_EASTSA_02_LATINO_FULL_01"

vehicle = -- ...
driver = -- ...
dest = -- ...
dist = CalculateTravelDistanceBetweenPoints(GetEntityCoords(GetPlayerPed(-1), dest))

	-- AUDIO
	SetAmbientVoiceName(driver, voice)

	Talk(driver, "TAXID_WHERE_TO", 7)

	"TAXID_WHERE_TO" -- 7 or "SPEECH_PARAMS_FORCE_NORMAL_CLEAR"
	"TAXID_BEGIN_JOURNEY" -- 7
	"TAXID_BANTER" -- 24 or "SPEECH_PARAMS_ADD_BLIP"
	"TAXID_ARRIVE_AT_DEST" -- 7
	"TAXID_CLOSE_AS_POSS" -- 7
	"TAXID_NO_MONEY" -- 7
	"TAXID_CHANGE_DEST" -- 7
	"TAXID_RUN_AWAY" -- 7
	"TAXID_GET_OUT_EARLY" -- 7
	"TAXID_TRASHED" -- 7
	"TAXID_AFFORD_PART_JOURNEY" -- 7
	"TAXID_TAKE_FIRST_CAB" -- 7
	"TAXID_SPEED_UP" -- 7

-- Passenger
	-- RADIO
	if not IsAmbientSpeechPlaying(GetPlayerPed(-1)) then
		Talk(GetPlayerPed(-1), RadioIndexAudioString(GetPlayerRadioStationIndex()), "SPEECH_PARAMS_FORCE_NORMAL_CLEAR")
		SetVehicleRadioEnabled(vehicle, true)	
	end

	-- AUDIO
	"TAXI_CHANGE_DEST" -- 7
	"TAXI_STEP_ON_IT" -- 7
	"THANKS" -- 7

Can we get this on a GitHub Repo so we can contribute :wink:

@LGDevelopment It was what I’ve planned for this script.
@wpgn worked on it and did a basic version. He requested to not share it until it’s stable. He is the creator of this script so, let’s see with him.

1 Like

yea ill have a new version soon any feed back TomTom?

2 Likes

I’ve tryed it, and even if its a basic version, the biggest part of the job is done. It totally correspond to the idea I had.
Suggestion that you could take into account if you have some free time:

  • When you get inside the taxi
  1. place marker
  2. presse E to go there
    • Add delay (wait(10000)) to let the time to passengers to get in.
      If passengers enters before triggering E, the script bug.

-When the taxi arrive at the location

  1. Difficulties to find the nearest position
  2. Dont really stop
    • Add a delay (wait(10000)) to let the time to passengers to exit the taxi

-When the taxi leaves

  1. He can do circles around your destination marker
    • make him drives to one direction and desappears after 10 secondes even if he is visible by all.

The script is fonctionnal for me (basic version) but most of users will complains about bugs if they aren’t able to fix it by themself.

@wpgn You are the owner so you have to take the decision :wink: between sharing it in this state, sharing it as a github project or continue to work on it or something else

nice feedback my friend i will sort some of this in next build

@wpgn Would you be willing to share the script early? Been working on my own and would love to compare. Otherwise I’ll wait until it’s on GitHub and contribute

script is still being worked one once i have a working version i will share it there no point doing a github with code that dont work as I learn that most fivem people are lazy and dont want to code anything them selfs and will complain if it dont work out of the box so waiting till it works is best option then people can just add to it when needed.

1 Like