Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile("autorun/dynload.lua")
- dynLoad={}
- if SERVER then
- dynLoad.UpdatedFiles={}
- function dynLoad.SendCodeToClient(v, ply)
- local code=v
- if !ValidEntity(ply) then
- ply=RecipientFilter():AddAllPlayers()
- end
- if code then
- for i=1, string.len(code)/200+1 do
- local ncode=string.sub(code, (i-1)*200, (i-1)*200+99)
- --Msg(ncode)
- --MsgN(string.len(ncode))
- umsg.Start("plugin_addcode", ply)
- umsg.String("runCode")
- umsg.String(ncode)
- umsg.End()
- end
- umsg.Start("plugin_runcode", ply)
- umsg.String("runCode")
- umsg.End()
- else
- error("Error! Code not sent!", 2)
- end
- end
- function _R.Player:SendLua(str)
- dynLoad.SendCodeToClient(str, self)
- end
- function dynLoad.SendLuaToClient(v, ply)
- local code=file.Read("lua/"..v, true)
- if !code then
- local hasFound=false
- for ind, addon in pairs(file.FindDir("addons/*", true)) do
- if file.Read("addons/"..addon.."/lua/"..v, true) and !hasFound then
- code=file.Read("addons/"..addon.."/lua/"..v, true)
- hasFound=true
- end
- end
- if file.Read("gamemodes/"..v, true) and !hasFound then
- code=file.Read("gamemodes/"..v, true)
- hasFound=true
- end
- end
- if !ValidEntity(ply) then
- ply=RecipientFilter():AddAllPlayers()
- end
- if code then
- for i=1, string.len(code)/100+1 do
- local ncode=string.sub(code, (i-1)*100, (i-1)*100+99)
- --Msg(ncode)
- --MsgN(string.len(ncode))
- umsg.Start("plugin_addcode", ply)
- umsg.String(v)
- umsg.String(ncode)
- umsg.End()
- end
- umsg.Start("plugin_runcode", ply)
- umsg.String(v)
- umsg.End()
- if !table.HasValue(dynLoad.UpdatedFiles, v) then
- dynLoad.UpdatedFiles[#dynLoad.UpdatedFiles+1]=v
- end
- else
- ErrorNoHalt("File "..v.." not found (anywhere)!\n")
- end
- end
- concommand.Add("lua_sendfiletoclient", function(ply, cmd, args)
- if !ply:IsPlayer() then
- dynLoad.SendLuaToClient(string.Implode(" ", args))
- end
- end)
- concommand.Add("lua_openscript_cl", function(ply, cmd, args)
- if !ply:IsPlayer() then
- dynLoad.SendLuaToClient(string.Implode(" ", args))
- end
- end)
- concommand.Add("lua_openscript_dl", function(ply, cmd, args)
- if !ply:IsPlayer() then
- dynLoad.SendLuaToClient(string.Implode(" ", args))
- include(string.Implode(" ", args))
- end
- end)
- concommand.Add("lua_openscript_sh", function(ply, cmd, args)
- if !ply:IsPlayer() then
- dynLoad.SendLuaToClient(string.Implode(" ", args))
- include(string.Implode(" ", args))
- end
- end)
- hook.Add("PlayerInitialSpawn", "sendUpdatedFiles", function(ply)
- for f, v in pairs(dynLoad.UpdatedFiles) do
- dynLoad.SendLuaToClient(v, ply)
- end
- end)
- end
- if CLIENT then
- dynLoad.PluginCode={}
- usermessage.Hook("plugin_addcode", function(data)
- local fname=data:ReadString()
- local code=data:ReadString()
- if dynLoad.PluginCode[fname] then
- dynLoad.PluginCode[fname]=dynLoad.PluginCode[fname]..code
- else
- dynLoad.PluginCode[fname]=code
- end
- end)
- usermessage.Hook("plugin_runcode", function(data)
- local fname=data:ReadString()
- if !(fname=="runCode") then
- MsgN(fname.." loaded from server.")
- end
- RunString(dynLoad.PluginCode[fname])
- dynLoad.PluginCode[fname]=nil
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment