Jump to content

Improvement Of Notification


Recommended Posts

Hello, I have a problem with the script on the notifications. The point is that the notifications show up one what I mean, but if you call it a few times the notification is imposed on each other. I want to show only one and the other to display only when the first one disappears. I have no idea how to do it. Thank you in advance for your help!
Here The Code:

 

local cFunc={}
local cSetting={}

NTSClient={}
NTSClient.__index=NTSClient

addEvent('onClientAddNotification', true)

-- send to client - triggerClientEvent(player, 'onClientAddNotification', player, text, 'type')
-- send to all clients - triggerClientEvent(root, 'onClientAddNotification', root, text, 'type')

function NTSClient:new(...)
	local obj=setmetatable({}, {__index=self})
	if obj.constructor then
		obj:constructor(...)
	end
	return obj
end

function NTSClient:render()
	local now = getTickCount() 
	if now >= self.tick then 
		self.tick = getTickCount()+30
		self.count = self.count-2
	end 
	
	local bg_x, bg_y=937, 186
	local x=self.sx/2-(bg_x/self.zoom)/2
	
	
	if self.count==0 and self.nts[1] then
		self.fadeOut=self.nts[1]
		table.remove(self.nts, 1)
	end
	if self.count<=1 and self.count>0 then
		self.pos_y=4.7/self.zoom+self.count/self.zoom
		self.posTXT_y=4.20/self.zoom+self.count/self.zoom
	elseif self.count==0 then
		self.pos_y=4.7/self.zoom
		self.posTXT_y=4.20/self.zoom
		self.count=280
	end
	
	if self.fadeOut then
		self.fadeOut.alpha=math.max(self.fadeOut.alpha-0.005, 0)
		dxDrawImage(x, self.pos_y, bg_x/self.zoom, bg_y/self.zoom, self.textures[tostring(self.fadeOut.type)], 0, 0, 0, tocolor(255, 255, 255, 255*self.fadeOut.alpha), true)
		dxDrawText(self.fadeOut.msg, x+(bg_x/6.25/self.zoom), self.posTXT_y, x+(bg_x/7/self.zoom)+bg_x/self.zoom-bg_x/5/self.zoom, self.posTXT_y+(bg_y/self.zoom), tocolor(255, 255, 255, 255*self.fadeOut.alpha), 0.5, self.font1, 'center', 'center', true, true, true)
		if self.fadeOut.alpha==0 then
			self.fadeOut=nil
		end
	end
	
	for i,v in pairs(self.nts) do
		if i>1 then return end
		if i>2 then return end
		v.alpha=math.min(v.alpha+0.065, 1)
		dxDrawImage(x, self.pos_y+((i-1)*150)/self.zoom, bg_x/self.zoom, bg_y/self.zoom, self.textures[tostring(v.type)], 0, 0, 0, tocolor(255, 255, 255, 255*v.alpha), true)
		dxDrawText(v.msg, x+(bg_x/6.25/self.zoom), self.posTXT_y+((i-1)*150)/self.zoom, x+(bg_x/7/self.zoom)+bg_x/self.zoom-bg_x/5/self.zoom, self.posTXT_y+(bg_y/self.zoom)+((i-1)*150)/self.zoom, tocolor(255, 255, 255, 255*v.alpha), 0.5, self.font1, 'center', 'center', true, true, true)
	end
end

function NTSClient:add(msg, type)
	if #self.nts==0 then
		self.count=280
	end
	
	outputConsole("["..string.upper(type).."] "..msg)
	table.insert(self.nts, {
		msg=msg, 
		type=type,
		alpha=0,
		tick=getTickCount()
	})
	local snd=playSound('s/' ..type.. '.mp3')
	setSoundVolume(snd, 0.3)
end

function NTSClient:onAddNTS(data, type)
	if not data then return end
	if not type then return end
	
	NTSClass:add(data, type)
end

function NTSClient:constructor(...)
	self.count=280
	self.fadeOut=nil
	self.nts={}
	
	local sx,sy=guiGetScreenSize()
	self.sx, self.sy=sx, sy
	self.zoom=2.4

	self.lu_start=getTickCount()
	self.pos_y, self.posTXT_y=6/self.zoom, 4/self.zoom
	
	self.textures={
		['warning']=dxCreateTexture('i/nts_warning.png', 'dxt5', false, 'wrap'),
		['error']=dxCreateTexture('i/nts_error.png', 'dxt5', false, 'wrap'),
		['success']=dxCreateTexture('i/nts_success.png', 'dxt5', false, 'wrap'),
		['info']=dxCreateTexture('i/nts_info.png', 'dxt5', false, 'wrap'),
	}

	self.font=dxCreateFont('f/myriad_prop.ttf', 20)
	self.font1=dxCreateFont('f/archivo_narrow.ttf', 20) 
	
	self.funcAddNTS=function(data, type) self:onAddNTS(data, type) end
	addEventHandler('onClientAddNotification', root, self.funcAddNTS)
	
	self.renderFunc=function() self:render() end
	addEventHandler('onClientRender', root, self.renderFunc)

	self.tick = 10 
end
NTSClass=NTSClient:new()

 

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