ULX

Author Topic: I am ready to get yelled at... (Making ULib parse player names in Lua.)  (Read 2003 times)

0 Members and 1 Guest are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
The idea is to make is so that you can target players by just typing their name in your code thus making thins like "ulx luarun" a bit more interesting to use.

The metamethod is tried only when key is not present in table. Meaning that the code below will only effect values that are not there meaning that if you have some thing like... Entity(3):Slay() then it won't try to parse "Entity(3)" as a player name even if there is a player under that name. (Correct me if I am wrong.)



Code: [Select]
_G.__index = function(t, k)
     local tr = ULib.getUser(tostring(k),true,nil)
     if tr then
          return tr
     else
          return nil
     end
end
setmetatable(_G, _G)

or if you like you're code in one line...

Code: [Select]
_G.__index = function(t, k) local tr = ULib.getUser(tostring(k),true,nil) if tr then return tr else return nil end end setmetatable(_G, _G)


I have also made "ulx exlua" which pretty much does the same thing without messing with meta tables, and also returns errors cleanly.
« Last Edit: January 25, 2014, 09:10:35 PM by LuaTenshi »
I cry every time I see that I am not a respected member of this community.