Jump to content

Show icon when somone is typing.....


DazzaJay

Recommended Posts

Just want you all to know, that /seticonalpha is now /seticonvis. I made a last minute change and forgot all about it :x

ok... here is my little surprise.

Cool stuff. I'll definitely put it into the next update. I totally forgot that the helpmanager even exists.

i belive that the icon's default size should be 50%

Heh, I didn't make this easy to change yet, but if you look around line 45 in ktypestatus_cl.lua

local scaled = screenSizex * (1/(2*(dist+5))) *.85 

if you change the .85 to .5, it should start off at half size. I'll probably make this a global variable later.

i have a funy idea for a next release:

when i am chat /[command] the icon dont show, and when i chat with a number or a letter in beginning, the icon are show :mrgreen:

I'll have to change some things around, but I'll see what I can do :D

Link to comment
  • 3 weeks later...
  • Replies 134
  • Created
  • Last Reply

Top Posters In This Topic

There's a few little bugs in this, but I like it, it's original for GTA too :D

  
function showTextIcon() 
local playerx,playery,playerz = getElementPosition ( getLocalPlayer() ) 
... 
  

When you're drawing things in a 3d world, you need to use the camera position as the origin, not the player's position.

You also need an 'isElementOnScreen' check in there somewhere.

Link to comment

Thanks for taking a look, Jax!

When you're drawing things in a 3d world, you need to use the camera position as the origin, not the player's position.

I'll be sure to try that out instead. Any particular reason why using the player's position is bad?

You also need an 'isElementOnScreen' check in there somewhere.

I'm doing this pretty manually right now. I wasn't aware of this function, but I'm glad it exists! I'll be sure to include this in an update.

Sorry to anyone that may be waiting for another release... It's been a busy month :|

But I'll still gladly take suggestions under consideration

Link to comment
  • 2 weeks later...

khepra, i found a bug with it...

i have noticed that it increases all players uploads in my server by 800%

without it i upload at 1.5kbps constant to the server, but when kchaticon is on, that amount of upload is increased to 12.0kbps

thats over 1000% increase in upload bandwidth.

same happens to download, add 10kbps to the top of what would normally be recived from the server.

any idea on why it would be causing all that bandwidth to be used?

(i have tested it on all 4 of my servers with the same results)

Link to comment

It could be because of this :

  
function chatCheckPulse() 
    if( isChatBoxInputActive() ) then 
        triggerServerEvent("playerChatting", getLocalPlayer()) 
    else 
        triggerServerEvent("playerNotChatting", getLocalPlayer()) 
    end 
     
    setTimer( chatCheckPulse, 500, 1) 
end 
  

Twice a second all players send data to the server to inform it of their chat status. This is wrong - it really needs to only send data when a change of chat state happens.

Edit : it's odd that it increases your bandwidth useage so much but I may be wrong. Either way, that code does not need to send the state twice a second.

Link to comment

here is the thing, if it does not check every so often, you will end up with bubbles stuck on your screen.... (a few other similar scripts do that, khepra's does not, but its the only one that uses bandwidth like this)

which makes me think.....

which is worse....

high pings....

or having peoples chat bubbles stuck on your screen.

Link to comment

What do you think about this:

chat = false 
  
function check () 
    if isChatBoxInputActive() == true and chat == false then 
        triggerServerEvent("playerChatting", getLocalPlayer()) 
        chat = true 
    elseif isChatBoxInputActive () == false and chat == true then 
        triggerServerEvent("playerNotChatting", getLocalPlayer()) 
        chat = false 
    end 
end 
  
addEventHandler ("onClientRender", getLocalPlayer(), check) 

I haven't tested it yet but maybe it works^^

Link to comment

You don't have to send the update constantly to avoid the sticky chat icon. I've done a chat icon display thing and it works fine as I suggested - only send the state to the server when it's changed - Mr.Hankey's code is what you're after. I have this running on a timer in the client :

  
function tuOverlayChatCheck() 
    -- Only inform the server if we're changing chat state (reduce bandwidth) 
    local chatState = isChatBoxInputActive() or isConsoleActive() 
    if chatState ~= gChatting then 
        gChatting = chatState 
        triggerServerEvent("tuOverlayChatUpdate",gMe,chatState) 
    end 
end 
  

Remember that 99% of the data pulses sent by the original code is redundant - there is no state change for the client chat for the vast majority of the time.

Link to comment
  • 2 weeks later...

Like tma said: "I have this running on a timer in the client", that is: "I call this function using timer in client-side script".

setTimer when the resource start (onClientResourceStart) and you should be ok.

Link to comment
  • 4 weeks later...
wait..... where do i add it in, (yeah yeah in the client script) but where? what line number? and what do i replace? Dont be so vauge all the time.

It's not a question of being vauge, it's just a question of time. I don't have much time to delve into other peoples code and make it work how it should. I was hoping by posting the snippet people could see the idea behind it or just modify it slightly and use it. The original author should be able to make the change to their resource from what I've posted.

Link to comment
what? :D

yea i don´t know how i have to place the script, same as DazzaJay

Well on your germen server you have a chat icon thingy.

ah yes but that is the "original version", tma postet a code that's better for server traffic but i don´t know how i have to place it, same as DazzaJay

that's it ;)

Link to comment

Right, I don't know if this will work (I'm just coding it here) or if the version of the KChat thing is the correct one, but try swapping:

  
function chatCheckPulse() 
    if( isChatBoxInputActive() ) then 
        triggerServerEvent("playerChatting", getLocalPlayer()) 
    else 
        triggerServerEvent("playerNotChatting", getLocalPlayer()) 
    end 
     
    setTimer( chatCheckPulse, 500, 1) 
end 
  

with this:

  
gChatting = false 
  
function chatCheckPulse() 
    local chatState = isChatBoxInputActive() or isConsoleActive() 
  
    if chatState ~= gChatting then 
        if chatState then 
            triggerServerEvent("playerChatting", getLocalPlayer()) 
        else 
            triggerServerEvent("playerNotChatting", getLocalPlayer()) 
        end 
        gChatting = chatState 
    end 
    setTimer( chatCheckPulse, 500, 1) 
end 
  

I've modified the original code to be like the snippet I posted, with the exception being this one sends two different events - it doesn't need to do that, it could just send the state as a paramater. However, this will work with the existing code (probably). The bandwidth for this resource will drop dramatically.

Link to comment

Like I saw it looked like this:

local showMyIcon = true 
local chattingPlayers = {} 
local drawDistance = 100 
local transicon = true 
local chatIconFor = {} 
  
local screenSizex, screenSizey = guiGetScreenSize() 
local guix = screenSizex * 0.1 
local guiy = screenSizex * 0.1 
local globalscale = 1 
local globalalpha = .85 
  
addEvent("updateChatList", true ) 
  
function chatCheckPulse() 
    if( isChatBoxInputActive() ) then 
        triggerServerEvent("playerChatting", getLocalPlayer()) 
    else 
        triggerServerEvent("playerNotChatting", getLocalPlayer()) 
    end 
     
    setTimer( chatCheckPulse, 500, 1) 
end 
  
function showTextIcon() 
    local playerx,playery,playerz = getElementPosition ( getLocalPlayer() ) 
    for player, truth in pairs(chattingPlayers) do 
         
        if (player == getLocalPlayer()) then 
            if(not showMyIcon) then 
                return 
            end 
        end 
     
        if(truth) then 
            local chatx, chaty, chatz = getElementPosition( player ) 
            if(isPlayerInVehicle(player)) then 
                chatz = chatz + .5 
            end 
            local dist = getDistanceBetweenPoints3D ( playerx, playery, playerz, chatx, chaty, chatz ) 
            if dist < drawDistance then 
              if (isPlayerDucked(player)==false) then 
                if( isLineOfSightClear(playerx, playery, playerz, chatx, chaty, chatz, true, false, false, false )) then 
                    local screenX, screenY = getScreenFromWorldPosition ( chatx, chaty, chatz+1.2 ) 
                     
                    local scaled = screenSizex * (1/(2*(dist+5))) *.85 
                    local relx, rely = scaled * globalscale, scaled * globalscale 
                    -- -.0025 * dist+.125 
                    --if(dist < 1) then 
                    --  relx, rely = guix, guiy 
                    --end 
                    guiSetAlpha(chatIconFor[player], globalalpha) 
                    guiSetSize(chatIconFor[player], relx, rely, false) 
                    guiSetPosition(chatIconFor[player], screenX, screenY, false) 
                    if(screenX and screenY) then 
                        guiSetVisible(chatIconFor[player], true) 
                    end 
                end 
              end    
            end 
        end 
    end 
end 
  
function updateList(newEntry, newStatus) 
    chattingPlayers[newEntry] = newStatus 
    if(not chatIconFor[newEntry]) then 
        chatIconFor[newEntry] = guiCreateStaticImage(0, 0, guix, guiy, "chat___german_public_server_version--do_not_use.png", false ) 
    end 
    guiSetVisible(chatIconFor[newEntry], false) 
end 
  
function toggleIcon() 
    outputChatBox ( "Your icon is: " ) 
    if( showMyIcon ) then 
        showMyIcon = false 
        outputChatBox ( "off", 255, 0, 0) 
    else 
        showMyIcon = true 
        outputChatBox ( "on", 0, 255, 0) 
    end 
end 
  
function resizeIcon( command, newSize ) 
    if(newSize) then 
        local resize = tonumber( newSize ) 
        local percent = resize/100 
        globalscale = percent 
    end 
    outputChatBox("Chat icons are "..(globalscale * 100).."% normal size") 
end 
  
function setIconAlpha( command, newSize ) 
    if(newSize) then 
        globalalpha = tonumber( newSize ) / 100 
    end 
    outputChatBox("Chat icons are "..(globalalpha * 100).."% visible") 
end 
  
addEventHandler ( "updateChatList", getRootElement(), updateList ) 
  
addEventHandler ( "onClientResourceStart", getRootElement(), chatCheckPulse ) 
addEventHandler ( "onClientPlayerJoin", getRootElement(), chatCheckPulse ) 
addEventHandler ( "onClientRender", getRootElement(), showTextIcon ) 
  
addCommandHandler( "toggleicon", toggleIcon) 
addCommandHandler( "resizeicon", resizeIcon) 
addCommandHandler( "seticonvis", setIconAlpha) 

Link to comment
Right, I don't know if this will work (I'm just coding it here) or if the version of the KChat thing is the correct one, but try swapping:
  
function chatCheckPulse() 
    if( isChatBoxInputActive() ) then 
        triggerServerEvent("playerChatting", getLocalPlayer()) 
    else 
        triggerServerEvent("playerNotChatting", getLocalPlayer()) 
    end 
     
    setTimer( chatCheckPulse, 500, 1) 
end 
  

with this:

  
gChatting = false 
  
function chatCheckPulse() 
    local chatState = isChatBoxInputActive() or isConsoleActive() 
  
    if chatState ~= gChatting then 
        if chatState then 
            triggerServerEvent("playerChatting", getLocalPlayer()) 
        else 
            triggerServerEvent("playerNotChatting", getLocalPlayer()) 
        end 
        gChatting = chatState 
    end 
    setTimer( chatCheckPulse, 500, 1) 
end 
  

I've modified the original code to be like the snippet I posted, with the exception being this one sends two different events - it doesn't need to do that, it could just send the state as a paramater. However, this will work with the existing code (probably). The bandwidth for this resource will drop dramatically.

Thank you tma.

Works good. (i was trying to replace the wrong things, seeing as how nooone said where to put the code)

Link to comment

I'm pretty sure the change I suggested doesn't cause this problem. Can you check by swapping back to the original code and trying ?

I only made a change to send less data to the server, not weather they were/were not chatting. Dunno - could be the way the server handles things but it's more likely to be the overlay update code that needs to check if the player is on screen and to show/hide the icon accordingly. Does the original code do this OK ?

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