Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.65 KB | None | 0 0
  1. if(SERVER)
  2. then
  3.  
  4.     local _Spawns = {};
  5.  
  6.     concommand.Add("zombie_addspawn", function(ply, cmd, args, argstr)
  7.  
  8.         if(!ply:IsAdmin())
  9.         then
  10.        
  11.             return;
  12.  
  13.         end
  14.  
  15.         if(#args == 0)
  16.         then
  17.  
  18.             ply:ChatPrint("usage: zombie_addspawn <identifier> <maxzombies>");
  19.             return;
  20.  
  21.         end
  22.  
  23.         if(#args != 2)
  24.         then
  25.  
  26.             ply:ChatPrint("failed");
  27.             return;
  28.  
  29.         end
  30.  
  31.         _Spawns[args[1]] = {
  32.  
  33.             ["pos"] = ply:GetPos(),
  34.             ["maxzombies"] = tonumber(args[2]);
  35.  
  36.         };
  37.  
  38.     end);
  39.  
  40.     concommand.Add("zombie_removespawn", function(ply, cmd, args, argstr)
  41.  
  42.         if(!ply:IsAdmin())
  43.         then
  44.  
  45.             return;
  46.  
  47.         end
  48.  
  49.         if(#args == 0)
  50.         then
  51.  
  52.             ply:ChatPrint("usage: zombie_removespawn <identifier>");
  53.             return;
  54.  
  55.         end
  56.  
  57.         if(#args != 1)
  58.         then
  59.  
  60.             ply:ChatPrint("failed");
  61.             return;
  62.  
  63.         end
  64.  
  65.         if(_Spawns[args[1]] == nil)
  66.         then
  67.  
  68.             ply:ChatPrint("no such spawner");
  69.             return;
  70.  
  71.         end
  72.  
  73.         _Spawns[args[1]] = nil;
  74.         ply:ChatPrint("successfully removed");
  75.  
  76.     end);
  77.  
  78.     concommand.Add("zombie_gotospawn", function(ply, cmd, args, argstr)
  79.  
  80.         if(!ply:IsAdmin())
  81.         then
  82.  
  83.             return;
  84.  
  85.         end
  86.  
  87.         if(#args == 0)
  88.         then
  89.  
  90.             ply:ChatPrint("usage: zombie_gotospawn <identifier>");
  91.             return;
  92.  
  93.         end
  94.  
  95.         if(!_Spawns[args[1]])
  96.         then
  97.  
  98.             return;
  99.  
  100.         end
  101.  
  102.         ply:SetPos(_Spawns[args[1]]["pos"]);
  103.  
  104.     end);
  105.  
  106.     concommand.Add("zombie_listspawns", function(ply, cmd, args, argstr)
  107.  
  108.         if(!ply:IsAdmin())
  109.         then
  110.  
  111.             return;
  112.  
  113.         end
  114.  
  115.         for k,v in next, _Spawns do
  116.  
  117.             ply:ChatPrint(string.format("%s = %d (%f, %f, %f)", k, v["maxzombies"], v["pos"].x, v["pos"].y, v["pos"].z));
  118.  
  119.         end
  120.  
  121.     end);
  122.  
  123.     hook.Add("Think", "zombiem3n", function()
  124.  
  125.         for k,v in next, _Spawns do
  126.  
  127.             if(v["zombies"] == nil)
  128.             then
  129.  
  130.                 v["zombies"] = {};
  131.  
  132.             end
  133.  
  134.             if(v["curzombies"] == nil)
  135.             then
  136.  
  137.                 v["curzombies"] = 0;
  138.  
  139.             end
  140.  
  141.             if(v["curzombies"] > 0)
  142.             then
  143.  
  144.                 local idx = 1;
  145.                 while(true)
  146.                 do
  147.  
  148.                     if(idx > v["curzombies"])
  149.                     then
  150.  
  151.                         break;
  152.  
  153.                     end
  154.  
  155.                     if(v["zombies"][idx] == nil)
  156.                     then
  157.  
  158.                         print(idx);
  159.                         break;
  160.  
  161.                     end
  162.  
  163.                     if(!v["zombies"][idx]:IsValid())
  164.                     then
  165.  
  166.                         table.remove(v["zombies"], idx);
  167.                         v["curzombies"] = v["curzombies"] - 1;
  168.  
  169.                     else
  170.  
  171.                         idx = idx + 1;
  172.  
  173.                     end
  174.  
  175.                 end
  176.  
  177.             end
  178.  
  179.             while(v["curzombies"] < v["maxzombies"])
  180.             do
  181.  
  182.                 local newzombie = ents.Create("npc_zombie");
  183.                 newzombie:SetPos(v["pos"] + Vector(math.random(-200, 200), math.random(-200, 200), 0));
  184.                 newzombie:Spawn();
  185.                 v["zombies"][v["curzombies"] + 1] = newzombie;
  186.                 v["curzombies"] = v["curzombies"] + 1;
  187.  
  188.                 print(v["curzombies"]);
  189.  
  190.             end
  191.  
  192.         end
  193.  
  194.     end);
  195.  
  196. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement