downight Posted January 24, 2014 Share Posted January 24, 2014 (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 January 24, 2014 by Guest Link to comment
Moderators IIYAMA Posted January 24, 2014 Moderators Share Posted January 24, 2014 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 Link to comment
downight Posted January 24, 2014 Author Share Posted January 24, 2014 This doesn't even work And I wanted laughing out loud at [someone] Link to comment
Moderators IIYAMA Posted January 24, 2014 Moderators Share Posted January 24, 2014 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 Link to comment
downight Posted January 24, 2014 Author Share Posted January 24, 2014 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? Link to comment
Moderators IIYAMA Posted January 24, 2014 Moderators Share Posted January 24, 2014 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 ) Link to comment
downight Posted January 24, 2014 Author Share Posted January 24, 2014 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. Link to comment
Moderators IIYAMA Posted January 24, 2014 Moderators Share Posted January 24, 2014 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 ) Link to comment
downight Posted January 24, 2014 Author Share Posted January 24, 2014 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 ) 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