Jump to content

Lagging function


FuriouZ

Recommended Posts

Hello, i have problem, that when i repair car by pressing "r", then it makes lag for the server :roll:

And it you spam it, then it crashes server out , how i should fix it ?

client:

function fixVehicle() 
    triggerServerEvent("stuntage:RequestFix", getLocalPlayer()) 
end 
-- 
-- 
-- 
ddEventHandler ( "onClientRender", root, 
    function() 
        local gTeam = getPlayerTeam(localPlayer) 
        local StuntageTeam = getTeamFromName("Stuntage Arena") 
            if ( gTeam and StuntageTeam and gTeam == StuntageTeam ) then 
                bindKey("R","down", fixVehicle) 
-- 
-- 
-- 
  

server

addEvent("stuntage:RequestFix",true); 
addEventHandler("stuntage:RequestFix",getRootElement(), 
    function() 
        if (isPedInVehicle (source)) then 
            theVehicle = getPedOccupiedVehicle(source) 
            fixVehicle(theVehicle) 
        else 
            cancelEvent()        
        end 
    end      
) 

Link to comment

Of couse It would lag couse you are binding key every render. I made team change event, so in my idea it will look like

    _setPlayerTeam = setPlayerTeam 
      
    addEvent( "onPlayerChangeTeam", true ) 
      
    function setPlayerTeam ( thePlayer, theTeam ) 
        triggerEvent ( "onPlayerChangeTeam", root, thePlayer, theTeam )  
        return _setPlayerTeam ( thePlayer, theTeam ) 
    end 
     
  
    function fixing ( player ) 
        if ( isPedInVehicle ( player ) ) then 
            local theVehicle = getPedOccupiedVehicle ( player ) 
            if ( theVehicle ) then 
                fixVehicle ( theVehicle ) 
            end 
        else 
            return       
        end 
    end 
     
    addEventHandler ( "onPlayerChangeTeam", root, 
        function (player, team) 
            if ( getTeamName ( team ) == "Stuntage Arena" ) then 
                bindKey ( player, "R", "down", fixing ) 
            else 
                unbindKey ( player, "R", "down", fixing ) 
            end 
        end 
    ) 

Everything serverside.

It will work, If you are setting team using function setPlayerTeam.

Edited by Guest
Link to comment
  • Moderators
Of couse It would lag couse you are binding key every render. I made team change event, so in my idea it will look like
    _setPlayerTeam = setPlayerTeam 
      
    addEvent( "onPlayerChangeTeam", true ) 
      
    function setPlayerTeam ( thePlayer, theTeam ) 
        triggerEvent ( "onPlayerChangeTeam", root, thePlayer, theTeam )  
        return _setPlayerTeam ( thePlayer, theTeam ) 
    end 
     
  
    function fixing ( player ) 
        if ( isPedInVehicle ( player ) ) then 
            theVehicle = getPedOccupiedVehicle ( player ) 
            if ( theVehicle ) then 
                fixVehicle ( theVehicle ) 
            end 
        else 
            return       
        end 
    end 
     
    addEventHandler ( "onPlayerChangeTeam", root, 
        function (player, team) 
            if ( getTeamName ( team ) == "Stuntage Arena" ) then 
                bindKey ( player, "R", "down", fixing ) 
            else 
                unbindKey ( player, "R", "down", fixing ) 
            end 
        end 
    ) 

Everything serverside.

It will work, If you are setting team using function setPlayerTeam.

Nice script, I would just add the local in front of theVehicle at line 13.

Also, I would set thePlayer as source of the event, and just sending theTeam as parameter of the function.

Edited by Guest
Link to comment

I still don't understand what is the problem ?

I am setting player team in another resource

addEvent("onPlayerStuntageEnter", true) 
addEventHandler("onPlayerStuntageEnter",getRootElement(), 
    function() 
      -- 
      -- 
            setPlayerTeam(source, Stuntage) 
    --  
    -- 
  

If i join stuntage team, i still can't use "R" key .. nothing happens and there's no errors in debug

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...