• Print

Author Topic: Help with ULX Command  (Read 5316 times)

0 Members and 1 Guest are viewing this topic.

Offline LegendProtocol

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
Help with ULX Command
« on: January 28, 2015, 03:56:08 pm »
We currently have a command on our servers that allows us to place certain players on a watchlist. I was wondering how I would go about creating a watchid command, and what'd I have to change in the already existing print watchlist command. Below are the current watch, unwatch and watchlist commands as well as any related functions. I've tried making one myself based off the existing banid example but I haven't reached any success.

Code: [Select]
function ulx.watch(calling_ply, target_ply, reason)
target_ply:SetPData("Watched","true")
target_ply:SetPData("WatchReason",reason)
ulx.fancyLogAdmin( calling_ply, true, "#A marked #T as watched: "..reason.. "" , target_ply )
end
local watch = ulx.command("Essentials", "ulx watch", ulx.watch, "!watch",true)
watch:addParam{ type=ULib.cmds.PlayerArg }
watch:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.takeRestOfLine }
watch:defaultAccess( ULib.ACCESS_ADMIN )
watch:help( "Puts a player on watch list." )

function ulx.unwatch(calling_ply, target_ply)
target_ply:SetPData("Watched","false")
target_ply:RemovePData("WatchReason")
ulx.fancyLogAdmin( calling_ply, true, "#A removed #T from watch list", target_ply )
end
local unwatch = ulx.command("Essentials", "ulx unwatch", ulx.unwatch, "!unwatch",true)
unwatch:addParam{ type=ULib.cmds.PlayerArg }
unwatch:defaultAccess( ULib.ACCESS_ADMIN )
unwatch:help( "Removes a player from watch list." )

function userAuthed( ply, stid, unid )
if ply:GetPData("Watched") == "true" then
ulx.fancyLogAdmin(nil, true, "#T ("..stid.. ") is on the watchlist: "..ply:GetPData("WatchReason").. "",ply)
end
end
hook.Add( "PlayerAuthed", "watchlisthook", userAuthed )

function ulx.watchlist(calling_ply)
watchlist = {}
for k, v in pairs(player.GetAll()) do
if v:GetPData("Watched") == "true" then
table.insert( watchlist, v:Nick() or v:displayid())
table.insert(watchlist, v:GetPData("WatchReason"))
end
end
local watchstring = table.concat(  watchlist, ", " )
ulx.fancyLogAdmin( nil, true,  "Watchlist: #s ",watchstring )
end
local watchlist = ulx.command("Essentials", "ulx watchlist", ulx.watchlist, "!watchlist",true)
watchlist:defaultAccess( ULib.ACCESS_ADMIN )
watchlist:help( "Prints watch list." )
« Last Edit: January 28, 2015, 06:13:46 pm by LegendProtocol »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Help with ULX Command
« Reply #1 on: January 28, 2015, 04:03:46 pm »
Since you don't have the player object to us, you'll need to use util.SetPData and GetPData. This means you can only accept SteamID (rather than IP or UniqueID).
Experiencing God's grace one day at a time.

Offline LegendProtocol

  • Newbie
  • *
  • Posts: 4
  • Karma: 1
Re: Help with ULX Command
« Reply #2 on: January 28, 2015, 04:28:23 pm »
Since you don't have the player object to us, you'll need to use util.SetPData and GetPData. This means you can only accept SteamID (rather than IP or UniqueID).

Okay so this is what I have so far,

Code: [Select]
function ulx.watchid(calling_ply, target, reason)
if ULib.isValidSteamID(target) then
for k,v in pairs(player.GetAll()) do
if v:SteamID() == target then
ulx.watchid(calling_ply, v, reason)
return
end
end
target_ply:util.SetPData("Watched","true")
target_ply:util.SetPData("WatchReason",reason)
else
ULib.tsayError(calling_ply, "Invalid steamid.", true)
end
ulx.fancyLogAdmin( calling_ply, true, "#A marked #T as watched: "..reason.. "" , target )
end
local watchid = ulx.command("Essentials", "ulx watchid", ulx.watchid, "!watchid",true)
watchid:addParam{ type=ULib.cmds.StringArg, hint="steamid" }
watchid:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.takeRestOfLine }
watchid:defaultAccess( ULib.ACCESS_ADMIN )
watchid:help( "Puts a player on watch list via SteamID." )

Not sure where I would put getPData, I don't have much experience (I'm a complete newbie). :P
I know I'm doing something horribly wrong.
« Last Edit: January 28, 2015, 06:08:00 pm by LegendProtocol »

Offline lamb201

  • Newbie
  • *
  • Posts: 15
  • Karma: -1
Re: Help with ULX Command
« Reply #3 on: January 31, 2015, 07:12:46 pm »
Hello.

util.SetPData & util.GetPData require a SteamID argument. (See: http://wiki.garrysmod.com/page/util/SetPData) So it would be like this:
Code: Lua
  1. util.SetPData( steamID, name, value )

Also, i'm not quite sure what this is for?
Code: Lua
  1. for k,v in pairs(player.GetAll()) do
  2.                                 if v:SteamID() == target then
  3.                                         ulx.watchid(calling_ply, v, reason)
  4.                                         return
  5.                                 end
  6.                         end

This is what I came up with, it is 3:10 am so I haven't tested it. Just trying to help :)
Code: Lua
  1. function ulx.watchid( calling_ply, steamID, reason )
  2.  
  3.         if not ULib.isValidSteamID( steamID ) then
  4.                 ULib.tsayError( calling_ply, "Invalid SteamID." )
  5.                 return
  6.         end
  7.  
  8.         isWatched = util.GetPData( steamID, "Watched" ) or "false"
  9.         if isWatched == "true" then
  10.                 ULib.tsayError( calling_ply, "Player already being watched." )
  11.                 return
  12.         end
  13.  
  14.         local playerEntity = false
  15.  
  16.         for _, v in pairs( player.GetAll() ) do
  17.  
  18.                 if v:SteamID() == steamID then
  19.                         playerEntity = v
  20.                 end
  21.  
  22.         end
  23.  
  24.         local name = steamID
  25.  
  26.         if playerEntity ~= false then
  27.                 name = name .. " (" .. playerEntity:GetName() .. ")"
  28.         end
  29.  
  30.         util.SetPData( steamID, "Watched", "true" )
  31.         util.SetPData( steamID, "WatchReason", reason )
  32.  
  33.         ulx.fancyLogAdmin( calling_ply, true, "#A marked #T as watched (#s)", name, reason )
  34.  
  35. end
  36. local watchid = ulx.command("Essentials", "ulx watchid", ulx.watchid, "!watchid", true)
  37. watchid:addParam{ type=ULib.cmds.StringArg, hint="steamid" }
  38. watchid:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.takeRestOfLine }
  39. watchid:defaultAccess( ULib.ACCESS_ADMIN )
  40. watchid:help( "Puts a player on watch list via SteamID." )

  • Print