Jump to content

3D Glitch Effect Help


Recommended Posts

I writted shader for you.

Code for client.Lua:

local SHADER_CODE = base64Decode("AQn//sQCAAAAAAAABQAAAAQAAAAcAAAAAAAAAAAAAAABAAAADwAAAG15U2NyZWVuU291cmNlAAADAAAAAAAAAFAAAABcAAAAAAAAAAEAAAABAAAAAAAAAAYAAABnVGltZQAAAAUAAABUSU1FAAAAAAMAAAACAAAAxAAAAOAAAAAAAAAABAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFQAAAGdXb3JsZFZpZXdQcm9qZWN0aW9uAAAAABQAAABXT1JMRFZJRVdQUk9KRUNUSU9OAAoAAAAEAAAAKAIAAAAAAAAAAAAAAgAAAAUAAAAEAAAAAAAAAAAAAAAAAAAAAwAAAAIAAAACAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAADAAAAAgAAAAIAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAIAAAACAAAAAgAAAAAAAAAAAAAAAAAAAAEAAAABAAAAAgAAAAIAAAACAAAAAAAAAAAAAAAAAAAAAQAAAAEAAAACAAAAAgAAAAIAAAAAAAAAAAAAAAAAAAABAAAAAQAAAAYAAACkAAAAAAEAABABAAAMAQAApQAAAAABAAAoAQAAJAEAAKYAAAAAAQAASAEAAEQBAACqAAAAAAEAAGgBAABkAQAAqQAAAAABAACIAQAAhAEAAKsAAAAAAQAAqAEAAKQBAAAOAAAAU2NyZWVuU2FtcGxlcgAAAAMAAAAAAAAAXAIAAAAAAAAAAAAAAQAAAAEAAAAAAAAADAAAAEdsaXRjaFBvd2VyAAMAAAAQAAAABAAAAAAAAAAAAAAAAAAAAAQAAAAPAAAABAAAAAAAAAAAAAAAAAAAAAMAAABQMAAAAQAAAAAAAAADAAAAUDAAAAkAAABmYWxsYmFjawAAAAAFAAAAAgAAAAUAAAAFAAAABAAAABgAAAAAAAAAAAAAADAAAABMAAAAA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kgA4AxqACAOSABAAABAEAD4AEAOSAEADGoAEA5IAEAAAEAAAPgAAA5IAKAFqgAQDkgAUAAAMACA+AAADkgAwA5KD//wAAAAAAAAAAAAD/////AAAAAAAAAABwAQAAAAL+//7/NQBDVEFCHAAAAJ8AAAAAAv7/AQAAABwAAAAAAAAgmAAAADAAAAACAAAABAAAAEgAAABYAAAAZ1dvcmxkVmlld1Byb2plY3Rpb24Aq6urAwADAAQABAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB2c18yXzAATWljcm9zb2Z0IChSKSBITFNMIFNoYWRlciBDb21waWxlciA5LjI3Ljk1Mi4zMDIyAFEAAAUEAA+gAACAPwAAAAAAAAAAAAAAAB8AAAIAAACAAAAPkB8AAAIFAACAAQAPkAQAAAQAAA+AAAAkkAQAQKAEABWgCQAAAwAAAcAAAOSAAADkoAkAAAMAAALAAADkgAEA5KAJAAADAAAEwAAA5IACAOSgCQAAAwAACMAAAOSAAwDkoAEAAAIAAAPgAQDkkP//AAD/////AwAAAAAAAAAAAAAAAQAAAA8AAABteVNjcmVlblNvdXJjZQAA")

-- export to mta and writted code by: XaskeL
-- shader code from glsl by: Coolok

CGlitch = {
	GlitchPower = 0.001; -- Glitch Power (0.0f to 1.0f);
	ScreenSize = { guiGetScreenSize() }; -- default screen size

	-- example[1]: CGlitch:destroy()
	-- example[2]: CGlitch.destroy()
	-- function for destroy glitch effects
	destroy = function(self)
		if CGlitch.AlreadyHandlered then
			removeEventHandler('onClientHUDRender', root, CGlitch.draw);
			removeEventHandler('onClientPreRender', root, CGlitch.update);
			CGlitch.AlreadyHandlered = false;
		end
		if self.Shader then
			destroyElement(self.Shader);
			self.Shader = false;
		end
		if self.MyScreenSource then
			destroyElement(self.MyScreenSource);
			self.MyScreenSource = false;
		end
		return true;
	end;
	
	-- function for update screen source
	update = function()
		if CGlitch.MyScreenSource then
			dxUpdateScreenSource(CGlitch.MyScreenSource);
		end
	end;

	-- function for draw glitch effect
	draw = function()
		if CGlitch.Shader then
			dxDrawImage(0, 0, CGlitch.ScreenSize[1], CGlitch.ScreenSize[2], CGlitch.Shader)
		end
		if (CGlitch.fTime and CGlitch.fTime < getTickCount()) then
			CGlitch:destroy();
		end
	end;
	
	-- example [1]: CGlitch:show(500);
	-- example [2]: CGlitch.show(CGlitch, 500); 
	-- params: @self (table CGlitch), 500 (time in milliseconds or false for permanently drawing)
	show = function(self, fTime)
		-- create screen source & shader
		self.MyScreenSource = dxCreateScreenSource(CGlitch.ScreenSize[1], CGlitch.ScreenSize[2]);
		self.Shader = dxCreateShader(SHADER_CODE);
		-- set default parametres
		dxSetShaderValue(self.Shader, 'GlitchPower', self.GlitchPower);
		dxSetShaderValue(self.Shader, 'myScreenSource', self.MyScreenSource);
		-- set work time
		if fTime then self.fTime = getTickCount() + fTime; else self.fTime = false; end
		-- create event handlers
		if (not self.AlreadyHandlered) then
			addEventHandler('onClientPreRender', root, CGlitch.update);
			addEventHandler('onClientHUDRender', root, CGlitch.draw);
			self.AlreadyHandlered = true;
		end
	end;
};

--[[ example:
	CGlitch:show(500); -- show 500 ms
--]]

--[[ example:
	CGlitch:show(false); -- show permanently
	
	addCommandHandler('disableglitch', function()
		CGlitch:destroy();
	end )
--]]

Example for use:

local MarkerPos = { x = 0.0; y = 0.0; z = 0.0; };
local theMarker = createMarker(MarkerPos.x, MarkerPos.y, MarkerPos.z, "cylinder", 1.5, 255, 255, 0, 170)

addEventHandler('onClientMarkerHit', theMarker, function() 
	CGlitch:show(500); 
end);

Screenshot:
mta-screen-2020-01-21-02-05-13.png

Edited by XaskeL
  • Like 1
Link to post
	-- example [1]: CGlitch:show(500);
	-- example [2]: CGlitch.show(CGlitch, 500); 
	-- params: @self (table CGlitch), 500 (time in milliseconds or false for permanently drawing)
	show = function(self, fTime)
		-- create screen source & shader
		if not self.Shader then
			self.MyScreenSource = dxCreateScreenSource(CGlitch.ScreenSize[1], CGlitch.ScreenSize[2]);
			self.Shader = dxCreateShader(SHADER_CODE);
			-- set default parametres
			dxSetShaderValue(self.Shader, 'GlitchPower', self.GlitchPower);
			dxSetShaderValue(self.Shader, 'myScreenSource', self.MyScreenSource);
		end
		-- set work time
		if fTime then self.fTime = getTickCount() + fTime; else self.fTime = false; end
		-- create event handlers
		if (not self.AlreadyHandlered) then
			addEventHandler('onClientPreRender', root, CGlitch.update);
			addEventHandler('onClientHUDRender', root, CGlitch.draw);
			self.AlreadyHandlered = true;
		end
	end;

I forgot to add check, replace code this function.

Edited by XaskeL
Link to post

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