Jump to content

Problem with source


Recommended Posts

-- server side 

cylinder = createMarker(-712.09100, 967.01917, 12.33547-1, "cylinder", 1.5, 255, 50, 0, 255)

setElementData(cylinder, "BoxWithPoints", 0)

function TIMER()
	if getElementData(cylinder, "BoxWithPoints") >= 8 then
		setElementData(cylinder, "BoxWithPoints", 8)
	else
		setElementData(cylinder, "BoxWithPoints", getElementData(cylinder, "BoxWithPoints")+1)
	end
	
	if isElementWithinMarker(source, cylinder) then	
		triggerServerEvent("givePointsToServer", root)
		
		PointsServer = getElementData(source, "points")
		BoxPoints = getElementData(cylinder, "BoxWithPoints")
		
		setElementData(source, "points", PointsServer + BoxPoints)
		
		setElementData(cylinder, "BoxWithPoints", 0)
	end
end

setTimer(TIMER, 3000, 0)

-- client side

setElementData(getLocalPlayer(), "points", 0)

addCommandHandler("ShowMyPoints", function()
	outputChatBox(tostring(getElementData(getLocalPlayer(), "points")), 255, 255, 0)
end)

addEvent("givePointsToServer", true)

addEventHandler("givePointsToServer", root, function(player)
	local player = client
	
	setElementData(player, "points", getElementData(player, "points"))
end)

The problem is with the ruler where isElementWithinMarker (source, cylinder) shows me the error that argument 1 got nil, I don't know what to think about it because I checked meta.xml and server side and client side is the correct type, could someone explain why is this happening?

Link to comment
Quote

source -- The player or element the event was attached to

That's why you don't get the player since you're using timer.

Your code has some mistakes too such as you are trying to trigger client side from server by triggerServerEvent and the right is triggerClientEvent. 

infinity timer can cause some problems as well especially you made it every 3 sec. You can use this better

"onElementDataChange"

and about the element in marker, you can do this

function elementinmarker(element) 
  setTimer(function()
      if element then
        if isElementWithinMarker(element,cylinder) then
        -- Your code
        end
      end
     end,3000, 1)
end
addEventHandler("onMarkerHit",cylinder,elementinmarker) 

and it would be better if you make the whole code server side

Edited by Sisqo0
  • 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...