Jump to content

Example needed.


GanJaRuleZ

Recommended Posts

Hai all :P , 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
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

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 :P

EDIT : "name" comes from here :

local name = getPlayerName(source) 

Edited by Guest
Link to comment
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,xD,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
  
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

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

  
   
  
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

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

Link to comment
  
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

Thank you very much , but now , i want to add words in-game , like in oldskool mta :P

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

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

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

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

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