Jump to content

How to recognize/identify chars in variable.


Gawdzik

Recommended Posts

Hello, I'm totally newbie, and I'm learning LUA with making Role Play server. For the first, sorry for my bad English, please, be forgiving.

I have got a local chat, for the aesthetics I want to manipulate chars in var. Example, player press t (open chat) and write -> "hello, I'm new in the town", when he press enter in the chatbox there is a "Hello, I'm, new in the town." (capital letter and dot in the end). I hope you understand my request. I don't want ready script (if you want...), I look forward to tips.

My localchat function...

  
function sendMessageToNearbyPlayers( message, messageType ) 
    if messageType == 0 then 
        local posX, posY, posZ = getElementPosition( source ) 
  
        local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) 
        local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) 
        destroyElement( chatSphere ) 
        local gracz = getPlayerName (source) 
        local dlugosc = #message 
        for index, nearbyPlayer in ipairs( nearbyPlayers ) do 
            if dlugosc <= 8 then 
            outputChatBox( "#99b7d0" .. gracz .. " mówi: #c8e6ff" .. message .. "", nearbyPlayer,255,255,255,true ) 
            setPedAnimation( source, "ped", "IDLE_chat", #message*70, false, false, false, false) 
            else 
            outputChatBox( "#99b7d0" .. gracz .. " mówi: #c8e6ff" .. message .. "", nearbyPlayer,255,255,255,true ) 
            setPedAnimation( source, "ped", "IDLE_chat", #message*35, false, false, false, false) 
            end 
        end 
    end 
end 
  

Link to comment
local chatRadius = 15 
  
function sendMessageToNearbyPlayers ( message, messageType ) 
    if ( messageType == 0 ) then 
        local posX, posY, posZ = getElementPosition ( source ) 
        local chatSphere = createColSphere ( posX, posY, posZ, chatRadius ) 
        local nearbyPlayers = getElementsWithinColShape ( chatSphere, "player" ) 
        destroyElement ( chatSphere ) 
        local gracz = getPlayerName ( source ) 
        local dlugosc = #message 
        for index, nearbyPlayer in ipairs ( nearbyPlayers ) do 
            outputChatBox ( "#99b7d0".. gracz .." mówi: #c8e6ff".. message, nearbyPlayer, 255, 255, 255, true ) 
        end 
  
        if ( dlugosc <= 8 ) then 
            setPedAnimation ( source, "ped", "IDLE_chat", ( #message * 70 ), false, false, false, false ) 
        else 
            setPedAnimation ( source, "ped", "IDLE_chat", ( #message * 35 ), false, false, false, false ) 
        end 
    end 
end 
addEventHandler ( "onPlayerChat", root, sendMessageToNearbyPlayers ) 

Try that.

Link to comment

Oh, my bad, sorry.

local chatRadius = 15 
  
function sendMessageToNearbyPlayers ( message, messageType ) 
    if ( messageType == 0 ) then 
        local posX, posY, posZ = getElementPosition ( source ) 
        local chatSphere = createColSphere ( posX, posY, posZ, chatRadius ) 
        local nearbyPlayers = getElementsWithinColShape ( chatSphere, "player" ) 
        destroyElement ( chatSphere ) 
        local gracz = getPlayerName ( source ) 
        local dlugosc = #message 
        for index, nearbyPlayer in ipairs ( nearbyPlayers ) do 
            outputChatBox ( "#99b7d0".. gracz .." mówi: #c8e6ff".. message:gsub ( "^%l", string.upper ) ..".", nearbyPlayer, 255, 255, 255, true ) 
        end 
  
        if ( dlugosc <= 8 ) then 
            setPedAnimation ( source, "ped", "IDLE_chat", ( #message * 70 ), false, false, false, false ) 
        else 
            setPedAnimation ( source, "ped", "IDLE_chat", ( #message * 35 ), false, false, false, false ) 
        end 
    end 
end 
addEventHandler ( "onPlayerChat", root, sendMessageToNearbyPlayers ) 

Try that.

It should make the first letter uppercase and add a dot at the end of the message.

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