GanJaRuleZ Posted March 13, 2012 Share Posted March 13, 2012 Hai all , so , the only thing i ask yet, is an example.. If i have a table , and i want to outputChatBox each word from there in the same sentence , how should i make.. (Sry for english ) Like this: words = { "lol" "xD" "ssffdd" } function lolout() for i,v in ipairs">ipairs">ipairs(words) do outputChatBox(v , getRootElement() , 255 , 0 ,0 ,true) end end Idk if it's good , yet i made it , but , that will output each word in another sentence , like: lol ssffdd And i want it so : lol,,ssffdd Thank you in advance. Link to comment
Castillo Posted March 13, 2012 Share Posted March 13, 2012 words = { "lol", "xD", "ssffdd" } function lolout() local wordsString = "" for index, word in ipairs">ipairs ( words ) do wordsString = wordsString ..",".. word end outputChatBox( wordsString:gsub ( ",", "", 1 ), root, 255, 0, 0, true ) end Link to comment
GanJaRuleZ Posted March 13, 2012 Author Share Posted March 13, 2012 (edited) Ty , but , now i have a problem.. It says : WARNING: Loading script failed: censore/server.lua:42: unexpected symbol near ')' This error refers at these 2 lines ( idk wich of them ) setTimer( function() setPlayerMuted(source,false) end , 10000,1) setTimer( function() outputChatBox("[CENSORING SYSTEM] : The player "..name.." has been unmuted.",getRootElement(),250,0 ,0 , true ) ) Ty EDIT : "name" comes from here : local name = getPlayerName(source) Edited March 13, 2012 by Guest Link to comment
Kenix Posted March 13, 2012 Share Posted March 13, 2012 words = { "lol", "xD", "ssffdd" } function lolout() local wordsString = "" for index, word in ipairs">ipairs">ipairs">ipairs">ipairs">ipairs ( words ) do wordsString = wordsString ..",".. word end outputChatBox( wordsString:gsub ( ",", "", 1 ), root, 255, 0, 0, true ) end Hard way for him. local words = { "lol", "xD", "ssffdd" } function lolout( ) outputChatBox( table.concat( words, ',' ), root, 255, 0, 0, true ) end It's more easy. Output: lol,,ssffdd Ty , but , now i have a problem..It says : WARNING: Loading script failed: censore/server.lua:42: unexpected symbol near ')' This error refers at these 2 lines ( idk wich of them ) setTimer( function() setPlayerMuted(source,false) end , 10000,1) setTimer( function() outputChatBox("[CENSORING SYSTEM] : The player "..name.." has been unmuted.",getRootElement(),250,0 ,0 , true ) ) Ty EDIT : "name" comes from here : local name = getPlayerName(source) Can you show full code? Link to comment
GanJaRuleZ Posted March 13, 2012 Author Share Posted March 13, 2012 function whenSomeoneChats(msg,msgType) local name = getPlayerName(source) if (string.find(msg,theCensored)) then outputChatBox("That is a censored word , if you think that is a mistake , contact an admin.",player,255,0,0,true) outputChatBox("[CENSORING SYSTEM] : "..tostring">tostring(name).." used an censored word. He is muted for 10 seconds from now.",getRootElement(),255,0,0,true) setPlayerMuted(source,true ) setTimer( function() setPlayerMuted(source,false) end , 10000,1) setTimer( function() outputChatBox("[CENSORING SYSTEM] : The player "..name.." has been unmuted.",getRootElement(),250,0 ,0 , true ) ) end end end Link to comment
arezu Posted March 13, 2012 Share Posted March 13, 2012 you forgot 'end', and time to wait before calling it, and how many times. and why use two setTimers? setTimer(function(player) setPlayerMuted(player, false) outputChatBox("[CENSORING SYSTEM] : The player "..getPlayerName(player).." has been unmuted.", getRootElement(), 250, 0, 0, true) end, 10000, 1, source) Link to comment
Kenix Posted March 13, 2012 Share Posted March 13, 2012 function whenSomeoneChats( msg, msgType ) local name = getPlayerName( source ) if string.find( msg,theCensored ) then outputChatBox( 'That is a censored word , if you think that is a mistake , contact an admin.', source, 255, 0, 0, true ) outputChatBox( '[CENSORING SYSTEM] : '.. name .. ' used an censored word. He is muted for 10 seconds from now.', root, 255, 0, 0, true ) setPlayerMuted( source,true ) setTimer( function( uPlayer, name ) setPlayerMuted( uPlayer,false ) outputChatBox( '[CENSORING SYSTEM] : The player ' .. name .. ' has been unmuted.', root, 250, 0, 0, true ) end , 10000, 1, source, name ) end end Updated again. Variable theCensored is defined? Also you add event handler to this function? Link to comment
GanJaRuleZ Posted March 13, 2012 Author Share Posted March 13, 2012 theCensored is a table .. So i have this theCensored = { "STF" "LOL" "XDD" } And now it gives me the following error : WARNING : Loading script failed:censore\server.lua:4: '}' expected (to close '{' at line 2 ) near "LOL" ' Ty .. Link to comment
Castillo Posted March 13, 2012 Share Posted March 13, 2012 theCensored = { "STF", -- You forgot the comma. "LOL", -- You forgot the comma. "XDD" } Link to comment
GanJaRuleZ Posted March 13, 2012 Author Share Posted March 13, 2012 Now i've got this error : ERROR : censore\server.lua:42: bad argument #2 to 'find' ( string expected , got table ) Thanks Link to comment
Castillo Posted March 13, 2012 Share Posted March 13, 2012 Because you can't use string.find on a table. Link to comment
Kenix Posted March 13, 2012 Share Posted March 13, 2012 local theCensored = { "STF", -- You forgot the comma. "LOL", -- You forgot the comma. "XDD" } function fTableFind ( t , find, row, column ) if type( t ) == 'table' and type( find ) == 'string' then if type( row ) == 'number' then if t[ row ] then if string.find ( t[ row ], find ) then return true end return false end return false elseif type( row ) == 'number' and type( column ) == 'number' then if t[ row ][ column ] then if string.find ( t[ row ][ column ] , find ) then return true end return false end return false end local function fTableDimension( array ) local result = { } for _, value in pairs( array ) do if type( value ) == 'table' then for _, v in pairs( fTableDimension( value ) ) do table.insert( result, v ) end else table.insert( result, value ) end end return result end local Table = fTableDimension( t ) local returnValue = false for _ , v in pairs( Table ) do if tostring( v ) == find then returnValue = true end end return returnValue end return false end function whenSomeoneChats( msg, msgType ) local name = getPlayerName( source ) if fTableFind( theCensored, msg ) then outputChatBox( 'That is a censored word , if you think that is a mistake , contact an admin.', source, 255, 0, 0, true ) outputChatBox( '[CENSORING SYSTEM] : '.. name .. ' used an censored word. He is muted for 10 seconds from now.', root, 255, 0, 0, true ) setPlayerMuted( source,true ) setTimer( function( uPlayer, name ) setPlayerMuted( uPlayer,false ) outputChatBox( '[CENSORING SYSTEM] : The player ' .. name .. ' has been unmuted.', root, 250, 0, 0, true ) end , 10000, 1, source, name ) end end Link to comment
GanJaRuleZ Posted March 13, 2012 Author Share Posted March 13, 2012 Thank you very much , but now , i want to add words in-game , like in oldskool mta This is what i got function addAWord(player,_,...) local text = table.concat({...}," ") if ( text ~= nil ) then table.insert(theCensored,text) outputChatBox("Added the word ' "..tostring">tostring(text).." to the censored words , to remove it use /rcw or /removecensoreword",player,0,0,100,true) end end addCommandHandler("acw",addAWord) addCommandHandler("addcensoreword",addAWord) No errors , but when i write /acw lol for example , and when i say lol , nothing happens.. Link to comment
Kenix Posted March 13, 2012 Share Posted March 13, 2012 Try loop table.( for see values ) Link to comment
GanJaRuleZ Posted March 14, 2012 Author Share Posted March 14, 2012 Can you give me an example on how to use it ? I can't figure it out Link to comment
Kenix Posted March 14, 2012 Share Posted March 14, 2012 for i, v in pairs( theCensored ) do outputChatBox( tostring( i ) .. tostring( v ) ) end Link to comment
GanJaRuleZ Posted March 14, 2012 Author Share Posted March 14, 2012 I know that , but , still didn't know how to use in-script.. Link to comment
GanJaRuleZ Posted March 15, 2012 Author Share Posted March 15, 2012 Sorry for double post , but , nobody knows ? Link to comment
Kenix Posted March 15, 2012 Share Posted March 15, 2012 function addAWord( uPlayer, _, ... ) local text = table.concat( { ... }, ' ' ) if text then -- if ( text ~= nil ) then it same like if text then ( if variable text is not false or nil ) -> table.insert( theCensored, text ) outputChatBox( "Added the word ' "..tostring( text ).." to the censored words , to remove it use /rcw or /removecensoreword", uPlayer, 0, 0, 100, true ) for i, v in pairs( theCensored ) do outputChatBox( tostring( i ) .. tostring( v ) ) end end end addCommandHandler( "acw", addAWord ) addCommandHandler( "addcensoreword", addAWord ) Link to comment
GanJaRuleZ Posted March 17, 2012 Author Share Posted March 17, 2012 Ty , but now i have the following problems : 1. It outputChatBox all the words , in different sentences , maybe it is a way to make like : LOL,XDD,STF,XDA Now it's showing like this : 1LOL 2XDD 3STF 4XDA 2. I tried to make remove the words too .. But i have this problem ERROR: censore/server.lua:27: bad Argument #2 to 'remove' (number expected, got string) Code : function removeAWord(player,_,...) local text = table.concat({...}," ") if text then local removeWord = fTableFind( theCensored, text ) if removeWord then table.remove(theCensored,text) outputChatBox("Removed the word ' "..tostring(text).." from the censored words .",player,0,0,100,true) for i, v in pairs( theCensored ) do outputChatBox( tostring( i ) .. tostring( v ) ) end else outputChatBox("#990000That word doesn't exists , please do /shcl or /showcensoredlist to see the current censored words.",player,255,0,0,true) end else outputChatBox("#990000Please write at least one word.",player,255,0,0,true) end end addCommandHandler("rcw",removeAWord) addCommandHandler("removecensoreword",removeAWord) Ty for help :"> Link to comment
Kenix Posted March 17, 2012 Share Posted March 17, 2012 All is good.I just show code for test it (output or no). 2. I tried to make remove the words too .. But i have this problem ERROR: censore/server.lua:27: bad Argument #2 to 'remove' (number expected, got string) Because in 2 argument you need use NUMBER not STRING. Link to comment
GanJaRuleZ Posted March 17, 2012 Author Share Posted March 17, 2012 Ah , k , but can you fix it ? Link to comment
Kenix Posted March 17, 2012 Share Posted March 17, 2012 If i am fix, you not learn. And i write your mistake. Link to comment
GanJaRuleZ Posted March 17, 2012 Author Share Posted March 17, 2012 Actually , i reanalyze every fixed code , to see how to fix smth , and to know how to don't make the mistake again in the future. But if you don't know , it's better to recongize , not to put pretexts like this one Whatever , I'm waiting for a fair guy Btw, if i could fix it , i woudn't posted here .. Link to comment
Kenix Posted March 17, 2012 Share Posted March 17, 2012 Example tSome = { 'some..'; } print( tSome[1] ) --> some.. table.remove( tSome, 1 ) -- remove index 1 in table ( in index 1 we have string 'some..' ) print( tSome[1] ) --> nil 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