Advertisement
spinsquad

gamemode hooks

May 16th, 2015
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.53 KB | None | 0 0
  1. local h = {
  2.     hooks = {},
  3. };
  4.  
  5. local null = function() end
  6.  
  7. function h.detour(typ)
  8.     h.hooks[typ] = {};
  9.  
  10.     local ofunc = GAMEMODE[typ] || null;
  11.  
  12.     GAMEMODE[typ] = function(self, ...)
  13.  
  14.         ofunc(self, ...);
  15.  
  16.         for k,v in next, h.hooks[typ] do
  17.             local retable = { v(...) };
  18.             if (retable) then return(unpack(retable)); end
  19.         end
  20.  
  21.     end
  22. end
  23.  
  24. function h.Add(typ, func)
  25.     if(!h.hooks[typ]) then
  26.         h.detour(typ);
  27.     end
  28.  
  29.     h.hooks[typ][ #h.hooks[typ] + 1 ] = func;
  30. end
  31.  
  32. --example:
  33.  
  34. h.Add("Think", function() print("nice"); end);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement