Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.17 KB | None | 0 0
  1. /*-------------------------------------------------------------------------------------------------------------------------
  2.     Framework providing the main Evolve functions
  3. -------------------------------------------------------------------------------------------------------------------------*/
  4.  
  5. /*-------------------------------------------------------------------------------------------------------------------------
  6.     Comfortable constants
  7. -------------------------------------------------------------------------------------------------------------------------*/
  8.  
  9. evolve.constants = {}
  10. evolve.colors = {}
  11. evolve.ranks = {}
  12. evolve.privileges = {}
  13. evolve.bans = {}
  14. evolve.constants.notallowed = "You are not allowed to do that."
  15. evolve.constants.noplayers = "No matching players with an equal or lower immunity found."
  16. evolve.constants.noplayers2 = "No matching players with a lower immunity found."
  17. evolve.constants.noplayersnoimmunity = "No matching players found."
  18. evolve.admins = 1
  19. evolve.colors.blue = Color( 98, 176, 255, 255 )
  20. evolve.colors.red = Color( 255, 62, 62, 255 )
  21. evolve.colors.white = color_white
  22. evolve.category = {}
  23. evolve.category.administration = 1
  24. evolve.category.actions = 2
  25. evolve.category.punishment = 3
  26. evolve.category.teleportation = 4
  27. evolve.plugins = {}
  28.  
  29. /*-------------------------------------------------------------------------------------------------------------------------
  30.     Messages and notifications
  31. -------------------------------------------------------------------------------------------------------------------------*/
  32.  
  33. function evolve:Message( msg )
  34.     print( "[EV] " .. msg )
  35. end
  36.  
  37. if ( SERVER ) then
  38.     evolve.SilentNotify = false
  39.    
  40.     function evolve:Notify( ... )
  41.         local ply
  42.         local arg = { ... }
  43.        
  44.         if ( type( arg[1] ) == "Player" or arg[1] == NULL ) then ply = arg[1] end
  45.         if ( arg[1] == evolve.admins ) then
  46.             for _, pl in ipairs( player.GetAll() ) do
  47.                 if ( pl:IsAdmin() ) then
  48.                     table.remove( arg, 1 )
  49.                     evolve:Notify( pl, unpack( arg ) )
  50.                 end
  51.             end
  52.             return
  53.         end
  54.        
  55.         if ( ply != NULL and !self.SilentNotify ) then
  56.             umsg.Start( "EV_Notification", ply )
  57.                 umsg.Short( #arg )
  58.                 for _, v in ipairs( arg ) do
  59.                     if ( type( v ) == "string" ) then
  60.                         umsg.String( v )
  61.                     elseif ( type ( v ) == "table" ) then
  62.                         umsg.Short( v.r )
  63.                         umsg.Short( v.g )
  64.                         umsg.Short( v.b )
  65.                         umsg.Short( v.a )
  66.                     end
  67.                 end
  68.             umsg.End()
  69.         end
  70.        
  71.         local str = ""
  72.         for _, v in ipairs( arg ) do
  73.             if ( type( v ) == "string" ) then str = str .. v end
  74.         end
  75.        
  76.         if ( ply ) then
  77.             print( "[EV] " .. ply:Nick() .. " -> " .. str )
  78.             evolve:Log( evolve:PlayerLogStr( ply ) .. " -> " .. str )
  79.         else
  80.             print( "[EV] " .. str )
  81.             evolve:Log( str )
  82.         end
  83.     end
  84. else
  85.     function evolve:Notify( ... )
  86.         local arg = { ... }
  87.        
  88.         args = {}
  89.         for _, v in ipairs( arg ) do
  90.             if ( type( v ) == "string" or type( v ) == "table" ) then table.insert( args, v ) end
  91.         end
  92.        
  93.         chat.AddText( unpack( args ) )
  94.     end
  95.    
  96.     usermessage.Hook( "EV_Notification", function( um )
  97.         local argc = um:ReadShort()
  98.         local args = {}
  99.         for i = 1, argc / 2, 1 do
  100.             table.insert( args, Color( um:ReadShort(), um:ReadShort(), um:ReadShort(), um:ReadShort() ) )
  101.             table.insert( args, um:ReadString() )
  102.         end
  103.        
  104.         chat.AddText( unpack( args ) )
  105.     end )
  106. end
  107.  
  108. /*-------------------------------------------------------------------------------------------------------------------------
  109.     Utility functions
  110. -------------------------------------------------------------------------------------------------------------------------*/
  111.  
  112. function evolve:BoolToInt( bool )
  113.     if ( bool ) then return 1 else return 0 end
  114. end
  115.  
  116. function evolve:KeyByValue( tbl, value, iterator )
  117.     iterator = iterator or pairs
  118.     for k, v in iterator( tbl ) do
  119.         if ( value == v ) then return k end
  120.     end
  121. end
  122.  
  123. function evolve:FormatTime( t )
  124.     if ( t < 0 ) then
  125.         return "Forever"
  126.     elseif ( t < 60 ) then
  127.         if ( t == 1 ) then return "one second" else return t .. " seconds" end
  128.  
  129.     elseif ( t < 3600 ) then
  130.         if ( math.ceil( t / 60 ) == 1 ) then return "one minute" else return math.ceil( t / 60 ) .. " minutes" end
  131.     elseif ( t < 24 * 3600 ) then
  132.         if ( math.ceil( t / 3600 ) == 1 ) then return "one hour" else return math.ceil( t / 3600 ) .. " hours" end
  133.     elseif ( t < 24 * 3600 * 7 ) then
  134.         if ( math.ceil( t / ( 24 * 3600 ) ) == 1 ) then return "one day" else return math.ceil( t / ( 24 * 3600 ) ) .. " days" end
  135.     elseif ( t < 24 * 3600 * 30 ) then
  136.         if ( math.ceil( t / ( 24 * 3600 * 7 ) ) == 1 ) then return "one week" else return math.ceil( t / ( 24 * 3600 * 7 ) ) .. " weeks" end
  137.     else
  138.         if ( math.ceil( t / ( 24 * 3600 * 30 ) ) == 1 ) then return "one month" else return math.ceil( t / ( 24 * 3600 * 30 ) )  .. " months" end
  139.     end
  140. end
  141.  
  142. /*-------------------------------------------------------------------------------------------------------------------------
  143.     Plugin management
  144. -------------------------------------------------------------------------------------------------------------------------*/
  145.  
  146. local pluginFile
  147.  
  148. function evolve:LoadPlugins()
  149.     evolve.plugins = {}
  150.    
  151.     local plugins = file.FindInLua( "ev_plugins/*.lua" )
  152.     for _, plugin in ipairs( plugins ) do
  153.         local prefix = string.Left( plugin, string.find( plugin, "_" ) - 1 )
  154.         pluginFile = plugin
  155.        
  156.         if ( CLIENT and ( prefix == "sh" or prefix == "cl" ) ) then
  157.             include( "ev_plugins/" .. plugin )
  158.         elseif ( SERVER ) then
  159.             include( "ev_plugins/" .. plugin )
  160.             if ( prefix == "sh" or prefix == "cl" ) then AddCSLuaFile( "ev_plugins/" .. plugin ) end
  161.         end
  162.     end
  163. end
  164.  
  165. function evolve:RegisterPlugin( plugin )
  166.     if ( string.Left( pluginFile, string.find( pluginFile, "_" ) - 1 ) != "cl" or CLIENT ) then
  167.         table.insert( evolve.plugins, plugin )
  168.         plugin.File = pluginFile
  169.         if ( plugin.Privileges ) then table.Add( evolve.privileges, plugin.Privileges ) table.sort( evolve.privileges ) end
  170.     else
  171.         table.insert( evolve.plugins, { Title = plugin.Title, File = pluginFile } )
  172.     end
  173. end
  174.  
  175. function evolve:FindPlugin( name )
  176.     for _, plugin in ipairs( evolve.plugins ) do
  177.         if ( plugin.Title == name ) then return plugin end
  178.     end
  179. end
  180.  
  181. if ( !evolve.HookCall ) then evolve.HookCall = hook.Call end
  182. hook.Call = function( name, gm, ... )
  183.     local arg = { ... }
  184.    
  185.     for _, plugin in ipairs( evolve.plugins ) do
  186.         if ( plugin[ name ] ) then         
  187.             local retValues = { pcall( plugin[name], plugin, ... ) }
  188.            
  189.             if ( retValues[1] and retValues[2] != nil ) then
  190.                 table.remove( retValues, 1 )
  191.                 return unpack( retValues )
  192.             elseif ( !retValues[1] ) then
  193.                 evolve:Notify( evolve.colors.red, "Hook '" .. name .. "' in plugin '" .. plugin.Title .. "' failed with error:" )
  194.                 evolve:Notify( evolve.colors.red, retValues[2] )
  195.             end
  196.         end
  197.     end
  198.    
  199.     if ( CLIENT ) then
  200.         for _, tab in ipairs( evolve.MENU.Tabs ) do
  201.             if ( tab[ name ] ) then        
  202.                 local retValues = { pcall( tab[name], tab, ... ) }
  203.                
  204.                 if ( retValues[1] and retValues[2] != nil ) then
  205.                     table.remove( retValues, 1 )
  206.                     return unpack( retValues )
  207.                 elseif ( !retValues[1] ) then
  208.                     evolve:Notify( evolve.colors.red, "Hook '" .. name .. "' in tab '" .. tab.Title .. "' failed with error:" )
  209.                     evolve:Notify( evolve.colors.red, retValues[2] )
  210.                 end
  211.             end
  212.         end
  213.     end
  214.    
  215.     return evolve.HookCall( name, gm, ... )
  216. end
  217.  
  218. if ( SERVER ) then
  219.     concommand.Add( "ev_reloadplugin", function( ply, com, args )
  220.         if ( !ply:IsValid() and args[1] ) then
  221.             local found
  222.            
  223.             for k, plugin in ipairs( evolve.plugins ) do
  224.                 if ( string.lower( plugin.Title ) == string.lower( args[1] ) ) then
  225.                     found = k
  226.                     break
  227.                 end
  228.             end
  229.            
  230.             if ( found ) then
  231.                 print( "[EV] Reloading plugin " .. evolve.plugins[found].Title .. "..." )
  232.                
  233.                 local plugin = evolve.plugins[found].File
  234.                 local title = evolve.plugins[found].Title
  235.                 local prefix = string.Left( plugin, string.find( plugin, "_" ) - 1 )
  236.                
  237.                 if ( prefix != "cl" ) then table.remove( evolve.plugins, found ) pluginFile = plugin include( "ev_plugins/" .. plugin ) end
  238.                
  239.                 if ( prefix == "sh" or prefix == "cl" ) then
  240.                     datastream.StreamToClients( player.GetAll(), "EV_PluginFile", { Title = title, Contents = file.Read( "../lua/ev_plugins/" .. plugin ) } )
  241.                 end
  242.             else
  243.                 print( "[EV] Plugin '" .. tostring( args[1] ) .. "' not found!" )
  244.             end
  245.         end
  246.     end )
  247. else
  248.     datastream.Hook( "EV_PluginFile", function( handler, id, encoded, decoded )
  249.         for k, plugin in ipairs( evolve.plugins ) do
  250.             if ( string.lower( plugin.Title ) == string.lower( decoded.Title ) ) then
  251.                 found = k
  252.                 table.remove( evolve.plugins, k )
  253.             end
  254.         end
  255.        
  256.         RunString( decoded.Contents )
  257.     end )
  258. end
  259.  
  260. /*-------------------------------------------------------------------------------------------------------------------------
  261.     Player collections
  262. -------------------------------------------------------------------------------------------------------------------------*/
  263.  
  264. function evolve:IsNameMatch( ply, str )
  265.     if ( str == "*" ) then
  266.         return true
  267.     elseif ( str == "@" and ply:IsAdmin() ) then
  268.         return true
  269.     elseif ( str == "!@" and !ply:IsAdmin() ) then
  270.         return true
  271.     elseif ( string.match( str, "STEAM_[0-5]:[0-9]:[0-9]+" ) ) then
  272.         return ply:SteamID() == str
  273.     elseif ( string.Left( str, 1 ) == "\"" and string.Right( str, 1 ) == "\"" ) then
  274.         return ( ply:Nick() == string.sub( str, 2, #str - 1 ) )
  275.     else
  276.         return ( string.lower( ply:Nick() ) == string.lower( str ) or string.find( string.lower( ply:Nick() ), string.lower( str ), nil, true ) )
  277.     end
  278. end
  279.  
  280. function evolve:FindPlayer( name, def, nonum, noimmunity )
  281.     local matches = {}
  282.    
  283.     if ( !name or #name == 0 ) then
  284.         matches[1] = def
  285.     else
  286.         if ( type( name ) != "table" ) then name = { name } end
  287.         local name2 = table.Copy( name )
  288.         if ( nonum ) then
  289.             if ( #name2 > 1 and tonumber( name2[ #name2 ] ) ) then table.remove( name2, #name2 ) end
  290.         end
  291.        
  292.         for _, ply in ipairs( player.GetAll() ) do
  293.             for _, pm in ipairs( name2 ) do
  294.                 if ( evolve:IsNameMatch( ply, pm ) and !table.HasValue( matches, ply ) and ( noimmunity or !def or def:EV_BetterThanOrEqual( ply ) ) ) then table.insert( matches, ply ) end
  295.             end
  296.         end
  297.     end
  298.    
  299.     return matches
  300. end
  301.  
  302. function evolve:CreatePlayerList( tbl, notall )
  303.     local lst = ""
  304.     local lword = "and"
  305.     if ( notall ) then lword = "or" end
  306.    
  307.     if ( #tbl == 1 ) then
  308.         lst = tbl[1]:Nick()
  309.     elseif ( #tbl == #player.GetAll() ) then
  310.         lst = "everyone"
  311.     else
  312.         for i = 1, #tbl do
  313.             if ( i == #tbl ) then lst = lst .. " " .. lword .. " " .. tbl[i]:Nick() elseif ( i == 1 ) then lst = tbl[i]:Nick() else lst = lst .. ", " .. tbl[i]:Nick() end
  314.         end
  315.     end
  316.    
  317.     return lst
  318. end
  319.  
  320. /*-------------------------------------------------------------------------------------------------------------------------
  321.     Ranks
  322. -------------------------------------------------------------------------------------------------------------------------*/
  323.  
  324. function _R.Player:EV_IsRespected()
  325.     return self:EV_GetRank() == "respected" or self:EV_IsAdmin()
  326. end
  327.  
  328. function _R.Player:EV_IsAdmin()
  329.     return self:EV_GetRank() == "admin" or self:IsAdmin() or self:EV_IsSuperAdmin()
  330. end
  331.  
  332. function _R.Player:EV_IsSuperAdmin()
  333.     return self:EV_GetRank() == "superadmin" or self:IsSuperAdmin() or self:EV_IsOwner()
  334. end
  335.  
  336. function _R.Player:EV_IsOwner()
  337.     if ( SERVER ) then
  338.         return self:EV_GetRank() == "owner" or self:IsListenServerHost()
  339.     else
  340.         return self:EV_GetRank() == "owner"
  341.     end
  342. end
  343.  
  344. function _R.Player:EV_IsRank( rank )
  345.     return self:EV_GetRank() == rank
  346. end
  347.  
  348. /*-------------------------------------------------------------------------------------------------------------------------
  349.     Console
  350. -------------------------------------------------------------------------------------------------------------------------*/
  351.  
  352. function _R.Entity:Nick() if ( !self:IsValid() ) then return "Console" end end
  353. function _R.Entity:EV_IsRespected() if ( !self:IsValid() ) then return true end end
  354. function _R.Entity:EV_IsAdmin() if ( !self:IsValid() ) then return true end end
  355. function _R.Entity:EV_IsSuperAdmin() if ( !self:IsValid() ) then return true end end
  356. function _R.Entity:EV_IsOwner() if ( !self:IsValid() ) then return true end end
  357. function _R.Entity:EV_GetRank() if ( !self:IsValid() ) then return "owner" end end
  358. function _R.Entity:UniqueID() if ( !self:IsValid() ) then return 0 end end
  359.  
  360. /*-------------------------------------------------------------------------------------------------------------------------
  361.     Player information
  362. -------------------------------------------------------------------------------------------------------------------------*/
  363.  
  364. function evolve:LoadPlayerInfo()
  365.     if ( file.Exists( "ev_playerinfo.txt" ) ) then
  366.         debug.sethook()
  367.         self.PlayerInfo = glon.decode( file.Read( "ev_playerinfo.txt" ) )
  368.     else
  369.         self.PlayerInfo = {}
  370.     end
  371. end
  372. evolve:LoadPlayerInfo()
  373.  
  374. function evolve:SavePlayerInfo()
  375.     file.Write( "ev_playerinfo.txt", glon.encode( self.PlayerInfo ) )
  376. end
  377.  
  378. function _R.Player:GetProperty( id, defaultvalue ) 
  379.     if ( evolve.PlayerInfo[ self:UniqueID() ] ) then
  380.         return evolve.PlayerInfo[ self:UniqueID() ][ id ] or defaultvalue
  381.     else
  382.         return defaultvalue
  383.     end
  384. end
  385.  
  386. function _R.Player:SetProperty( id, value )
  387.     if ( !evolve.PlayerInfo[ self:UniqueID() ] ) then evolve.PlayerInfo[ self:UniqueID() ] = {} end
  388.    
  389.     evolve.PlayerInfo[ self:UniqueID() ][ id ] = value
  390. end
  391.  
  392. function evolve:UniqueIDByProperty( property, value, exact )   
  393.     for k, v in pairs( evolve.PlayerInfo ) do
  394.         if ( v[ property ] == value ) then
  395.             return k
  396.         elseif ( !exact and string.find( string.lower( v[ property ] or "" ), string.lower( value ) ) ) then
  397.             return k
  398.         end
  399.     end
  400. end
  401.  
  402. function evolve:GetProperty( uniqueid, id, defaultvalue )
  403.     uniqueid = tostring( uniqueid )
  404.    
  405.     if ( evolve.PlayerInfo[ uniqueid ] ) then
  406.         return evolve.PlayerInfo[ uniqueid ][ id ] or defaultvalue
  407.     else
  408.         return defaultvalue
  409.     end
  410. end
  411.  
  412. function evolve:SetProperty( uniqueid, id, value )
  413.     uniqueid = tostring( uniqueid )
  414.     if ( !evolve.PlayerInfo[ uniqueid ] ) then evolve.PlayerInfo[ uniqueid ] = {} end
  415.    
  416.     evolve.PlayerInfo[ uniqueid ][ id ] = value
  417. end
  418.  
  419. function evolve:CommitProperties()
  420.     /*-------------------------------------------------------------------------------------------------------------------------
  421.         Check if a cleanup would be convenient
  422.     -------------------------------------------------------------------------------------------------------------------------*/
  423.    
  424.     local count = table.Count( evolve.PlayerInfo )
  425.    
  426.     if ( count > 800 ) then
  427.         local original = count
  428.         local info = {}
  429.         for uid, entry in pairs( evolve.PlayerInfo ) do
  430.             table.insert( info, { UID = uid, LastJoin = entry.LastJoin, Rank = entry.Rank } )
  431.         end
  432.         table.SortByMember( info, "LastJoin", function(a, b) return a > b end )
  433.        
  434.         for _, entry in pairs( info ) do
  435.             if ( ( !entry.BanEnd or entry.BanEnd < os.time() ) and ( !entry.Rank or entry.Rank == "guest" ) ) then
  436.                 evolve.PlayerInfo[ entry.UID ] = nil
  437.                 count = count - 1
  438.                 if ( count < 800 ) then break end
  439.             end
  440.         end
  441.        
  442.         evolve:Message( "Cleaned up " .. original - count .. " players." )
  443.     end
  444.    
  445.     evolve:SavePlayerInfo()
  446. end
  447.  
  448. /*-------------------------------------------------------------------------------------------------------------------------
  449.     Entity ownership
  450. -------------------------------------------------------------------------------------------------------------------------*/
  451.  
  452. hook.Add( "PlayerSpawnedProp", "EV_SpawnHook", function( ply, model, ent ) ent.EV_Owner = ply:UniqueID() evolve:Log( evolve:PlayerLogStr( ply ) .. " spawned prop '" .. model .. "'." ) end )
  453. hook.Add( "PlayerSpawnedSENT", "EV_SpawnHook", function( ply, ent ) ent.EV_Owner = ply:UniqueID() evolve:Log( evolve:PlayerLogStr( ply ) .. " spawned scripted entity '" .. ent:GetClass() .. "'." ) end )
  454. hook.Add( "PlayerSpawnedNPC", "EV_SpawnHook", function( ply, ent ) ent.EV_Owner = ply:UniqueID() evolve:Log( evolve:PlayerLogStr( ply ) .. " spawned npc '" .. ent:GetClass() .. "'." ) end )
  455. hook.Add( "PlayerSpawnedVehicle", "EV_SpawnHook", function( ply, ent ) ent.EV_Owner = ply:UniqueID() evolve:Log( evolve:PlayerLogStr( ply ) .. " spawned vehicle '" .. ent:GetClass() .. "'." ) end )
  456. hook.Add( "PlayerSpawnedEffect", "EV_SpawnHook", function( ply, model, ent ) ent.EV_Owner = ply:UniqueID() evolve:Log( evolve:PlayerLogStr( ply ) .. " spawned effect '" .. model .. "'." ) end )
  457. hook.Add( "PlayerSpawnedRagdoll", "EV_SpawnHook", function( ply, model, ent ) ent.EV_Owner = ply:UniqueID() evolve:Log( evolve:PlayerLogStr( ply ) .. " spawned ragdoll '" .. model .. "'." ) end )
  458.  
  459. evolve.AddCount = _R.Player.AddCount
  460. function _R.Player:AddCount( type, ent )
  461.     ent.EV_Owner = self:UniqueID()
  462.     return evolve.AddCount( self, type, ent )
  463. end
  464.  
  465. evolve.CleanupAdd = cleanup.Add
  466. function cleanup.Add( ply, type, ent )
  467.     if ( ent ) then ent.EV_Owner = ply:UniqueID() end
  468.     return evolve.CleanupAdd( ply, type, ent )
  469. end
  470.  
  471. function _R.Entity:EV_GetOwner()
  472.     return self.EV_Owner
  473. end
  474.  
  475. /*-------------------------------------------------------------------------------------------------------------------------
  476.     Ranks
  477. -------------------------------------------------------------------------------------------------------------------------*/
  478.  
  479. // COMPATIBILITY
  480. evolve.compatibilityRanks = glon.decode( file.Read( "ev_ranks.txt" ) )
  481. // COMPATIBILITY
  482.  
  483. function _R.Player:EV_HasPrivilege( priv )
  484.     if ( evolve.ranks[ self:EV_GetRank() ] ) then
  485.         return self:EV_GetRank() == "owner" or table.HasValue( evolve.ranks[ self:EV_GetRank() ].Privileges, priv )
  486.     else
  487.         return false
  488.     end
  489. end
  490.  
  491. function _R.Entity:EV_BetterThan( ply )
  492.     return true
  493. end
  494.  
  495. function _R.Entity:EV_BetterThanOrEqual( ply )
  496.     return true
  497. end
  498.  
  499. function _R.Player:EV_BetterThan( ply )
  500.     return tonumber( evolve.ranks[ self:EV_GetRank() ].Immunity ) > tonumber( evolve.ranks[ ply:EV_GetRank() ].Immunity ) or self == ply
  501. end
  502.  
  503. function _R.Player:EV_BetterThanOrEqual( ply )
  504.     return tonumber( evolve.ranks[ self:EV_GetRank() ].Immunity ) >= tonumber( evolve.ranks[ ply:EV_GetRank() ].Immunity )
  505. end
  506.  
  507. function _R.Entity:EV_HasPrivilege( priv )
  508.     if ( self == NULL ) then return true end
  509. end
  510.  
  511. function _R.Entity:EV_BetterThan( ply )
  512.     if ( self == NULL ) then return true end
  513. end
  514.  
  515. function _R.Player:EV_SetRank( rank )
  516.     self:SetProperty( "Rank", rank )
  517.     evolve:CommitProperties()
  518.    
  519.     self:SetNWString( "EV_UserGroup", rank )
  520.    
  521.     evolve:RankGroup( self, rank )
  522.    
  523.     if ( self:EV_HasPrivilege( "Ban menu" ) ) then
  524.         evolve:SyncBans( self )
  525.     end
  526. end
  527.  
  528. function _R.Player:EV_GetRank()
  529.     if ( SERVER and self:IsListenServerHost() ) then return "owner" end
  530.    
  531.     local rank
  532.    
  533.     if ( SERVER ) then
  534.         rank = self:GetProperty( "Rank", "guest" )
  535.     else
  536.         rank = self:GetNWString( "EV_UserGroup", "guest" )
  537.     end
  538.    
  539.     if ( evolve.ranks[ rank ] ) then
  540.         return rank
  541.     else
  542.         return "guest"
  543.     end
  544. end
  545.  
  546. function evolve:RankGroup( ply, rank )
  547.     ply:SetUserGroup( evolve.ranks[ rank ].UserGroup )
  548. end
  549.  
  550. function evolve:Rank( ply )
  551.     if ( !ply:IsValid() ) then return end
  552.    
  553.     self:TransferPrivileges( ply )
  554.     self:TransferRanks( ply )
  555.    
  556.     if ( ply:IsListenServerHost() ) then ply:SetNWString( "EV_UserGroup", "owner" ) ply:SetNWString( "UserGroup", "superadmin" ) return end
  557.    
  558.     local usergroup = ply:GetNWString( "UserGroup", "guest" )
  559.     if ( usergroup == "user" ) then usergroup = "guest" end
  560.     ply:SetNWString( "EV_UserGroup", usergroup )
  561.    
  562.     local rank = ply:GetProperty( "Rank" )
  563.     if ( rank and evolve.ranks[ rank ] ) then
  564.         ply:SetNWString( "EV_UserGroup", rank )
  565.         usergroup = rank
  566.     else
  567.         // COMPATIBILITY
  568.         if ( evolve.compatibilityRanks ) then
  569.             for _, ranks in ipairs( evolve.compatibilityRanks ) do
  570.                 if ( ranks.steamID == ply:SteamID() ) then
  571.                     rank = ranks.rank
  572.                    
  573.                     ply:SetNWString( "EV_UserGroup", rank )
  574.                     usergroup = rank
  575.                    
  576.                     ply:SetProperty( "Rank", rank )
  577.                     evolve:CommitProperties()
  578.                    
  579.                     break
  580.                 end
  581.             end
  582.         end
  583.         // COMPATIBILITY
  584.     end
  585.    
  586.     if ( ply:EV_HasPrivilege( "Ban menu" ) ) then
  587.         evolve:SyncBans( ply )
  588.     end
  589.    
  590.     evolve:RankGroup( ply, usergroup )
  591. end
  592.  
  593. hook.Add( "PlayerSpawn", "EV_RankHook", function( ply )
  594.     if ( !ply.EV_Ranked ) then
  595.         ply:SetNWString( "EV_UserGroup", ply:GetProperty( "Rank", "guest" ) )
  596.        
  597.         timer.Simple( 1, function()
  598.             evolve:Rank( ply )
  599.         end )
  600.         ply.EV_Ranked = true
  601.     end
  602. end )
  603.  
  604. /*-------------------------------------------------------------------------------------------------------------------------
  605.     Rank management
  606. -------------------------------------------------------------------------------------------------------------------------*/
  607.  
  608. function evolve:SaveRanks()
  609.     file.Write( "ev_userranks.txt", glon.encode( evolve.ranks ) )
  610. end
  611.  
  612. function evolve:LoadRanks()
  613.     if ( file.Exists( "ev_userranks.txt" ) ) then
  614.         evolve.ranks = glon.decode( file.Read( "ev_userranks.txt" ) )
  615.     else
  616.         include( "ev_defaultranks.lua" )
  617.         evolve:SaveRanks()
  618.     end
  619. end
  620.  
  621. if ( SERVER ) then evolve:LoadRanks() end
  622.  
  623. function evolve:SyncRanks()
  624.     for _, pl in ipairs( player.GetAll() ) do evolve:TransferRanks( pl ) end
  625. end
  626.  
  627. function evolve:TransferPrivileges( ply )
  628.     if ( !ply:IsValid() ) then return end
  629.    
  630.     for id, privilege in ipairs( evolve.privileges ) do
  631.         umsg.Start( "EV_Privilege", ply )
  632.             umsg.Short( id )
  633.             umsg.String( privilege )
  634.         umsg.End()
  635.     end
  636. end
  637.  
  638. function evolve:TransferRank( ply, rank )
  639.     if ( !ply:IsValid() ) then return end
  640.    
  641.     local data = evolve.ranks[ rank ]
  642.     local color = data.Color
  643.    
  644.     umsg.Start( "EV_Rank", ply )           
  645.         umsg.String( rank )
  646.         umsg.String( data.Title )
  647.         umsg.String( data.Icon )
  648.         umsg.String( data.UserGroup )
  649.         umsg.Short( data.Immunity )
  650.        
  651.         if ( color ) then
  652.             umsg.Bool( true )
  653.             umsg.Short( color.r )
  654.             umsg.Short( color.g )
  655.             umsg.Short( color.b )
  656.         else
  657.             umsg.Bool( false )
  658.         end
  659.     umsg.End()
  660.    
  661.     local privs = #( data.Privileges or {} )
  662.     local count
  663.    
  664.     for i = 1, privs, 100 do
  665.         count = math.min( privs, i + 99 ) - i
  666.        
  667.         umsg.Start( "EV_RankPrivileges", ply )
  668.             umsg.String( rank )
  669.             umsg.Short( count )
  670.            
  671.             for ii = i, i + count do
  672.                 umsg.Short( evolve:KeyByValue( evolve.privileges, data.Privileges[ii], ipairs ) )
  673.             end
  674.         umsg.End()
  675.     end
  676. end
  677.  
  678. function evolve:TransferRanks( ply )
  679.     for id, data in pairs( evolve.ranks ) do
  680.         evolve:TransferRank( ply, id )
  681.     end
  682. end
  683.  
  684. usermessage.Hook( "EV_Rank", function( um )
  685.     local id = string.lower( um:ReadString() )
  686.     local title = um:ReadString()
  687.     local created = evolve.ranks[id] == nil
  688.    
  689.     evolve.ranks[id] = {
  690.         Title = title,
  691.         Icon = um:ReadString(),
  692.         UserGroup = um:ReadString(),
  693.         Immunity = um:ReadShort(),
  694.         Privileges = {},
  695.     }
  696.    
  697.     if ( um:ReadBool() ) then
  698.         evolve.ranks[id].Color = Color( um:ReadShort(), um:ReadShort(), um:ReadShort() )
  699.     end
  700.    
  701.     evolve.ranks[id].IconTexture = surface.GetTextureID( "gui/silkicons/" .. evolve.ranks[id].Icon )
  702.    
  703.     if ( created ) then
  704.         hook.Call( "EV_RankCreated", nil, id )
  705.     else
  706.         hook.Call( "EV_RankUpdated", nil, id )
  707.     end
  708. end )
  709.  
  710. usermessage.Hook( "EV_Privilege", function( um )
  711.     local id = um:ReadShort()
  712.     local name = um:ReadString()
  713.    
  714.     evolve.privileges[ id ] = name
  715. end )
  716.  
  717. usermessage.Hook( "EV_RankPrivileges", function( um )
  718.     local rank = um:ReadString()
  719.     local privilegeCount = um:ReadShort()
  720.    
  721.     for i = 1, privilegeCount do
  722.         table.insert( evolve.ranks[ rank ].Privileges, evolve.privileges[ um:ReadShort() ] )
  723.     end
  724. end )
  725.  
  726. usermessage.Hook( "EV_RemoveRank", function( um )
  727.     local rank = um:ReadString()
  728.     hook.Call( "EV_RankRemoved", nil, rank )
  729.     evolve.ranks[ rank ] = nil
  730. end )
  731.  
  732. usermessage.Hook( "EV_RenameRank", function( um )
  733.     local rank = um:ReadString():lower()
  734.     evolve.ranks[ rank ].Title = um:ReadString()
  735.    
  736.     hook.Call( "EV_RankRenamed", nil, rank, evolve.ranks[ rank ].Title )
  737. end )
  738.  
  739. usermessage.Hook( "EV_RankPrivilege", function( um )
  740.     local rank = um:ReadString()
  741.     local priv = evolve.privileges[ um:ReadShort() ]
  742.     local enabled = um:ReadBool()
  743.    
  744.     if ( enabled ) then
  745.         table.insert( evolve.ranks[ rank ].Privileges, priv )
  746.     else
  747.         table.remove( evolve.ranks[ rank ].Privileges, evolve:KeyByValue( evolve.ranks[ rank ].Privileges, priv ) )
  748.     end
  749.    
  750.     hook.Call( "EV_RankPrivilegeChange", nil, rank, priv, enabled )
  751. end )
  752.  
  753. usermessage.Hook( "EV_RankPrivilegeAll", function( um )
  754.     local rank = um:ReadString()
  755.     local enabled = um:ReadBool()
  756.     local filter = um:ReadString()
  757.    
  758.     if ( enabled ) then
  759.         for _, priv in ipairs( evolve.privileges ) do
  760.             if ( ( ( #filter == 0 and !string.match( priv, "[@:#]" ) ) or string.Left( priv, 1 ) == filter ) and !table.HasValue( evolve.ranks[rank].Privileges, priv ) ) then             
  761.                 hook.Call( "EV_RankPrivilegeChange", nil, rank, priv, true )
  762.                 table.insert( evolve.ranks[ rank ].Privileges, priv )
  763.             end
  764.         end
  765.     else
  766.         local i = 1
  767.        
  768.         while ( i <= #evolve.ranks[rank].Privileges ) do
  769.             if ( ( #filter == 0 and !string.match( evolve.ranks[rank].Privileges[i], "[@:#]" ) ) or string.Left( evolve.ranks[rank].Privileges[i], 1 ) == filter ) then
  770.                 hook.Call( "EV_RankPrivilegeChange", nil, rank, evolve.ranks[rank].Privileges[i], false )
  771.                 table.remove( evolve.ranks[rank].Privileges, i )
  772.             else
  773.                 i = i + 1
  774.             end
  775.         end
  776.     end
  777. end )
  778.  
  779. /*-------------------------------------------------------------------------------------------------------------------------
  780.     Rank modification
  781. -------------------------------------------------------------------------------------------------------------------------*/
  782.  
  783. if ( SERVER ) then
  784.     concommand.Add( "ev_renamerank", function( ply, com, args )
  785.         if ( ply:EV_HasPrivilege( "Rank modification" ) ) then
  786.             if ( #args > 1 and evolve.ranks[ args[1] ] ) then
  787.                 evolve:Notify( evolve.colors.red, ply:Nick(), evolve.colors.white, " has renamed ", evolve.colors.blue, evolve.ranks[ args[1] ].Title, evolve.colors.white, " to ", evolve.colors.blue, table.concat( args, " ", 2 ), evolve.colors.white, "." )
  788.                
  789.                 evolve.ranks[ args[1] ].Title = table.concat( args, " ", 2 )
  790.                 evolve:SaveRanks()
  791.                
  792.                 umsg.Start( "EV_RenameRank" )
  793.                     umsg.String( args[1] )
  794.                     umsg.String( evolve.ranks[ args[1] ].Title )
  795.                 umsg.End()
  796.             end
  797.         end
  798.     end )
  799.    
  800.     concommand.Add( "ev_setrank", function( ply, com, args )
  801.         if ( ply:EV_HasPrivilege( "Rank modification" ) ) then
  802.             if ( #args == 3 and args[1] != "owner" and evolve.ranks[ args[1] ] and table.HasValue( evolve.privileges, args[2] ) and tonumber( args[3] ) ) then
  803.                 local rank = args[1]
  804.                 local privilege = args[2]
  805.                
  806.                 if ( tonumber( args[3] ) == 1 ) then
  807.                     if ( !table.HasValue( evolve.ranks[ rank ].Privileges, privilege ) ) then
  808.                         table.insert( evolve.ranks[ rank ].Privileges, privilege )
  809.                     end
  810.                 else
  811.                     if ( table.HasValue( evolve.ranks[ rank ].Privileges, privilege ) ) then
  812.                         table.remove( evolve.ranks[ rank ].Privileges, evolve:KeyByValue( evolve.ranks[ rank ].Privileges, privilege ) )
  813.                     end
  814.                 end
  815.                
  816.                 evolve:SaveRanks()
  817.                
  818.                 umsg.Start( "EV_RankPrivilege" )
  819.                     umsg.String( rank )
  820.                     umsg.Short( evolve:KeyByValue( evolve.privileges, privilege ) )
  821.                     umsg.Bool( tonumber( args[3] ) == 1 )
  822.                 umsg.End()
  823.             elseif ( #args >= 2 and evolve.ranks[ args[1] ] and tonumber( args[2] ) and ( !args[3] or #args[3] == 1 ) ) then
  824.                 local rank = args[1]
  825.                
  826.                 if ( tonumber( args[2] ) == 1 ) then                   
  827.                     for _, priv in ipairs( evolve.privileges ) do
  828.                         if ( ( ( !args[3] and !string.match( priv, "[@:#]" ) ) or string.Left( priv, 1 ) == args[3] ) and !table.HasValue( evolve.ranks[ rank ].Privileges, priv ) ) then
  829.                             table.insert( evolve.ranks[ rank ].Privileges, priv )
  830.                         end
  831.                     end
  832.                 else
  833.                     local i = 1
  834.                    
  835.                     while ( i <= #evolve.ranks[rank].Privileges ) do
  836.                         if ( ( !args[3] and !string.match( evolve.ranks[rank].Privileges[i], "[@:#]" ) ) or string.Left( evolve.ranks[rank].Privileges[i], 1 ) == args[3] ) then
  837.                             table.remove( evolve.ranks[rank].Privileges, i )
  838.                         else
  839.                             i = i + 1
  840.                         end
  841.                     end
  842.                 end
  843.                
  844.                 evolve:SaveRanks()
  845.                
  846.                 umsg.Start( "EV_RankPrivilegeAll" )
  847.                     umsg.String( rank )
  848.                     umsg.Bool( tonumber( args[2] ) == 1 )
  849.                     umsg.String( args[3] or "" )
  850.                 umsg.End()
  851.             end
  852.         end
  853.     end )
  854.    
  855.     concommand.Add( "ev_setrankp", function( ply, com, args )
  856.         if ( ply:EV_HasPrivilege( "Rank modification" ) ) then
  857.             if ( #args == 6 and tonumber( args[2] ) and evolve.ranks[ args[1] ] and ( args[3] == "guest" or args[3] == "admin" or args[3] == "superadmin" ) and tonumber( args[4] ) and tonumber( args[5] ) and tonumber( args[6] ) ) then                     
  858.                 if ( args[1] != "owner" ) then
  859.                     evolve.ranks[ args[1] ].Immunity = tonumber( args[2] )
  860.                     evolve.ranks[ args[1] ].UserGroup = args[3]
  861.                 end
  862.                
  863.                 evolve.ranks[ args[1] ].Color = Color( args[4], args[5], args[6] )
  864.                 evolve:SaveRanks()
  865.                
  866.                 for _, pl in ipairs( player.GetAll() ) do
  867.                         evolve:TransferRank( pl, args[1] )
  868.                        
  869.                         if ( args[1] != "owner" and pl:EV_GetRank() == args[1] ) then
  870.                             pl:SetNWString( "UserGroup", args[3] )
  871.                         end
  872.                     end
  873.             end
  874.         end
  875.     end )
  876.    
  877.     concommand.Add( "ev_removerank", function( ply, com, args )
  878.         if ( ply:EV_HasPrivilege( "Rank modification" ) ) then
  879.             if ( args[1] != "guest" and args[1] != "owner" and evolve.ranks[ args[1] ] ) then
  880.                 evolve:Notify( evolve.colors.red, ply:Nick(), evolve.colors.white, " has removed the rank ", evolve.colors.blue, evolve.ranks[ args[1] ].Title, evolve.colors.white, "." )
  881.                
  882.                 evolve.ranks[ args[1] ] = nil
  883.                 evolve:SaveRanks()
  884.                
  885.                 for _, pl in ipairs( player.GetAll() ) do
  886.                     if ( pl:EV_GetRank() == args[1] ) then
  887.                         pl:EV_SetRank( "guest" )
  888.                     end
  889.                 end
  890.                
  891.                 umsg.Start( "EV_RemoveRank" )
  892.                     umsg.String( args[1] )
  893.                 umsg.End()
  894.             end
  895.         end
  896.     end )
  897.    
  898.     concommand.Add( "ev_createrank", function( ply, com, args )
  899.         if ( ply:EV_HasPrivilege( "Rank modification" ) ) then
  900.             if ( ( #args == 2 or #args == 3 ) and !string.find( args[1], " " ) and string.lower( args[1] ) == args[1] and !evolve.ranks[ args[1] ] ) then
  901.                 if ( #args == 2 ) then
  902.                     evolve.ranks[ args[1] ] = {
  903.                         Title = args[2],
  904.                         Icon = "user",
  905.                         UserGroup = "guest",
  906.                         Immunity = 0,
  907.                         Privileges = {},
  908.                     }
  909.                 elseif ( #args == 3 and evolve.ranks[ args[3] ] ) then
  910.                     local parent = evolve.ranks[ args[3] ]
  911.                    
  912.                     evolve.ranks[ args[1] ] = {
  913.                         Title = args[2],
  914.                         Icon = parent.Icon,
  915.                         UserGroup = parent.UserGroup,
  916.                         Immunity = tonumber( parent.Immunity ),
  917.                         Privileges = table.Copy( parent.Privileges ),
  918.                     }
  919.                 end
  920.                
  921.                 evolve:SaveRanks()
  922.                 evolve:SyncRanks()
  923.                
  924.                 evolve:Notify( evolve.colors.red, ply:Nick(), evolve.colors.white, " has created the rank ", evolve.colors.blue, args[2], evolve.colors.white, "." )
  925.             end
  926.         end
  927.     end )
  928. end
  929.  
  930. /*-------------------------------------------------------------------------------------------------------------------------
  931.     Banning
  932. -------------------------------------------------------------------------------------------------------------------------*/
  933.  
  934. if ( SERVER ) then
  935.     function evolve:SyncBans( ply )
  936.         for uniqueid, info in pairs( evolve.PlayerInfo ) do
  937.             if ( info.BanEnd and ( info.BanEnd > os.time() or info.BanEnd == 0 ) ) then
  938.                 local time = info.BanEnd - os.time()
  939.                 if ( info.BanEnd == 0 ) then time = 0 end
  940.                 SendUserMessage( "EV_BanEntry", ply, tostring( uniqueid ), info.Nick, info.SteamID, info.BanReason, evolve:GetProperty( info.BanAdmin, "Nick" ), time )
  941.             end
  942.         end
  943.     end
  944.    
  945.     function evolve:Ban( uid, length, reason, adminuid )       
  946.         if ( length == 0 ) then length = -os.time() end
  947.        
  948.         evolve:SetProperty( uid, "BanEnd", os.time() + length )
  949.         evolve:SetProperty( uid, "BanReason", reason )
  950.         evolve:SetProperty( uid, "BanAdmin", adminuid )
  951.         evolve:CommitProperties()
  952.        
  953.         local a = "Console"
  954.         if ( adminuid != 0 ) then a = player.GetByUniqueID( adminuid ):Nick() end
  955.         SendUserMessage( "EV_BanEntry", nil, uid, evolve:GetProperty( uid, "Nick" ), evolve:GetProperty( uid, "SteamID" ), reason, a, length )
  956.        
  957.         -- Let SourceBans do the kicking or Evolve
  958.         if ( sourcebans ) then
  959.             local admin
  960.             if ( adminuid != 0 ) then admin = player.GetByUniqueID( adminuid ) end
  961.            
  962.             sourcebans.BanPlayerBySteamIDAndIP( evolve:GetProperty( uid, "SteamID" ), evolve:GetProperty( uid, "IPAddress" ) or "", math.max( 0, length ), reason, admin, evolve:GetProperty( uid, "Nick" ) )
  963.         else
  964.             local pl
  965.             if ( uid != 0 ) then pl = player.GetByUniqueID( uid ) end
  966.            
  967.             if ( pl ) then
  968.                 game.ConsoleCommand( "banid " .. length / 60 .. " " .. pl:SteamID() .. "\n" )
  969.                
  970.                 if ( length < 0 ) then
  971.                     pl:Kick( "Permabanned! (" .. reason .. ")" )
  972.                 else
  973.                     pl:Kick( "Banned for " .. length / 60 .. " minutes! (" .. reason .. ")" )
  974.                 end
  975.             else
  976.                 game.ConsoleCommand( "addip " .. length / 60 .. " \"" .. string.match( evolve:GetProperty( uid, "IPAddress" ), "(%d+%.%d+%.%d+%.%d+)" ) .. "\"\n" )
  977.             end
  978.         end
  979.     end
  980.    
  981.     function evolve:UnBan( uid, adminuid )     
  982.         evolve:SetProperty( uid, "BanEnd", nil )
  983.         evolve:SetProperty( uid, "BanReason", nil )
  984.         evolve:SetProperty( uid, "BanAdmin", nil )
  985.         evolve:CommitProperties()
  986.        
  987.         SendUserMessage( "EV_RemoveBanEntry", nil, tostring( uid ) )
  988.        
  989.         if ( sourcebans ) then
  990.             local admin
  991.             if ( adminuid != 0 ) then admin = player.GetByUniqueID( adminuid ) end
  992.            
  993.             sourcebans.UnbanPlayerBySteamID( evolve:GetProperty( uid, "SteamID" ), "No reason specified.", admin )
  994.         else
  995.             game.ConsoleCommand( "removeip \"" .. evolve:GetProperty( uid, "IPAddress" ) .. "\"\n" )
  996.             game.ConsoleCommand( "removeid " .. evolve:GetProperty( uid, "SteamID" ) .. "\n" )
  997.         end
  998.     end
  999.    
  1000.     function evolve:IsBanned( uid )
  1001.         local banEnd = evolve:GetProperty( uid, "BanEnd" )
  1002.        
  1003.         if ( banEnd and os.time() > banEnd ) then
  1004.             evolve:UnBan( uid )
  1005.             return false
  1006.         end
  1007.        
  1008.         return banEnd and ( banEnd > os.time() or banEnd == 0 )
  1009.     end
  1010. else
  1011.     usermessage.Hook( "EV_BanEntry", function( um )
  1012.         if ( !evolve.bans ) then evolve.bans = {} end
  1013.        
  1014.         local id = um:ReadString()
  1015.         evolve.bans[id] =  {
  1016.             Nick = um:ReadString(),
  1017.             SteamID = um:ReadString(),
  1018.             Reason = um:ReadString(),
  1019.             Admin = um:ReadString()
  1020.         }
  1021.        
  1022.         local time = um:ReadLong()
  1023.         if ( time > 0 ) then
  1024.             evolve.bans[id].End = time + os.time()
  1025.         else
  1026.             evolve.bans[id].End = 0
  1027.         end
  1028.        
  1029.         hook.Call( "EV_BanAdded", nil, id )    
  1030.     end )
  1031.    
  1032.     usermessage.Hook( "EV_RemoveBanEntry", function( um )
  1033.         if ( !evolve.bans ) then return end
  1034.        
  1035.         local id = um:ReadString()
  1036.         hook.Call( "EV_BanRemoved", nil, id )
  1037.         evolve.bans[id] = nil
  1038.     end )
  1039. end
  1040.  
  1041. /*-------------------------------------------------------------------------------------------------------------------------
  1042.     Global data system
  1043. -------------------------------------------------------------------------------------------------------------------------*/
  1044.  
  1045. function evolve:SaveGlobalVars()
  1046.     file.Write( "ev_globalvars.txt", glon.encode( evolve.globalvars ) )
  1047. end
  1048.  
  1049. function evolve:LoadGlobalVars()
  1050.     if ( file.Exists( "ev_globalvars.txt" ) ) then
  1051.         evolve.globalvars = glon.decode( file.Read( "ev_globalvars.txt" ) )
  1052.     else
  1053.         evolve.globalvars = {}
  1054.         evolve:SaveGlobalVars()
  1055.     end
  1056. end
  1057. evolve:LoadGlobalVars()
  1058.  
  1059. function evolve:SetGlobalVar( name, value )
  1060.     evolve.globalvars[name] = value
  1061.     evolve:SaveGlobalVars()
  1062. end
  1063.  
  1064. function evolve:GetGlobalVar( name, default )
  1065.     return evolve.globalvars[name] or default
  1066. end
  1067.  
  1068. /*-------------------------------------------------------------------------------------------------------------------------
  1069.     Log system
  1070. -------------------------------------------------------------------------------------------------------------------------*/
  1071.  
  1072. function evolve:Log( str )
  1073.     if ( CLIENT ) then return end
  1074.    
  1075.     local logFile = "ev_logs/" .. os.date( "%d-%m-%Y" ) .. ".txt"
  1076.     local files = file.Find( "ev_logs/" .. os.date( "%d-%m-%Y" ) .. "*.txt" )
  1077.     table.sort( files )
  1078.     if ( #files > 0 ) then logFile = "ev_logs/" .. files[math.max(#files-1,1)] end
  1079.    
  1080.     local src = file.Read( logFile ) or ""
  1081.     if ( #src > 200 * 1024 ) then
  1082.         logFile = "ev_logs/" .. os.date( "%d-%m-%Y" ) .. " (" .. #files + 1 .. ").txt"
  1083.     end
  1084.    
  1085.     filex.Append( logFile, "[" .. os.date() .. "] " .. str .. "\n" )
  1086. end
  1087.  
  1088. function evolve:PlayerLogStr( ply )
  1089.     if ( ply:IsValid() ) then
  1090.         if ( ply:IsPlayer() ) then
  1091.             return ply:Nick() .. " [" .. ply:SteamID() .. "|" .. ply:IPAddress() .. "]"
  1092.         else
  1093.             return ply:GetClass()
  1094.         end
  1095.     else
  1096.         return "Console"
  1097.     end
  1098. end
  1099.  
  1100. hook.Add( "InitPostEntity", "EV_LogInit", function()
  1101.     evolve:Log( "== Started in map '" .. game.GetMap() .. "' and gamemode '" .. GAMEMODE.Name .. "' ==" )
  1102. end )
  1103.  
  1104. hook.Add( "PlayerDisconnected", "EV_LogDisconnect", function( ply )
  1105.     evolve:Log( evolve:PlayerLogStr( ply ) .. " disconnected from the server." )
  1106. end )
  1107.  
  1108. hook.Add( "PlayerInitialSpawn", "EV_LogSpawn", function( ply )
  1109.     evolve:Log( evolve:PlayerLogStr( ply ) .. " spawned for the first time this session." )
  1110. end )
  1111.  
  1112. hook.Add( "PlayerConnect", "EV_LogConnect", function( name, address )
  1113.     evolve:Log( name .. " [" .. address .. "] connected to the server." )
  1114. end )
  1115.  
  1116. hook.Add( "PlayerDeath", "EV_LogDeath", function( ply, inf, killer )
  1117.     if ( ply != killer ) then
  1118.         evolve:Log( evolve:PlayerLogStr( ply ) .. " was killed by " .. evolve:PlayerLogStr( killer ) .. "." )
  1119.     end
  1120. end )
  1121.  
  1122. hook.Add( "PlayerSay", "EV_PlayerChat", function( ply, txt )
  1123.     evolve:Log( evolve:PlayerLogStr( ply ) .. ": " ..  txt )
  1124. end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement