Jump to content

[Question]How to set clients weather


kieran

Recommended Posts

I'm trying to make a really simple settings panel, check boxes are easy, but I have a problem setting the clients weather when they click the button, it shows the number in chat but won't set the weather, even if I use tonumber.... 

The idea is you type  a number in edit box, click the button, it sets the weather.

local screenW, screenH = guiGetScreenSize()

function GUI()
	if ( window ) then
    	if ( guiGetVisible( window )) then    	
    		showCursor( false )
			toggleAllControls(true)
            guiSetVisible( window, false )
       	else
       		guiSetInputEnabled(false)
    		showCursor(true)
			toggleAllControls(false)
       		guiSetVisible( window, true )
       	end
    else
        window = guiCreateWindow((screenW - 275) / 2, (screenH - 203) / 2, 275, 203, "Settings", false)
        guiWindowSetMovable(window, false)
        guiWindowSetSizable(window, false)
		
		guiSetInputEnabled(false)
    	showCursor(true)
		toggleAllControls(false)
        
		blur = guiCreateCheckBox(10, 99, 59, 21, "Blur", false, false, window)
		clouds = guiCreateCheckBox(69, 99, 59, 21, "Clouds", false, false, window)
        
		weather_lbl = guiCreateLabel(138, 102, 60, 15, "Weather: ", false, window)
        weather_edit = guiCreateEdit(190, 105, 44, 15, "", false, window) --edit box
		weather_button = guiCreateButton(242, 103, 23, 20, ">>", false, window) --button

		addEventHandler("onClientGUIClick",weather_button,setWeather)
	end
end
	
bindKey("F6", "down", GUI)


function setWeather(button,state) --Function to change weather
	if(button == "left" and state == "up") then
		if (source == weather_button) then
			weather = guiGetText(weather_edit) --Getting the text
			setWeather(tonumber(weather)) --Doesn't set
			outputChatBox(""..weather) --Outputs the text so I can check
			--Checking weather that's set, returns same value every time
			local weatherID = getWeather()
			outputChatBox ( "The current weather ID is " .. weatherID )
		end
	end
end

Thanks for any help :P can't see where I went wrong.

  • Haha 1
Link to comment
  • Moderators
addEventHandler("onClientGUIClick",weather_button,setCustomWeather)

 

function setCustomWeather(button,state) --Function to change weather

 

You can't use the same name for the function `setWeather`, because it will actually overwrite it. Which means that if you call setWeather on line 42, it will re-call the function setWeather of line 38 (and not the mta function).

 

  • Thanks 1
Link to comment
17 minutes ago, IIYAMA said:

addEventHandler("onClientGUIClick",weather_button,setCustomWeather)

 


function setCustomWeather(button,state) --Function to change weather

 

You can't use the same name for the function `setWeather`, because it will actually overwrite it. Which means that if you call setWeather on line 42, it will re-call the function setWeather of line 38 (and not the mta function).

 

I didn't even notice that...  Thanks bud :D

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