• SteamID64 of my Data (player connect)... Need conversion ?
    9 replies, posted
Hey ! I have a problem in my code, i want to return the game time on gmod of the player connected, i made this : [CODE] if SERVER then gameevent.Listen( "player_connect" ) hook.Add( "player_connect", "AnnounceConnection", function( data ) for k,v in pairs( player.GetAll() ) do SteamID = data:SteamID64() http.Fetch( "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key="..Key.."&format=json&input_json={%22appids_filter%22:[4000],%22steamid%22:"..SteamID.."}", function( body, len, headers, code ) TableJson = util.JSONToTable(body) ForeverTime = TableJson.response.games[1].playtime_forever RunConsoleCommand("say",ForeverTime/60) end ) break end end ) [/CODE] It's broken because DATA:STEAMID64 doesnt work, because the steamID64 need a player entity, not a data. And my http.Fetch, need a STEAMID in 64 bit... How i can convert the steamID of my data in 64 bits ? Thx
That's not how it works. [i]data[/i] is a table containing informations about the player and not a player object (as he didn't connect yet), therefore it should be data.steamid and not data:SteamID64(). But it's not a 64bit steamid, so you should use [URL="http://wiki.garrysmod.com/page/GM/CheckPassword"]CheckPassword[/URL] instead.
Well you could just do this... [CODE] if SERVER then gameevent.Listen( "player_connect" ) hook.Add( "player_connect", "AnnounceConnection", function( data ) local SteamID = util.SteamIDTo64( data.networkid ) http.Fetch( "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key="..Key.."&format=json&input_json={%22appids_filter%22:[4000],%22steamid%22:"..SteamID.."}", function( body, len, headers, code ) ForeverTime = util.JSONToTable(body).response.games[1].playtime_forever RunConsoleCommand("say",ForeverTime/60 ) end ) end ) end [/CODE] But I wouldn't really recommend it. The event fires when a player clicks "connect" in the server browser. If they start downloading and then leave, it could print your player connected text many times for players that never end up actually joining your server. I would recommend this instead: [CODE] if SERVER then hook.Add( "PlayerInitialSpawn", "AnnounceConnection", function( ply ) local SteamID = ply:SteamID64() http.Fetch( "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key="..Key.."&format=json&input_json={%22appids_filter%22:[4000],%22steamid%22:"..SteamID.."}", function( body, len, headers, code ) ForeverTime = util.JSONToTable(body).response.games[1].playtime_forever RunConsoleCommand("say",ForeverTime/60 ) end ) end end ) [/CODE]
Ok Thx CallMePyro, I use your first version, its for restriction on my server ;) ! I have an another question : I can return if my data (player) are admin or not ?
Depends. If you're using ULX, then yes. Simply do this: [CODE] if SERVER then local admins = { ["admin"] = true, ["superadmin"] = true, ["owner"] = true, } gameevent.Listen( "player_connect" ) hook.Add( "player_connect", "AnnounceConnection", function( data ) local sid64 = util.SteamIDTo64( data.networkid ) http.Fetch( "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key="..Key.."&format=json&input_json={%22appids_filter%22:[4000],%22steamid%22:"..sid64.."}", function( body, len, headers, code ) local ForeverTime = util.JSONToTable(body).response.games[1].playtime_forever RunConsoleCommand("say",ForeverTime/60 ) end ) if admins[ULib.ucl.users[data.networkid].group] then print( "THIS GUY IS AN ADMIN" ) end end ) end [/CODE] To add groups that are recognized as an admin, simply add entries to the 'admins' table in the format that I showed you. ["groupname"] = true, don't forget the brackets, quotes, or ending comma.
The Guy is a lua king. Really thx dude !
I have one problem with your line : if(AllowedGroup[ULib.ucl.users[data.networkid].group]) then If the player havent group (user) it return NIL :/
I suggest you use the CheckPassword hook instead, it's called earlier (Assumption) and allows you to return false and kick him with a reason. [lua] if SERVER then local admins = { admin = true, superadmin = true, owner = true } hook.Add("CheckPassword", "AnnounceConnection", function(id) http.Fetch( "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key="..Key.."&format=json&input_json={%22appids_filter%22:[4000],%22steamid%22:"..id.."}", function( body, len, headers, code ) local ForeverTime = util.JSONToTable(body).response.games[1].playtime_forever RunConsoleCommand("say",ForeverTime/60 ) end) if admins[ULib.ucl.users[id].group] then return true end if true then return false, "Here's the reason!" end end) end[/lua] With the [lua]if true then[/lua] replace that with your condition to kick them from the server.
[QUOTE=Jarva;45581173]I suggest you use the CheckPassword hook instead, it's called earlier (Assumption) and allows you to return false and kick him with a reason. [lua] if SERVER then local admins = { admin = true, superadmin = true, owner = true } hook.Add("CheckPassword", "AnnounceConnection", function(id) http.Fetch( "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key="..Key.."&format=json&input_json={%22appids_filter%22:[4000],%22steamid%22:"..id.."}", function( body, len, headers, code ) local ForeverTime = util.JSONToTable(body).response.games[1].playtime_forever RunConsoleCommand("say",ForeverTime/60 ) end) if admins[ULib.ucl.users[id].group] then return true end if true then return false, "Here's the reason!" end end) end[/lua] With the [lua]if true then[/lua] replace that with your condition to kick them from the server.[/QUOTE] Sure but the guy specifically asked for player_connect gameevent, so that's what I used. edit: Here's the fix for a null user. [CODE]if SERVER then local admins = { ["admin"] = true, ["superadmin"] = true, ["owner"] = true, } gameevent.Listen( "player_connect" ) hook.Add( "player_connect", "AnnounceConnection", function( data ) local sid64 = util.SteamIDTo64( data.networkid ) http.Fetch( "http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key="..Key.."&format=json&input_json={%22appids_filter%22:[4000],%22steamid%22:"..sid64.."}", function( body, len, headers, code ) local ForeverTime = util.JSONToTable(body).response.games[1].playtime_forever RunConsoleCommand("say",ForeverTime/60 ) end ) local info = ULib.ucl.users[data.networkid] if info and admins[info.group] then print( "THIS GUY IS AN ADMIN" ) end end ) end [/CODE]
I wasn't criticizing, I was just saying it's more effective.
Sorry, you need to Log In to post a reply to this thread.