Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[---------------------------------------------------------
- Name: Setup
- -----------------------------------------------------------]]
- local Ply = {}
- Ply.Data = VoidChar.Ply and VoidChar.Ply.Data or {}
- util.AddNetworkString("VoidChar.RequestCharacters")
- util.AddNetworkString("VoidChar.SelectCharacter")
- util.AddNetworkString("VoidChar.Whitelist")
- util.AddNetworkString("VoidChar.CreateCharacter")
- util.AddNetworkString("VoidChar.DeleteCharacter")
- util.AddNetworkString("VoidChar.DeployFail")
- util.AddNetworkString("VoidChar.DeploySuccess")
- util.AddNetworkString("VoidChar.ChangeJob")
- util.AddNetworkString("VoidChar.ChangeIdentity")
- util.AddNetworkString("VoidChar.SendBWhitelistFactions")
- util.AddNetworkString("VoidChar.RequestFactions")
- util.AddNetworkString("VoidChar.ForceOpenMenu")
- util.AddNetworkString("VoidChar.AdminGetCharacters")
- util.AddNetworkString("VoidChar.AdminModifyCharacter")
- util.AddNetworkString("VoidChar.AdminDeleteCharacter")
- util.AddNetworkString("VoidChar.AdminGetWhitelist")
- util.AddNetworkString("VoidChar.AdminRemoveWhitelist")
- util.AddNetworkString("VoidChar.AdminAddWhitelist")
- local function phrase(...)
- return VoidChar.Lang.GetPhrase(...)
- end
- --[[---------------------------------------------------------
- Name: Functions
- -----------------------------------------------------------]]
- function Ply.Initalize(ply)
- Ply.Data[ply] = Ply.Data[ply] or {}
- ply:KillSilent()
- ply:SetTeam(TEAM_SPECTATOR)
- VoidChar.SQL.GetCharacters(ply, function(succ, tbl)
- VoidChar.Print("Loaded (".. #tbl.. ") characters from ".. ply:Name())
- end)
- VoidChar.SQL.GetWhitelists(ply:SteamID64(), function(data)
- local jobs = data == {} and data or data[1] and util.JSONToTable(data[1].jobs) or data.data and util.JSONToTable(data.jobs) or {}
- if VoidChar.Config.ULXRanks[ply:GetUserGroup()] then
- local groupCheck = (VoidChar.Config.xAdminSupport and ply:xAdminGetTag()) or ply:GetUserGroup()
- for k, v in pairs(VoidChar.Config.ULXRanks[groupCheck]) do
- jobs[k] = true
- end
- end
- for k, v in pairs(VoidChar.Config.DefaultJobs) do
- jobs[k] = true
- end
- if VoidChar.Config.WhitelistSteamID[ply:SteamID()] or VoidChar.Config.WhitelistRanks[ply:GetUserGroup()] then
- for k, v in pairs(RPExtraTeams) do
- jobs[v.team] = true
- end
- end
- Ply.Data[ply].whitelist = jobs
- end)
- end hook.Add("PlayerInitialSpawn", "VoidChar.Ply.Initalize", Ply.Initalize)
- function Ply.DarkRPVarChanged(ply, varname, oldValue, newValue)
- if !VoidChar.Config.LevelSystemSupport then return end
- if varname != "xp" then return end
- if !Ply.Data[ply] then return end
- local character = ply:GetCharacterID()
- if !character then return end
- Ply.Data[ply].character.xp = newValue
- Ply.Data[ply].character.level = ply:getDarkRPVar("level")
- VoidChar.SQL.UpdateValue(character, "xp", newValue )
- VoidChar.SQL.UpdateValue(character, "level", ply:getDarkRPVar("level") )
- end hook.Add("DarkRPVarChanged", "VoidChar.Ply.DarkRPVarChanged", Ply.DarkRPVarChanged)
- hook.Add("PlayerSay", "VoidChar.Ply.PlayerSayCommands", function (ply, text)
- if (!VoidChar.Config.AdminMenu[ply:GetUserGroup()]) then return end
- text = string.lower(text)
- local args = string.Split(text, " ")
- if (args[1] != "!setcharjob") then return end
- local playerName = table.concat( args, " ", 2, #args - 1 )
- local charPly
- for k, v in pairs(player.GetAll()) do
- if (string.StartWith(string.lower(v:Nick()), playerName)) then
- charPly = v
- break
- end
- end
- if (!charPly) then return end
- local job = DarkRP.getJobByCommand(args[#args])
- if (!job) then return end
- Ply.Data[charPly].character.job = job.team
- Ply.Data[charPly].character.model = (type(job.model) == "table" and job.model[1]) or job.model
- VoidChar.SQL.UpdateValue(charPly:GetCharacterID(), "job", "\'".. job.command .. "\'")
- VoidChar.SQL.UpdateValue(charPly:GetCharacterID(), "model", "\'".. Ply.Data[charPly].character.model .. "\'")
- VoidChar.SQL.UpdateCharacters(charPly, function()
- local characters = ply:GetCharacters()
- characters = util.TableToJSON(characters)
- characters = util.Compress(characters)
- net.Start("VoidChar.RequestCharacters")
- net.WriteUInt(#characters, 32)
- net.WriteData(characters, #characters)
- net.WriteBool(false)
- net.Send(ply)
- end)
- charPly:changeTeam(job.team, true)
- ply:ChatPrint("Successfully set " .. playerName .. "'s job to " .. job.name .. "!")
- return "";
- end)
- function Ply.SaveItemStoreInv(ply)
- if !VoidChar.Config.ItemStoreSupport then return end
- local character = ply:GetCharacterID()
- if !character then return end
- local inventoryItems = ply.Inventory:GetItems()
- for k, v in pairs(inventoryItems) do
- inventoryItems[k].Container = nil
- end
- local inventoryJSON = util.TableToJSON(inventoryItems)
- Ply.Data[ply].character.inventory = inventoryJSON
- VoidChar.SQL.UpdateValue(character, "inventory", "\'".. inventoryJSON .. "\'" )
- end
- function Ply.SaveClothes(ply)
- if !VoidChar.Config.CharacterClothesSupport then return end
- local character = ply:GetCharacterID()
- if !character then return end
- local clothingJSON = util.TableToJSON(ply:CM_GetInfos())
- Ply.Data[ply].character.clothing = clothingJSON
- VoidChar.SQL.UpdateValue(character, "clothing", "\'".. clothingJSON .. "\'" )
- end
- if VoidChar.Config.ItemStoreSupport then
- // thanks for adding no hooks....
- gameevent.Listen( "player_disconnect" )
- hook.Add( "player_disconnect", "VoidChar.Ply.ItemStoreSaveOnDisconnect", function( data )
- if itemstore.config.SaveOnWrite then return end
- local pl = player.GetBySteamID( data.networkid )
- if not IsValid( pl ) then return end
- Ply.SaveItemStoreInv(pl)
- end )
- hook.Add( "Tick", "VoidChar.Ply.ItemStoreSaveOnWrite", function()
- if not itemstore.config.SaveOnWrite then return end
- for _, pl in ipairs( player.GetAll() ) do
- if pl.NextInventorySave and pl.NextInventorySave < CurTime() + 0.02 then // for real??
- Ply.SaveItemStoreInv(pl)
- end
- end
- end )
- end
- if VoidChar.Config.CharacterClothesSupport then
- hook.Add("ClothesMod.OnInfosSaved", "VoidChar.Ply.CharacterClothesSave", function (pl)
- Ply.SaveClothes(pl)
- end)
- end
- function Ply.SelectCharacter(ply, character, callback)
- Ply.Data[ply] = Ply.Data[ply] or {}
- if Ply.Data[ply].changing then
- ply:ChatPrint(phrase("changing"))
- return
- end
- Ply.IsPlayerWhitelisted(ply, character.job, function (result)
- if !result and !VoidChar.Config.EnableUsingNonWhitelistedJobs then
- net.Start("VoidChar.DeployFail")
- net.WriteString("whitelist_fail")
- net.Send(ply)
- return
- end
- // check if can change team
- local canDeploy, reason, add = ply:CanDeploy(tonumber(character.job), false)
- if (!add) then
- add = ""
- end
- if !canDeploy then
- net.Start("VoidChar.DeployFail")
- net.WriteString(reason)
- net.WriteString(add)
- net.Send(ply)
- return
- end
- local onlinePlayers = player.GetCount()
- local isFactionFull = false
- if VoidChar.Config.FactionSystem and !VoidChar.Config.IgnoreExistingCharactersFactionLimit and table.Count(VoidChar.Config.FactionMaxPlayerPercent) > 0 and VoidChar.Config.FactionMaxPlayerPercent[character.faction] then
- if VoidChar.Config.FactionMaxPlayerPercent[character.faction] != 0 then
- local plyCountFaction = 0
- for k, v in pairs(player.GetAll()) do
- if v==ply then continue end
- if v:GetCharacter() then
- local plyChar = v:GetCharacter()
- if plyChar.faction == character.faction then
- plyCountFaction = plyCountFaction + 1
- end
- end
- end
- if (onlinePlayers * (VoidChar.Config.FactionMaxPlayerPercent[character.faction]/100) <= plyCountFaction) then
- isFactionFull = true
- end
- end
- end
- if isFactionFull then
- net.Start("VoidChar.DeployFail")
- net.WriteString(phrase("faction_full"))
- net.Send(ply)
- return
- end
- local CTeam = RPExtraTeams[tonumber(character.job)]
- if (CTeam.vote or CTeam.RequiresVote) and ply:Team() != tonumber(character.job) then
- if CTeam.canStartVote and not CTeam.canStartVote(ply) then
- net.Start("VoidChar.DeployFail")
- net.WriteString("vote_error")
- net.Send(ply)
- return
- end
- ply.LastVoteCop = ply.LastVoteCop or -80
- if CurTime() - ply.LastVoteCop < 80 then
- net.Start("VoidChar.DeployFail")
- net.WriteString("vote_error")
- net.Send(ply)
- return
- end
- net.Start("VoidChar.DeployFail")
- net.WriteString("vote_created")
- net.Send(ply)
- DarkRP.createVote(DarkRP.getPhrase("wants_to_be", ply:Nick(), CTeam.name), "job", ply, 20, function(vote, choice)
- local target = vote.target
- if not IsValid(target) then return end
- if choice >= 0 then
- ply:changeTeam(tonumber(character.job), true, true)
- net.Start("VoidChar.DeploySuccess")
- net.Send(ply)
- else
- DarkRP.notifyAll(1, 4, DarkRP.getPhrase("has_not_been_made_team", target:Nick(), CTeam.name))
- net.Start("VoidChar.DeployFail")
- net.WriteString("vote_failed")
- net.Send(ply)
- end
- end, nil, nil, {
- targetTeam = tonumber(character.job)
- })
- ply.LastVoteCop = CurTime()
- else
- net.Start("VoidChar.DeploySuccess")
- net.Send(ply)
- ply:changeTeam(tonumber(character.job), true, true)
- end
- local prevCharacter = Ply.Data[ply].character
- Ply.Data[ply].character = character
- hook.Run("VoidChar.CharacterSelected", ply, character)
- if VoidChar.Config.LevelSystemSupport then
- ply:setDarkRPVar("level", tonumber(character.level) )
- ply:setDarkRPVar("xp", tonumber(character.xp) )
- end
- if VoidChar.Config.CharacterClothesSupport then
- if !CLOTHESMOD then VoidChar.PrintError("Character & Clothes support is enabled, but the addon was not found!") return end
- local clothing = util.JSONToTable(character.clothing)
- if clothing and table.Count(clothing) > 0 then
- VoidChar.Print("Setting clothesmod info")
- CLOTHESMOD.PlayerInfos[ply:SteamID64()] = clothing
- timer.Simple(1, function ()
- ply:CM_ApplyModel()
- end)
- end
- end
- if VoidChar.Config.BodygroupOption then
- local bodygroups = (character.bodygroups and util.JSONToTable(character.bodygroups)) or nil
- if bodygroups then
- for k, v in pairs(bodygroups) do
- ply:SetBodygroup(k,v)
- end
- end
- end
- if VoidChar.Config.ItemStoreSupport then
- local inventory = util.JSONToTable(character.inventory)
- for k, v in pairs(ply.Inventory:GetItems()) do
- local amount = 0
- if !v.Data or !v.Data.Amount then
- amount = 1
- else
- amount = v.Data.Amount
- end
- ply.Inventory:TakeItems(v.Class, amount)
- end
- for k, v in pairs(inventory) do
- if v.Data then
- ply.Inventory:SetItem(v.Slot, itemstore.Item(v.Class, v.Data))
- else
- ply.Inventory:SetItem(v.Slot, itemstore.Item(v.Class))
- end
- end
- end
- if character.clone_id != "NULL" and character.clone_id != false and VoidChar.Config.EnableCloneID then
- local hashtag = (VoidChar.Config.ShowHashtag and "#") or ""
- if VoidChar.Config.DisplayAsSuffix then
- ply:setDarkRPVar("rpname", hashtag .. character.clone_id.. " " .. character.name)
- else
- ply:setDarkRPVar("rpname", character.name.. " " .. hashtag .. character.clone_id)
- end
- else
- ply:setDarkRPVar("rpname", character.name)
- end
- ply:setDarkRPVar("money", character.wallet)
- end)
- if callback then callback() end
- end
- function Ply.ChangeIdentity(len, ply)
- if not ply:GetCharacterID() then return end
- local name = net.ReadString()
- local model = net.ReadString()
- local bodygroups = net.ReadTable()
- if !ply:canAfford(VoidChar.Config.IdentityChangeCost) then
- DarkRP.notify(ply, 1, 5, phrase("cant_afford"))
- return
- end
- if #name > VoidChar.Config.MaxNameLength then
- DarkRP.notify(ply, 1, 5, string.format(phrase("name_long"), VoidChar.Config.MaxNameLength) )
- return
- end
- if #name < VoidChar.Config.MinNameLength then
- DarkRP.notify(ply, 1, 5, string.format(phrase("name_short"), VoidChar.Config.MinNameLength))
- return
- end
- local plyJob = RPExtraTeams[ply:Team()]
- if (( type(plyJob.model) == "table" and !table.HasValue(plyJob.model, model) ) or ( type(plyJob.model) == "string" and plyJob.model != model )) then
- return
- end
- local nameWords = string.Explode(" ", name)
- if VoidChar.Config.ForceTwoNames and ((VoidChar.Config.RestrictThreeNames and #nameWords ~= 3) or #nameWords > 3 or #nameWords < 2) then
- local maxWords = 2
- if !VoidChar.Config.RestrictThreeNames then
- maxWords = 3
- end
- DarkRP.notify(ply, 1, 5, string.format(phrase("too_many_words"), maxWords) )
- return
- end
- if Ply.Data[ply].character.clone_id != "NULL" and Ply.Data[ply].character.clone_id != false and VoidChar.Config.EnableCloneID then
- local hashtag = (VoidChar.Config.ShowHashtag and "#") or ""
- if VoidChar.Config.DisplayAsSuffix then
- ply:setDarkRPVar("rpname", hashtag .. Ply.Data[ply].character.clone_id.. " " .. Ply.Data[ply].character.name)
- else
- ply:setDarkRPVar("rpname", Ply.Data[ply].character.name.. " " .. hashtag .. Ply.Data[ply].character.clone_id)
- end
- else
- ply:setDarkRPVar("rpname", name)
- end
- Ply.Data[ply].character.name = name
- Ply.Data[ply].character.model = model
- VoidChar.SQL.UpdateValue(ply:GetCharacterID(), "name", "\'".. name .. "\'")
- VoidChar.SQL.UpdateValue(ply:GetCharacterID(), "model", "\'".. model .. "\'")
- if (VoidChar.Config.BodygroupOption and VoidChar.Config.BodygroupChangeInNPCs) then
- if (bodygroups) then
- for k, v in pairs(bodygroups) do
- ply:SetBodygroup(k,v)
- end
- end
- local bodygroupsJSON = util.TableToJSON(bodygroups)
- Ply.Data[ply].character.bodygroups = bodygroupsJSON
- VoidChar.SQL.UpdateValue(ply:GetCharacterID(), "bodygroups", "\'".. bodygroupsJSON .. "\'")
- end
- ply:SetModel(model)
- local characters = ply:GetCharacters()
- characters = util.TableToJSON(characters)
- characters = util.Compress(characters)
- net.Start("VoidChar.RequestCharacters")
- net.WriteUInt(#characters, 32)
- net.WriteData(characters, #characters)
- net.WriteBool(false)
- net.Send(ply)
- ply:addMoney(-VoidChar.Config.IdentityChangeCost)
- DarkRP.notify(ply, 0, 5, phrase("success_identity"))
- end net.Receive("VoidChar.ChangeIdentity", Ply.ChangeIdentity)
- function Ply.ChangeJob(len, ply)
- if not ply:GetCharacterID() then return end
- local job = net.ReadInt(20)
- local model = net.ReadString()
- local jobNPC = net.ReadString()
- local bodygroups = net.ReadTable()
- local jobChangeCost = (jobNPC != "" and VoidChar.Config.JobNPCs[jobNPC].changeCost) or VoidChar.Config.JobChangeCost
- if !ply:canAfford(jobChangeCost) then
- DarkRP.notify(ply, 1, 5, phrase("cant_afford"))
- return
- end
- local plyChar = ply:GetCharacter()
- if VoidChar.Config.FactionSystem and !VoidChar.Config.DifferentFactionJobSwitch and !VoidChar.Config.Factions[plyChar.faction][job] then return end
- local canDeploy, reason, add = ply:CanDeploy(job, true)
- if !canDeploy then
- if (add) then
- DarkRP.notify(ply, 1, 5, string.format(phrase(reason), add))
- else
- DarkRP.notify(ply, 1, 5, phrase(reason))
- end
- return
- end
- if ply.lastSwitchedCharJob and ply.lastSwitchedCharJob + (VoidChar.Config.JobSwitchCooldown * 60) > CurTime() then
- local cooldownExpire = math.ceil( (ply.lastSwitchedCharJob + (VoidChar.Config.JobSwitchCooldown * 60) - CurTime()) / 60)
- DarkRP.notify(ply, 1, 5, string.format(phrase("char_jobswitch_cooldown"), cooldownExpire) )
- return
- end
- ply.lastSwitchedCharJob = CurTime()
- Ply.IsPlayerWhitelisted(ply, job, function (result)
- if !result then return end
- if job == ply:Team() then return end
- Ply.Data[ply].character.job = job
- Ply.Data[ply].character.model = model
- local jobCommand = RPExtraTeams[job].command
- VoidChar.SQL.UpdateValue(ply:GetCharacterID(), "job", "\'".. jobCommand .. "\'")
- VoidChar.SQL.UpdateValue(ply:GetCharacterID(), "model", "\'".. model .. "\'")
- if (VoidChar.Config.BodygroupOption and VoidChar.Config.BodygroupChangeInNPCs) then
- if (bodygroups) then
- for k, v in pairs(bodygroups) do
- ply:SetBodygroup(k,v)
- end
- end
- local bodygroupsJSON = util.TableToJSON(bodygroups)
- Ply.Data[ply].character.bodygroups = bodygroupsJSON
- VoidChar.SQL.UpdateValue(ply:GetCharacterID(), "bodygroups", "\'".. bodygroupsJSON .. "\'")
- end
- local CTeam = RPExtraTeams[tonumber(job)]
- if (CTeam.vote or CTeam.RequiresVote) then
- if CTeam.canStartVote and not CTeam.canStartVote(ply) then
- DarkRP.notify(ply, 1, 5, phrase("vote_error"))
- return
- end
- ply.LastVoteCop = ply.LastVoteCop or -80
- if CurTime() - ply.LastVoteCop < 80 then
- DarkRP.notify(ply, 1, 5, phrase("vote_error"))
- return
- end
- DarkRP.notify(ply, 0, 5, phrase("vote_created"))
- DarkRP.createVote(DarkRP.getPhrase("wants_to_be", ply:Nick(), CTeam.name), "job", ply, 20, function(vote, choice)
- local target = vote.target
- if not IsValid(target) then return end
- if choice >= 0 then
- ply:changeTeam(job, true, true)
- else
- DarkRP.notifyAll(1, 4, DarkRP.getPhrase("has_not_been_made_team", target:Nick(), CTeam.name))
- DarkRP.notify(ply, 1, 5, phrase("vote_failed"))
- end
- end, nil, nil, {
- targetTeam = job
- })
- ply.LastVoteCop = CurTime()
- else
- ply:changeTeam(job, true, true)
- end
- DarkRP.notify(ply, 0, 5, phrase("success_job"))
- ply:addMoney(-jobChangeCost)
- local characters = ply:GetCharacters()
- characters = util.TableToJSON(characters)
- characters = util.Compress(characters)
- net.Start("VoidChar.RequestCharacters")
- net.WriteUInt(#characters, 32)
- net.WriteData(characters, #characters)
- net.WriteBool(false)
- net.Send(ply)
- end)
- end net.Receive("VoidChar.ChangeJob", Ply.ChangeJob)
- function Ply.UpdateWallet(ply, amount, money)
- if not ply:GetCharacterID() then return end
- Ply.Data[ply].character.wallet = money + amount
- VoidChar.SQL.UpdateValue(ply:GetCharacterID(), "wallet", money + amount)
- end hook.Add("playerWalletChanged", "VoidChar.Ply.Wallet", Ply.UpdateWallet)
- function Ply.GetCharacter(ply)
- return Ply.Data[ply].character or {}
- end
- function Ply.SaveAllNPCs(ply)
- if !VoidChar.Config.AdminMenu[ply:GetUserGroup()] then return end
- local npcTable = {}
- npcTable["job"] = {}
- npcTable["identity"] = {}
- for k, v in pairs(ents.FindByClass("vc_jobnpc")) do
- local posArray = {}
- posArray[1] = v:GetPos()
- posArray[2] = v:GetAngles()
- if v.npcType then
- posArray[3] = v.npcType
- end
- table.insert(npcTable["job"], posArray)
- end
- for k, v in pairs(ents.FindByClass("vc_identitynpc")) do
- local posArray = {}
- posArray[1] = v:GetPos()
- posArray[2] = v:GetAngles()
- table.insert(npcTable["identity"], posArray)
- end
- local json = util.TableToJSON(npcTable)
- file.Write("voidchar_npclocations.txt", json)
- ply:ChatPrint("[VoidChar] Successfully saved all NPCs.")
- end concommand.Add( "voidchar_savenpc", Ply.SaveAllNPCs)
- function Ply.LoadAllNPCs()
- local text = file.Read("voidchar_npclocations.txt")
- if !text then return end
- local npcTable = util.JSONToTable(text)
- if !npcTable["job"] then
- npcTable["job"] = {}
- end
- if !npcTable["identity"] then
- npcTable["identity"] = {}
- end
- for k, v in pairs(npcTable["job"]) do
- local npc = ents.Create("vc_jobnpc")
- npc:SetPos(v[1])
- npc:SetAngles(v[2])
- if v[3] then
- npc:SetNWString("npcType", v[3])
- npc.npcType = v[3]
- end
- npc:Spawn()
- if v[3] then
- npc:SetNPCModel(VoidChar.Config.JobNPCs[v[3]].npcModel)
- end
- end
- for k, v in pairs(npcTable["identity"]) do
- local npc = ents.Create("vc_identitynpc")
- npc:SetPos(v[1])
- npc:SetAngles(v[2])
- npc:Spawn()
- end
- VoidChar.Print("Successfully loaded all NPCs.")
- end
- --[[---------------------------------------------------------
- Name: Meta
- -----------------------------------------------------------]]
- local PLAYER = FindMetaTable("Player")
- function PLAYER:GetCharacters()
- return VoidChar.SQL.PlayerInfo[self:SteamID64()] or {}
- end
- function PLAYER:CanDeploy(t, switch)
- local CTeam = RPExtraTeams[tonumber(t)]
- if (CTeam.vote or CTeam.RequiresVote) and self:Team() == tonumber(t) then
- return true
- end
- if self:isArrested() then
- return false, "arrested"
- end
- local allowed, time = self:changeAllowed(t)
- if t ~= GAMEMODE.DefaultTeam and not allowed and not force then
- return false, "demoted"
- end
- if self.IsBeingDemoted then
- self:teamBan()
- self.IsBeingDemoted = false
- self:changeTeam(GAMEMODE.DefaultTeam, true)
- return false, "try_demote"
- end
- local TEAM = RPExtraTeams[t]
- if not TEAM then return false end
- if TEAM.customCheck and not TEAM.customCheck(self) and (not force or force and not GAMEMODE.Config.adminBypassJobRestrictions) then
- return false, "noperms"
- end
- if (TEAM.NeedToChangeFrom and self:Team() != TEAM.NeedToChangeFrom) and (switch or !VoidChar.Config.NeedToChangeFromOnlyInJobNPC) then // We need to check if player used the job npc to change his character
- return false, "char_diffntcf", team.GetName(TEAM.NeedToChangeFrom)
- end
- local max = TEAM.max
- local numPlayers = team.NumPlayers(t)
- if max ~= 0 and -- No limit
- (max >= 1 and numPlayers >= max or -- absolute maximum
- max < 1 and (numPlayers + 1) / player.GetCount() > max) then -- fractional limit (in percentages) [655615ee9481efcebe24c7991b5cc95ed551f3ea59da2ed78542506e0b5dbeb9]
- return false, "limit_reached"
- end
- return true
- end
- function PLAYER:GetCharacterID()
- return Ply.GetCharacter(self).id or nil
- end
- function PLAYER:SelectCharacter(character, callback)
- return Ply.SelectCharacter(self, character, callback)
- end
- function PLAYER:GetCharacterByID(id)
- for k, v in pairs(self:GetCharacters()) do
- if tonumber(v.id) == tonumber(id) then
- return v
- end
- end
- return nil
- end
- function PLAYER:GetCharacter()
- return Ply.GetCharacter(self)
- end
- function PLAYER:GetReserved()
- local allowed = {}
- for k, v in pairs(VoidChar.Config.CharacterRank) do
- if v.customCheck(self) then
- allowed[k] = true
- end
- end
- return allowed
- end
- --[[---------------------------------------------------------
- Name: Networking
- -----------------------------------------------------------]]
- function Ply.RequestCharacters(len, ply)
- if Ply.Data[ply] and Ply.Data[ply].sent then return end
- local characters = ply:GetCharacters()
- characters = util.TableToJSON(characters)
- characters = util.Compress(characters)
- net.Start("VoidChar.RequestCharacters")
- net.WriteUInt(#characters, 32)
- net.WriteData(characters, #characters)
- net.WriteBool(true)
- net.Send(ply)
- Ply.Data[ply] = Ply.Data[ply] or {}
- Ply.Data[ply].sent = true
- end net.Receive("VoidChar.RequestCharacters", Ply.RequestCharacters)
- function Ply.RequestFactions(len, ply)
- if VoidChar.Config.UseBWhitelistFactions then
- local tbl = VoidChar.GetBWhitelistFactions()
- if tbl then
- tbl = util.TableToJSON(tbl)
- tbl = util.Compress(tbl)
- net.Start("VoidChar.SendBWhitelistFactions")
- net.WriteUInt(#tbl, 32)
- net.WriteData(tbl, #tbl )
- net.Send(ply)
- end
- end
- end net.Receive("VoidChar.RequestFactions", Ply.RequestFactions)
- function Ply.SelectCharacterNet(len, ply)
- Ply.Data[ply] = Ply.Data[ply] or {}
- -- if Ply.Data[ply].character then return end
- local char_id = net.ReadInt(20)
- if not ply:GetCharacterByID(char_id) then return end
- ply:SelectCharacter(ply:GetCharacterByID(char_id), function()
- net.Start("VoidChar.SelectCharacter")
- net.WriteInt(char_id, 20)
- net.Send(ply)
- end)
- end net.Receive("VoidChar.SelectCharacter", Ply.SelectCharacterNet)
- function Ply.RequestWhitelist(len, ply, override)
- if VoidChar.Config.UseBWhitelist then
- local AccessibleJobs, AccessibleJobsCount = GAS.JobWhitelist:GetPlayerAccessibleJobs(ply)
- AccessibleJobs = util.TableToJSON(AccessibleJobs)
- AccessibleJobs = util.Compress(AccessibleJobs)
- net.Start("VoidChar.Whitelist")
- net.WriteUInt(#AccessibleJobs, 32)
- net.WriteData(AccessibleJobs, #AccessibleJobs)
- net.Send(ply)
- end
- Ply.Data[ply] = Ply.Data[ply] or {}
- if Ply.Data[ply].sentwhitelist and not override then return end
- local data = {}
- if VoidChar.Config.WhitelistSteamID[ply:SteamID()] or VoidChar.Config.WhitelistRanks[ply:GetUserGroup()] then
- for k, v in pairs(RPExtraTeams) do
- data[k] = true
- end
- Ply.Data[ply].sentwhitelist = true
- data = util.TableToJSON(data)
- data = util.Compress(data)
- net.Start("VoidChar.Whitelist")
- net.WriteUInt(#data, 32)
- net.WriteData(data, #data)
- net.Send(ply)
- return
- end
- VoidChar.SQL.GetWhitelists(ply:SteamID64(), function(data)
- data = data or {}
- local jobs = data == {} and data or data[1] and util.JSONToTable(data[1].jobs) or data.data and util.JSONToTable(data.jobs) or {}
- local groupCheck = (VoidChar.Config.xAdminSupport and ply:xAdminGetTag()) or ply:GetUserGroup()
- if VoidChar.Config.ULXRanks[groupCheck] then
- for k, v in pairs(VoidChar.Config.ULXRanks[groupCheck]) do
- jobs[k] = true
- end
- end
- Ply.Data[ply].sentwhitelist = jobs
- jobs = util.TableToJSON(jobs)
- jobs = util.Compress(jobs)
- net.Start("VoidChar.Whitelist")
- net.WriteUInt(#jobs, 32)
- net.WriteData(jobs, #jobs)
- net.Send(ply)
- end)
- end net.Receive("VoidChar.Whitelist", Ply.RequestWhitelist)
- function Ply.RequestCreateCharacter(len, ply)
- Ply.Data[ply] = Ply.Data[ply] or {}
- if table.Count(VoidChar.SQL.PlayerInfo[ply:SteamID64()]) > VoidChar.Config.MaxCharacters - (table.Count(VoidChar.Config.CharacterRank) - table.Count(ply:GetReserved())) then
- error("Player ".. ply:Nick().. " attempted to create more characters than allowed.")
- return
- end
- local data = net.ReadTable() or {}
- local restrictedFound = false
- for k, v in pairs(VoidChar.Config.RestrictedWords) do
- if string.find(data.name, string.lower(v) ) then
- restrictedFound = true
- end
- end
- if ply.lastCreatedCharacter and ply.lastCreatedCharacter + (VoidChar.Config.CharacterCreateCooldown * 60) > CurTime() then return end
- ply.lastCreatedCharacter = CurTime()
- if not data.name or data.name == "" then return end
- if not data.job or data.job == 0 then return end
- if not data.model or data.model == "" then return end
- if VoidChar.Config.FactionSystem and !VoidChar.Config.Factions[data.faction][data.job] then return end
- if restrictedFound then return end
- if data.bodygroups then
- data.bodygroups = util.TableToJSON(data.bodygroups)
- end
- Ply.IsPlayerWhitelisted(ply, data.job, function (result)
- if !result then return end
- if VoidChar.Config.DisableCreationWhitelist and !VoidChar.Config.DefaultJobs[data.job] then return end
- if VoidChar.Config.ForceCloneID then
- data.clone_id = true
- end
- if VoidChar.Config.CharacterClothesSupport then
- net.Start("ClothesMod:CharacterCreationMenu")
- net.Send(ply)
- end
- hook.Run("VoidChar.CharacterCreated", ply, data)
- if data.clone_id then // Clone Counter :v <3
- if VoidChar.Config.CloneID then
- VoidChar.SQL.GetCloneID(function(number)
- data.clone_id = number
- VoidChar.SQL.CreateCharacter(ply, {
- name = data.name,
- clone_id = data.clone_id,
- job = data.job,
- model = data.model,
- wallet = VoidChar.Config.DefaultMoney or 200,
- faction = data.faction,
- bodygroups = data.bodygroups or ""
- }, function(succ, tbl, index)
- if !succ then return end
- Ply.SelectCharacter(ply, tbl[index])
- local characters = ply:GetCharacters()
- characters = util.TableToJSON(characters)
- characters = util.Compress(characters)
- net.Start("VoidChar.RequestCharacters")
- net.WriteUInt(#characters, 32)
- net.WriteData(characters, #characters)
- net.WriteBool(false)
- net.Send(ply)
- net.Start("VoidChar.SelectCharacter")
- net.WriteInt(tbl[index].id, 20)
- net.Send(ply)
- end)
- end)
- return
- else
- data.clone_id = math.random(1000, 9999)
- end
- end
- VoidChar.SQL.CreateCharacter(ply, {
- name = data.name,
- clone_id = data.clone_id,
- job = data.job,
- model = data.model,
- wallet = VoidChar.Config.DefaultMoney or 200,
- faction = data.faction,
- bodygroups = data.bodygroups or ""
- }, function(succ, tbl, index)
- if !succ then return end
- Ply.SelectCharacter(ply, tbl[index])
- local characters = ply:GetCharacters()
- characters = util.TableToJSON(characters)
- characters = util.Compress(characters)
- net.Start("VoidChar.RequestCharacters")
- net.WriteUInt(#characters, 32)
- net.WriteData(characters, #characters)
- net.WriteBool(false)
- net.Send(ply)
- net.Start("VoidChar.SelectCharacter")
- net.WriteInt(tbl[index].id, 20)
- net.Send(ply)
- end)
- end)
- end net.Receive("VoidChar.CreateCharacter", Ply.RequestCreateCharacter)
- function Ply.RequestDeleteCharacter(len, ply)
- Ply.Data[ply] = Ply.Data[ply] or {}
- local char_id = net.ReadInt(20)
- if not char_id then return end
- if not ply:GetCharacterByID(char_id) then return end
- hook.Run("VoidChar.CharacterDeleted", ply, ply:GetCharacterByID(char_id))
- VoidChar.SQL.DeleteCharacter(ply, char_id)
- end net.Receive("VoidChar.DeleteCharacter", Ply.RequestDeleteCharacter)
- --[[---------------------------------------------------------
- Name: Admin Menu
- -----------------------------------------------------------]]
- function Ply.AdminGetCharacters(len, ply)
- if not VoidChar.Config.AdminMenu[ply:GetUserGroup()] then return end
- VoidChar.SQL.GetAllCharacters(function(characters)
- characters = util.TableToJSON(characters)
- characters = util.Compress(characters)
- net.Start("VoidChar.AdminGetCharacters")
- net.WriteUInt(#characters, 32)
- net.WriteData(characters, #characters)
- net.WriteBool(false)
- net.Send(ply)
- end)
- end net.Receive("VoidChar.AdminGetCharacters", Ply.AdminGetCharacters)
- function Ply.AdminGetWhitelist(len, ply)
- if VoidChar.Config.UseBWhitelist then return end
- if not VoidChar.Config.AdminMenu[ply:GetUserGroup()] then return end
- local sid = net.ReadString()
- VoidChar.SQL.GetWhitelists(sid, function(data)
- net.Start("VoidChar.AdminGetWhitelist")
- net.WriteTable(data)
- net.Send(ply)
- end)
- end net.Receive("VoidChar.AdminGetWhitelist", Ply.AdminGetWhitelist)
- function Ply.AdminRemoveWhitelist(len, ply)
- if VoidChar.Config.UseBWhitelist then return end
- if not VoidChar.Config.AdminMenu[ply:GetUserGroup()] then return end
- local sid = net.ReadString()
- local job = net.ReadFloat()
- local pl = player.GetBySteamID64(sid)
- VoidChar.SQL.RemoveWhitelist(sid, job)
- if (IsValid(pl)) then
- Ply.Data[pl].whitelist[tonumber(job)] = true
- Ply.RequestWhitelist(0, ply, true)
- Ply.RequestWhitelist(0, pl, true)
- end
- end net.Receive("VoidChar.AdminRemoveWhitelist", Ply.AdminRemoveWhitelist)
- function Ply.AdminAddWhitelist(len, ply)
- if VoidChar.Config.UseBWhitelist then return end
- if not VoidChar.Config.AdminMenu[ply:GetUserGroup()] then return end
- local sid = net.ReadString()
- local job = net.ReadFloat()
- local pl = player.GetBySteamID64(sid)
- Ply.Data[pl].whitelist[tonumber(job)] = true
- VoidChar.SQL.AddWhitelist(sid, job)
- Ply.RequestWhitelist(0, ply, true)
- Ply.RequestWhitelist(0, pl, true)
- end net.Receive("VoidChar.AdminAddWhitelist", Ply.AdminAddWhitelist)
- function Ply.AdminRemoveCharacter(len, ply)
- if not VoidChar.Config.AdminMenu[ply:GetUserGroup()] then return end
- local characterid = net.ReadInt(32)
- if not characterid then return end
- local plySid
- VoidChar.SQL.GetCharacterByCharID(characterid, function (result)
- if (result and #result > 0) then
- plySid = result[1].sid
- end
- if (plySid) then
- local charPly = player.GetBySteamID64(plySid)
- if (charPly) then
- VoidChar.SQL.DeleteCharacter(charPly, characterid)
- end
- if (VoidChar.Config.ForceCharSelectionOnDelete) then
- net.Start("VoidChar.ForceOpenMenu")
- net.Send(charPly)
- end
- end
- hook.Run("VoidChar.CharacterDeleted", nil, characterid)
- end)
- end net.Receive("VoidChar.AdminDeleteCharacter", Ply.AdminRemoveCharacter)
- function Ply.AdminModifyCharacter(len, ply)
- if not VoidChar.Config.AdminMenu[ply:GetUserGroup()] then return end
- local character = net.ReadTable()
- if not character.id then return end
- ply = player.GetBySteamID64(character.sid)
- local jobCheck = DarkRP.getJobByCommand(character.job)
- local factionCheck = (VoidChar.Config.FactionSystem and VoidChar.Config.Factions[character.faction]) or false
- VoidChar.SQL.GetCharacterByID(character.id, function(char)
- for k, v in pairs(character) do
- VoidChar.SQL.UpdateValue(character.id, "wallet", character.wallet)
- if jobCheck then
- VoidChar.SQL.UpdateValue(character.id, "job", "\"".. character.job.. "\"")
- end
- VoidChar.SQL.UpdateValue(character.id, "name", "\"".. character.name.. "\"")
- if factionCheck then
- VoidChar.SQL.UpdateValue(character.id, "faction", "\"".. character.faction.. "\"")
- end
- end
- local prevChar = character.job
- local tbl, i = DarkRP.getJobByCommand(character.job)
- character.job = i
- if ply and ply:GetCharacter().id == character.id then
- ply:setDarkRPVar("money", character.wallet)
- if jobCheck then
- ply:changeTeam(tonumber(character.job), true, true)
- end
- if character.clone_id != "NULL" and character.clone_id != false and VoidChar.Config.EnableCloneID then
- local hashtag = (VoidChar.Config.ShowHashtag and "#") or ""
- if VoidChar.Config.DisplayAsSuffix then
- ply:setDarkRPVar("rpname", hashtag .. character.clone_id.. " " .. character.name)
- else
- ply:setDarkRPVar("rpname", character.name.. " " .. hashtag .. character.clone_id)
- end
- else
- ply:setDarkRPVar("rpname", character.name)
- end
- character.job = prevChar
- if !jobCheck then
- character.job = ply:GetCharacter().job
- end
- VoidChar.SQL.UpdateCharacters(ply, function()
- local characters = ply:GetCharacters()
- characters = util.TableToJSON(characters)
- characters = util.Compress(characters)
- net.Start("VoidChar.RequestCharacters")
- net.WriteUInt(#characters, 32)
- net.WriteData(characters, #characters)
- net.WriteBool(false)
- net.Send(ply)
- end)
- end
- end)
- end net.Receive("VoidChar.AdminModifyCharacter", Ply.AdminModifyCharacter)
- --[[---------------------------------------------------------
- Name: Character API
- -----------------------------------------------------------]]
- function PLAYER:SetCharacterVar(key, value)
- if !key or !value then return end
- Ply.Data[self].character[key] = value
- end
- function PLAYER:GetCharacterVar(key)
- if !key then return end
- local value = Ply.Data[self].character[key]
- if !value then return end
- return value
- end
- --[[---------------------------------------------------------
- Name: Whitelist API
- -----------------------------------------------------------]]
- function Ply.IsPlayerWhitelisted(sid, job, callback)
- if !IsEntity(sid) and VoidChar.Config.UseBWhitelist then
- callback(false)
- return false
- end
- if VoidChar.Config.UseBWhitelist then
- if !GAS.JobWhitelist:IsWhitelistEnabled( job ) then
- callback(true)
- return true
- else
- local AccessibleJobs, AccessibleJobsCount = GAS.JobWhitelist:GetPlayerAccessibleJobs( sid )
- if (AccessibleJobs[job] or GAS.JobWhitelist:IsWhitelisted( sid, job )) then
- callback(true)
- return true
- else
- callback(false)
- return false
- end
- end
- end
- local ply = (IsEntity(sid) and sid) or nil
- sid = (IsEntity(sid) and sid:SteamID64()) or sid
- VoidChar.SQL.GetWhitelists(sid, function(data)
- local jobs = {}
- for k, v in pairs(VoidChar.Config.DefaultJobs) do
- jobs[k] = true
- end
- if ply then
- local groupCheck = (VoidChar.Config.xAdminSupport and ply:xAdminGetTag()) or ply:GetUserGroup()
- if VoidChar.Config.ULXRanks[groupCheck] then
- for k, v in pairs(VoidChar.Config.ULXRanks[groupCheck]) do
- jobs[k] = true
- end
- end
- if VoidChar.Config.WhitelistSteamID[ply:SteamID()] or VoidChar.Config.WhitelistRanks[ply:GetUserGroup()] then
- for k, v in pairs(RPExtraTeams) do
- jobs[v.team] = true
- end
- end
- end
- if data and data[1] then
- local _jobs = util.JSONToTable(data[1].jobs)
- for k, v in pairs(_jobs) do
- jobs[k] = v
- end
- end
- if jobs[tonumber(job)] then
- callback(true)
- return true
- end
- callback(false)
- end)
- end
- function Ply.WhitelistPlayer(sid, job)
- local pl = player.GetBySteamID64(sid)
- if pl and IsValid(pl) then
- Ply.Data[pl].whitelist[tonumber(job)] = true
- end
- VoidChar.SQL.AddWhitelist(sid, job)
- if pl and IsValid(pl) then
- Ply.RequestWhitelist(0, pl, true)
- end
- end
- function Ply.UnWhitelistPlayer(sid, job)
- local pl = player.GetBySteamID64(sid)
- if pl and IsValid(pl) then
- Ply.Data[pl].whitelist[tonumber(job)] = false
- end
- VoidChar.SQL.RemoveWhitelist(sid, job)
- if pl and IsValid(pl) then
- Ply.RequestWhitelist(0, pl, true)
- end
- end
- VoidChar.Ply = Ply
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement