If Statement help LUA


#1

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.



#2

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

#3

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.


#4
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


#5

Perfect, thanks! (20char)