Jump to content

How to recognize/identify chars in variable.


Gawdzik

Recommended Posts

Posted

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 
  

Be RolePlayER - BERP, Project Master.

Posted

Thanks for reply, but don't have idea how to do that. Maybe function to edit a var message? And create if last char == . then outputchatbox, else message == ... says: " .. message .. "."

Be RolePlayER - BERP, Project Master.

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

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

Okey... but, you don't understand me. I know that, I post only a piece of my code. Read the first topic what I want to do. Thanks for help, but it's not that :D

Be RolePlayER - BERP, Project Master.

Posted

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.

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

Yes! That's it! Thank you very much for help. Now I'm reading about gsub in Lua DOC. ;) Thanks. Have a nice day.

Be RolePlayER - BERP, Project Master.

Posted

You're welcome.

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