#EntityCreate , EntityCreated

1 messages · Page 1 of 1 (latest)

spring hearth
#

Hello. Currently working on a stretcher system ,but when i want to check if the vehicle is an ambulance vehicle in EntityCreated i dont get back any print after the first attempt

RegisterNetEvent('entityCreating')
AddEventHandler('entityCreating', function(entity)
    while not DoesEntityExist(entity) do Wait(100) end

    local model = GetEntityModel(entity)
    if mainConfig.stretcherVehicles[model] then
        print('asd')
    end
end)

RegisterNetEvent('entityCreating')
AddEventHandler('entityCreating', function(entity)
    while not DoesEntityExist(entity) do Wait(100) end

    local model = GetEntityModel(entity)
    if mainConfig.stretcherVehicles[model] then
        print('asd')
    end
end)

When i get out the vehicle (garage) or spawn 1 in serverSide i got back the asd print. after that i can spawn 3623888+ doesent give me any print.

obsidian fox
#

I'm either an idiot or you just add the eventhandler, and don't use the register

dusky raft
#

Snowy is right, its just AddEventHandler. As a side note and more of a nitpick, I recommend you check that the entity is of type 2 before proceeding with the model check. Maybe also try entityCreated instead.

Furthermore, I'm not exactly sure what you mean by it doesnt print after the first attempt but regardless I would add a print statement for when it fails and see what model hash is returning. Hopefully this is helpful.

AddEventHandler('entityCreated', function(entity)
    if not DoesEntityExist(entity) then return end
    if GetEntityType(entity) ~= 2 then return end

    local model = GetEntityModel(entity)
    if mainConfig.stretcherVehicles[model] then
        print('asd')
    else
        print(entity, model)
    end
end)
obsidian fox
#

OMG IM RIGHT ONCE

obsidian fox
#

i told ya

spring hearth
obsidian fox
#

whats ur artifacts

spring hearth
#

10191 XD

#

2024-10-03

obsidian fox
#

great uhhh

#

check against this list

spring hearth
#

10191GetVehicleNumberPlateText server native broken, will cause issues with scripts involving vehicles

obsidian fox
#

yeah saw it

spring hearth
#

Thats why i got back shit letters in GetVehnumberplate XD

obsidian fox
spring hearth
#

im gonna update a artifact then check it

#

Still not working. I got print if the game spawn the vehicles down.

#

Dont ask it why i put the lorem ipsum in.

dusky raft
# spring hearth Still not working. I got print if the game spawn the vehicles down.

I did a little bit of research into this and here is what I found, seems you may need to implement your own custom event handler instead.
https://github.com/citizenfx/fivem/issues/1737

GitHub

if i created a vehicle using this CreateVehicleServerSetter Native. the entityCreated event handler are not getting feedback / notified from server. RegisterCommand('carspawn', function(sou...

spring hearth
dusky raft
# spring hearth Yep i thought about thats ,but idk how to check if a vehicle just spawned

Understandable. Basically you add a custom event and then trigger it within your garage script when a vehicle is created and/or the script thats creating/spawning the ambulances. Here's an example:

server.lua

local vehicle = nil
local spawn = vector4(247.527, -1514.301, 29.143, 131.245)

local stretcherVehicles = {
    [`ambulance`] = true
}

AddEventHandler('onResourceStop', function(resource)
    if resource ~= cache.resource then return end
    if vehicle and DoesEntityExist(vehicle) then DeleteEntity(vehicle) end
end)

-- Example event handler for logic after spawning
AddEventHandler('test:vehicleSpawned', function(entity)
    -- Need to wait a little after spawning, otherwise DoesEntityExist returns false
    SetTimeout(100, function()
        if not DoesEntityExist(entity) then return end
        if GetEntityType(entity) ~= 2 then return end

        local model = GetEntityModel(entity)
        if stretcherVehicles[model] then
            print('Ambulance spawned!')
        end
    end)
end)

CreateThread(function()
    Wait(1)
    vehicle = CreateVehicle(`ambulance`, spawn.x, spawn.y, spawn.z, spawn.w, true, false)
    TriggerEvent('test:vehicleSpawned', vehicle)
end)