Author Topic: Grab SteamID  (Read 2307 times)

0 Members and 1 Guest are viewing this topic.

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Grab SteamID
« on: July 15, 2014, 09:17:20 PM »
I want to add a command to copy a player's SteamID to your clipboard by typing "!steamid PlayerName"

This is what I have so far (Not much :P)

Code: [Select]
function ulx.steamid( calling_ply )

end

local steamid = ulx.steamid( CATEGORY_NAME, "ulx steamid", ulx.steamid, "!steamid", true )
steamid:addParam{ type=ULib.cmds.PlayerArg }
steamid:defaultAccess( ULib.ACCESS_ALL )
steamid:help( "Copies a player's SteamID to your clipboard" )

I tried to figure this out on my own, and this is what I ended up with :P

Code: [Select]
function ulx.steamid( target_ply )
if (string.sub(text, 1, 7) == "/steamid") then
SetClipboardText( v:SteamID() )
end

local steamid = ulx.steamid( CATEGORY_NAME, "ulx steamid", ulx.steamid, "!steamid", true )
steamid:addParam{ type=ULib.cmds.PlayerArg }
steamid:defaultAccess( ULib.ACCESS_ALL )
steamid:help( "Copies a player's SteamID to your clipboard" )

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Grab SteamID
« Reply #1 on: July 15, 2014, 10:31:02 PM »
Did you get errors when you tried using that code?
I'm not even sure it would load at startup.

Some hints - (I don't like giving people out-right answers at first...doesn't always teach people to debug own code)

1) Your "if" statement has no "end"ing (you only have one "end" and it "end"s the function)
2) You don't need an if statement for the idea you're trying to use.
3) Your variable "v" doesn't exist. I understand you're trying to perform a command on a player object, but, you never tell lua what v is.
4) As written, your "target" is always going to end up being your "calling player". ULX command structure always passes the caller first, then other variables after...you used PlayerArg, so the second variable passed to your function is going to be your "target"; but you've set up your function to accept one variable, and it will be the caller (even if you name it target)
5) You don't necessarily NEED to use v, or tell what v is. You could just use the "target_ply" already passed into the function (ie, target_ply:SetClipboardText)
6) You'll need to research how to make sure this only runs on the client side or it won't work (though, running on server side shouldn't hurt, it just won't work)

Hopefully, enough hints to keep you going.
« Last Edit: July 15, 2014, 10:36:25 PM by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Zmaster

  • Full Member
  • ***
  • Posts: 235
  • Karma: 25
Re: Grab SteamID
« Reply #2 on: July 16, 2014, 04:36:01 PM »
Thanks for the help, JamminR
I was able to figure it out :)

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Grab SteamID
« Reply #3 on: July 16, 2014, 10:46:41 PM »
Glad you figured it out.
Here's closer to what it should look like, for anyone else that might be interested.
Code: [Select]
if not SERVER then
function ulx.steamid( calling_ply, target_ply )
SetClipboardText( target_ply:SteamID() )
end

local steamid = ulx.steamid( "Zmaster Custom", "ulx steamid", ulx.steamid, "!steamid", true )
steamid:addParam{ type=ULib.cmds.PlayerArg }
steamid:defaultAccess( ULib.ACCESS_ALL )
steamid:help( "Copies a player's SteamID to your clipboard" )
end
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming