Jump to content

Notifaction system


Dimos7

Recommended Posts

function sendClientMessage(message, r, g, b, colorCode)
    local x, y = guiGetScreenSize()
	local message = string.gsub(message, "")
    if not message then return end
	r,g ,b = tonumber(r), tonumber(g), tonumber(b)
	if not colorCode then
	   colorCode = false
	else
	   colorCode = true
       r,g,b = getColorFromString(message)
	 end
	 dxDrawRectangle(x/2, 0, 200, 200, tocolor(0, 0, 0, 220), false, false)
	 dxDrawText(message,0, 0, x, y, tocolor(r, g, b, 220), 1, "default", "center", "center", false, false, true)
end
addEvent("sendClientMessage", true)
addEventHandler("sendClientMessage", root, sendClientMessage)

it draw the rectangle but for very few seconds why?

Edited by Dimos7
Link to comment

i try it like this 

function sendClientMessage(message, r, g, b, colorCode)
    local x, y = guiGetScreenSize()
	local message = tostring(message)
    if not message then return end
	r,g ,b = tonumber(r), tonumber(g), tonumber(b)
	if not colorCode then
	   colorCode = false
	else
	   colorCode = true
       r,g,b = getColorFromString(message)
	 end 
	    if getTickCount() <= 5000 then
	       dxDrawRectangle(x/2, 0, 200, 100, tocolor(0, 0, 0, 220), false, false)
	       dxDrawText(message,x/2, 0, x, y, tocolor(r, g, b, 220), 1, "default", "left", "top", false, false, true)
		end
end
addEvent("sendClientMessage", true)
addEventHandler("sendClientMessage", root, sendClientMessage)

but didn't show up nothing

Edited by Dimos7
Link to comment
function sendClientMessage(message, r, g, b, colorCode)
    local x, y = guiGetScreenSize()
	local message = tostring(message)
    if not message then return end
	r,g ,b = tonumber(r), tonumber(g), tonumber(b)
	if not colorCode then
	   colorCode = false
	else
	   colorCode = true
       r,g,b = getColorFromString(message)
	 end 
	     addEventHandler("onClientRender", root, 
	         function()
	            dxDrawRectangle(x/2-800/2, 0, 800, 50, tocolor(0, 0, 0, 220), false, false)
	            dxDrawText(message, 0, 15, x, y, tocolor(r, g, b, 220), 1, "default", "center", "top", false, false, true)
			 end
	      )
		  setTimer(removeEventHandler, 5000, 1, "onClientRender", root, sendClientMessage)
end		  
addEvent("sendClientMessage", true)
addEventHandler("sendClientMessage", root, sendClientMessage)

i try it like that but in time need function and put the functionstart function say take nill

Edited by Dimos7
Link to comment

Example:

 

function whatever()
	addEventHandler("onClientRender", getRootElement(), example)
	setTimer(function()
		removeEventHandler("onClientRender", getRootElement(), example)
	end, 5000, 1)
end

function example()
	--dxdrawstuff
end

 

The function needs a name so the removeEventHandler knows where to find the function to be removed

Link to comment

Did you read the example cause it's really that simple:

 

function dxDrawStuff()
	dxDrawRectangle(x/2-800/2, 0, 800, 50, tocolor(0, 0, 0, 220), false, false)
	dxDrawText(message, 0, 15, x, y, tocolor(r, g, b, 220), 1, "default", "center", "top", false, false, true)
end

function sendClientMessage(message, r, g, b, colorCode)
    local x, y = guiGetScreenSize()
	local message = tostring(message)
    if not message then return end
	r,g ,b = tonumber(r), tonumber(g), tonumber(b)
	if not colorCode then
	   colorCode = false
	else
	   colorCode = true
       r,g,b = getColorFromString(message)
	 end 

	addEventHandler("onClientRender", root, dxDrawStuff)
	setTimer(function()
      removeEventHandler("onClientRender", root, dxDrawStuff)
    end, 5000, 1)
end		  
addEvent("sendClientMessage", true)
addEventHandler("sendClientMessage", root, sendClientMessage)

You might look at setTimer cause that one was quite messed up

Link to comment

Like that will be apear many erroy x ,y message etc not take them from one to other function

function sendClientMessage(message, r, g, b, colorCode)
    local x, y = guiGetScreenSize()
	local message = tostring(message)
    if not message then return end
	r,g ,b = tonumber(r), tonumber(g), tonumber(b)
	if not colorCode then
	   colorCode = false
	else
	   colorCode = true
       r,g,b = getColorFromString(message)
	 end 
	    dxDrawRectangle(x/2-800/2, 0, 800, 50, tocolor(0, 0, 0, 220), false, false)
	    dxDrawText(message, 0, 15, x, y, tocolor(r, g, b, 220), 1, "default", "center", "top", false, false, true)
end
addEvent("sendClientMessage", true)
addEventHandler("sendClientMessage", root, sendClientMessage)

function Notifactions()
   sendClientMessage()
   addEventHandler("onClientRender", root, Notifactions)
   setTimer(
   function()
       removeEventHandler("onClientRender", root, Notifactions)
   end, 15000, 1)
end

i try it like this but again in few seconds dissapear

Link to comment
54 minutes ago, Dimos7 said:

i mean x not take from guiGetScreenSize neither message

oh yeah my bad didn't notice. I see what you mean.

local x, y = guiGetScreenSize() --can be at the top since your screensize won't change during runtime
local message = false
local r, g, b

function notification()
	dxDrawRectangle(x/2-800/2, 0, 800, 50, tocolor(0, 0, 0, 220), false, false)
	dxDrawText(message, 0, 15, x, y, tocolor(r, g, b, 220), 1, "default", "center", "top", false, false, true)
end

function sendClientMessage(message, r, g, b, colorCode)
	message = tostring(message)
    if not message then return end
	r,g ,b = tonumber(r), tonumber(g), tonumber(b)
	if not colorCode then
	   colorCode = false
	else
	   colorCode = true
       r,g,b = getColorFromString(message)
	 end 

	addEventHandler("onClientRender", root, notification)
	setTimer(function()
      removeEventHandler("onClientRender", root, notification)
      message = false
    end, 5000, 1)
end		  
addEvent("sendClientMessage", true)
addEventHandler("sendClientMessage", root, sendClientMessage)

Try this

Edited by ViRuZGamiing
Link to comment
local x, y = guiGetScreenSize()
local message = false
local r, g, b 

function Notifactions()
    dxDrawRectangle(x/2-800/2, 0, 800, 50, tocolor(0, 0, 0, 220), false, false)
	dxDrawText(message, 0, 15, x, y, tocolor(r, g, b, 220), 1, "default", "center", "top", false, false, true)
end

function sendClientMessage(message, r, g, b, colorCode)
	message = tostring(message)
    if not message then return end
	r,g ,b = tonumber(r), tonumber(g), tonumber(b)
	if not colorCode then
	   colorCode = false
	else
	   colorCode = true
       r,g,b = getColorFromString(message)
	 end 
	   addEventHandler("onClientRender", root, Notifactions)
	   setTimer(function()
	      removeEventHandler("onClientRender", root, Notifactions)
		  message = false
		  end, 5000, 1)
end
addEvent("sendClientMessage", true)
addEventHandler("sendClientMessage", root, sendClientMessage)

dxDrawText expect string argument 1  got boolean

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