Jump to content

Server values and elements to client?


Recommended Posts

I've got a marker, created on serverside, and i made an onClientRender for it, and says:
wnvREY8.png
The serverside marker is below, and clientside script is under it.

local kamuszefmarker = createMarker(2485.787109375, -1663.3155517578, 13.335947036743-1, "cylinder", 4, 161, 212, 144)
function drawSzef_alap()
    function drawSzef_alap_renderer()
        if isElementWithinMarker (localPlayer, kamuszefmarker) then
            local x, y = guiGetScreenSize()
            dxDrawImage ("fajlok/kepanyag/szef[0].png", x/2, y/2, 500, 300)
        else
        end
    end
    addEventHandler ("onClientRender", getRootElement(), drawSzef_alap_renderer)
end
addEventHandler ("onClientRender", getRootElement(), drawSzef_alap)

And i'm really lagging right now BTW my cpu slowed down AF, event the characters i type here are delayed. Guess, because of the onClientRenders. Any ideas?

Link to comment

Having onClientRender inside another onClientRender is the easiest way to kill your fps/game. Do not, ever, ever put onClientRender inside onClientRender, because you're adding the event again and again at every single frame. This should be enough:

function drawSzef_alap_renderer()
	if isElementWithinMarker (localPlayer, kamuszefmarker) then
		local x, y = guiGetScreenSize()
		dxDrawImage ("fajlok/kepanyag/szef[0].png", x/2, y/2, 500, 300)
	end
end
addEventHandler ("onClientRender", getRootElement(), drawSzef_alap_renderer)

But that will not work anyway, as the server-side variables (kamuszefmarker) are not shared between the server and client. You should either trigger to client with the marker element and hook the event to that element or add an element data to it i.e. "safeMarker_1" and check in the onClientRender if the player is inside a marker with the element data "safeMarker_1".

  • Like 1
Link to comment
function drawSzef_alap()
	local kamuszefmarker = createMarker(2485.787109375, -1663.3155517578, 13.335947036743-1, "cylinder", 4, 161, 212, 144)
	setElementAlpha (kamuszefmarker, 0)
	if isElementWithinMarker (localPlayer, kamuszefmarker) then
		local x, y = guiGetScreenSize()
		dxDrawImage (x/2, y/2, 500, 300, "fajlok/kepanyag/szef[0].png")
	else
	end
end
addEventHandler ("onClientRender", getRootElement(), drawSzef_alap)

I tried to be creative :D But still lagging. What could be the problem?

Link to comment

onClientRender - an event that runs at every frame. For example if you have 60 fps, it will run 60 times per second. That is a lot... Anything you have in the onClientRender will be called over and over again including the creation of the marker. If you run your script for 1 minutes with 60 fps, you will have 3600 marker on top of each other, that is causing the lag. You should also consider whether it has to be create on each frame or not, in this case, the marker will need to be created only once. Most of the times you only do GUI / DX parts in the onClientRender anyway.

So, to fix the lag, move your local kamuszef... and setElementAlpha outside the onClientRender, possibly before the function

 

 

  • Like 1
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...