Jump to content

Laughing command


downight

Recommended Posts

Posted (edited)

I made this:

function saytext(player, command) 
     outputChatBox ( "[ "..getPlayerName(player).." ] is laughing out loud!", root, 255, 0, 0, true) 
end 
addCommandHandler ( "lol", saytext ) 

but I also want to have laughing out loud at [here is typed player name]. I heard it is possible with this:

function getPlayerFromNamePart(name) 
    if name then 
        for i, player in ipairs(getElementsByType("player")) do 
            if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                return player 
            end 
        end 
    end 
    return false 
end 

I want to make it like that: someone types /lol - the message on server says [playername] is laughing out loud!

and also I want /lol [playernamepart] and it says [playername] is laughing out loud at [playernamepart] for example:

my nick is downight and the other person nick is intmain. I want to type just /lol int so it will automatically recognize his nick.

but I don't know how to do this + make it one script out of two. Please help :)

Edited by Guest
  • Moderators
Posted
function saytext(thePlayer, command,argument) 
local player = getPlayerFromNamePart(argument) 
if player then 
         outputChatBox ( "[ "..getPlayerName(player).." ] is laughing out loud!", root, 255, 0, 0, true) 
end 
end 
addCommandHandler ( "lol", saytext ) 

/lol IIYAMA

  • Moderators
Posted

You didn't forget to add:

    function getPlayerFromNamePart(name) 
        if name then 
            for i, player in ipairs(getElementsByType("player")) do 
                if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                    return player 
                end 
            end 
        end 
        return false 
    end 

Posted
You didn't forget to add:
    function getPlayerFromNamePart(name) 
        if name then 
            for i, player in ipairs(getElementsByType("player")) do 
                if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                    return player 
                end 
            end 
        end 
        return false 
    end 

But I want to make it like that

Two people: downight and intmain

I type /lol int and it recognizes his nick and server says: downight is laughing out loud at intmain.

You know what I'm talking about?

  • Moderators
Posted

Maybe,

- The message contains the name of the one that wrote the command or the name of the target?

- Message must be send to everybody?

    function saytext(thePlayer, command,argument) 
    local player = getPlayerFromNamePart(argument) 
        if player then 
            outputChatBox ( "[ " .. getPlayerName(thePlayer).. " ]  is laughing out loud at " .. getPlayerName(player) .. "!", root, 255, 0, 0, true) 
        end 
    end 
    addCommandHandler ( "lol", saytext ) 

Posted

Yes man. This is what I wanted! Now I just want to combine these two. /lol - Player is laughing out loud! and /lol [nick] - Player is laughing out loud at [nick]. The /lol [nick] is done but I need /lol alone to be working too somehow.

  • Moderators
Posted
function saytext(thePlayer, command,argument) 
        if argument then 
            local player = getPlayerFromNamePart(argument) 
            if player then 
                outputChatBox ( "[ " .. getPlayerName(thePlayer).. " ]  is laughing out loud at " .. getPlayerName(player) .. "!", root, 255, 0, 0, true) 
            end 
        else 
            outputChatBox ("Player is laughing out loud!") 
        end 
    end 
    addCommandHandler ( "lol", saytext ) 

Posted

THANK YOU MAN! I just changed a code little bit:

function getPlayerFromNamePart(name) 
        if name then 
            for i, player in ipairs(getElementsByType("player")) do 
                if string.find(getPlayerName(player):lower(), tostring(name):lower(), 1, true) then 
                    return player 
                end 
            end 
        end 
        return false 
    end 
  
function saytext(thePlayer, command,argument) 
        if argument then 
            local player = getPlayerFromNamePart(argument) 
            if player then 
                outputChatBox ( "*" .. getPlayerName(thePlayer).. " is laughing out loud at " .. getPlayerName(player) .. "!", root, 255, 0, 0, true) 
            end 
        else 
            outputChatBox ("*" .. getPlayerName(thePlayer).. " is laughing out loud!", root, 255, 0, 0, true) 
        end 
    end 
    addCommandHandler ( "lol", saytext ) 

:mrgreen:

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