Jump to content

Example needed.


GanJaRuleZ

Recommended Posts

Posted

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.

My Projects!

No one.

Posted
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 

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

EDIT : "name" comes from here :

local name = getPlayerName(source) 

Edited by Guest

My Projects!

No one.

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

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted
  
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 

My Projects!

No one.

Posted

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) 

Posted

  
   
  
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?

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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

My Projects!

No one.

Posted
theCensored =  
    { 
        "STF", -- You forgot the comma. 
        "LOL", -- You forgot the comma. 
        "XDD" 
    } 

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

Because you can't use string.find on a table.

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

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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

My Projects!

No one.

Posted
for i, v in pairs( theCensored ) do 
    outputChatBox( tostring( i ) .. tostring( v ) ) 
end 

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

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

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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

My Projects!

No one.

Posted

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.

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

Posted

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

My Projects!

No one.

Posted

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 

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

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