General > Developers Corner

Help with ULX Command

(1/1)

LegendProtocol:
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: ---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." )

--- End code ---

Megiddo:
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).

LegendProtocol:

--- Quote from: Megiddo 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).

--- End quote ---

Okay so this is what I have so far,


--- Code: ---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." )

--- End code ---

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.

An Error Has Occurred!

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

[0] Board index

Go to full version