Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- gamemodes/egmrp/gamemode/shared.lua
- --]]
- ---------------------------------------
- ---------------------------------------
- -- Einfach Gaming Roleplay --
- -- (EGM:RP) --
- -- --
- -- Created by --
- -- Pascal 'P4sca1' Sthamer, --
- -- Jan 'Oninoni' Ziegler, --
- -- Konstantin 'Airfox' Zisiadis, --
- -- Mattis 'Mattzi' Krämer --
- -- --
- -- This software is only allowed --
- -- to be used with a valid license --
- -- --
- -- Copyright © 2018 Pascal Sthamer --
- ---------------------------------------
- ---------------------------------------
- ---------------------------------------
- -- Shared | Initialization --
- ---------------------------------------
- DeriveGamemode("sandbox")
- -- Gamemode variables
- GM.Name = "EGM:RP"
- GM.Author = "P4sca1, Oninoni, Mattzi, Konsti"
- GM.Email = "admin@einfach-gaming.de"
- GM.TeamBased = false
- GM.IsSandboxDerived = true
- GM.Website = "www.einfach-gaming.de"
- GM.Version = "1.13.0"
- GM.LoadedModules = {}
- include("eula.lua")
- -- Enter your License Key here.
- GM.LicenseKey = "LCwY8UaEglKy6BaEjLOCj5WmHpC6u8atStJilTTE3J3FD2elBcgBqr0wSOKANGE1"
- -- Load required files
- if SERVER then
- AddCSLuaFile("sh_config.lua")
- AddCSLuaFile("sh_utils.lua")
- include("sh_config.lua")
- include("sh_utils.lua")
- include("sv_content.lua")
- LogInfo("Loading DRM System ...")
- require("egmrp_drm")
- LogInfo("DRM System Loaded!")
- require("mysqloo")
- end
- if CLIENT then
- include("sh_config.lua")
- include("sh_utils.lua")
- end
- -------------------------------------------------------------------------------------------------------------------------------
- -- Important notice for using the GM and GAMEMODE table inside egmrp:
- --
- -- 1) The GM table only exists when a gamemode is currently being loaded (also on file refresh).
- -- It contains the gamemode table of the gamemode that is currently being loaded.
- -- 2) The GAMEMODE table does only exist after the active gamemode is loaded (PostGamemodeLoaded).
- -- It always contains the gamemode table of the active gamemode.
- -- 3) When calling a gamemode function, the one of the active gamemode is always used (not the one of any deriving gamemode),
- -- BUT when loading a derived gamemode, all it's gamemode functions are pushed to the active gamemode.
- -- So when refreshing a file in egmrp, all GM functions are pushed to GAMEMODE.
- -- Therefore we need to use GM for gamemode functions when a file got changed.
- -- The problem is that we can't use GM on initialize because it does not exist, because we are loading egmrp
- -- after the deriving gamemode (because the deriving gamemode contains info about which configs / modules to use).
- -- We have to use GAMEMODE for gamemode functions on initialize. That is the reason why we have to use
- -- `GM or GAMEMODE` when writing gamemode functions in egmrp.
- --
- -- => When GM exists, use this table because changes are pushed to GAMEMODE.
- -- Otherwise use GAMEMODE, because changes are not overwritten.
- --------------------------------------------------------------------------------------------------------------------------------
- GM.DRMLoadingTries = 0
- -- Load the gamemode including all core modules and activated modules.
- -- Called after the deriving gamemode was loaded (PostGamemodeLoaded) or
- -- when there was a file refresh.
- local function LoadGamemode()
- // This loads the DRM. The DRM Contains vital Functions so if it is not successfull the Gamemode cannot run and loading is aborted.
- if SERVER then
- local success, e = InitDRM()
- if not success then
- // Override Check Password to prevent Joining while loading Gamemode.
- GAMEMODE.OldCheckPassword = GAMEMODE.CheckPassword
- GAMEMODE.CheckPassword = function()
- return false, "Server startet noch!"
- end
- // If there are more than 10 tries sth is really going wrong.
- if GAMEMODE.DRMLoadingTries > 10 then
- LogWarning("DRM could not be Initialized. Please Contact our Support.")
- LogError(e)
- end
- GAMEMODE.DRMLoadingTries = GAMEMODE.DRMLoadingTries +1
- timer.Simple(1, LoadGamemode)
- return
- end
- // Reset to old Function
- if isfunction(GAMEMODE.OldCheckPassword) then
- GAMEMODE.CheckPassword = GAMEMODE.OldCheckPassword
- end
- end
- local folderName = GAMEMODE.FolderName
- local configPath = folderName .. "/gamemode/config/"
- -- Load gamemode config.
- if SERVER then
- AddCSLuaFile(configPath .. "gamemode.lua")
- include(configPath .. "gamemode.lua")
- else
- include(configPath .. "gamemode.lua")
- end
- -- Load Localization first.
- LoadModule("localization", true)
- -- Load core modules.
- LoadModule("sql", true)
- LoadModule("ui", true)
- LoadModule("scoreboard", true)
- LoadModule("notify", true)
- LoadModule("keybinds", true)
- LoadModule("eventlog", true)
- LoadModule("loading", true)
- LoadModule("propertymodel", true)
- LoadModule("player", true)
- LoadModule("chat", true)
- LoadModule("factionrank", true)
- LoadModule("character", true)
- LoadModule("deathsystem", true)
- LoadModule("whitelist", true)
- LoadModule("settings", true)
- LoadModule("joinmanager", true)
- -- Load activated modules.
- for module, activated in pairs(Config.Modules) do
- if activated then
- LoadModule(module)
- end
- end
- -- Overwrite module configs.
- local files = file.Find(configPath .. "*.lua", "LUA")
- for k, fileName in pairs(files) do
- local split = string.Split(string.StripExtension(fileName), "_")
- local realm = table.remove(split, 1)
- local module = string.Implode("", split)
- if module and IsModuleLoaded(module) then
- if realm == "sv" then
- if SERVER then
- include(configPath .. fileName)
- end
- elseif realm == "sh" then
- if SERVER then
- AddCSLuaFile(configPath .. fileName)
- end
- include(configPath .. fileName)
- elseif realm == "cl" then
- if SERVER then
- AddCSLuaFile(configPath .. fileName)
- end
- if CLIENT then
- include(configPath .. fileName)
- end
- end
- end
- end
- -- Load workshop content file.
- if file.Exists("gamemodes/" .. GAMEMODE.BaseClass.FolderName .. "/gamemode/sv_content.lua", "GAME") then
- include(GAMEMODE.BaseClass.FolderName .. "/gamemode/sv_content.lua")
- end
- if file.Exists("gamemodes/" .. GAMEMODE.FolderName .. "/gamemode/sv_content.lua", "GAME") then
- include(GAMEMODE.FolderName .. "/gamemode/sv_content.lua")
- end
- hook.Run("EGMRP.Loaded")
- end
- -- Initialize the deriving gamemode after it finished loading.
- hook.Add("PostGamemodeLoaded", "EGMRP.Load", function()
- LoadGamemode()
- end)
- -- Support file system refresh.
- -- Detect whether this is a file refresh or the first initialize (GAMEMODE will not be set on first initialize).
- if GAMEMODE then
- -- Set LoadedModules to an empty table, to force a refresh of all
- -- modules when reinitializing the derived gamemode.
- GAMEMODE.LoadedModules = {}
- LoadGamemode()
- end
- -- Lag fix. For more info: https://github.com/Facepunch/garrysmod-issues/issues/2902
- hook.Remove("PlayerTick", "TickWidgets")
- -- Another lag fix. For more info: https://steamcommunity.com/sharedfiles/filedetails/?id=622814666
- local table_insert = table.insert
- hook.Add( "OnEntityCreated", "seats_network_optimizer", function( seat )
- if seat:GetClass()=="prop_vehicle_prisoner_pod" then
- seat:AddEFlags( EFL_NO_THINK_FUNCTION ) -- disable seat's Think
- seat.seats_network_optimizer = true -- Now we know that this seat has been processed by this addon.
- end
- end )
- local i
- local seats
- local last_enabled -- previously processed seat
- -- This function enables the Think of one seat during each frame to save network traffic.
- -- The Think of seats is only needed for animation handling.
- hook.Add( "Think", "seats_network_optimizer", function()
- -- Make list:
- if not seats or not seats[i] then
- -- Begin a new loop, with a new seats list.
- i = 1
- seats = {}
- for _,seat in ipairs( ents.FindByClass( "prop_vehicle_prisoner_pod" ) ) do
- if seat.seats_network_optimizer then
- table.insert( seats, seat )
- end
- end
- end
- -- Find a valid seat:
- while seats[i] and not IsValid( seats[i] ) do
- -- Jump to the next valid seat.
- i = i+1
- end
- local seat = seats[i]
- -- Disable the previously processed seat's Think if ready:
- if last_enabled~=seat and IsValid( last_enabled ) then -- ignore a seat's Think that is gonna be re-enabled
- -- last_enabled's Think is kept enabled until m_bEnterAnimOn and m_bExitAnimOn are reset.
- local saved = last_enabled:GetSaveTable()
- if not saved["m_bEnterAnimOn"] and not saved["m_bExitAnimOn"] then
- last_enabled:AddEFlags( EFL_NO_THINK_FUNCTION ) -- disable last_enabled's Think
- last_enabled = nil
- end
- end
- -- Enable a seat's Think:
- if IsValid( seat ) then
- -- seat's Think is enabled, letting the values m_bEnterAnimOn and m_bExitAnimOn being updated.
- seat:RemoveEFlags( EFL_NO_THINK_FUNCTION )
- last_enabled = seat
- end
- i = i+1
- end )
- local function EnteredOrLeaved( ply, seat )
- if IsValid( seat ) and seat.seats_network_optimizer then
- table.insert( seats, i, seat ) -- seat's Think will be enabled on next game's Think
- end
- end
- hook.Add( "PlayerEnteredVehicle", "seats_network_optimizer", EnteredOrLeaved )
- hook.Add( "PlayerLeaveVehicle", "seats_network_optimizer", EnteredOrLeaved )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement