Jump to content

xDrawText position


Estevam2d

Recommended Posts

Would be useful if you post the code you use to render it.

What you could do would be to do it server-side(with ColShape), and then use triggerClientEventto pass the player element as an argument. As for the rendering, make an if statement to check if the local player's element/name is the same as the one passed down with triggerClientEvent.

If true, render it. If false, don't render it. :) Hope I made it understandable :P

Link to comment

sorry :D

Here's cliente.lua

I want to create a DrawText only for the player and not for all

only one posisao de los santos

local messagesList = { 
        "Bem vindo", 
    "Sempre olhe MTA-BRASIL", 
    "Talves voce perca", 
    "E sempre estaremos",  
        "Traga jogadores", 
        "Traga 3 e ganhe", 
        "traga 5 e ganhe", 
        "Tem alguma duvida?", 
        "MTA-BRASIL JOB's", 
        "Armas agora sao salvas ao morrer", 
  
} 
local currentMessage = 0 
  
-- ******************** 
-- *  Event handlers  * 
-- ******************** 
addEventHandler("onClientPreRender", getRootElement(), 
    function() 
        local screenWidth, screenHeight = guiGetScreenSize() 
  
        -- Draw the news sticker. 
        dxDrawRectangle(screenWidth - 310, 325, 200, 20, tocolor(0, 0, 0, 100), false) 
         
        -- Draw all strings. 
        dxDrawText(messagesList[currentMessage + 1], screenWidth - 400, 330, screenWidth - 6, 16, tocolor(255, 255, 255, 150), 1, "default-bold", "center", "top", false, false, false) 
    end 
) 
  
function updateMessage() 
    if (currentMessage == 11) then 
        currentMessage = 0 
    else 
        currentMessage = currentMessage + 1 
    end 
end 
setTimer(updateMessage, 4000, 0) 
  

Link to comment

So, I don't even know what I am thinking anymore. I was writing some examples for you, then I realized it's not even necessary.

The problem you have, is that you're using the event onClientPreRender. So whenever a client loads that script, it will draw that. This is why everyone saw it.

You can go ahead and try this, I haven't tested it - and you'll also have to create a proper ColShape. I just provided an example, you fill in the rest. Also, do try to read and understand it, instead of just copying and pasting.

local messagesList = { 
    "Bem vindo", 
    "Sempre olhe MTA-BRASIL", 
    "Talves voce perca", 
    "E sempre estaremos", 
    "Traga jogadores", 
    "Traga 3 e ganhe", 
    "traga 5 e ganhe", 
    "Tem alguma duvida?", 
    "MTA-BRASIL JOB's", 
    "Armas agora sao salvas ao morrer" 
} 
  
local currentMessage = 0 
local screenWidth, screenHeight = guiGetScreenSize() 
-- Create a ColShape when the script is loaded. (Most likely when Resource starts) 
local ammunitionColShape = createColRectangle(X, Y, Width, Height) 
  
function updateMessage() 
    if (currentMessage == 11) then 
        currentMessage = 0 
    else 
        currentMessage = currentMessage + 1 
    end 
end 
setTimer(updateMessage, 4000, 0) 
  
-- Check when the client enters the ColShape. Start rendering. 
function onClientInAmmunition() 
    -- Isolate it from other ColShapes, if you have any. 
    if(source == ammunitionColShape) then 
        -- Start the rendering 
        addEventHandler("onClientRender", getRootElement(), ammunitionDXDrawings) 
    end 
end 
addEventHandler("onClientColShapeHit", getRootElement(), onClientInAmmunition) 
  
-- Check when the client leaves the ColShape. Stop rendering. 
function onClientLeaveAmmunition() 
    -- Isolate it from other ColShapes, if you have any. 
    if(source == ammunitionColShape) then 
        -- Stop the rendering 
        removeEventHandler("onClientRender", getRootElement(), ammunitionDXDrawings) 
    end 
end 
addEventHandler("onClientColShapeLeave", getRootElement(), onClientLeaveAmmunition) 
  
-- Do take note how this function does not have an event handler. That's because we add it manually with the above functions. 
function ammunitionDXDrawings() 
    -- Draw the news sticker. 
    dxDrawRectangle(screenWidth - 310, 325, 200, 20, tocolor(0, 0, 0, 100), false) 
    -- Draw all strings. 
    dxDrawText(messagesList[currentMessage + 1], screenWidth - 400, 330, screenWidth - 6, 16, tocolor(255, 255, 255, 150), 1, "default-bold", "center", "top", false, false, false) 
end 

Note: onClientRender and onClientPreRender repeats the entire function for every frame. That means it will repeat the one same function 30-60 times per second. Thus, you need to be very careful when working with it.

In this case, you were getting the client's screen resolution with every frame. Not very efficient and might cause instability depending on what you're doing with it.

Link to comment

I am beginner in script

I try to understand with patience.

But I do not need to put the positions x, y, z so it appears the drawText ?

Solidsnake14 is nearly so, not only in los santos entire

is only in store Ammunation.

Like when I get near the shop appeared drawText with the rules Ammunation

Link to comment

You need to use:

https://wiki.multitheftauto.com/wiki/CreateColRectangle -- the position where you want to start the rendering

https://wiki.multitheftauto.com/wiki/On ... olShapeHit -- start rendering

https://wiki.multitheftauto.com/wiki/On ... ShapeLeave --stop rendering

https://wiki.multitheftauto.com/wiki/RemoveEventHandler -- to remove the event "onClientRender"

If you need help with the colshape, then feel free to ask me, or just post your used code here.

Link to comment

The drawText already ready, I put the two dxDrawRectangle and is working.

But what I need is to make this event start only in a particular area.

need a funciton that allows me to put x, y, z.

I tested the getScreenFromWorldPosition, only appears in the game I want just about to the display.

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