Gawdzik Posted May 28, 2012 Share Posted May 28, 2012 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
Castillo Posted May 29, 2012 Share Posted May 29, 2012 You must use the event: onPlayerChat, cancel the default message with: cancelEvent then put your code. Link to comment
Gawdzik Posted May 29, 2012 Author Share Posted May 29, 2012 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 .. "." Link to comment
Castillo Posted May 29, 2012 Share Posted May 29, 2012 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
Gawdzik Posted May 29, 2012 Author Share Posted May 29, 2012 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 Link to comment
Castillo Posted May 30, 2012 Share Posted May 30, 2012 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
Gawdzik Posted May 30, 2012 Author Share Posted May 30, 2012 Yes! That's it! Thank you very much for help. Now I'm reading about gsub in Lua DOC. Thanks. Have a nice day. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now