Jump to content

[HELP] Chat


K4stic

Recommended Posts

Posted

How remake Chatbubbles to make bubles for local chat with U and no to chat with T

Chatbubbles:

Client side

local textsToDraw = {} 
  
local hideown 
local showtime 
local characteraddition 
local maxbubbles 
  
local showthebubbles = true 
  
function income(message,messagetype) 
    if source ~= getLocalPlayer() or not hideown then 
        if messagetype == 2 then 
            if getPlayerTeam(source) == getPlayerTeam(getLocalPlayer()) then 
                addText(source,message,messagetype) 
            end 
        else 
            addText(source,message,messagetype) 
        end 
    end 
end 
  
function addText(source,message,messagetype) 
    local notfirst = false 
    for i,v in ipairs(textsToDraw) do 
        if v[1] == source then 
            v[4] = v[4] + 1 
            notfirst = true 
        end 
    end 
    local infotable = {source,message,messagetype,0} 
    table.insert(textsToDraw,infotable) 
    if not notfirst then 
        setTimer(removeText,showtime + (#message * characteraddition),1,infotable) 
    end 
end 
  
function removeText(infotable) 
    for i,v in ipairs(textsToDraw) do 
        if v[1] == infotable[1] and v[2] == infotable[2] then 
            for i2,v2 in ipairs(textsToDraw) do 
                if v2[1] == v[1] and v[4] - v2[4] == 1 then 
                    setTimer(removeText,showtime + (#v2[2] * characteraddition),1,v2) 
                end 
            end 
            table.remove(textsToDraw,i) 
            break 
        end 
    end 
end 
  
function getTextsToRemove() 
    for i,v in ipairs(textsToDraw) do 
        if v[1] == source then 
            removeText(v) 
        end 
    end 
end 
  
function handleDisplay() 
    if showthebubbles then 
        for i,v in ipairs(textsToDraw) do 
            if isElement(v[1]) then 
                if getElementHealth(v[1]) > 0 then 
                    local camPosXl, camPosYl, camPosZl = getPedBonePosition (v[1], 6) 
                    local camPosXr, camPosYr, camPosZr = getPedBonePosition (v[1], 7) 
                    local x,y,z = (camPosXl + camPosXr) / 2, (camPosYl + camPosYr) / 2, (camPosZl + camPosZr) / 2 
                    --local posx,posy = getScreenFromWorldPosition(x,y,z+0.25) 
                    local cx,cy,cz = getCameraMatrix() 
                    local px,py,pz = getElementPosition(v[1]) 
                    local distance = getDistanceBetweenPoints3D(cx,cy,cz,px,py,pz) 
                    local posx,posy = getScreenFromWorldPosition(x,y,z+0.020*distance+0.10) 
                    local elementtoignore1 = getPedOccupiedVehicle(getLocalPlayer()) or getLocalPlayer() 
                    local elementtoignore2 = getPedOccupiedVehicle(v[1]) or v[1] 
                    if posx and distance <= 45 and ( isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore1) or isLineOfSightClear(cx,cy,cz,px,py,pz,true,true,false,true,false,true,true,elementtoignore2) ) and ( not maxbubbles or  v[4] < maxbubbles ) then -- change this when multiple ignored elements can be specified 
                        local width = dxGetTextWidth(v[2],1,"default") 
                         
                        dxDrawRectangle(posx - (3 + (0.5 * width)),posy - (2 + (v[4] * 20)),width + 5,19,tocolor(0,0,0,255)) 
                        dxDrawRectangle(posx - (6 + (0.5 * width)),posy - (2 + (v[4] * 20)),width + 11,19,tocolor(0,0,0,40)) 
                        dxDrawRectangle(posx - (8 + (0.5 * width)),posy - (1 + (v[4] * 20)),width + 15,17,tocolor(0,0,0,255)) 
                        dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (1 + (v[4] * 20)),width + 19,17,tocolor(0,0,0,40)) 
                        dxDrawRectangle(posx - (10 + (0.5 * width)),posy - (v[4] * 20) + 1,width + 19,13,tocolor(0,0,0,255)) 
                        dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (v[4] * 20) + 1,width + 23,13,tocolor(0,0,0,40)) 
                        dxDrawRectangle(posx - (12 + (0.5 * width)),posy - (v[4] * 20) + 4,width + 23,7,tocolor(0,0,0,255)) 
                         
                        local r,g,b = 255,255,255 
                        if v[3] == 2 then 
                            r,g,b = getTeamColor(getPlayerTeam(v[1])) 
                        end 
                         
                        dxDrawText(v[2],posx - (0.5 * width),posy - (v[4] * 20),posx - (0.5 * width),posy - (v[4] * 20),tocolor(r,g,b,255),1,"default","left","top",false,false,false) 
                    end 
                end 
            end 
        end 
    end 
end 
  
function getServerSettings() 
    triggerServerEvent("onAskForBubbleSettings",getLocalPlayer()) 
end 
  
function saveSettings(settings) 
    showtime = settings[1] 
    characteraddition = settings[2] 
    maxbubbles = settings[3] 
    hideown = settings[4] 
    addEvent("onChatbubblesMessageIncome",true) 
    addEventHandler("onChatbubblesMessageIncome",getRootElement(),income) 
end 
  
function toggleBubblesOnOff() 
    showthebubbles = not showthebubbles 
    outputChatBox("Toggled chatbubbles " ..( not showthebubbles and "#FF0000off#FFFFFF." or "#00FF00on#FFFFFF." ),255,255,255,true) 
end 
  
addEventHandler("onClientPlayerQuit",getRootElement(),getTextsToRemove) 
addEventHandler("onClientRender",getRootElement(),handleDisplay) 
addEventHandler("onClientResourceStart",getResourceRootElement(getThisResource()),getServerSettings) 
addEvent("onBubbleSettingsReturn",true) 
addEventHandler("onBubbleSettingsReturn",getRootElement(),saveSettings) 
addCommandHandler("chatbubbles",toggleBubblesOnOff) 

Server side

local showtime = tonumber(get("chatbubbles.DefaultTime")) 
local characteraddition = tonumber(get("chatbubbles.PerCharacterAddition")) 
local maxbubbles = get("chatbubbles.MaxBubbles") 
if maxbubbles == "false" then maxbubbles = false else maxbubbles = tonumber(maxbubbles) end 
local hideown = get("chatbubbles.HideOwn") 
if hideown == "true" then hideown = true else hideown = false end 
  
function sendMessageToClient(message,messagetype) 
    if not wasEventCancelled() then 
        if messagetype == 0 or messagetype == 2 then 
            triggerClientEvent("onChatbubblesMessageIncome",source,message,messagetype) 
        end 
    end 
end 
  
function returnSettings() 
    local settings = 
    { 
    showtime, 
    characteraddition, 
    maxbubbles, 
    hideown 
    } 
    triggerClientEvent(source,"onBubbleSettingsReturn",getRootElement(),settings) 
end 
  
addEventHandler("onPlayerChat",getRootElement(),sendMessageToClient) 
addEvent("onAskForBubbleSettings",true) 
addEventHandler("onAskForBubbleSettings",getRootElement(),returnSettings) 

Local chat:

Server side

chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
bindKey(source,"u","down","chatbox","Local") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
for index, player in pairs(getElementsByType("player")) do 
bindKey(player,"u","down","chatbox","Local") 
  end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,_,...) 
  local px,py,pz=getElementPosition(player) 
  local msg = table.concat({...}, " ") 
  local nick=getPlayerName(player) 
local r,g,b = getTeamColor(getPlayerTeam(player)) 
  for _,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("[Local] "..nick..": "..msg,v,r,g,b,true) 
    end 
  end 
end 
addCommandHandler("Local",onChat) 
  

Giving a Fuck? Nope, That isn't in My Skill Set

castie11.png

Posted

At your local chat script you can trigger a custom event, then you can use it instead of 'onPlayerChat' at the chatbubbles.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Trigger a event from the local chat script when a player chats, then on chatbubbles:

function sendMessageToClient(message,messagetype) 
    if not wasEventCancelled() then 
        if messagetype == 0 or messagetype == 2 then 
            triggerClientEvent("onChatbubblesMessageIncome",source,message,messagetype) 
        end 
    end 
end 
addEventHandler("onPlayerChat",getRootElement(),sendMessageToClient) 

Instead of:

addEventHandler("onPlayerChat",getRootElement(),sendMessageToClient) 

You put your custom event, like this:

addEvent ( "onPlayerLocalChat", true ) 
addEventHandler("onPlayerLocalChat",getRootElement(),sendMessageToClient) 

And remove 'messageType' from 'sendMessageToClient' function.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

You mean this?

function sendMessageToClient(message) 
    if not wasEventCancelled() then 
            triggerClientEvent("onChatbubblesMessageIncome",source,message,messagetype) 
        end 
    end 
end 
addEvent ( "onPlayerLocalChat", true ) 
addEventHandler("onPlayerLocalChat",getRootElement(),sendMessageToClient) 

Giving a Fuck? Nope, That isn't in My Skill Set

castie11.png

Posted

And you must add the custom event on local chat.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Use:

triggerEvent 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

If you would at least try to do it, but you don't.

chat_range=100 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
bindKey(source,"u","down","chatbox","Local") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
for index, player in pairs(getElementsByType("player")) do 
bindKey(player,"u","down","chatbox","Local") 
  end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,_,...) 
  local px,py,pz=getElementPosition(player) 
  local msg = table.concat({...}, " ") 
  local nick=getPlayerName(player) 
local r,g,b = getTeamColor(getPlayerTeam(player)) 
  for _,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("[Local] "..nick..": "..msg,v,r,g,b,true) 
    end 
  end 
 triggerEvent ( "onPlayerLocalChat", player, msg ) 
end 
addCommandHandler("Local",onChat) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

you mean this

triggerEvent ( "onPlayerLocalChat", player, msg ) 

to tigger the event to chatbubbles

LOL i'm so BAD in LUA :(

But Thx for help you are the best! :)

Giving a Fuck? Nope, That isn't in My Skill Set

castie11.png

Posted

That won't really work though, since it doesn't trigger it for all these who are near. The chatbbubles was not made for this, you'll have to edit that script as well.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Last ask in this topic

addEventHandler ( "onPlayerTeamChat", root, chatbox ) 

is correct code for Teamchat with Y ?

Giving a Fuck? Nope, That isn't in My Skill Set

castie11.png

Posted

No, there's no such event "onPlayerTeamChat", is all part of "onPlayerChat".

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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