• Print

Author Topic: Automatically move someone to a group if they join the steam group?  (Read 15156 times)

0 Members and 1 Guest are viewing this topic.

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Is this possible with Lua? Automatically moving someone to a ULX group if they join my steam group?
Ulx group: member
Steam group: http://steamcommunity.com/groups/sandboxwars
If someone could write me up a quick code that would be great!

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Automatically move someone to a group if they join the steam group?
« Reply #1 on: December 20, 2014, 03:47:14 pm »
I heard about a Steam callback but I still am clueless on if this is possible or not.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Automatically move someone to a group if they join the steam group?
« Reply #2 on: December 20, 2014, 09:14:53 pm »
ULX forum search within Dev corner is your friend.
/index.php/topic,7247.0.html
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Automatically move someone to a group if they join the steam group?
« Reply #3 on: December 20, 2014, 09:37:25 pm »
ULX forum search within Dev corner is your friend.
/index.php/topic,7247.0.html

Wow Great! Sadly I'm still pretty new to Lua, so I have no Idea what function to add so they get ulx group member if they join the steam group.

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Automatically move someone to a group if they join the steam group?
« Reply #4 on: December 20, 2014, 10:53:29 pm »
I thought this would work, replacing the prints with commands, didnt work...
Original:
Code: [Select]
function CommunityCheckStatus( communityID, ply )
        if not IsValid(ply) then return end
        local id = util.SteamIDTo64( ply:SteamID() )
        http.Fetch( "http://steamcommunity.com/groups/sandboxwars" .. communityID .. "/memberslistxml/?xml=1?lolwat="..os.time(),
                function( body, _, _, _ )
                        if string.find( body, id ) then
                                SetPlayerMember( ply )
                        else
                                print( "FALSE" )
                        end
                end,
                function( error )
                        print( "Something went terribly wrong!" )
                        print( error )
                end
        )
end
 
function CommunityCheckStatusID( communityID, sid )
        local id = util.SteamIDTo64( sid )
        http.Fetch( "http://steamcommunity.com/groups/sandboxwars" .. communityID .. "/memberslistxml/?xml=1?lolwat="..os.time(),
                function( body, _, _, _ )
                        if string.find( body, id ) then
                                SetPlayerMemberID( id )
                        else
                                print( "FALSE" )
                        end
                end,
                function( error )
                        print( "Something went terribly wrong!" )
                        print( error )
                end
        )
end
 
function SetPlayerMember( ply )
        if not IsValid(ply) then return end
        print( "THIS PLAYER IS A MEMBER!")
end
 
function SetPlayerMemberID( id )
        print( "THIS PLAYER IS A MEMBER!")
end

Modified:

Code: [Select]
function CommunityCheckStatus( communityID, ply )
if not IsValid(ply) then return end
local id = util.SteamIDTo64( ply:SteamID() )
http.Fetch( "http://steamcommunity.com/groups/sandboxwars" .. communityID .. "/memberslistxml/?xml=1?lolwat="..os.time(),
function( body, _, _, _ )
if string.find( body, id ) then
SetPlayerMember( ply )
else
print( "FALSE" )
end
end,
function( error )
print( "Something went terribly wrong!" )
print( error )
end
)
end
 
function CommunityCheckStatusID( communityID, sid )
local id = util.SteamIDTo64( sid )
http.Fetch( "http://steamcommunity.com/groups/sandboxwars" .. communityID .. "/memberslistxml/?xml=1?lolwat="..os.time(),
function( body, _, _, _ )
if string.find( body, id ) then
SetPlayerMemberID( id )
else
print( "FALSE" )
end
end,
function( error )
print( "Something went terribly wrong!" )
print( error )
end
)
end
 
function SetPlayerMember( ply )
if not IsValid(ply) then return end
    RunConsoleCommand("ulx", "adduser", ply:SteamID(), "member")
end
 
function SetPlayerMemberID( id )
RunConsoleCommand("ulx", "adduser", ply:SteamID(), "member")
end

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Automatically move someone to a group if they join the steam group?
« Reply #5 on: December 21, 2014, 01:46:52 am »
You'd have to add a hook or function/say command to call the check function.
It's not going to run on it's own.

Also, you can't just add "Sandboxwars" to the url in the code (you posted 'original' code but have that in it too)
CommunityID variable would have to be passed or assigned within the function.
« Last Edit: December 21, 2014, 01:50:52 am by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Automatically move someone to a group if they join the steam group?
« Reply #6 on: December 21, 2014, 08:25:07 am »
Ok I tried this, didn't work:

Code: [Select]
hook.Add("PlayerSpawn", "Spawn", function(ply)
function CommunityCheckStatus( sandboxwars, ply )
if not IsValid(ply) then return end
local id = util.SteamIDTo64( ply:SteamID() )
http.Fetch( "http://steamcommunity.com/groups/sandboxwars" .. sandboxwars .. "/memberslistxml/?xml=1?lolwat="..os.time(),
function( body, _, _, _ )
if string.find( body, id ) then
SetPlayerMember( ply )
else
print( "FALSE" )
end
end,
function( error )
print( "Something went terribly wrong!" )
print( error )
end
)
end
 
function CommunityCheckStatusID( sandboxwars, sid )
local id = util.SteamIDTo64( sid )
http.Fetch( "http://steamcommunity.com/groups/sandboxwars" .. sandboxwars .. "/memberslistxml/?xml=1?lolwat="..os.time(),
function( body, _, _, _ )
if string.find( body, id ) then
SetPlayerMemberID( id )
else
print( "FALSE" )
end
end,
function( error )
print( "Something went terribly wrong!" )
print( error )
end
)
end
 
function SetPlayerMember( ply )
if not IsValid(ply) then return end
    RunConsoleCommand("ulx", "adduserid", ply:SteamID(), "member")
end
 
function SetPlayerMemberID( id )
RunConsoleCommand("ulx", "adduserid", ply:SteamID(), "member")
end
end)

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Automatically move someone to a group if they join the steam group?
« Reply #7 on: December 21, 2014, 08:45:44 am »
Found a HUGE MISTAKE in the URL's and corrected it, thought for sure this would work but nope.
Code: [Select]
hook.Add("PlayerSpawn", "Spawn", function(ply)
function CommunityCheckStatus( sandboxwars, ply )
if not IsValid(ply) then return end
local id = util.SteamIDTo64( ply:SteamID() )
http.Fetch("http://steamcommunity.com/groups/sandboxwars/memberslistxml/?xml=1?lolwat="..os.time(),
function( body, _, _, _ )
if string.find( body, id ) then
SetPlayerMember( ply )
else
print( "FALSE" )
end
end,
function( error )
print( "Something went terribly wrong!" )
print( error )
end
)
end
 
function CommunityCheckStatusID( sandboxwars, sid )
local id = util.SteamIDTo64( sid )
http.Fetch("http://steamcommunity.com/groups/sandboxwars/memberslistxml/?xml=1?lolwat="..os.time(),
function( body, _, _, _ )
if string.find( body, id ) then
SetPlayerMemberID( id )
else
print( "FALSE" )
end
end,
function( error )
print( "Something went terribly wrong!" )
print( error )
end
)
end
 
function SetPlayerMember( ply )
if not IsValid(ply) then return end
    RunConsoleCommand("ulx", "adduserid", ply:SteamID(), "member")
end
 
function SetPlayerMemberID( id )
RunConsoleCommand("ulx", "adduserid", ply:SteamID(), "member")
end
end)

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Automatically move someone to a group if they join the steam group?
« Reply #8 on: December 21, 2014, 12:11:24 pm »
Though I usually don't just flat out write code for people...
Code: Lua
  1. if SERVER then
  2.         function CommunityCheckStatus( ply )
  3.                 if not IsValid(ply) then return end
  4.                 local id = util.SteamIDTo64( ply:SteamID() )
  5.                 http.Fetch("http://steamcommunity.com/groups/sandboxwars/memberslistxml/?xml=1&lolwat="..os.time(),
  6.                         function( body, _, _, _ )
  7.                                 if string.find( body, id ) then
  8.                                         SetPlayerMember( ply )
  9.                                 else
  10.                                         print( "FALSE" )
  11.                                 end
  12.                         end,
  13.                         function( error )
  14.                                 print( "Something went terribly wrong!" )
  15.                                 print( error )
  16.                         end
  17.                 )
  18.         end
  19.          
  20.         function SetPlayerMember( ply )
  21.                 if not IsValid(ply) then return end
  22.                 game.ConsoleCommand("ulx adduserid" .. ply:SteamID() .. "member")
  23.         end
  24.  
  25.         hook.Add("PlayerSpawn",
  26.                 "SteamGroupMemberCheck",
  27.                 function(ply)
  28.                         CommunityCheckStatus( ply )
  29.                 end)
  30. end

  • You were defining functions inside a function, and never doing anything with those functions
  • Those query strings were a bit off
  • You had a few extra functions that you wouldn't need if you were using the PlayerSpawn hook
  • Your hook identifier wasn't very unique
« Last Edit: December 21, 2014, 12:16:31 pm by Bytewave »
bw81@ulysses-forums ~ % whoami
Homepage

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Automatically move someone to a group if they join the steam group?
« Reply #9 on: December 21, 2014, 01:20:24 pm »
Additionally, I'd strongly recommend ensuring those your checking aren't in another group but "user" first.
If not, you yourself will lose admin when you join. :)
From Bytewave - line 20-23
Code: [Select]
     function SetPlayerMember( ply )
          if not IsValid(ply) then return end
          game.ConsoleCommand("ulx adduserid" .. ply:SteamID() .. "member")
      end

Recommended check
Code: [Select]
     function SetPlayerMember( ply )
          if not IsValid(ply) then return end
          if ply:GetUserGroup() == "user" then game.ConsoleCommand("ulx adduserid " .. ply:SteamID() .. " member") end
      end

EDIT - ALSO Bytewave's command (and my original edit) needs spaces to run as is.
Now fixed in my suggestion
« Last Edit: December 21, 2014, 01:24:56 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Automatically move someone to a group if they join the steam group?
« Reply #10 on: December 21, 2014, 01:34:02 pm »
Thank you all! Once my servers done with maintenance i'll be sure to test this.

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Automatically move someone to a group if they join the steam group?
« Reply #11 on: December 21, 2014, 04:15:22 pm »
EDIT - ALSO Bytewave's command (and my original edit) needs spaces to run as is.
Now fixed in my suggestion
Whoops! This is why I don't write code when I've just woken up.
bw81@ulysses-forums ~ % whoami
Homepage

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Automatically move someone to a group if they join the steam group?
« Reply #12 on: December 21, 2014, 04:37:43 pm »
No worries Bytewave.
I'm so used to having my nose in the top level Ulib/ULX code base that I had to ask a fellow team member if default group was "user" or "users" for that GetUserGroup command. :)
(it IS user, btw)
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Jaden Zepeda

  • Newbie
  • *
  • Posts: 28
  • Karma: 0
Re: Automatically move someone to a group if they join the steam group?
« Reply #13 on: December 21, 2014, 04:45:55 pm »
Well it triggered the command thats for sure, but heres what my console is saying when a player joins the group and respawns

Error, bad server command ulx adduserid STEAM_0:0:86623958 member
« Last Edit: December 21, 2014, 05:28:08 pm by Jaden Zepeda »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Automatically move someone to a group if they join the steam group?
« Reply #14 on: December 21, 2014, 05:31:42 pm »
Can you run the command without the script?
That doesn't seem like a normal Gmod or ulx console error.

Might be choking on the colon in the actual code?

Whatever the reason, you might try;
Code: [Select]
if ply:GetUserGroup() == "user" then game.ConsoleCommand("ulx adduserid \"" .. ply:SteamID() .. "\" member") end(Look closely, I added double quotes, so command would be like ulx adduser "steam:0:0:####" member, hopefully server will like it better.
If that doesn't work, we go back to trying ply:Nick() and adduser
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print