Ulysses

General => Developers Corner => Topic started by: Snell on March 13, 2014, 11:49:52 PM

Title: ULX - SteamID to clipboard
Post by: Snell on March 13, 2014, 11:49:52 PM
This is my code
http://pastebin.com/1BviDHau (http://pastebin.com/1BviDHau)
or
Code: [Select]
function ulx.floop ( calling_ply, target_ply )

calling_ply:SetClipboardText ( target_ply:SteamID()  )
ulx.fancyLogAdmin( calling_ply, true, "#A copied the SteamID of #T", target_ply )

end
local floop = ulx.command ( CATEGORY_NAME, "ulx id", ulx.floop, "!id" )
floop:addParam{ type=ULib.cmds.PlayersArg }
floop:defaultAccess ( ULib.ACCESS_ALL )
floop:help ( "Copies target's SteamID" )

I have tried a lot, with no success. The recurring error re guards the method "SteamID" being a Nil Value.
Title: Re: ULX - SteamID to clipboard
Post by: Decicus on March 14, 2014, 09:12:55 AM
I believe I had a similar issue, just with a different code: http://forums.ulyssesmod.net/index.php/topic,6722.msg32743.html#msg32743 (http://forums.ulyssesmod.net/index.php/topic,6722.msg32743.html#msg32743)

Try changing "PlayersArg" to "PlayerArg" on line 8 (according to the Pastebin).

Edit: I forgot to CTRL+V the post I was referring to...
Title: Re: ULX - SteamID to clipboard
Post by: JamminR on March 14, 2014, 01:55:19 PM
ULib.cmds.PlayersArg (http://ulyssesmod.net/docs/files/lua/ulib/shared/commands-lua.html#cmds.PlayersArg) returns a table of player objects, even if the table only has one object.
You'd have to cycle through it using for loop.
ULib.cmds.PlayerArg (http://ulyssesmod.net/docs/files/lua/ulib/shared/commands-lua.html#cmds.PlayerArg) will only be one player object.
Title: Re: ULX - SteamID to clipboard
Post by: Snell on March 14, 2014, 05:55:56 PM
This is what happened when I tested the Altered Code, I really have no idea what happened
http://i.imgur.com/04TsWMN.jpg (http://i.imgur.com/04TsWMN.jpg)
Title: Re: ULX - SteamID to clipboard
Post by: Cobalt on March 14, 2014, 07:56:14 PM
SetClipboardText is a clientside function.
Title: Re: ULX - SteamID to clipboard
Post by: MrPresident on March 14, 2014, 09:37:05 PM
So try..

calling_ply:SendLua("LocalPlayer():SetClipboardText( target_ply:SteamID() )")
Title: Re: ULX - SteamID to clipboard
Post by: Cobalt on March 15, 2014, 09:14:04 AM
So try..

calling_ply:SendLua("LocalPlayer():SetClipboardText( target_ply:SteamID() )")
You don't need LocalPlayer() for that.
Title: Re: ULX - SteamID to clipboard
Post by: MrPresident on March 15, 2014, 10:16:21 AM
Ahh, yeah. Indeed you don't. I just took his 'server side' code and made it 'client side' verbatim.

You would need this:

Code: [Select]
calling_ply:SendLua("SetClipboardText( target_ply:SteamID() )")
Title: Re: ULX - SteamID to clipboard
Post by: Snell on March 15, 2014, 10:51:41 PM
Firstly, Thank you MrPresident for the SendLua (I tested it and worked with a basic string)

This is my current code, and apparently the Universe Explodes if these 2 functions a put together. (I tested the 2 seperately)
http://pastebin.com/hdcCe4C0 (http://pastebin.com/hdcCe4C0)

Code: [Select]
-- Copies Target's SteamID to Clipboard
function ulx.steam_id ( calling_ply, target_ply )

local steamid = tostring ( target_ply:SteamID() )

calling_ply:SendLua( " SetClipboardText ( " .. steamid .. " ) " )

-- calling_ply:SendLua( " SetClipboardText ( 'taco' ) " ) -- Sets Clipboard to Taco, works and tested

-- Prints targets SteamID to console (works and tested)
Msg ( steamid )
ulx.fancyLogAdmin ( calling_ply, true, "#A's clipboard consist of #T's SteamID", target_ply )

end

local steam_id = ulx.command ( CATEGORY_NAME, "ulx id", ulx.steam_id, "!id" )
steam_id:addParam { type = ULib.cmds.PlayerArg }
steam_id:defaultAccess ( ULib.ACCESS_ALL )
steam_id:help ( "Copies the Target's SteamID to Clipboard." )

Console and Server Error
Code: [Select]
[ERROR] LuaCmd:1: '<name>' expected near '0'
  1. unknown - LuaCmd:0

I fixed (with a friend) this to my knowledge and it works, so thank you for you help.