Jump to content

Why is this yet another code not working?


Recommended Posts

function apagarRadar()
    setPlayerHudComponentVisible(source, "radar", false)
    setElementData(source, "semradar", radar)
end
addEventHandler("onPlayerJoin", root, apagarRadar)

function mostrarRadar(thePlayer)
    local naoTemRadar = getElementData(thePlayer, "semradar")
    if naoTemRadar then
        setElementData(thePlayer, "comradar", radar)
        setPlayerHudComponentVisible(thePlayer, "radar", true)
        removeElementData(thePlayer, "semradar")
    else
        outputChatBox("Já tens um mapa.")
    end
end
addCommandHandler("mapa", mostrarRadar)

So, the idea: whenever a player join he is given the Data "semradar" and his radar is erased. Whener he types /mapa, it will check if he has the Data "semradar" and if he does, he will erase it, give him the Data "comradar" and set his radar visible. If he already has the data "comradar", it will just send him an error message.

 

The problem is that whenever I type /mapa I just the the error message.

It works if I delete the if statement, but in that way I can't send him the error message.

Link to comment

I think you were setting the wrong element datas, try this code
 

function apagarRadar ()
	setPlayerHudComponentVisible(source,"radar",false)
	setElementData(source,"showRadar",false)
end
addEventHandler("onPlayerJoin",getRootElement(),apagarRadar)

function mostrarRadar (source)
	if not ( getElementData(source,"showRadar") ) then
		setElementData(source,"showRadar",true)
		setPlayerHudComponentVisible(source,"radar",true)
	else
		outputChatBox("Já tens um mapa.",source)
	end
end
addCommandHandler("mapa",mostrarRadar)

 

  • Like 1
Link to comment
3 hours ago, Hugo_Almeidowski said:

Doesn't work.

The map is showing whenever I enter the map and I get the same error message when I type /mapa.

And the console tells me that that command is depracated. Thanks anyways!

My bad, try this:

setPlayerHudComponentVisible ( thePlayer, 'radar', false ) -- server-side.

or

setPlayerHudComponentVisible ( 'radar', false ) -- client-side.

 

Edited by Peti
Link to comment
15 hours ago, Erknneto said:

I think you were setting the wrong element datas, try this code
 


function apagarRadar ()
	setPlayerHudComponentVisible(source,"radar",false)
	setElementData(source,"showRadar",false)
end
addEventHandler("onPlayerJoin",getRootElement(),apagarRadar)

function mostrarRadar (source)
	if not ( getElementData(source,"showRadar") ) then
		setElementData(source,"showRadar",true)
		setPlayerHudComponentVisible(source,"radar",true)
	else
		outputChatBox("Já tens um mapa.",source)
	end
end
addCommandHandler("mapa",mostrarRadar)

 

It worked! Thanks! I just don't get why mine didn't work.

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...