Advertisement
Guest User

Untitled

a guest
Sep 9th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.63 KB | None | 0 0
  1. AddCSLuaFile("cl_init.lua")
  2. AddCSLuaFile("shared.lua")
  3. include('shared.lua')
  4. local host = "207.210.254.42"
  5. local username = "castle"
  6. local password = "j@gg3r"
  7. local database = "castle"
  8. local port = 3306
  9. local connections = 6
  10. local threads = 5
  11. /*
  12.     Dont edit this
  13. */
  14. require( "tmysql" )
  15. /*
  16.     Initialize the connection to mysql
  17. */
  18. tmysql.initialize(host, username, password, database, port, connections, threads)
  19.  
  20. function Query(...)
  21.     DebugPrint("Query executing.")
  22.     return tmysql.query(...)
  23. end
  24.  
  25. function Esc(esc)
  26.     return tmysql.escape(esc)
  27. end
  28.  
  29. function QueryErrors(res,status,error)
  30.     print(error)
  31. end
  32.  
  33. wave = 0
  34. door = 1000
  35. lost = 0
  36. npccount = 0
  37.  
  38. timer.Create("NPC Check", 5, 0, function()
  39.     npccount = #ents.FindByClass("npc_*")
  40. end)
  41.  
  42. maps = {"c_jaggerscastle", "c_royalcastle_beta2"}
  43. for k,v in pairs(ents.FindByClass("npc_*")) do
  44. v:Remove()
  45. end
  46.  
  47. timer.Create("CheckPlayers", 5, 0, function()
  48.     if #ents.FindByClass("player") == 0 then
  49.    
  50.     end
  51. end)
  52.  
  53.  
  54.  
  55. function Money(ply, amt)
  56.     ply:SetNWInt("money", GetMoney(ply) + amt)
  57. end
  58.  
  59. function GetMoney(ply)
  60.     return ply:GetNWInt("money")
  61. end
  62.  
  63. function SetMoney(ply, amt)
  64.     ply:SetNWInt("money", amt)
  65. end
  66.  
  67. function GM:PlayerLoadout(ply)
  68. ply:Give("weapon_pistol")
  69. ply:GiveAmmo(50000, "pistol")
  70. ply:Give("weapon_smg1")
  71. ply:GiveAmmo(45, "smg1")
  72. end
  73.  
  74. function CheckPlayers()
  75.     if #ents.FindByClass(player.GetAll()) == 0 then
  76.         print("Restarting")
  77.         game.ConsoleCommand("changelevel "..tostring(table.Random(maps)).."\n")
  78.     end
  79. end
  80.  
  81.  
  82. function DebugVar(arg)
  83.     for _,b in pairs(player.GetAll()) do
  84.         b:ChatPrint(arg)
  85.     end
  86. end
  87.  
  88.  
  89. function Buy(ply, cmd, args)
  90.     if ply:IsValid() then
  91.         local a = 0
  92.         if args[2] then
  93.             a = 1
  94.             args[2] = math.ceil(args[2])
  95.         end
  96.         if a == 1 then
  97.             amt = math.ceil(args[2] + 0)
  98.             if amt > 0 then
  99.                 if table.HasValue(ammo, args[1]) then
  100.                       for k,v in pairs(ammo) do
  101.                         if v == args[1] then
  102.                             cost = ammocost[k]
  103.                             if GetMoney(ply) > cost * args[2] then
  104.                             cost = cost * args[2]
  105.                             Money(ply, -cost)
  106.                             ply:GiveAmmo(args[2] + 0, args[1])
  107.                             return
  108.                             else
  109.                                 chat.AddText(ply, Color(0,0,255,255), "You don't have enough money! Need: $"..cost * args[2])
  110.                                 return
  111.                             end
  112.                         end
  113.                       end
  114.                 else
  115.                     chat.AddText(ply, Color(0,0,255,255), "This is an invalid ammo type.")
  116.                     return
  117.                 end
  118.             else
  119.                 chat.AddText(ply, Color(0,0,255,255), "You need to enter a value above 0!")
  120.                 return
  121.             end
  122.         else
  123.             if table.HasValue(weapons, args[1]) then
  124.                 for k,v in pairs(weapons) do
  125.                     if v == args[1] then
  126.                         cost = math.ceil(weaponcost[k] + 0)
  127.                         if GetMoney(ply) > cost then
  128.                             print("Has Enough")
  129.                             Money(ply,-cost)
  130.                             if args[1] == "Grenade" then
  131.                                 ply:Give("weapon_frag")
  132.                                 return
  133.                             end
  134.                                 tmysql.query("UPDATE users SET Has"..args[1].."='1' WHERE SteamID = '"..ply:SteamID().."'")
  135.                                 ply:Give("weapon_"..string.lower(args[1]))
  136.                         else
  137.                             chat.AddText(ply, Color(0,0,255,255), "You don't have enough money! Need: $"..cost)
  138.                             return
  139.                         end
  140.                     end
  141.                 end
  142.             else
  143.                 chat.AddText(ply, Color(0,0,255,255), "This is an invalid weapon.")
  144.                 return
  145.             end
  146.         end
  147.     end
  148. end
  149. concommand.Add("buy", Buy)
  150.  
  151. timer.Create('save', 30, 0, function()
  152. Save()
  153. end)
  154.  
  155. hook.Add("PlayerDisconnect", "saveplayer", function(ply)
  156. Save(ply)
  157. end)
  158.  
  159. function GM:CanPlayerSuicide ( ply )
  160.     chat.AddText(ply, Color(0,0,0,255), "Don't be emo.")
  161.      return false
  162. end
  163.  
  164.  
  165. function SpawnWave()
  166.     Save()
  167.     chat.AddText(Color(200,200,200,255), "Wave "..(wave + 1).." starting.")
  168.     game.CleanUpMap()
  169.     players = player.GetAll()
  170.     door = door + (250 * math.Clamp(wave / 5, 1, 5))
  171.     timer.Create("spawn", 2, #players + math.random(1,3) + (wave / 8), function()
  172.         for k,v in pairs(ents.FindByClass("info_target")) do
  173.             npc = ents.Create(table.Random(npcs))
  174.             pos = v:GetPos()
  175.             health = wave * 1.28 * (#players * 0.5) + 2
  176.             npc:SetHealth(math.ceil(health))
  177.             npc:SetPos(pos)
  178.             npc:Spawn()
  179.             npccount = npccount + 1
  180.         end
  181.         UpdateNPCS()
  182.     end)
  183.     wave = wave + 1
  184.     for k,v in pairs(players) do
  185.         v:GiveAmmo(45, "smg1")
  186.         v:SetNWInt("wave", wave)
  187.         v:SetNWInt("door" , door)
  188.     end
  189. end
  190.  
  191.  
  192. timer.Create("CheckWave", 5, 0, function()
  193.     if npccount == 0 then
  194.         SpawnWave()
  195.     end
  196. end)
  197.  
  198. hook.Add("OnNPCKilled", "OnNpckill", function(npc, killer, weapon)
  199. if table.HasValue(npcs, npc:GetClass()) then
  200. local amt = math.Clamp(wave * 0.5, 0.5, 25)
  201. Money(killer, math.ceil(amt))
  202. npccount = npccount - 1
  203. UpdateNPCS()
  204. end
  205. end)
  206.  
  207. function UpdateNPCS(ply)
  208. if !ply then
  209.     local ply = RecipientFilter()
  210.     ply:AddAllPlayers()
  211. end
  212. umsg.Start("updatenpcs", ply)
  213.     umsg.Short( npccount )
  214. umsg.End()
  215. end
  216.  
  217. hook.Add("Think", "Headcrabs", function()
  218.     headcrabs = ents.FindByClass("npc_headcrab*")
  219.     for k,v in pairs(headcrabs) do
  220.         v:Remove()
  221.     end
  222.     if door <= 0 and lost == 0 then
  223.         if player.GetAll() then
  224.             lost = 1
  225.             Restart()
  226.         end
  227.     end
  228. end)
  229.  
  230. function GM:ShowHelp(ply)
  231.     ply:ConCommand("buymenu")
  232. end
  233.  
  234. function GM:ScaleNPCDamage(npc,hitgroup,dmginfo)
  235. if dmginfo:GetAttacker():IsPlayer() then
  236. local class = dmginfo:GetAttacker():GetActiveWeapon():GetClass()
  237. if class == "weapon_pistol" or class == "weapon_smg1" then
  238.     dmginfo:SetDamage(math.random(3, 7))
  239. elseif class == "weapon_ar2" then
  240.     dmginfo:SetDamage(math.random(21, 23))
  241. end
  242. end
  243. end
  244.  
  245. function GM:PlayerAuthed( ply, SteamID, UniqueID )
  246.     if !ply or !ply:SteamID() then return end
  247.     UpdateNPCS(ply)
  248.     tmysql.query("SELECT * FROM users WHERE SteamID='"..ply:SteamID().."'", function(res, status, error)
  249.         if res[1] then
  250.         print("SELECT * FROM users WHERE SteamID='"..ply:SteamID().."'")
  251.             local user = res[1]
  252.             SetMoney(ply,user[3])
  253.             ply.IsDonator = user[13]
  254.             ply:ChatPrint("Loaded Profile!")
  255.             ply.Weapons = "1|1|"..user[7].."|"..user[8].."|"..user[9].."|"..user[10].."|"..user[11].."|"..user[12]
  256.             else
  257.             tmysql.query("INSERT INTO users (SteamID, Name, Money, Kills, HasPistol,HasSmg ,Donator, Time) VALUES('"..ply:SteamID().."','"..ply:Nick().."',0,0,1,1,0,0)", QueryErrors(res, status, error))
  258.             ply:ChatPrint("Created New Profile! Welcome!")
  259.         end
  260.         ply:SetNWInt("wave", wave)
  261.         ply:SetNWInt("door", door)
  262.         end)
  263.     timer.Create(tostring(ply:SteamID()), 2, 1, function()
  264. local weapon = string.Explode("|", ply.Weapons)
  265. PrintTable(weapon)
  266. if weapon then
  267. if weapon[3] == "1" then
  268. ply:Give("weapon_357")
  269. end
  270. if weapon[4] == "1" then
  271. ply:Give("weapon_shotgun")
  272. end
  273. if weapon[5] == "1" then
  274. ply:Give("weapon_ar2")
  275. end
  276. if weapon[6] == "1" then
  277. ply:Give("weapon_crossbow")
  278. end
  279. if weapon[7] == "1" then
  280. ply:Give("weapon_rpg")
  281. end
  282. if weapon[8] == "1" then
  283. ply:Give("weapon_frag")
  284. end
  285. end
  286.     end)
  287. end
  288.  
  289. hook.Add("PlayerSpawn", "playerspawn", function(ply)
  290. ply:GodEnable()
  291. end)
  292.  
  293. function ShouldCollideTestHook(ent1,ent2)
  294.     if string.find(ent1:GetClass(), "npc_") and string.find(ent2:GetClass(), "npc_") or string.find(ent1:GetClass(), "player") and string.find(ent2:GetClass(), "player") then
  295.         return false
  296.     end
  297.    
  298. end
  299. hook.Add("ShouldCollide","ShouldCollideTestHook",ShouldCollideTestHook)
  300.  
  301. function Save(ply)
  302.     if !ply then
  303.         for k,v in pairs(player.GetAll()) do
  304.             tmysql.query("UPDATE users SET money = '"..GetMoney(v).."' WHERE SteamID='"..v:SteamID().."'")
  305.             v:ChatPrint("Saved Account!")
  306.         end
  307.     else
  308.         tmysql.query("UPDATE users SET money = '"..GetMoney(ply).."' WHERE SteamID='"..ply:SteamID().."'")
  309.         ply:ChatPrint("Saved Account!")
  310.     end
  311. end
  312.  
  313. function Restart()
  314.     for k,v in pairs(player.GetAll()) do
  315.         chat.AddText(v, Color(100,100,100,255), "You have lost! Restarting in 5 seconds.")
  316.         timer.Create("restart", 5, 1, function()
  317.             game.ConsoleCommand("changelevel "..tostring(table.Random(maps)).."\n")
  318.         end)
  319.     end
  320. end
  321.  
  322.  
  323.  
  324. timer.Create("GotGate", 1, 0, function()
  325. if lost == 0 then
  326. local doorold = door
  327.     for k,v in pairs(ents.FindByClass("npc_*")) do
  328.         if string.lower(v:GetName()) == "gotgate" then
  329.             door = door - (math.Clamp(wave * 15, 50, 1000))
  330.         end
  331.     end
  332. if doorold > door then
  333.     for k,v in pairs(player.GetAll()) do
  334.         v:SetNWInt("door", door)
  335.         chat.AddText(v, Color(255, 0, 0, 255), "Your door is being attacked! Door Life lost: "..doorold - door)
  336.     end
  337. end
  338. end
  339. end)
  340.  
  341.  
  342. chat = {}
  343.  
  344. function chat.AddText(...)
  345.     local ply
  346.     if type(arg[1]) == "Player" then
  347.         ply = arg[1]
  348.     else
  349.         ply = RecipientFilter()
  350.         ply:AddAllPlayers()
  351.     end
  352.     umsg.Start("AddText",ply)
  353.         umsg.Short(table.Count(arg))
  354.         for _,v in pairs(arg) do
  355.             if type(v) == "string" then
  356.                 umsg.String(v)
  357.             elseif type(v) == "table" then
  358.                 umsg.Short(v.r)
  359.                 umsg.Short(v.g)
  360.                 umsg.Short(v.b)
  361.                 umsg.Short(v.a)
  362.             end
  363.         end
  364.     umsg.End()
  365. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement