Jump to content

Show text above head.


WolfPire

Recommended Posts

So i've been making a script that it's a re-made code of "chatIcon" but this will show what yo usay into the chatbox. I know this has been made before, but i want to make my own.

So, the problem is that... Ok it works like a charm... But other players won't be able to see eachtohers texts, so i've been trying for 2 h now to fix it. But for some strange reason, it won't show for others than you.

Here's the code:

Client

local showMyIcon = true 
local drawDistance = 1000 
local transicon = false 
local textPlayers = {} 
local chatTextFor = {} 
local timerFor = {} 
  
local screenSizex, screenSizey = guiGetScreenSize() 
local guix = screenSizex * 0.1 
local guiy = screenSizex * 0.1 
local globalscale = 1 
local globalalpha = .85 
  
function iconRender() 
    local playerx,playery,playerz = getElementPosition ( getLocalPlayer() ) 
    for player, truth in pairs(textPlayers) do 
         
        if (player == getLocalPlayer()) then 
            if(not showMyIcon) then 
                return 
            end 
        end 
         
        if(truth) then 
            local chatx, chaty, chatz = getElementPosition( player ) 
            if(isPedInVehicle(player)) then 
                chatz = chatz + .5 
            end 
            local dist = getDistanceBetweenPoints3D ( playerx, playery, playerz, chatx, chaty, chatz ) 
            if dist < drawDistance then 
                if( isLineOfSightClear(playerx, playery, playerz, chatx, chaty, chatz, true, false, false, false )) then 
                    local screenX, screenY = getScreenFromWorldPosition ( chatx, chaty-0.5, chatz+1.3 ) 
                        if(screenX and screenY) then 
                    local scaled = screenSizex * (1/(2*(dist+5))) *.85 
                    local relx, rely = scaled * globalscale, scaled * globalscale 
                    guiSetPosition(chatTextFor[player], screenX, screenY, false) 
                    guiSetAlpha(chatTextFor[player], globalalpha) 
                    extent = guiLabelGetTextExtent ( chatTextFor[player] ) 
                    guiSetSize(chatTextFor[player], relx + extent, rely, false) 
                    else 
                    guiSetAlpha(chatTextFor[player], 0) 
                    end 
                        else 
                        guiSetAlpha(chatTextFor[player], 0) 
                    end 
                end 
            end 
        end 
    end 
  
addEvent("drawText", true) 
addEventHandler("drawText", root, 
function(msg, thePlayer) 
    textPlayers[thePlayer] = true 
        if not chatTextFor[thePlayer] then 
        chatTextFor[thePlayer] = guiCreateLabel(0, 0, guix, guiy, msg, false ) 
        timerFor[thePlayer] = setTimer(guiSetText, 5000, 1, chatTextFor[thePlayer], "") 
        addEventHandler("onClientRender", root, iconRender) 
        else 
        if not isTimer(timerFor[thePlayer]) then 
        guiSetAlpha(chatTextFor[thePlayer], 255) 
        guiSetText(chatTextFor[thePlayer], msg) 
        timerFor[thePlayer] = setTimer(guiSetText, 5000, 1, chatTextFor[thePlayer], "") 
        else 
        killTimer(timerFor[thePlayer]) 
        timerFor[thePlayer] = setTimer(guiSetText, 5000, 1, chatTextFor[thePlayer], "") 
        guiSetText(chatTextFor[thePlayer], msg) 
        end 
    end 
end 
) 

Server

function sendInfo(msg) 
    thePlayer = source 
    triggerClientEvent(source, "drawText", root, msg, thePlayer) 
end 
  
addEventHandler("onPlayerChat", root, sendInfo) 

Thanks in advance,

- WolfPire

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