53 lines
1.2 KiB
Lua
53 lines
1.2 KiB
Lua
|
require("effil")
|
||
|
|
||
|
GM.MT = {}
|
||
|
local m = GM.MT
|
||
|
|
||
|
local charset = {}
|
||
|
|
||
|
for i = 48, 57 do table.insert(charset, string.char(i)) end
|
||
|
for i = 65, 90 do table.insert(charset, string.char(i)) end
|
||
|
for i = 97, 122 do table.insert(charset, string.char(i)) end
|
||
|
|
||
|
function randStr(length)
|
||
|
math.randomseed(os.time())
|
||
|
|
||
|
if length > 0 then
|
||
|
return randomStr(length - 1) .. charset[math.random(1, #charset)]
|
||
|
else
|
||
|
return ""
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function m:WaitForAll(threads)
|
||
|
local results = {}
|
||
|
for i=1, #threads do
|
||
|
results[i] = threads[i]:get()
|
||
|
end
|
||
|
return results
|
||
|
end
|
||
|
|
||
|
function m:MarkEntity(ent)
|
||
|
if not ent or not ent:IsValid() then return nil end
|
||
|
ent._MT_ID = ent._MT_ID or randStr(5)
|
||
|
return {ent:GetClass(), ent._MT_ID}
|
||
|
end
|
||
|
|
||
|
function m:FindEnt(id)
|
||
|
if not id then return nil end
|
||
|
for _,v in pairs(ents.FindByClass(id[1])) do
|
||
|
if v._MT_ID == id[2] then return v end
|
||
|
end
|
||
|
return nil
|
||
|
end
|
||
|
|
||
|
hook.Add("PlayerSpawn", "aa", function(ply)
|
||
|
effil.thread(function()print("we are on the other thread")end)()
|
||
|
local id = GAMEMODE.MT.MarkEntity(ply)
|
||
|
PrintTable(id)
|
||
|
print("main")
|
||
|
--[[effil.thread(function(t)
|
||
|
local p = GAMEMODE.MT.FindEnt(t)
|
||
|
print("t p", p)
|
||
|
end)]]
|
||
|
end)
|