Szerző Téma: Lagg a Realism-Systemnél  (Megtekintve 804 alkalommal)

Lagg a Realism-Systemnél
« Dátum: 2018. április 04. - 00:24:25 »
0 Show voters

fuellessVehicle = { [510]=true, [509]=true, [481]=true }
enginelessVehicle = { [510]=true, [509]=true, [481]=true }
local active = true
local fuel = 100
local tiltva = false
 
function syncFuel(ifuel)
if not (ifuel) then
   fuel = 100
else
   fuel = ifuel
end
end
addEvent(\"syncFuel\", true)
addEventHandler(\"syncFuel\", getRootElement(), syncFuel)
function onVehicleEnter(thePlayer, seat)
if (thePlayer==getLocalPlayer()) then
   if (seat==0) or (seat==1) then
      local id = getElementModel(source)
      if not (enginelessVehicle[id]) then
         addEventHandler(\"onClientRender\", getRootElement(), drawSpeedo)
      end
   end
end
end
addEventHandler(\"onClientVehicleEnter\", getRootElement(), onVehicleEnter)
function onVehicleExit(thePlayer, seat)
if (thePlayer==getLocalPlayer()) then
   if (seat==0) or (seat==1) then
      local id = getElementModel(source)
      if not(enginelessVehicle[id]) then
         removeEventHandler(\"onClientRender\", getRootElement(), drawSpeedo)
         if isTimer(csipogas) then
            killTimer(csipogas)
            end
         if isTimer(csipogasTimer) then
            killTimer(csipogasTimer)
         end
      end
   end
end
end
addEventHandler(\"onClientVehicleStartExit\", getRootElement(), onVehicleExit)
addEventHandler(\"onClientVehicleExit\", getRootElement(), onVehicleExit)
function hideSpeedo()
removeEventHandler(\"onClientRender\", getRootElement(), drawSpeedo)
end
 
function showSpeedo()
source = getPedOccupiedVehicle(getLocalPlayer())
if source then
   if getVehicleOccupant( source ) == getLocalPlayer() then
      onVehicleEnter(getLocalPlayer(), 0)
   elseif getVehicleOccupant( source, 1 ) == getLocalPlayer() then
      onVehicleEnter(getLocalPlayer(), 1)
   end
end
end
function updateOdometer( currentKilometers )
local currentKilometers = math.floor(currentKilometers/100)
local odoKM = string.format(\"%00d\", currentKilometers)
   
odometer = guiCreateLabel(0, 0, 0, 0, tostring(odoKM), true)
guiSetText(odometer, tostring(odoKM))
end
addEvent(\"updateOdo\", true)
addEventHandler(\"updateOdo\", getLocalPlayer(), updateOdometer)
function VehicleEnter ()
odometer = guiCreateLabel(0, 0, 0, 0, tostring(odoKM), true)
guiSetText(odometer, tostring(0))
end
addEventHandler(\"onClientVehicleEnter\", getRootElement(), VehicleEnter)
addEventHandler(\"onClientResourceStart\", getRootElement(), VehicleEnter)
 
Igen = false
function Enter ()
setTimer ( function()
   Igen = true
end, 100, 1 )
end
function Exit ()
Igen = false
end
addEventHandler(\"onClientVehicleEnter\", getRootElement(), Enter)
addEventHandler(\"onClientVehicleExit\", getRootElement(), Exit)
 
local Font = dxCreateFont( \"DS-DIGI.ttf\", 12 )
local elozogear = 1
function drawSpeedo()
if active and not isPlayerMapVisible() then
   local text = guiGetText ( odometer )
   --if Igen == true then
      local vehicle = getPedOccupiedVehicle(getLocalPlayer())
      if (vehicle) then
         speed = exports.global:getVehicleVelocity(vehicle)
         local width, height = guiGetScreenSize()
         local x = width
         local y = height
         
      --   local speedkmh = getElementSpeed(localPlayer, 1)
      --   local kmh = math.floor(speedkmh) == speedkmh and speedkmh or string.format(speedkmh, \"%.1f\")
      --   local sebesseg = kmh..\" km/h\"
         
         local streetname = getElementData(getLocalPlayer(), \"speedo:street\" )
         if streetname and getVehicleType(vehicle) ~= \"Boat\" and getVehicleType(vehicle) ~= \"Helicopter\" and getVehicleType(vehicle) ~= \"Plane\" then
            local width = dxGetTextWidth( streetname )
            local x = width < 200 and ( x - 110 - width / 2 ) or ( x - 10 - width )
            dxDrawRectangle( x - 8, y - 296, width + 17, 24, tocolor( 5, 5, 5, 220 ) )
            dxDrawText( streetname, x, y - 292 )
         end
         
         arany = 0.765
         
         forgas = speed*arany
         
         --dxDrawImage(x-422, y-386, 512, 512, \"disc.png\", 0, 0, 0, tocolor(255, 255, 255, 200))
         dxDrawRectangle( x - 400, y - 100, 400, 69, tocolor( 5, 5, 5, 155 ) )
         dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/checkengine_med.png\", 0, 0, 0, tocolor(255, 255, 255, 200))
         dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/handbrake_med.png\", 0, 0, 0, tocolor(255, 255, 255, 200))
         dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/lowfuel_med.png\", 0, 0, 0, tocolor(255, 255, 255, 200))
         dxDrawImage(x-260, y-330+4, 400, 380, \"speedo/lampa_be.png\", 0, 0, 0, tocolor(255, 255, 255, 200))
         dxDrawImage(x-255, y-330+34, 369, 340, \"speedo/ajto_be.png\", 0, 0, 0, tocolor(255, 255, 255, 200))
         --dxDrawRectangle( x - 400, y - 100, 400, 69, tocolor( 5, 5, 5, 155 ) )
      --   dxDrawText(sebesseg, x-422, y-386, 512, 512)
         ----------------------------------------------------------
         sx, sy, sz = getElementVelocity (getPedOccupiedVehicle(localPlayer))
         kmhs = math.floor(((sx^2 + sy^2 + sz^2)^(0.5))*180) --Calculate speed
         --dxDrawText(\"\"..tostring(kmhs)..\"\",10,540,758,364.0,tocolor(255,255,255,255),0.9,Digital,\"right\",\"top\",false,false,false) --Speedometer positsion
         --dxDrawText ( tostring(kmhs)..\" km/h\",x-370, y-77.6,296.0,364.0,tocolor(255,255,255,255),1.6,\"default-bold\",\"left\",\"top\",false,false,false) --km/h   
         dxDrawText ( tostring(kmhs)..\" km/h\",x-370, y-88.6,296.0,364.0,tocolor(255,255,255,255),1.6,\"default-bold\",\"left\",\"top\",false,false,false) --km/h   
         ----------------------------------------------------------
         dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/left_med.png\", 0, 0, 0, tocolor(255, 255, 255, 200))
         dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/right_med.png\", 0, 0, 0, tocolor(255, 255, 255, 200))
         
         if(getElementData(vehicle, \"i:right\")) then
            dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/right_med.png\", 0, 0, 0, tocolor(0, 255, 255, 200))
         end
      
         if(getElementData(vehicle, \"i:left\")) then
            dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/left_med.png\", 0, 0, 0, tocolor(0, 255, 255, 200))
         end
         
         local lights = getVehicleOverrideLights(vehicle)
         
         if (lights==2) then
         dxDrawImage(x-260, y-330+4, 400, 380, \"speedo/lampa_be.png\", 0, 0, 0, tocolor(0, 255, 255, 200))
         end
         
         if isVehicleLocked(vehicle) then
         dxDrawImage(x-255, y-330+34, 369, 340, \"speedo/ajto_be.png\", 0, 0, 0, tocolor(0, 255, 255, 200))
         end
         
         if fuel < 11 then
            dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/lowfuel_med.png\", 0, 0, 0, tocolor(0, 255, 255, 200))
         end
         if getElementHealth ( vehicle ) < 500 then
            dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/checkengine_med.png\", 0, 0, 0, tocolor(0, 255, 255, 200))
         end
         if isElementFrozen ( vehicle ) == true then
            dxDrawImage(x-400, y-330-10, 512, 512, \"speedo/handbrake_med.png\", 0, 0, 0, tocolor(0, 255, 255, 200))
         end
         
         speed = speed - 100
         nx = x + math.sin(math.rad(-(speed)-150)) * 90
         ny = y + math.cos(math.rad(-(speed)-150)) * 90
         
         --if fuel > 99.9 then
            fueltext = 100
         --else
            fueltext = math.floor(fuel)
         --end
         
         if fuel < 1.001 then
            fueltext = 0
         end
         
         panelAdatok = {guiGetScreenSize()}
         gear = getVehicleCurrentGear(vehicle)
         --dxDrawText(gear, x-400, y-330-10, 100, 30, tocolor (255, 255, 255, 255), 1, \"sans\",\"left\",\"top\",false,false,true,true)
         --dxDrawText(elozogear, panelAdatok[1]/2 + 20, panelAdatok[2]/2-30/2 - 144, 100, 30, tocolor (255, 255, 255, 255), 3, \"sans\",\"left\",\"top\",false,false,true,true)
         --if text == text then
         --test = test + (distance/1000) --math.floor ( text / 10 )
            --outputChatBox ( test .. \"   \" .. (text-(test*10)) )
            --outputChatBox ( text - test )
         --end
         
         if isElementFrozen ( vehicle ) == true then
         gearfelirat = \"P\"
         elseif getVehicleEngineState(vehicle) == false then
         gearfelirat = \"N\"
         elseif gear >= 1 then
         gearfelirat = gear
         elseif gear == 0 then
         gearfelirat = \"R\"
         end
         dxDrawText ( gearfelirat, x-350, y-65.6,296.0,364.0,tocolor(255,255,255,255),1.6,\"default-bold\",\"left\",\"top\",false,false,false) --km/h   
         csipogasTimer = setTimer(
         function ()
         if getPedOccupiedVehicle(getLocalPlayer()) then
            local theVehID = getElementModel(vehicle)
            luxusKocsikSipolas = luxusKocsik[theVehID]
            if luxusKocsikSipolas then
            bekapcsolva = getElementData(localPlayer, \"biztonsagiov\")
            if bekapcsolva == 0 then
               if not isTimer(csipogas) then
                  csipogas = setTimer(function()
                     ov_jelzes = playSound(\"ov_jelzes.mp3\")
                     setSoundVolume(ov_jelzes, 10)
                     setTimer(stopSound, 999, 1, ov_jelzes)
                  end,1000,0)
               end
               elseif isTimer(csipogas) then
               killTimer(csipogas)
            end
            end
         elseif isTimer(csipogas) then
            killTimer(csipogas)
         end
         end, 100, 0)
         dxDrawText( \"Benzin:\", (x*2) - 400, (y*2) - 165, 5, 5, tocolor (255,255,255, 255), 1, Font, \"center\", \"center\")
         dxDrawText( fueltext..\"L/100L\", (x*2) - 400, (y*2) - 115, 5, 5, tocolor (255,255,255, 255), 1, Font, \"center\", \"center\")
         dxDrawText( \"----------\", (x*2) - 400, (y*2) - 140, 5, 5, tocolor (255,255,255, 255), 1, Font, \"center\", \"center\")
         --dxDrawImage(x-420, y-388, 512, 512, \"needle.png\", forgas, 0, 0, tocolor(255, 255, 255, 200))
      --end
   end
end
end

 
Sziasztok! Az a gondom hogy, mikor elindítom ezt a realism-systemet (Zero alapú szerveren) akkor egy maximálisan megítélésem szerint 5 percig bírja lagg nélkül, utána viszont orbitális módon elkezdek laggolni ha beszálok egy kocsiba és megjelenik a speedo. Valakinek valami ötlete? A hasznos válaszokat előre is nagyon szépen köszönöm! :) 

Lagg a Realism-Systemnél
« Válasz #1 Dátum: 2018. április 04. - 15:51:47 »
0 Show voters
Én arra tudok csak gondolni, hogy a Timer miatt. Render alá van rakva, mindig létrehozza a timer-t. Ha nem ez, akkor nem tudom. Ránézésre nem látok benne olyan nagy hibát.

 

SimplePortal 2.3.7 © 2008-2024, SimplePortal