FuriouZ Posted March 2, 2014 Share Posted March 2, 2014 Hello, i have problem, that when i repair car by pressing "r", then it makes lag for the server 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
WhoAmI Posted March 2, 2014 Share Posted March 2, 2014 (edited) 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 March 2, 2014 by Guest Link to comment
Moderators Citizen Posted March 2, 2014 Moderators Share Posted March 2, 2014 (edited) 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 March 2, 2014 by Guest Link to comment
WhoAmI Posted March 2, 2014 Share Posted March 2, 2014 Ah yea. Thanks man, that means a lot to me. Link to comment
Dealman Posted March 2, 2014 Share Posted March 2, 2014 For future reference, make sure you read the functions and events thoroughly. onClientRender and onClientPreRender will run the function it's assigned to once with every frame - so depending on what the server's maximum FPS is, and your computer's current FPS - you might be triggering the function 30-60 times per second. This is why you'll get massive lag and/or crashes. Link to comment
FuriouZ Posted March 2, 2014 Author Share Posted March 2, 2014 It will work, If you are setting team using function setPlayerTeam. I don't get it, what do you mean ? I am setting player team in another resource Link to comment
FuriouZ Posted March 2, 2014 Author Share Posted March 2, 2014 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
WhoAmI Posted March 2, 2014 Share Posted March 2, 2014 In meta in resource with team event export function function="setPlayerTeam" type="server" /> And then in resource where are you setting team exports.resource_name:setPlayerTeam ( player, team ) 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