Jump to content

Help Needed


BogdanRTB

Recommended Posts

  • Moderators
1 hour ago, BogdanRTB said:

disappear-appear infinity

Most of the dx effects have color arguments.

 

--[[
	Constants
]]
local animationDuration = 1000


--[[
	Get the current machine time
]]
local timeNow = getTickCount()

--[[
	Progress:
	timeNow % 1000 = 0 t/m 999.99
	(0 t/m 999.99) / 1000 = 0 t/m 1
]]
local progress = (timeNow % animationDuration) / animationDuration

--[[
	local opacityProgress = progress * 2
	| progress: 0.4 = opacityProgress: 0.8
	------------------------------------
	if progress > 0.5 then
	------------------------------------
	opacityProgress = progress * 2 - 1
	| progress: 0.6 = opacityProgress: 0.2
]]
local opacityProgress = progress * 2
if progress > 0.5 then
  opacityProgress = progress * 2 - 1
end

local bleepColor = tocolor(255, 255, 255, 255 * opacityProgress)

 

 

Link to comment

Hello BogdanRTB,

I think that @IIYAMA has made a wonderful solution if you want the UI to blend in and out using alpha. If you want to simulate a beep-like appearing and disappearing then I think that you might be interested in instant animation instead. This can be solved by the use of a simple timer in connection with the "beep"-duration.

-- The beep duration basically how long a visibility or non-visibility phase
-- is supposed to last.
local beepDuration = 1000;

-- This is the variable that you should use in your DX UI to determine whether
-- to draw it or not. You should reset it to true when you "call" your DX UI.
local is_dx_ui_beep_visible = true;

-- This variable should store the timer. It should be reset if the DX UI is "called".
local uiBeepTimer = false;

-- Call this function whenever you "call" or show your DX GUI.
local call_dx_gui()
    is_dx_ui_beep_visible = true;
    uiBeepTimer = setTimer(
        function()
            is_dx_ui_beep_visible = not is_dx_ui_beep_visible;
        end, beepDuration, 0
    );
end

-- Call this function whenever you hide your DX GUI.
local hide_dx_gui()
    is_dx_ui_beep_visible = false;
    killTimer(uiBeepTimer);
end

-- Example drawing code.
local show_dx_gui = true;
call_dx_gui();

addEventHandler("onClientRender", root,
    function()
        if (show_dx_gui) and (is_dx_ui_beep_visible) then
            dxDrawRectangle(100, 100, 400, 400, tocolor(255, 0, 0, 255));
        end
    end
);

 

  • Like 1
Link to comment

Okay but I have some issues at calling it because it is triggered by a event handler 

 

This is the basic script without any other added

--TEST
local sx, sy = guiGetScreenSize()

-- dx stuff
local textString = ""
local show = false
local r, b, g = 255, 255, 255
local posX = sx
local stringLegth = 0
local speed = 1
local alphaBG = 0
local fadeSpeed = 0.5
local height = 25

function drawAnnText()
	if show then
		setElementData(localPlayer, "annHeight", height, false)
		if (getPedWeapon(localPlayer) ~= 43 or not getPedControlState(localPlayer, "aim_weapon")) then
			dxDrawImage(1639, 429, 267, 550, "poze/tel.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
			dxDrawImage(1649, 529, 252, 323, "poze/bgroalert.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
			dxDrawImage(1673, 559, 39, 36, "poze/warning.png", 0, 0, 0, tocolor(255, 255, 255, 255), false)
			dxDrawText("RO-ALERT", 1716, 562, 1822, 595, tocolor(36, 36, 36, 255), 1.40, "sans", "left", "center", false, false, false, true, false)
			dxDrawText("Primit: 21 sept., 10:15", 1668, 604, 1844, 635, tocolor(36, 35, 35, 255), 1.00, "default-bold", "left", "center", false, false, false, false, false)
        	dxDrawText(textString, 1668, 651, 1878, 805, tocolor(36, 35, 35, 255), 1.20, "default-bold", "left", "top", false, true, false, false, false)
		end

		if alphaBG < 100 then
			alphaBG = alphaBG + fadeSpeed
		end

		if (posX + stringLegth) < 0 then
			if alphaBG < 0 then
				alphaBG = alphaBG - fadeSpeed
			else
				show = false
				removeEventHandler("onClientRender", getRootElement(), drawAnnText)
				setElementData(localPlayer, "annHeight", 0, false)
			end
		else
			posX = math.floor(posX - speed)
		end
	end
end

local function handleClick(button, state, absX, absY)
	if button == 'left' and state == 'down' and show and #textString > 0 then
		-- make sure it's not just at the border, since that might sometimes be buggy.
		if absX > 0 and absX < sx and absY > 0 and absY <= height then
			-- check if it contains an URL
			local url = exports.global:getUrlFromString(textString)
			if url and setClipboard(url) then
				outputChatBox('Copiat "' .. url .. '".')
			end
		end
	end
end

addEventHandler('onClientClick', root, handleClick)

function postAnn(msg, r1, b1, g1, playsound)
	if msg and (string.len(msg) > 0) then
		if playsound and tonumber(playsound) and (tonumber(playsound) > 0) then
			playSound(playsound .. ".mp3")
		end
		alphaBG = 0
		textString = msg
		stringLegth = string.len(textString) * 11
		posX = sx
		if r1 and b1 and g1 then
			r, b, g = r1, b1, g1
		end
		show = true
		addEventHandler("onClientRender", getRootElement(), drawAnnText)
	end
end

addEvent("rl:post", true)
addEventHandler("rl:post", getRootElement(), postAnn)

 

Edited by BogdanRTB
Link to comment
  • Moderators

 

5 minutes ago, BogdanRTB said:

Okay but I have some issues at calling it

You might want to add some debug lines to figure out the issue.

function postAnn(msg, r1, b1, g1, playsound)
  	iprint("postAnn arguments", msg, r1, b1, g1, playsound)
	if msg and (string.len(msg) > 0) then
		iprint("postAnn message is OK")
		if playsound and tonumber(playsound) and (tonumber(playsound) > 0) then
			iprint("postAnn play audio")
			playSound(playsound .. ".mp3")
		end
		alphaBG = 0
		textString = msg
		stringLegth = string.len(textString) * 11
		posX = sx
		if r1 and b1 and g1 then
			r, b, g = r1, b1, g1
		end
		show = true
		addEventHandler("onClientRender", getRootElement(), drawAnnText)
	end
end

addEvent("rl:post", true)
addEventHandler("rl:post", getRootElement(), postAnn)

If none of the debug lines are displayed, the issue is probably on serverside (or less likely but possible somewhere else clientside). You will be looking for:

triggerClientEvent( [optional,] "rl:post"

You should search for:

rl:post

 

 

2 minutes ago, BogdanRTB said:
alphaBG = alphaBG + fadeSpeed

Keep in mind that doing it this way, the effect speed is based on FPS and not time. Which means that the effect speed is reduced depending on the user his FPS. So better to use 1 of the 2 methods above.

Link to comment

It still doesn't work it now appears just under the white background (Orange Triangle is the dxImage that I want to make to Bleep)

spacer.png

And this is the serverside

--[[
	server.lua
	Allows server administrators to create banner annoucements
]]

mysql = exports.mysql
integration = exports.integration
pool = exports.pool

-- Admin announcement
addCommandHandler("roalert",
	function(player, commandName, ...)
		local isLoggedIn = getElementData(player, "loggedin") == 1

		if isLoggedIn and (integration:isPlayerTrialAdmin(player) or integration:isPlayerSupporter(player)) then
			if not (...) then
				outputChatBox("Comanda: /" .. commandName .. " [Mesaj]", player, 255, 194, 14)
				return
			end

			local message = table.concat({ ... }, " ")
			local players = exports.pool:getPoolElementsByType("player")
			local username = getPlayerName(player)

			for _, arrayPlayer in ipairs(players) do
				if integration:isPlayerTrialAdmin(player) then
					triggerClientEvent(arrayPlayer, "rl:post", arrayPlayer, "" .. message, 255, 194, 14, 1)
					outputChatBox("[RO-ALERT] "..message.."", player, 255, 255, 255)
				elseif integration:isPlayerSupporter(player) then
					triggerClientEvent(arrayPlayer, "rl:post", arrayPlayer, "" .. message, 255, 100, 150, 1)
					outputChatBox("[RO-ALERT] "..message.."", player, 255, 255, 255)
				end
			end
			outputConsole("Adm/SUPCmd: " .. message)
			exports.global:sendMessageToAdmins("Adm/SUPCmd: " .. username .. " a facut un ro-alert")
			exports.logs:dbLog(player, 4, player, "ANN " .. message)
		end
	end,
	false,
	false
)

 

Link to comment

I do not recommend you to do the following:

function postAnn(msg, r1, b1, g1, playsound)
	if msg and (string.len(msg) > 0) then
		...
		addEventHandler("onClientRender", getRootElement(), drawAnnText)
	end
end

MTA does not allow you to add the event twice but this will be reported as bad usage inside the debug console. Triggering these warnings is a bad idea. Instead add the event handler just like the other event handlers outside of any named function and use a boolean to control the execution. Or you could check if the event handler is already registered using that boolean and remove/add only after the check. But now on to the problem you face regarding your report...

If you want to make the orange triangle "bleep", then you have to change the following clientside line:

dxDrawImage(1649, 529, 252, 323, "poze/bgroalert.png", 0, 0, 0, bleepColor, false)

... where bleepColor is the variable from IIYAMA's solution. Could you try adjusting your code and the reporting back to us?

Edited by The_GTA
Link to comment
14 minutes ago, The_GTA said:

Oh my lord. I have detected a peculiar problem in your code unrelated to your original question.

function postAnn(msg, r1, b1, g1, playsound)
	if msg and (string.len(msg) > 0) then
		...
		addEventHandler("onClientRender", getRootElement(), drawAnnText)
	end
end

If you add the event handler in postAnn then it could be added many times and for each time the drawing code gets executed. I absolutely do not recommend you to add event handlers from inside event handlers unless you absolute know what you are doing!

Instead add the event handler just like the other event handlers outside of any named function. But now on to the problem you face regarding your report...

If you want to make the orange triangle "bleep", then you have to change the following clientside line:

dxDrawImage(1649, 529, 252, 323, "poze/bgroalert.png", 0, 0, 0, bleepColor, false)

... where bleepColor is the variable from IIYAMA's solution. Could you try adjusting your code and the reporting back to us?

Actually I added bleepColor in the dxDrawImage and the result was that image (Triangle just gets under the whitebg whitout doing any beep 

spacer.png

Link to comment

BogdanRTB, you have not told us exactly how you wanted that thing to work. First you say beep and then bleep. So you want that triangle to switch from half transparency to full transparency? You want the animation to be fluent? The issue with IIYAMA's solution is that the triangle does not fade out (probably a little oversight by him). Maybe try the following adjustment by me:

local animationDuration = 1000

local timeNow = getTickCount()

local progress = (timeNow % animationDuration) / animationDuration

local opacityProgress = progress * 2
if progress > 0.5 then
  opacityProgress = -(progress - 0.5) * 2 + 1
end

local bleepColor = tocolor(255, 255, 255, 255 * (0.5 + opacityProgress * 0.5))

 

Edited by The_GTA
bugfix
Link to comment

OK. Here is my adjustment to match your specification:

-- Put at the top of your script.
local interval_show = 1000;
local interval_hide = 2000;
local full_interval = ( interval_show + interval_hide );

local interval_start = getTickCount();

local function get_beep_alphafactor()
    local now = getTickCount();
    
    local ms_diff = ( now - interval_start );

    local interval_progress = ( ms_diff % full_interval );
    
    if (interval_progress < interval_show) then
        return 1.0;
    else
        return 0.0;
    end
end

-- Adjust the triangle dxDrawImage:
dxDrawImage(1649, 529, 252, 323, "poze/bgroalert.png", 0, 0, 0, tocolor(255, 255, 255, 255 * get_beep_alphafactor()), false)

I don't know what funny business you wanna do with this, lol. But I like that you are working on some inspiring work of art! ??

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