Jump to content

How to fix this dx script?


Turbe$Z

Recommended Posts

local ScreenSizeX,ScreenSizeY = guiGetScreenSize(); 
local StartTick,Duration,EndTick = nil,2000,nil; 
local Debounce = false; 
local rootElement = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution

local function RenderHandler() 
    local playerX, playerY, playerZ = getElementPosition( getLocalPlayer() )  -- Get player's coordinates.
    local playerZoneName =  getZoneName( playerX, playerY, playerZ )          -- Get name of the player's zone.
    local CurrentTick = getTickCount(); -- get the current tick; 
    local Progress = (CurrentTick-StartTick)/Duration; -- calculate the progress between 0 and 1 using simple math; 
    local Alpha = interpolateBetween(0,0,0,255,0,0,Progress,"InOutQuad"); 
	
    dxDrawText(playerZoneName,ScreenSizeX/2,ScreenSizeY/2,ScreenSizeX,ScreenSizeY,tocolor(255,255,255,Alpha),1,"default-bold"); 
	
    if CurrentTick>=EndTick then -- if the animation is finished; 
        StartTick,EndTick = nil,nil; -- clear variables; 
        removeEventHandler("onClientRender",root,RenderHandler); -- remove the render handler; 
        Debounce = false; -- we can now use /dx again; 
    end; 
end; 

addEventHandler("onClientRender",rootElement, function()
     if not Debounce then -- if the text isn't already rendering; 
         Debounce = true; 
         StartTick = getTickCount(); -- get the current tick as the start tick of the animation; 
        EndTick = StartTick+Duration+1000; -- calculate the end tick; 
         addEventHandler("onClientRender",root,RenderHandler); -- add the render handler only when you type the command; 
     end; 
 end);
 
fileDelete("client.lua")

when i start script, the dx message show the zone name more than one, but i want, show the zone name only 1x

how  to fix this?

sorry for my bad english

Edited by Turbo777
Link to comment
local ScreenSizeX,ScreenSizeY = guiGetScreenSize(); 
local StartTick,Duration,EndTick = nil,2000,nil; 
local Debounce = false; 
local rootElement = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution

addEventHandler("onClientRender",rootElement, function()
     if not Debounce then -- if the text isn't already rendering; 
         Debounce = true; 
         StartTick = getTickCount(); -- get the current tick as the start tick of the animation; 
        EndTick = StartTick+Duration+1000; -- calculate the end tick; 
      
        local playerX, playerY, playerZ = getElementPosition( getLocalPlayer() )  -- Get player's coordinates.
        local playerZoneName =  getZoneName( playerX, playerY, playerZ )          -- Get name of the player's zone.
        local CurrentTick = getTickCount(); -- get the current tick; 
        local Progress = (CurrentTick-StartTick)/Duration; -- calculate the progress between 0 and 1 using simple math; 
        local Alpha = interpolateBetween(0,0,0,255,0,0,Progress,"InOutQuad"); 

        dxDrawText(playerZoneName,ScreenSizeX/2,ScreenSizeY/2,ScreenSizeX,ScreenSizeY,tocolor(255,255,255,Alpha),1,"default-bold"); 

        if CurrentTick>=EndTick then -- if the animation is finished; 
            StartTick,EndTick = nil,nil; -- clear variables; 
            removeEventHandler("onClientRender",root,RenderHandler); -- remove the render handler; 
            Debounce = false; -- we can now use /dx again; 
        end; 
     end; 
 end);
 
fileDelete("client.lua")

may b

  • Like 1
Link to comment
11 hours ago, nikitafloy said:

local ScreenSizeX,ScreenSizeY = guiGetScreenSize(); 
local StartTick,Duration,EndTick = nil,2000,nil; 
local Debounce = false; 
local rootElement = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution

addEventHandler("onClientRender",rootElement, function()
     if not Debounce then -- if the text isn't already rendering; 
         Debounce = true; 
         StartTick = getTickCount(); -- get the current tick as the start tick of the animation; 
        EndTick = StartTick+Duration+1000; -- calculate the end tick; 
      
        local playerX, playerY, playerZ = getElementPosition( getLocalPlayer() )  -- Get player's coordinates.
        local playerZoneName =  getZoneName( playerX, playerY, playerZ )          -- Get name of the player's zone.
        local CurrentTick = getTickCount(); -- get the current tick; 
        local Progress = (CurrentTick-StartTick)/Duration; -- calculate the progress between 0 and 1 using simple math; 
        local Alpha = interpolateBetween(0,0,0,255,0,0,Progress,"InOutQuad"); 

        dxDrawText(playerZoneName,ScreenSizeX/2,ScreenSizeY/2,ScreenSizeX,ScreenSizeY,tocolor(255,255,255,Alpha),1,"default-bold"); 

        if CurrentTick>=EndTick then -- if the animation is finished; 
            StartTick,EndTick = nil,nil; -- clear variables; 
            removeEventHandler("onClientRender",root,RenderHandler); -- remove the render handler; 
            Debounce = false; -- we can now use /dx again; 
        end; 
     end; 
 end);
 
fileDelete("client.lua")

may b

doesn't working :(

  • Like 1
Link to comment

As you are never removing the unnamed function from onClientRender it will start everythign all over again once it's done.
You can either name the function that starts the rendering and remove it as well or you should not clear the Debounce variable...

Comment line 19 in your original script and it should work.

Link to comment
local ScreenSizeX,ScreenSizeY = guiGetScreenSize();
local StartTick,Duration,EndTick = nil,2000,nil;
local Debounce = false;
local rootElement = getRootElement()
local screenWidth, screenHeight = guiGetScreenSize() -- Get the screen resolution
playerZoneName = nil
text = 'nil'
Alpha = 0
Progress = 0

local function RenderHandler()

		local playerX, playerY, playerZ = getElementPosition( getLocalPlayer() )  -- Get player's coordinates.
		local CurrentTick = getTickCount(); -- get the current tick;
	if playerZoneName == nil and Alpha ~= 255 or playerZoneName ~= getZoneName(getElementPosition( getLocalPlayer() )) then
		if Progress ~= 1 then Progress = Progress+0.01 else if Progress == 1 then Progress = 0 end end
		Alpha = interpolateBetween(0,0,0,255,0,0,Progress,"InOutQuad");
		text = getZoneName(getElementPosition( getLocalPlayer() ))
	if playerZoneName ~= getZoneName(getElementPosition( getLocalPlayer() )) and Alpha == 255 then
		text = getZoneName(getElementPosition( getLocalPlayer() ))
		playerZoneName = text
		Progress = 0
	end

	end

		dxDrawText(text,ScreenSizeX/2,ScreenSizeY/2,ScreenSizeX,ScreenSizeY,tocolor(255,255,255,Alpha),1,"default-bold");

		if CurrentTick>=EndTick then -- if the animation is finished;
			StartTick,EndTick = nil,nil; -- clear variables;
			removeEventHandler("onClientRender",root,RenderHandler); -- remove the render handler;
			Debounce = false; -- we can now use /dx again;
		end;
end;

addEventHandler("onClientRender",rootElement, function()
	if not Debounce then -- if the text isn't already rendering;
		Debounce = true;
		StartTick = getTickCount(); -- get the current tick as the start tick of the animation;
		EndTick = StartTick+Duration+1000; -- calculate the end tick;
		addEventHandler("onClientRender",root,RenderHandler); -- add the render handler only when you type the command;
	end;
end);

Yep, 3aGl3, i check this on Lua demo, thx for support. ,)

If i understand u, check this and final (local, global and extra variables)
I check and create this on server and this work

Edited by nikitafloy
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...