Chaos Posted August 26, 2013 Share Posted August 26, 2013 hi, how can i add this function setClipboard ? function showaccountname (player, cmd, target) local target = getPlayerFromNamePart(target) local accName = getAccountName ( getPlayerAccount ( target ) ) outputChatBox ("Name: "..getPlayerName(target).. " , Account Name: "..accName,player,255, 255, 0 ) end addCommandHandler ( "ac", showaccountname ) 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
TAPL Posted August 26, 2013 Share Posted August 26, 2013 setClipboard is client side only and for that you'll need to trigger from server side to client side. triggerClientEvent Link to comment
Chaos Posted August 27, 2013 Author Share Posted August 27, 2013 is that correct? Server side: function showaccountname (player, cmd, target) local target = getPlayerFromNamePart(target) local accName = getAccountName ( getPlayerAccount ( target ) ) outputChatBox ("Name: "..getPlayerName(target).. " , Account Name: "..accName,player,255, 255, 0 ) triggerClientEvent(player, "copytoclipboard", player) end addCommandHandler ( "ac", showaccountname ) Client side: addEvent("copytoclipboard", true) addEventHandler("copytoclipboard", root, function () setClipboard (accName) end) Link to comment
TAPL Posted August 27, 2013 Share Posted August 27, 2013 Line 5 at server side replace this: triggerClientEvent(player, "copytoclipboard", player) With: triggerClientEvent(player, "copytoclipboard", player, accName) And line 3 at client side replace this: function () With: function (accName) Link to comment
Chaos Posted August 27, 2013 Author Share Posted August 27, 2013 [2013-08-27 07:16:40] WARNING: account\s.lua:4: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got boolean] [2013-08-27 07:16:40] WARNING: account\s.lua:4: Bad argument @ 'getAccountName' [Expected account at argument 1, got boolean] [2013-08-27 07:16:40] WARNING: account\s.lua:5: Bad argument @ 'triggerClientEvent' [Expected string at argument 1, got nil] [2013-08-27 07:16:40] WARNING: account\s.lua:4: Bad argument @ 'getPlayerAccount' [Expected element at argument 1, got boolean] [2013-08-27 07:16:40] WARNING: account\s.lua:4: Bad argument @ 'getAccountName' [Expected account at argument 1, got boolean] [2013-08-27 07:16:40] WARNING: account\s.lua:5: Bad argument @ 'triggerClientEvent' [Expected string at argument 1, got nil] Server side: function showaccountname (player, cmd, target) local target = getPlayerFromNamePart(target) local accName = getAccountName ( getPlayerAccount ( target ) ) outputChatBox ("Name: "..getPlayerName(target).. " , Account Name: "..accName,player,255, 255, 0 ) triggerClientEvent(player, "copytoclipboard", player, accName) end addCommandHandler ( "ac", showaccountname ) 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 Client side: addEvent("copytoclipboard", true) addEventHandler("copytoclipboard", root, function (accName) setClipboard (accName) end) Link to comment
EstrategiaGTA Posted August 27, 2013 Share Posted August 27, 2013 Line 3: getPlayerFromNamePart(target) Where is target defined? Link to comment
Chaos Posted August 27, 2013 Author Share Posted August 27, 2013 what should i do now ? Link to comment
TAPL Posted August 27, 2013 Share Posted August 27, 2013 These errors appears when you use invalid target name, to avoid it you have to use if statement to check if the target aren't false or nil. Link to comment
Chaos Posted August 27, 2013 Author Share Posted August 27, 2013 i just added full name /ac Chaos and it's not worked Link to comment
TAPL Posted August 27, 2013 Share Posted August 27, 2013 I guess that's because your name has hex color. Link to comment
Chaos Posted August 27, 2013 Author Share Posted August 27, 2013 no my name Chaos with out hex color Link to comment
TAPL Posted August 27, 2013 Share Posted August 27, 2013 I tested it and it worked. http://i.imgur.com/OorQyDp.jpg Link to comment
Chaos Posted August 27, 2013 Author Share Posted August 27, 2013 ah i just restarted my server and it's worked thanks TAPL 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