I wasn't quiet sure where to put this, but this a little code that I made and its useful to me, so it may be useful to everyone else, feel free to include it in the wiremodsvn. I don't know how to.
Quote:
Syntax:
Console Command
- findUniqueID [full name] - Echo's back the UniqueID of a player based on full name, which is not case sensitive.
E2 Commands
- e:uniqueid() - Returns the UniqueID of a player entity as a string, returns nothing if not player.
- getplayer(s) - Returns player entity using UniqueID, returns nothing if no player can be found by that uniqueid
|
Quote:
Reasoning/Usages:
Why UniqueID instead of SteamID?
- Lua does not have a way to create an entity variable from a SteamID.
Why use this when I could use a target finder specific to SteamID?
- With this, you could program a method of changing which players it'll target without needing to update an entity, or allow someone else to change or add a target who can't because of prop protection.
Why did you even make it?
- Actually a few people have requested something like this and they're always told to use target finders, here's an alternative. |
Lua Code. I would add this to console.lua since its already included in init.lua, and its basically empty.
Code:
function finduniqueid( players, command, args )
if (args) then
local lowerargs = string.lower(table.concat(args," "))
for spaceholder, theplayer in pairs(player.GetAll()) do
local Nick = string.lower(theplayer:Nick())
if (Nick == lowerargs) then
players:PrintMessage( HUD_PRINTTALK, theplayer:Nick() .. "'s UniqueID is " .. theplayer:UniqueID() )
return ""
end
end
end
players:PrintMessage( HUD_PRINTTALK, "findUniqueID USAGE:" )
players:PrintMessage( HUD_PRINTTALK, " findUniqueID [full name] - Fetches UniqueID based on full name, which is not case sensitive." )
end
concommand.Add( "finduniqueid", finduniqueid )
registerFunction("uniqueid", "e:", "s", function(self, args)
local op1 = args[2]
local rv1 = op1[1](self, op1)
local entity = checkEntity(rv1)
if(!entity) then return "" end
if(!rv1:IsPlayer()) then return "" end
return rv1:UniqueID()
end)
registerFunction("getplayer", "s", "e", function(self, args)
local op1 = args[2]
local rv1 = op1[1](self, op1)
local getplayer = player.GetByUniqueID(rv1)
if getplayer then return getplayer end
end)