Problem with entityCreating onesyne event

Client

Using canary? NO
Windows version: win 10 v2004(19041.450)
System specifications: i7 , ram 16 , ssd

Server

Operating system: win 10 v2004(19041.450)
Artifact version: FXServer 2901
IP address: local
Resources:
System specifications: i7 , ram 16 , ssd

Incident

Summary: problem with entityCreating which if you spam the CreateObject and block it with CancelEvent() eventually that object will be shown in the other user’s game
Expected behavior: dont network / shown the canceled object no matter what ?
Actual behavior: will half network or just shown the canceled object even if you cancel it everytime
Steps to reproduce: just create an object with script and spam it like 20 times ( need even less ) to see that it will be shown on other players system
Server/Client?
Files for repro (if any):

local SelectedPlayer = PASS ID HERE --SelectedPlayer is the other players id
function SpawnObjOnPlayer(modelHash)
	
    local coords = GetEntityCoords(GetPlayerPed(SelectedPlayer), true)					
    local obj CreateObject(modelHash, coords.x, coords.y, coords.z, true, true, true)
        if attachProp then
            AttachEntityToEntity(obj ,GetPlayerPed(selectedPlayer), GetPedBoneIndex(GetPlayerPed(selectedPlayer), 57005), 0.4, 0, 0, 0, 270.0, 60.0, true ,true ,false, true, 1, true)
        end
end


Citizen.CreateThread(function()
    while true do
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
		Citizen.Wait(1)
	end
end)


AddEventHandler('entityCreating', function(entity)
	CancelEvent()--even if i cancel all the objects it will not work as intended
end)

Error screenshot (if any):
.dmp files/report IDs:

Any additional info:
the problem is the entity will be canceled but the ghost of that object will be shown to all others and by (ghost) i mean you can see that object clearly but you can walk throw it
i guess i explained all of it if there is a question or you need more info please ask

i made a video to demonstrate the issue ,

The code you provided as “repro” seems to have a syntax error. Any actual working repro? :open_mouth:


function SpawnObjOnPlayer(modelHash)
    local coords = GetEntityCoords(GetPlayerPed(SelectedPlayer), true)
    local obj CreateObject(modelHash, coords.x, coords.y, coords.z, true, true, true)
    if attachProp then
        AttachEntityToEntity(obj ,GetPlayerPed(selectedPlayer), GetPedBoneIndex(GetPlayerPed(selectedPlayer), 57005), 0.4, 0, 0, 0, 270.0, 60.0, true ,true ,false, true, 1, true)
    end
end

Citizen.CreateThread(function()
    while true do
        if GetPlayerServerId(PlayerId()) == 1 then --change this to your server id so it dont create object for you
            print("SPAM NOW")


            local ped = PlayerPedId()

            for _, player in ipairs(GetActivePlayers()) do
                if NetworkIsPlayerActive(player) then
                    local otherPlayer = GetPlayerPed(player)

                    if ped ~= otherPlayer then

                        SelectedPlayer = player

                        print("otherPlayer => " .. GetPlayerServerId(player))


                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))

                    end
                end
            end
        end

        Citizen.Wait(500)
    end
end)


please change the server id to yours in the above code

Right - can you check if the objects don’t sync to anyone else anymore in server build 2936 or above?

(it seems they still appear on the client spawning them, but nobody else sees them for more than a frame at worst now)

it got really much better now ! but if i push it harder and as soon as i see the plane ( any object ) and stopping the script that is creating the object , the shown object will remain on the screen again . ( sry for bad explaining )

this is the same repo but i added more create object

function SpawnObjOnPlayer(modelHash)
    local coords = GetEntityCoords(GetPlayerPed(SelectedPlayer), true)
    local obj CreateObject(modelHash, coords.x, coords.y, coords.z, true, true, true)
    if attachProp then
        AttachEntityToEntity(obj ,GetPlayerPed(selectedPlayer), GetPedBoneIndex(GetPlayerPed(selectedPlayer), 57005), 0.4, 0, 0, 0, 270.0, 60.0, true ,true ,false, true, 1, true)
    end
end

Citizen.CreateThread(function()
    while true do
        if GetPlayerServerId(PlayerId()) == 1 then --change this to your server id so it dont create object for you
            print("SPAM NOW")


            local ped = PlayerPedId()

            for _, player in ipairs(GetActivePlayers()) do
                if NetworkIsPlayerActive(player) then
                    local otherPlayer = GetPlayerPed(player)

                    if ped ~= otherPlayer then

                        SelectedPlayer = player

                        print("otherPlayer => " .. GetPlayerServerId(player))


                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))
                        SpawnObjOnPlayer(GetHashKey("p_med_jet_01_s"))

                    end
                end
            end
        end

        Citizen.Wait(500)
    end
end)

so the steps are these =>

run the script , move a little or not to see a flickering of that object ( comes and goes ) , then as soon as you see the complete image of that object stop the script immediatly then the object will be there and will NOT get deleted

Does that also happen if the entityCreating event is in another resource?

right now my entityCreating event is in another resource , which is started from the start and i wont stop it at all but it contains some check for blacklisted objects etc stuff , i will try now with empty one to cancel all type of the objects and will tell you the result

as ive tested on both low-end and high-end system , i will give some info based on what ive gathered with latest version .

1- if i do some little checks on objects like blacklisting or so , like if that object is in my blacklist array then cancel it -> the result : 20% that object WILL network or ghosted

2-if i do a cancel to all objects without any checks => it will block 100% and those objects will not be shown / i cant see any flickers too , ( which i guess maybe i have a good cpu for hosting the server ??? or maybe i have a high-end system ? )

so based on test 2 -> ive test the same thing on a low-end system , it will network / ghost the object on low-end users like 20% of the time ( have to really abuse the event )

so my fear is if someone has a low cpu for hosting OR even no mater how ! if server get a high hitch or the user cant handle it maybe, then the event dont work and object gets networked / ghost .

also doing a Cancel on all objects without any reasonable checks is not a good way to deal with.

for the best result on high-end system users ->

AddEventHandler('entityCreating', function(entity)
    CancelEvent()
end)

and the way i tested but didnt get the best result

local ObjectsBlackList = {
    [GetHashKey("prop_cs_cardbox_01")] = true,
    [GetHashKey("prop_cs_burger_01")] = true,
    [GetHashKey("prop_cash_pile_01")] = true,
    [GetHashKey("prop_tool_broom")] = true,
    [GetHashKey("prop_money_bag_01")] = true,
    [GetHashKey("prop_carjack")] = true,
    [GetHashKey("prop_fib_badge")] = true,
    [GetHashKey("p_car_keys_01")] = true,
    [GetHashKey("hei_prop_heist_thermite")] = true,
    [GetHashKey("hei_p_m_bag_var22_arm_s")] = true,
    [GetHashKey("hei_prop_hst_laptop")] = true,
    [GetHashKey("hei_prop_heist_card_hack_02")] = true,
    [GetHashKey("p_ld_id_card_01")] = true,
    [GetHashKey("hei_prop_hei_cash_trolly_01")] = true,
    [2007413986] = true,
    [881130828] = true,
    [-685641702] = true,
    [GetHashKey("hei_prop_heist_cash_pile")] = true,
    [GetHashKey("ch_prop_gold_bar_01a")] = true,
    [GetHashKey("ch_prop_vault_dimaondbox_01a")] = true,
    [GetHashKey("prop_poly_bag_01")] = true,
    [GetHashKey("prop_ld_jerrycan_01")] = true,

    [GetHashKey("WEAPON_SNIPERRIFLE")] = true,
    [GetHashKey("WEAPON_HEAVYSNIPER")] = true,
    [GetHashKey("WEAPON_CARBINERIFLE")] = true,
    [GetHashKey("WEAPON_ADVANCEDRIFLE")] = true,
    [GetHashKey("WEAPON_CARBINERIFLE_MK2")] = true,
    [GetHashKey("WEAPON_HEAVYSHOTGUN")] = true,
    [GetHashKey("WEAPON_SMGMK2")] = true,
    [-1357824103] = true,
    [-2084633992] = true,
    [-1074790547] = true,
    [-1063057011] = true,
    [2132975508] = true,
    [1627465347] = true,
    [736523883] = true,
    [-270015777] = true,
    [-1466123874] = true,
    [-494615257] = true,
    [-1654528753] = true,
    [324215364] = true,
    [487013001] = true,

    [GetHashKey("prop_amb_phone")] = true,
    [GetHashKey("prop_cs_remote_01")] = true,
    [GetHashKey("prop_cs_hand_radio")] = true,
    [GetHashKey("prop_v_cam_01")] = true,
    [GetHashKey("p_ing_microphonel_01")] = true,
    [GetHashKey("prop_v_bmike_01")] = true,
    [GetHashKey("p_med_jet_01_s")] = true,
}

AddEventHandler('entityCreating', function(entity)
    local entity = entity

    if not DoesEntityExist(entity) then
        return
    end

    local src = NetworkGetEntityOwner(entity)
    local type = GetEntityType(entity)

    if type ~= 0 then
        local model = GetEntityModel(entity)

        if type == 3 then-- object
            if ObjectsBlackList[model] then
                CancelEvent()
            end
        end
    end
end)

Can you try again on 2940 or above?

1 Like

will test more and post the results here , cause ive got random results right now,

so, if i ,mix the entityCreating event with entityCreated like this =>

AddEventHandler('entityCreated', function(entity)
    local TheEntity = entity

    if not DoesEntityExist(TheEntity) then
        print("NOT VALID ENTITY")
        return
    end

    local model = GetEntityModel(TheEntity)

    if ObjectsBlackList[model] then
        DeleteEntity(TheEntity)
        print("DELETE " .. model)
    end
end)

i can see the flickers and it will bug from 1 of 50 , or just by stopping the CreateObject as soon as you see the complete object shown on the screen ,

but without the entityCreated it will cause the game to crash which i will attach the log here and because of that i cant check it further , so please check the logs , CfxCrashDump_2020_09_10_14_36_10.zip (1.5 MB)