Author Topic: Help with ULX Command  (Read 2360 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 »

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given