Compare commits
1 commit
master
...
multithrea
Author | SHA1 | Date | |
---|---|---|---|
e1ef031c4d |
3 changed files with 57 additions and 0 deletions
|
@ -82,6 +82,8 @@ AddCSLuaFile("vgui/zshealtharea.lua")
|
||||||
AddCSLuaFile("vgui/zsstatusarea.lua")
|
AddCSLuaFile("vgui/zsstatusarea.lua")
|
||||||
AddCSLuaFile("vgui/zsgamestate.lua")
|
AddCSLuaFile("vgui/zsgamestate.lua")
|
||||||
|
|
||||||
|
include("multithread.lua")
|
||||||
|
|
||||||
include("sh_globals.lua")
|
include("sh_globals.lua")
|
||||||
|
|
||||||
include("obj_entity_extend_sv.lua")
|
include("obj_entity_extend_sv.lua")
|
||||||
|
|
53
gamemodes/zombiesurvival/gamemode/multithread.lua
Normal file
53
gamemodes/zombiesurvival/gamemode/multithread.lua
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
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)
|
|
@ -1,5 +1,7 @@
|
||||||
English | [中文(简体)](readme_zh-CN.md)
|
English | [中文(简体)](readme_zh-CN.md)
|
||||||
|
|
||||||
|
**WARNING: This edition of Zombie Survival requires extra library on server.**
|
||||||
|
|
||||||
# Zombie Survival
|
# Zombie Survival
|
||||||
The definitive zombie experience.
|
The definitive zombie experience.
|
||||||
A gamemode for Garry's Mod.
|
A gamemode for Garry's Mod.
|
||||||
|
|
Loading…
Reference in a new issue