Lalalu Posted September 9, 2023 Share Posted September 9, 2023 Hola, una pregunta ¿cual podría ser la mejor forma de crear varios peds sin que generen lag o disminuya el rendimiento? Cada ped tiene un icono encima (dx imagen). Si coloco muchos peds en el servidor me genera bastantes bajones de fps de 60 a 30 - 35, habrá alguna forma de mejorar el rendimiento sin tener que eliminar los peds? o alguna otra forma de crearlos? por lo general los creo todos client side, con sus dx Link to comment
alex17" Posted September 11, 2023 Share Posted September 11, 2023 (edited) local peds = [] addEventHandler( "onClientElementStreamIn", root, function () if getElementType(source) == "ped" and not peds[source] then peds[source] = source end end ) addEventHandler( "onClientElementStreamOut", root, function () if peds[source] then peds[source] = nil end end ) addEventHandler("onClientElementDestroy", root, function () if peds[source] then peds[source] = nil end end ) addEventHandler("onClientRender", root, function() for _, ped in ipairs(peds) do local x, y, z = getElementPosition(ped) dxDraw(...) ... end end ) Puedes usar onClientElementStreamIn para almacenar en una tabla los peds que empiezan a trasmitir y luego onClientElementStreamOut para eliminarlos de la tabla cuando ya no trasmitan, luego en la función para los dx solo dibuja los dx en los peds que esten en la tabla que en teoria son los que estan cerca a ti Edited September 11, 2023 by alex17" Link to comment
Lalalu Posted September 11, 2023 Author Share Posted September 11, 2023 (edited) Thank you... like this? @alex17" local sX, sY = guiGetScreenSize ( ) function dxDrawImageOnWeapon (TheWeapon,ImageWeapon, distance,height,width,R,G,B,alpha) local cx, cy, cz = getCameraMatrix ( ); local x, y, z = getPedBonePosition ( TheWeapon, 6 ); local dWeaponIcon = getDistanceBetweenPoints3D( cx, cy, cz, x, y, z); if ( dWeaponIcon < 10 ) then if (isLineOfSightClear(cx, cy, cz, x, y, z, true, true, false, false, true, false, false, localPlayer )) then local sx, sy = getScreenFromWorldPosition ( x, y, z+0.55 ) if ( sx ) and ( sy ) then local sWeaponIcon =760 / dWeaponIcon; dxDrawImage ( sx - ( sWeaponIcon / 2 ), sy - ( sWeaponIcon / 2 ), sWeaponIcon, sWeaponIcon, ImageWeapon, 0, 0, 0, tocolor (R or 255, G or 255, B or 255, alpha or 255) ); end end end end local Pos_Weapon = { {310, 2442.2729492188, -1592.2652587891, 2383.9047851562, 267}, {310, 1825.6822509766, -285.5888671875, 2399.453125, 2} } local NPCWeapon = {} local TagWeapon = dxCreateTexture("myimage.webp") for i,v in ipairs (Pos_Weapon) do local CrearPedWeapon = createPed(v[1],v[2],v[3],v[4],v[5]) table.insert(NPCWeapon,#NPCWeapon + 1,CrearPedWeapon) end addEventHandler( "onClientElementStreamIn", root, function () if getElementType(source) == "ped" and not NPCWeapon[source] then NPCWeapon[source] = source end end ) addEventHandler( "onClientElementStreamOut", root, function () if NPCWeapon[source] then NPCWeapon[source] = nil end end ) addEventHandler("onClientElementDestroy", root, function () if NPCWeapon[source] then NPCWeapon[source] = nil end end ) addEventHandler("onClientRender",root,function() for _,PedWeapon in ipairs(NPCWeapon) do local x, y, z = getElementPosition(PedWeapon) dxDrawImageOnWeapon(PedWeapon,TagWeapon) end end) Edited September 11, 2023 by Lalalu Link to comment
alex17" Posted September 12, 2023 Share Posted September 12, 2023 para desconponer la tabla con el for en este caso debe usar pairs en vez ipairs , tambien toma en cosideración si el uso de isLineOfSightClear es necesario ya que es en parte lo que aumentara los bajones de fps cuando haya muchos peds , asi mismo tambien le añadiria una variable que te indique si la tabla tiene elementos para que el onClientRender siga ejecutandose o debe pararse, pequeñas cositas que aligeraran la carga a los fps addEventHandler( "onClientElementStreamOut", root, function () if NPCWeapon[source] then NPCWeapon[source] = nil end removeEventHandler("onClientRender", root, dxDrawImagenOnPed) addEventHandler("onClientRender", root, dxDrawImagenOnPed) end ) addEventHandler("onClientElementDestroy", root, function () if NPCWeapon[source] then NPCWeapon[source] = nil end end ) function dxDrawImagenOnPed)() local draw = false for _,PedWeapon in pairs(NPCWeapon) do if PedWeapon then draw = true local x, y, z = getElementPosition(PedWeapon) dxDrawImageOnWeapon(PedWeapon,TagWeapon) end end if not draw then removeEventHandler("onClientRender", root, dxDrawImagenOnPed) end end Link to comment
Lalalu Posted December 15, 2023 Author Share Posted December 15, 2023 (edited) On 12/09/2023 at 09:38, alex17" said: para desconponer la tabla con el for en este caso debe usar pairs en vez ipairs , tambien toma en cosideración si el uso de isLineOfSightClear es necesario ya que es en parte lo que aumentara los bajones de fps cuando haya muchos peds , asi mismo tambien le añadiria una variable que te indique si la tabla tiene elementos para que el onClientRender siga ejecutandose o debe pararse, pequeñas cositas que aligeraran la carga a los fps addEventHandler( "onClientElementStreamOut", root, function () if NPCWeapon[source] then NPCWeapon[source] = nil end removeEventHandler("onClientRender", root, dxDrawImagenOnPed) addEventHandler("onClientRender", root, dxDrawImagenOnPed) end ) addEventHandler("onClientElementDestroy", root, function () if NPCWeapon[source] then NPCWeapon[source] = nil end end ) function dxDrawImagenOnPed)() local draw = false for _,PedWeapon in pairs(NPCWeapon) do if PedWeapon then draw = true local x, y, z = getElementPosition(PedWeapon) dxDrawImageOnWeapon(PedWeapon,TagWeapon) end end if not draw then removeEventHandler("onClientRender", root, dxDrawImagenOnPed) end end Holaa, gracias por responder mi post. Disculpa, no suelo visitar frecuentemente el foro, pero acabo de testear así: local sX, sY = guiGetScreenSize ( ) function dxDrawImageOnArmas (TheArmas,ImageArmas, distance,height,width,R,G,B,alpha) local cx, cy, cz = getCameraMatrix ( ); local x, y, z = getPedBonePosition ( TheArmas, 6 ); local dArmasIcon = getDistanceBetweenPoints3D( cx, cy, cz, x, y, z); if ( dArmasIcon < 10 ) then if (isLineOfSightClear(cx, cy, cz, x, y, z, true, true, false, false, true, false, false, localPlayer )) then local sx, sy = getScreenFromWorldPosition ( x, y, z+0.55 ) if ( sx ) and ( sy ) then local sArmasIcon =760 / dArmasIcon; dxDrawImage ( sx - ( sArmasIcon / 2 ), sy - ( sArmasIcon / 2 ), sArmasIcon, sArmasIcon, ImageArmas, 0, 0, 0, tocolor (R or 255, G or 255, B or 255, alpha or 255) ); end end end end local Pos_Armas = { {117, -169.2294921875, -75.96875, 711.21716308594, 315}, {141, -166.08984375, 1883.509765625, 724, 272}, {245, -1591.166015625, -607.01483154297, 711.17346191406, 39}, {207, 2073.5895996094, 88.1796875, 721.94860839844, 9}, {117, 2560.8657226562, 1050.4641113281, 727.25622558594, 270} } local NPCArmas = {} local TagArmas = dxCreateTexture("Images/Icon.webp") for i,v1 in ipairs (Pos_Armas) do CrearPedArmas = createPed(v1[1],v1[2],v1[3],v1[4],v1[5]) table.insert(NPCArmas,#NPCArmas + 1,CrearPedArmas) setElementFrozen ( CrearPedArmas, true ) setPedVoice(CrearPedArmas, "PED_TYPE_DISABLED", "") setPedAnimation( CrearPedArmas, "SMOKING", "M_SMK_LOOP",-1,true,false,false,false ) addEventHandler ( "onClientPedDamage",CrearPedArmas, function () cancelEvent() end) addEventHandler("onClientPlayerStealthKill",localPlayer, function (targetPlayer) if targetPlayer == CrearPedArmas then cancelEvent() end end) end addEventHandler( "onClientElementStreamIn", root, function () if getElementType(source) == "ped" and not NPCArmas[source] then NPCArmas[source] = source end end ) addEventHandler( "onClientElementStreamOut", root, function () if NPCArmas[source] then NPCArmas[source] = nil end removeEventHandler("onClientRender", root, dxDrawImageOnArmas) addEventHandler("onClientRender", root, dxDrawImageOnArmas) end ) addEventHandler("onClientElementDestroy", root, function () if NPCArmas[source] then NPCArmas[source] = nil end end ) function dxDrawImageOnArmas() local draw = false for _,PedArmas in pairs(NPCArmas) do if PedArmas then draw = true local x, y, z = getElementPosition(PedArmas) dxDrawImageOnArmas(PedArmas,TagArmas) end end if not draw then removeEventHandler("onClientRender", root, dxDrawImageOnArmas) end end Pero no funciona, me aparece un error y me ocasiona muchisimo lag.. :line 71: stack overflow Edited December 15, 2023 by Lalalu Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now