If Statement help LUA

Hi, I am trying to make it so when someone joins the server, a statement is true, providing an output. When they run a command, it will change the variable to false, not providing the output. Output in this scenario is drawtext2.

Here is what I have:

function DrawText2(x,y ,width,height,scale, text, r,g,b,a)
    SetTextFont(1)
    SetTextProportional(0)
    SetTextScale(scale, scale)
    SetTextColour(r, g, b, a)
    SetTextDropShadow(0, 0, 0, 0,255)
    SetTextEdge(2, 0, 0, 0, 255)
    SetTextDropShadow()
    SetTextOutline()
    SetTextEntry("STRING")
    AddTextComponentString(text)
    DrawText(x - width/2, y - height/2 + 0.005)
end


local showText = true

	if(showText==true)
	then
		DrawText2(0.674, 1.358, 1.0,0.90,0.50, "message1", 255, 255, 255, 150)		
		DrawText2(0.674, 1.358, 1.0,0.96,0.50, "message2", 255, 255, 255, 150)	
		DrawText2(0.674, 1.358, 1.0,1.02,0.50, "message3 ", 255, 255, 255, 150)		
else
print('its false')		
	end

Not only does it not print “its false” anywhere, but it seems to load without issue besides that its not loading what I want it to. Without the variable implementation, it was working fine.

https://gyazo.com/a54ae4a95b45043c67baeaaed6aadfe0
https://gyazo.com/9de92d478eb5bf4426d6d8171da7a5fc

Hey there @CakeArmy_Max,

Give this a go:

local showText = true

RegisterCommand('patientdossier', function(source, args, rawCommand)
  local showText = false
end)


Citizen.CreateThread(function()
  while true do
      Wait(1)

        if ( showText == true ) then
    		   DrawText2(0.674, 1.358, 1.0,0.90,0.50, "message1", 255, 255, 255, 150)
    		   DrawText2(0.674, 1.358, 1.0,0.96,0.50, "message2", 255, 255, 255, 150)
    		   DrawText2(0.674, 1.358, 1.0,1.02,0.50, "message3 ", 255, 255, 255, 150)
        elseif ( showText == false ) then
           print('its false')
    	  end

  		end
end)

function DrawText2(x,y ,width,height,scale, text, r,g,b,a)
    SetTextFont(1)
    SetTextProportional(0)
    SetTextScale(scale, scale)
    SetTextColour(r, g, b, a)
    SetTextDropShadow(0, 0, 0, 0,255)
    SetTextEdge(2, 0, 0, 0, 255)
    SetTextDropShadow()
    SetTextOutline()
    SetTextEntry("STRING")
    AddTextComponentString(text)
    DrawText(x - width/2, y - height/2 + 0.005)
end

Tell me how it goes,

Cheers!

  • Julie

Thanks so much, I still wasn’t able to get it to disable however. The command is registering (the tooltip) but it doesn’t actually change anything.

local showText = true

RegisterCommand('showtext', function(source, args, rawCommand)
  showText = false
end)


Citizen.CreateThread(function()
  while true do
      Wait(1)

        if ( showText == true ) then
    		   DrawText2(0.674, 1.358, 1.0,0.90,0.50, "message1", 255, 255, 255, 150)
    		   DrawText2(0.674, 1.358, 1.0,0.96,0.50, "message2", 255, 255, 255, 150)
    		   DrawText2(0.674, 1.358, 1.0,1.02,0.50, "message3 ", 255, 255, 255, 150)
        elseif ( showText == false ) then
           print('its false')
    	  end

  		end
end)

function DrawText2(x,y ,width,height,scale, text, r,g,b,a)
    SetTextFont(1)
    SetTextProportional(0)
    SetTextScale(scale, scale)
    SetTextColour(r, g, b, a)
    SetTextDropShadow(0, 0, 0, 0,255)
    SetTextEdge(2, 0, 0, 0, 255)
    SetTextDropShadow()
    SetTextOutline()
    SetTextEntry("STRING")
    AddTextComponentString(text)
    DrawText(x - width/2, y - height/2 + 0.005)
end

try that, the command is /showtext

1 Like

Perfect, thanks! (20char)