Jump to content

Kind of cool messages


S3Nn4oXx

Recommended Posts

Posted

Hello guys i really interesting in Lua and it's really cool :)

so look what i made here, ik that i can't do getLocalPlayer i think, so how i am supposed to do that ?

server.lua

  
function Lol() 
    local localPlayerName = getPlayerName(getLocalPlayer()) 
    outputChatBox ( "#164F8C[TEXT]..localPlayerName..#FFFFFFis Laughing out loud!", getRootElement(), 255, 255, 255, true ) 
end 
addCommandHandler("lol", Lol) 
  

Btw I want to learn how to do that when i type /lol [otherplayername]

so it shows in mainchat, [TEXT]PlayerName thinks [otherplayername] is Laughing out Loud

and when i type just /lol so it shows [MyName] Is laughing out loud and when i type /lol [otherplayername] it shows [MyName] thinks [otherplayername] is Laughing out loud

Thanks for your attention!

Posted
  
function Lol(thePlayer) 
    local localPlayerName = getPlayerName(thePlayer) 
    outputChatBox ( "#164F8C[TEXT]"..localPlayerName.."#FFFFFFis Laughing out loud!", getRootElement(), 255, 255, 255 ) 
end 
addCommandHandler("lol", Lol) 
  

Posted

getLocalPlayer can be used only in the client side (and you're trying to use this in the server side), When you add a command with addCommandHandler the function which you pass as parameter in the third argument automatically gain 2 new parameters

playerSource, string commandName 

playerSource will be the player who triggered the command (then you can use this instead of getLocalPlayer), commandName will be the command name (eh, obviously )

Your final code will be like this one:

function Lol( playerSource, commandName ) 
    local localPlayerName = getPlayerName( playerSource ) 
    outputChatBox ( "#164F8C[TEXT]"..localPlayerName.."#FFFFFFis Laughing out loud!", getRootElement(), 255, 255, 255, true ) 
end 
addCommandHandler("lol", Lol) 

about using parameters in the commands you can read about it in the wiki (scroll down a bit until find "Handler function parameters"), Read the examples also.

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