Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile("cl_init.lua")
- AddCSLuaFile("shared.lua")
- include('shared.lua')
- local host = "207.210.254.42"
- local username = "castle"
- local password = "j@gg3r"
- local database = "castle"
- local port = 3306
- local connections = 6
- local threads = 5
- /*
- Dont edit this
- */
- require( "tmysql" )
- /*
- Initialize the connection to mysql
- */
- tmysql.initialize(host, username, password, database, port, connections, threads)
- function Query(...)
- DebugPrint("Query executing.")
- return tmysql.query(...)
- end
- function Esc(esc)
- return tmysql.escape(esc)
- end
- function QueryErrors(res,status,error)
- print(error)
- end
- wave = 0
- door = 1000
- lost = 0
- npccount = 0
- timer.Create("NPC Check", 5, 0, function()
- npccount = #ents.FindByClass("npc_*")
- end)
- maps = {"c_jaggerscastle", "c_royalcastle_beta2"}
- for k,v in pairs(ents.FindByClass("npc_*")) do
- v:Remove()
- end
- timer.Create("CheckPlayers", 5, 0, function()
- if #ents.FindByClass("player") == 0 then
- end
- end)
- function Money(ply, amt)
- ply:SetNWInt("money", GetMoney(ply) + amt)
- end
- function GetMoney(ply)
- return ply:GetNWInt("money")
- end
- function SetMoney(ply, amt)
- ply:SetNWInt("money", amt)
- end
- function GM:PlayerLoadout(ply)
- ply:Give("weapon_pistol")
- ply:GiveAmmo(50000, "pistol")
- ply:Give("weapon_smg1")
- ply:GiveAmmo(45, "smg1")
- end
- function CheckPlayers()
- if #ents.FindByClass(player.GetAll()) == 0 then
- print("Restarting")
- game.ConsoleCommand("changelevel "..tostring(table.Random(maps)).."\n")
- end
- end
- function DebugVar(arg)
- for _,b in pairs(player.GetAll()) do
- b:ChatPrint(arg)
- end
- end
- function Buy(ply, cmd, args)
- if ply:IsValid() then
- local a = 0
- if args[2] then
- a = 1
- args[2] = math.ceil(args[2])
- end
- if a == 1 then
- amt = math.ceil(args[2] + 0)
- if amt > 0 then
- if table.HasValue(ammo, args[1]) then
- for k,v in pairs(ammo) do
- if v == args[1] then
- cost = ammocost[k]
- if GetMoney(ply) > cost * args[2] then
- cost = cost * args[2]
- Money(ply, -cost)
- ply:GiveAmmo(args[2] + 0, args[1])
- return
- else
- chat.AddText(ply, Color(0,0,255,255), "You don't have enough money! Need: $"..cost * args[2])
- return
- end
- end
- end
- else
- chat.AddText(ply, Color(0,0,255,255), "This is an invalid ammo type.")
- return
- end
- else
- chat.AddText(ply, Color(0,0,255,255), "You need to enter a value above 0!")
- return
- end
- else
- if table.HasValue(weapons, args[1]) then
- for k,v in pairs(weapons) do
- if v == args[1] then
- cost = math.ceil(weaponcost[k] + 0)
- if GetMoney(ply) > cost then
- print("Has Enough")
- Money(ply,-cost)
- if args[1] == "Grenade" then
- ply:Give("weapon_frag")
- return
- end
- tmysql.query("UPDATE users SET Has"..args[1].."='1' WHERE SteamID = '"..ply:SteamID().."'")
- ply:Give("weapon_"..string.lower(args[1]))
- else
- chat.AddText(ply, Color(0,0,255,255), "You don't have enough money! Need: $"..cost)
- return
- end
- end
- end
- else
- chat.AddText(ply, Color(0,0,255,255), "This is an invalid weapon.")
- return
- end
- end
- end
- end
- concommand.Add("buy", Buy)
- timer.Create('save', 30, 0, function()
- Save()
- end)
- hook.Add("PlayerDisconnect", "saveplayer", function(ply)
- Save(ply)
- end)
- function GM:CanPlayerSuicide ( ply )
- chat.AddText(ply, Color(0,0,0,255), "Don't be emo.")
- return false
- end
- function SpawnWave()
- Save()
- chat.AddText(Color(200,200,200,255), "Wave "..(wave + 1).." starting.")
- game.CleanUpMap()
- players = player.GetAll()
- door = door + (250 * math.Clamp(wave / 5, 1, 5))
- timer.Create("spawn", 2, #players + math.random(1,3) + (wave / 8), function()
- for k,v in pairs(ents.FindByClass("info_target")) do
- npc = ents.Create(table.Random(npcs))
- pos = v:GetPos()
- health = wave * 1.28 * (#players * 0.5) + 2
- npc:SetHealth(math.ceil(health))
- npc:SetPos(pos)
- npc:Spawn()
- npccount = npccount + 1
- end
- UpdateNPCS()
- end)
- wave = wave + 1
- for k,v in pairs(players) do
- v:GiveAmmo(45, "smg1")
- v:SetNWInt("wave", wave)
- v:SetNWInt("door" , door)
- end
- end
- timer.Create("CheckWave", 5, 0, function()
- if npccount == 0 then
- SpawnWave()
- end
- end)
- hook.Add("OnNPCKilled", "OnNpckill", function(npc, killer, weapon)
- if table.HasValue(npcs, npc:GetClass()) then
- local amt = math.Clamp(wave * 0.5, 0.5, 25)
- Money(killer, math.ceil(amt))
- npccount = npccount - 1
- UpdateNPCS()
- end
- end)
- function UpdateNPCS(ply)
- if !ply then
- local ply = RecipientFilter()
- ply:AddAllPlayers()
- end
- umsg.Start("updatenpcs", ply)
- umsg.Short( npccount )
- umsg.End()
- end
- hook.Add("Think", "Headcrabs", function()
- headcrabs = ents.FindByClass("npc_headcrab*")
- for k,v in pairs(headcrabs) do
- v:Remove()
- end
- if door <= 0 and lost == 0 then
- if player.GetAll() then
- lost = 1
- Restart()
- end
- end
- end)
- function GM:ShowHelp(ply)
- ply:ConCommand("buymenu")
- end
- function GM:ScaleNPCDamage(npc,hitgroup,dmginfo)
- if dmginfo:GetAttacker():IsPlayer() then
- local class = dmginfo:GetAttacker():GetActiveWeapon():GetClass()
- if class == "weapon_pistol" or class == "weapon_smg1" then
- dmginfo:SetDamage(math.random(3, 7))
- elseif class == "weapon_ar2" then
- dmginfo:SetDamage(math.random(21, 23))
- end
- end
- end
- function GM:PlayerAuthed( ply, SteamID, UniqueID )
- if !ply or !ply:SteamID() then return end
- UpdateNPCS(ply)
- tmysql.query("SELECT * FROM users WHERE SteamID='"..ply:SteamID().."'", function(res, status, error)
- if res[1] then
- print("SELECT * FROM users WHERE SteamID='"..ply:SteamID().."'")
- local user = res[1]
- SetMoney(ply,user[3])
- ply.IsDonator = user[13]
- ply:ChatPrint("Loaded Profile!")
- ply.Weapons = "1|1|"..user[7].."|"..user[8].."|"..user[9].."|"..user[10].."|"..user[11].."|"..user[12]
- else
- 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))
- ply:ChatPrint("Created New Profile! Welcome!")
- end
- ply:SetNWInt("wave", wave)
- ply:SetNWInt("door", door)
- end)
- timer.Create(tostring(ply:SteamID()), 2, 1, function()
- local weapon = string.Explode("|", ply.Weapons)
- PrintTable(weapon)
- if weapon then
- if weapon[3] == "1" then
- ply:Give("weapon_357")
- end
- if weapon[4] == "1" then
- ply:Give("weapon_shotgun")
- end
- if weapon[5] == "1" then
- ply:Give("weapon_ar2")
- end
- if weapon[6] == "1" then
- ply:Give("weapon_crossbow")
- end
- if weapon[7] == "1" then
- ply:Give("weapon_rpg")
- end
- if weapon[8] == "1" then
- ply:Give("weapon_frag")
- end
- end
- end)
- end
- hook.Add("PlayerSpawn", "playerspawn", function(ply)
- ply:GodEnable()
- end)
- function ShouldCollideTestHook(ent1,ent2)
- 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
- return false
- end
- end
- hook.Add("ShouldCollide","ShouldCollideTestHook",ShouldCollideTestHook)
- function Save(ply)
- if !ply then
- for k,v in pairs(player.GetAll()) do
- tmysql.query("UPDATE users SET money = '"..GetMoney(v).."' WHERE SteamID='"..v:SteamID().."'")
- v:ChatPrint("Saved Account!")
- end
- else
- tmysql.query("UPDATE users SET money = '"..GetMoney(ply).."' WHERE SteamID='"..ply:SteamID().."'")
- ply:ChatPrint("Saved Account!")
- end
- end
- function Restart()
- for k,v in pairs(player.GetAll()) do
- chat.AddText(v, Color(100,100,100,255), "You have lost! Restarting in 5 seconds.")
- timer.Create("restart", 5, 1, function()
- game.ConsoleCommand("changelevel "..tostring(table.Random(maps)).."\n")
- end)
- end
- end
- timer.Create("GotGate", 1, 0, function()
- if lost == 0 then
- local doorold = door
- for k,v in pairs(ents.FindByClass("npc_*")) do
- if string.lower(v:GetName()) == "gotgate" then
- door = door - (math.Clamp(wave * 15, 50, 1000))
- end
- end
- if doorold > door then
- for k,v in pairs(player.GetAll()) do
- v:SetNWInt("door", door)
- chat.AddText(v, Color(255, 0, 0, 255), "Your door is being attacked! Door Life lost: "..doorold - door)
- end
- end
- end
- end)
- chat = {}
- function chat.AddText(...)
- local ply
- if type(arg[1]) == "Player" then
- ply = arg[1]
- else
- ply = RecipientFilter()
- ply:AddAllPlayers()
- end
- umsg.Start("AddText",ply)
- umsg.Short(table.Count(arg))
- for _,v in pairs(arg) do
- if type(v) == "string" then
- umsg.String(v)
- elseif type(v) == "table" then
- umsg.Short(v.r)
- umsg.Short(v.g)
- umsg.Short(v.b)
- umsg.Short(v.a)
- end
- end
- umsg.End()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement