Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AddCSLuaFile( "client/fonts.lua" )
- AddCSLuaFile( "client/hud.lua" )
- AddCSLuaFile( "client/scoreboard.lua" )
- AddCSLuaFile( "client/menu_f1.lua" )
- AddCSLuaFile( "client/menu_f2.lua" )
- AddCSLuaFile( "client/menu_f3.lua" )
- AddCSLuaFile( "client/menu_f4.lua" )
- AddCSLuaFile( "client/menu_q.lua" )
- AddCSLuaFile( "cl_init.lua" ) --Tell the server that the client needs to download these files
- AddCSLuaFile( "shared.lua" )
- include( "config.lua" )
- include( "shared.lua" )
- include( "server/commands.lua" )
- local db = mysqloo.connect(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME, DB_PORT)
- function checkQuery(query)
- local playerInfo = query:getData()
- if playerInfo[1] ~= nil then
- return true
- else
- return false
- end
- end
- function db:onConnected()
- print("[MySQL] Connected to database on "..DB_HOST..":"..DB_PORT.." and version "..db:serverInfo())
- -- local q = self:query( "SELECT * FROM `test` WHERE `SteamID` = 'Ben';" )
- -- function q:onSuccess( data )
- -- print( "Query successful!" )
- -- PrintTable( data )
- -- end
- -- function q:onError( err, sql )
- -- print( "Query errored!" )
- -- print( "Query:", sql )
- -- print( "Error:", err )
- -- end
- -- q:start()
- end
- function db:onConnectionFailed( err )
- print("[MySQL] Failed to connect to database on "..DB_HOST..":"..DB_PORT)
- print( "Error:", err )
- end
- function LoadPly( ply )
- -- if db:status() == DATABASE_NOT_CONNECTED then print("[MySQL] Not connected to database while trying to load player \"" .. ply:Nick() .. "\", trying to re-connect.") db:connect() db:wait() end
- local query1 = db:query( "SELECT * FROM `players` WHERE `SteamID` = '"..ply:SteamID().."';" )
- function query1:onSuccess( data )
- if not checkQuery(q) then
- print("[MySQL]: Player \""..ply:Nick().."\" loaded from database.")
- PrintTable( data )
- else
- local query2 = db:query("INSERT INTO `players` (`Nick`, `SteamID`, `Money`, `Job`) VALUES ('" .. ply:Nick() .. "', '" .. ply:SteamID() .. "', " .. 200 .. ", " .. 1 .. ")")
- query2.onSuccess = function(q) print("[MySQL]: Player \""..ply:Nick().."\" added to the database.") end
- query2.onError = function(q,e) print("[MySQL]: Error: "..e) end
- query2:start()
- end
- end
- function query1:onError( err, sql )
- print( "[MySQL]: Query error while trying to load player \""..ply:Nick().."\" from the database!" )
- print( "Query:", sql )
- print( "Error:", err )
- end
- query1:start()
- end
- function Initialize()
- db:connect()
- db:wait()
- end
- hook.Add("Initialize", "Initialize", Initialize)
- function GM:PlayerInitialSpawn( ply )
- if db:status() == DATABASE_NOT_CONNECTED then print("[MySQL] Not connected to database while trying to load player \"" .. ply:Nick() .. "\", trying to re-connect.") db:connect() db:wait() end
- LoadPly( ply )
- end
- function GM:PlayerSpawn( ply )
- ply:SetTeam( TEAM_CITIZEN )
- GAMEMODE:PlayerLoadout( ply )
- GAMEMODE:PlayerSetModel ( ply )
- if !ply:IsBot() then
- ply:SetPlayerColor( Vector( 0.4, 0.4, 0.4 ) )
- ply:SetWeaponColor( Vector( 0.4, 0.4, 0.4 ) )
- else
- ply:SetModel( "models/player/police.mdl" )
- ply:SetPlayerColor( Vector( 1,0,0 ) )
- end
- end
- function GM:PlayerLoadout( ply )
- ply:StripWeapons()
- ply:RemoveAllAmmo()
- if ply:Team() == TEAM_CITIZEN then
- ply:Give( "weapon_physcannon" )
- ply:Give( "weapon_physgun" )
- elseif ply:Team() == TEAM_COP then
- ply:Give( "weapon_physcannon" )
- ply:Give( "weapon_physgun" )
- ply:GiveAmmo( 100, "pistol", true )
- ply:Give( "weapon_pistol" )
- ply:GiveAmmo( 100, "buckshot", true )
- ply:Give( "weapon_shotgun" )
- elseif ply:Team() == TEAM_MEDIC then
- ply:Give( "weapon_physcannon" )
- ply:Give( "weapon_physgun" )
- elseif ply:Team() == TEAM_MAYOR then
- ply:Give( "weapon_physcannon" )
- ply:Give( "weapon_physgun" )
- end
- end
- function InitPostEntity()
- local npcs =
- {
- {
- class = "npc_job_cop",
- pos = Vector(370, 4420, 132.031250),
- ang = Angle(0, -180, 0),
- name = "Cop"
- },
- {
- class = "npc_job_cop",
- pos = Vector(370, 3845, 132.031250),
- ang = Angle(0, -180, 0),
- name = "Cop"
- },
- }
- for k,v in pairs(npcs or {}) do
- local npc = ents.Create(v.class)
- if npc:IsValid() then
- npc:SetPos(v.pos)
- npc:SetAngles(v.ang)
- npc:SetName(v.name)
- npc:Spawn()
- else print("[ERROR] Trying to spawn invalid NPC "..v)
- end
- end
- end
- hook.Add("InitPostEntity", "InitPostEntity", InitPostEntity)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement