AddCSLuaFile("cl_loadoutaddon.lua")
AddCSLuaFile("autorun/shared_loadoutaddon.lua")
include("autorun/shared_loadoutaddon.lua")
require("datastream")
function ShowMenuF1(ply)
ply:ConCommand("OpenLoadoutMenu")
return false
end
hook.Add("ShowHelp", "ShowMenuF1", ShowMenuF1)
-- Console Command to unlock a weapon for a player
-- argument one is the players name and argument two is the weapon's name
local function GivePlayerIndividualWeapon(ply, cmd, args)
playerfound = false
if not ply:IsAdmin() or not ply:IsSuperAdmin() and not args[1] and not args[2] and not RealWeapons[args[2]] then return end
for k,v in pairs(player.GetAll()) do
if string.find(string.lower(v:Nick()), string.lower(args[1])) then
playerfound = true
v.StringOfWeapons = v.StringOfWeapons .. "END" .. args[2]
v:SetPData("UnlockedWeapons", v.StringOfWeapons)
OnePlayersInfo = {}
OnePlayersInfo[v:Nick()] = {v.Group, v.StringOfWeapons}
datastream.StreamToClients(player.GetAllAdmins(), "OneClientsData", OnePlayersInfo)
ply:ChatPrint("You have given player: " .. v:Nick() .. " weapon: " .. args[2])
timer.Simple(10, function()
SendUserMessage("UnlockedWeaponsToClient", v, v.StringOfWeapons)
end)
v.UnlockedWeapons = string.Explode("END", v.StringOfWeapons)
end
end
if not playerfound then ply:ChatPrint("No player was found by the name of" .. args[1]) end
end
concommand.Add("GivePlayerWeapon", GivePlayerIndividualWeapon)
local function PlayerGroupCollect(ply)
ply.Group = ply:GetPData("Group")
if not ply.Group then
ply.Group = "Guest"
ply:SetPData("Group", "Guest")
end
GetPlayersIndividualWeapons(ply)
SendUserMessage("ClientLoadoutGroup", ply, ply.Group)
timer.Simple(3, function()
SendUserMessage("OpenLoadoutMenu", ply)
end)
ply:ChatPrint("Welcome" .. ply:Nick() or ply:Name() .. ", of usergroup" .. ply.Group ".")
end
hook.Add("PlayerInitialSpawn", "PlayerGroupCollect", PlayerGroupCollect)
function AdminCheckCL(ply)
if ply:IsAdmin() or ply:IsSuperAdmin() then
SendUserMessage("YouAreAnAdmin", ply)
AllPlayersInfo = {}
for k,v in pairs(player.GetAll()) do
AllPlayersInfo[v:Nick()] = {v.Group, v.StringOfWeapons}
end
datastream.StreamToClients(ply, "AllClientsData", AllPlayersInfo)
end
OnePlayersInfo = {}
OnePlayersInfo[ply:Nick()] = {ply.Group, ply.StringOfWeapons}
datastream.StreamToClients(player.GetAllAdmins(), "OneClientsData", OnePlayersInfo)
end
hook.Add("PlayerInitialSpawn", "AdminCheckCL", AdminCheckCL)
concommand.Add("ResendAllPlayerStats", AdminCheckCL)
function Testinglll(ply)
ply:ConCommand("ResendAllPlayerStats")
end
hook.Add("PlayerInitialSpawn", "Testinglll", Testinglll)
function GetPlayersIndividualWeapons(ply)
ply.StringOfWeapons = ply:GetPData("UnlockedWeapons")
if not ply.StringOfWeapons then ply.StringOfWeapons = 0
return
else SendUserMessage("UnlockedWeaponsToClient", ply, StringOfWeapons)
ply.UnlockedWeapons = string.Explode("END", ply.StringOfWeapons)
end
end
local function PlayerEquipWeapon(ply, cmd, args)
if table.HasValue( weapons[ply.Group] , args[1]) or table.HasValue(ply.UnlockedWeapons, args[1]) then
if MaxWeapons[ply.Group] <= #ply.WeaponsChosen
then ply:ChatPrint("You have met your limit of weapons selected. Unequip other weapons and try again. Your limit is" .. MaxWeapons[ply.Group]) return
end
if not ply.WeaponsChosen then
ply.WeaponsChosen = {args[1]}
else
table.insert(ply.WeaponsChosen, args[1])
end
end
end
concommand.Add("EquipWeapon", PlayerEquipWeapon)
local function PlayerUnequipWeapon(ply, cmd, args)
if table.HasValue(ply.WeaponsChosen, args[1]) then
for k,v in pairs(WeaponsChosen) do
if v == args[1] then
table.remove(WeaponsChosen, i)
end
end
end
end
concommand.Add("UnequipWeapon", PlayerUnequipWeapon)
local function GivePlayerEffects(ply)
ply.GivenWeapons = 0
if not ply.WeaponsChosen then
for k,v in pairs(Weapons[ply.Group]) do
if ply.GivenWeapons >= MaxWeapons[ply.Group] then break end
ply:Give(RealWeapons[v])
ply.GivenWeapons = ply.GivenWeapons + 1
end
else
for k,v in pairs(ply.WeaponsChosen) do
ply:Give(RealWeapons[v])
end
end
ply:SetHealth(Health[ply.Group])
ply:SetHealth(Health[ply.Group])
ply:SetArmor(Armor[ply.Group])
ply:SetWalkSpeed(WalkSpeed[ply.Group])
ply:SetRunSpeed(RunSpeed[ply.Group])
end
hook.Add("PlayerLoadout", "GivePlayerEffects", GivePlayerEffects)
local function ChangePlayerGroup(ply, cmd, args)
if ply:IsAdmin() or ply:IsSuperAdmin() and args[1] and args[2] then
if table.HasValue(PlayerLoadoutGroups, args[2]) then
for k,v in pairs(player.GetAll()) do
if string.find(string.lower(v:Nick()), string.lower(args[1])) then
local playerfound = true
v:SetPData("Group", args[2])
v.Group = args[2]
SendUserMessage("ClientLoadoutGroup", v, v.Group)
OnePlayersInfo = {}
OnePlayersInfo[v:Nick()] = {v.Group, v.StringOfWeapons}
datastream.StreamToClients(player.GetAllAdmins(), "OneClientsData", OnePlayersInfo)
end
end
else playerfound = true ply:ChatPrint("There is no group of the name" .. args[2] .. ". For a list of groups type \"groupnames\" in console")
end
if not playerfound then ply:ChatPrint("No player was found by the name of" .. args[1]) end
end
end
concommand.Add("ChangePlayerGroup", ChangePlayerGroup)
function player.GetAllAdmins()
local admins = {}
for k,v in pairs(player.GetAll()) do
if v:IsAdmin() then
table.insert(admins, v)
end
end
return admins
end
-- lua_openscript autorun/server/server_loadoutaddon.lua
include( "autorun/shared_loadoutaddon.lua" )
require("datastream")
UnlockedWeapons = {}
EquippedWeapons = {}
ClientsInfo = {}
function LoadoutMenu()
-- Making frame
panelopened = true
DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 65,50 )
DermaPanel:SetSize( 360, 353 )
DermaPanel:SetTitle( "PlayerLoadout" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( true )
DermaPanel:MakePopup()
-- Making Property Sheet to organise tabs with
local PropertySheet = vgui.Create( "DPropertySheet", DermaPanel )
PropertySheet:SetPos( 5, 30 )
PropertySheet:SetSize( 340, 315 )
-- Making a text label to explain to the user and also so that it can be added to the property sheet and things can be parented to it. Organisation.
local TheseAreYourUnlockedWeapons = vgui.Create("DLabel")
local Text = vgui.Create("DLabel", TheseAreYourUnlockedWeapons)
Text:SetText("There are your unlocked weapons")
Text:SizeToContents()
Text:SetPos(0,5)
Text:SetTextColor(Color(0,0,0,255))
-- Making a list of all of the player's unlocked weapons.
local YourUnlockedWeaponsBox = vgui.Create("DComboBox", TheseAreYourUnlockedWeapons)
YourUnlockedWeaponsBox:SetPos(0, 30)
YourUnlockedWeaponsBox:SetSize(100, 200)
-- Looping through the player's group given weapons and adding them to the DComboBox
for k,v in pairs(Weapons[MyGroup]) do
YourUnlockedWeaponsBox:AddItem(v)
end
-- Looping through the player's specific weapons and adding them to the list.
for k,v in pairs(UnlockedWeapons) do
YourUnlockedWeaponsBox:AddItem(v)
end
-- Create a DComboBox to keep your equipped weapons on
local EquippedWeaponsBox = vgui.Create("DComboBox", TheseAreYourUnlockedWeapons)
EquippedWeaponsBox:SetPos(200, 30)
EquippedWeaponsBox:SetSize(100,200)
-- Add the equipped weapons to the box
for k,v in pairs(EquippedWeapons) do
EquippedWeaponsBox:AddItem(v)
end
-- Make a button to equip a weapon
local EquipWeaponButton = vgui.Create("DButton", TheseAreYourUnlockedWeapons)
EquipWeaponButton:SetSize(130, 30)
EquipWeaponButton:SetPos(0, 230)
EquipWeaponButton:SetText("Equip selected weapon")
EquipWeaponButton.DoClick = function()
if not YourUnlockedWeaponsBox:GetSelectedItems() and YourUnlockedWeaponsBox:GetSelectedItems()[1] then
return end
local weaponname = YourUnlockedWeaponsBox:GetSelectedItems()[1]:GetValue()
if not table.HasValue(EquippedWeapons, weaponname) then
RunConsoleCommand("UnequipWeapon", weaponname)
table.insert(EquippedWeapons, weaponname)
EquippedWeaponsBox:Clear()
for k,v in pairs(EquippedWeapons) do
EquippedWeaponsBox:AddItem(v)
end
end
end
-- Make a button to unequip a weapon
local UnequipWeaponButton = vgui.Create("DButton", TheseAreYourUnlockedWeapons)
UnequipWeaponButton:SetSize(150, 30)
UnequipWeaponButton:SetPos(180, 230)
UnequipWeaponButton:SetText("Unequip selected weapon")
UnequipWeaponButton.DoClick = function()
if not EquippedWeaponsBox:GetSelectedItems() and EquippedWeaponsBox:GetSelectedItems()[1] then
return end
local weaponname = EquippedWeaponsBox:GetSelectedItems()[1]:GetValue()
if table.HasValue(EquippedWeapons, weaponname) then
RunConsoleCommand("UnequipWeapon", weaponname)
for k,v in pairs(EquippedWeapons) do
if v == weaponname then
table.remove(EquippedWeapons, i)
end
end
-- Reloading equipped weapons box
EquippedWeaponsBox:Clear()
for k,v in pairs(EquippedWeapons) do
EquippedWeaponsBox:AddItem(v)
end
end
end
PropertySheet:AddSheet( "Your weapons", TheseAreYourUnlockedWeapons, "gui/silkicons/wrench", false, false, "Your weapons and loadout" )
-- Admin panel things. Only done if the client is an admin.
if meadmin then
PlayersTextAMN = vgui.Create("DLabel")
PlayersTextAMN2 = vgui.Create("DLabel", PlayersTextAMN)
PlayersTextAMN2:SetText("Players List:")
PlayersTextAMN2:SizeToContents()
PlayersTextAMN2:SetTextColor( Color ( 0, 0, 0, 255) )
-- Text labels
PlayerGroupText = vgui.Create("DLabel", PlayersTextAMN)
PlayerGroupText:SetPos(0, 230)
PlayerGroupText:SetTextColor( Color ( 0, 0, 0, 255) )
PlayerGroupText:SetText("No player selected.")
PlayerGroupText:SizeToContents()
PlayersGunsText = vgui.Create("DLabel", PlayersTextAMN)
PlayersGunsText:SetPos(110,0)
PlayersGunsText:SetTextColor( Color ( 0, 0, 0, 255) )
PlayersGunsText:SetText("The Player's \ncurrent weapons.")
PlayersGunsText:SizeToContents()
-- Players in game list
PlayerBoxListAMN = vgui.Create("DComboBox", PlayersTextAMN)
PlayerBoxListAMN:SetSize(100, 200)
PlayerBoxListAMN:SetPos(0, 30)
PlayerBoxListAMN:EnableVerticalScrollbar( true )
-- Adds every player to the list
for k,v in pairs(player.GetAll()) do
PlayerBoxListAMN:AddItem(v:Nick() or v:Name())
end
-- Player's weapon list
PlayerBoxCurrentWeaponsListAMN = vgui.Create("DComboBox", PlayersTextAMN)
PlayerBoxCurrentWeaponsListAMN:SetSize(100, 200)
PlayerBoxCurrentWeaponsListAMN:SetPos(110, 30)
PlayerBoxCurrentWeaponsListAMN:EnableVerticalScrollbar( true )
-- Add to player's weapon list
PlayerBoxAvailableWeaponsListAMN = vgui.Create("DComboBox", PlayersTextAMN)
PlayerBoxAvailableWeaponsListAMN:SetSize(100, 200)
PlayerBoxAvailableWeaponsListAMN:SetPos(220, 30)
PlayerBoxAvailableWeaponsListAMN:EnableVerticalScrollbar( true )
for k,v in pairs(RealWeapons) do
PlayerBoxAvailableWeaponsListAMN:AddItem(k)
end
-- Button to give players weapons
GiveWeaponButtonAMN = vgui.Create("DButton", PlayersTextAMN)
GiveWeaponButtonAMN:SetPos(220,240)
GiveWeaponButtonAMN:SetSize(100, 50)
GiveWeaponButtonAMN:SetText("Give Weapon")
GiveWeaponButtonAMN.DoClick = function()
if PlayerBoxListAMN:GetSelectedItems()[1] and PlayerBoxAvailableWeaponsListAMN:GetSelectedItems()[1] then
RunConsoleCommand("GivePlayerWeapon", PlayerBoxListAMN:GetSelectedItems()[1]:GetValue(), PlayerBoxAvailableWeaponsListAMN:GetSelectedItems()[1]:GetValue())
end end
-- Add the admin sheet to the propertysheet
PropertySheet:AddSheet( "Admin settings", PlayersTextAMN, "gui/silkicons/wrench", false, false, "If you are an admin you can do admin things" )
end
end
usermessage.Hook("OpenLoadoutMenu", LoadoutMenu)
concommand.Add("OpenLoadoutMenu", LoadoutMenu)
oldstuff = 0
function WeaponsAvaliableListResync(plyname)
if oldstuff == ClientsData[plyname][2] then return end
if ClientsData[plyname][2] == 0 then
local oldstuff = ClientsData[plyname][2]
PlayerBoxAvailableWeaponsListAMN:Clear()
for k,v in pairs(RealWeapons) do
PlayerBoxAvailableWeaponsListAMN:AddItem(k)
end
else PlayerBoxAvailableWeaponsListAMN:Clear()
for k,v in pairs(RealWeapons) do
if not table.HasValue(ClientsData[plyname][3], k) then
PlayerBoxAvailableWeaponsListAMN:AddItem(k)
end
end
end
end
function ForceTextChange()
-- if not panelopened then return end
if not meadmin then return end
if not PlayerBoxListAMN then return end
if PlayerBoxListAMN:IsVisible() then
if PlayerBoxListAMN:GetSelectedItems() and PlayerBoxListAMN:GetSelectedItems()[1] then
local plyname = PlayerBoxListAMN:GetSelectedItems()[1]:GetValue()
PlayerGroupText:SetText( plyname .. "'s\ngroup is: " .. ClientsData[plyname][1] )
PlayerGroupText:SizeToContents()
PlayersGunsText:SetText( plyname .. "'s\nweapons")
PlayersGunsText:SizeToContents()
WeaponsAvaliableListResync(plyname)
if ClientsData[plyname][2] == 0 then return end
if lastrefresh == ClientsData[plyname][2] then return end
lastrefresh = ClientsData[plyname][2]
PlayerBoxCurrentWeaponsListAMN:Refresh()
for k,v in pairs(ClientsData[plyname][2]) do
PlayerBoxCurrentWeaponsListAMN:AddItem(v)
end
end
end
end
hook.Add("Think", "ForceTextChange", ForceTextChange)
function ReceiveUnlockedWeapons(um)
UnlockedWeapons = string.Explode("END", um:ReadString())
for k,v in pairs(UnlockedWeapons) do
table.insert(UnlockedWeapons, v)
end
end
usermessage.Hook("UnlockedWeaponsToClient", ReceiveUnlockedWeapons)
function ReceiveLoadoutGroup(um)
MyGroup = um:ReadString()
end
usermessage.Hook("ClientLoadoutGroup", ReceiveLoadoutGroup)
function PrintGroupNames(ply, cmd, args)
for k,v in pairs(PlayerLoadoutGroups) do
Msg(v .. " ")
end
end
concommand.Add("groupnames", PrintGroupNames)
function MyLoadoutGroup(ply, cmd, args)
Msg("You're loadout group is currently set to : " .. MyGroup)
end
concommand.Add("myloadoutgroup", MyLoadoutGroup)
function AdminCheckCL(um)
meadmin = true
end
usermessage.Hook("YouAreAnAdmin", AdminCheckCL)
-- When you first spawn you are sent all player data
function AllPlayersInfoReceiveADM(handler, id, encoded, decoded)
ClientsData = decoded
for k,v in pairs(ClientsData) do
ClientsData[k][3] = string.Explode("END", ClientsData[k][2])
PrintTable(ClientsData[k][3])
end
end
datastream.Hook("AllClientsData", AllPlayersInfoReceiveADM)
-- When someone else first spawns you are sent their data
function OnePlayersInfoReceiveADM(handler, id, encoded, decoded)
for k,v in pairs(decoded) do
ClientsData[k] = v
end
end
datastream.Hook("OneClientsData", PlayersInfoReceiveADM)
-- lua_openscript_cl autorun/client/cl_loadoutaddon.lua
-- To add a group add it to this list and then fill in the following sections below, like weapons, armor etc, with the new group name.
PlayerLoadoutGroups = {"Guest", "Member", "Respected", "Donator", "Admin", "Super Admin"}
-- To add weapons copy this example and fill it in, removing the --
-- RealWeapons["Weapon name that you want people to see it as"] = "folder name for the weapon"
RealWeapons = {}
RealWeapons["shotgun"] = "weapon_shotgun"
RealWeapons["crowbar"] = "weapon_crowbar"
RealWeapons["slam"] = "weapon_slam"
RealWeapons["stun stick"] = "weapon_stunstick"
RealWeapons["Physics gun"] = "weapon_physcannon"
RealWeapons["357"] = "weapon_357"
RealWeapons["ar2"] = "weapon_ar2"
RealWeapons["crossbow"] = "weapon_crossbow"
MaxWeapons = {}
MaxWeapons["Guest"] = 1
MaxWeapons["Member"] = 2
MaxWeapons["Respected"] = 3
MaxWeapons["Donator"] = 5
MaxWeapons["Admin"] = 5
MaxWeapons["SuperAdmin"] = 5
-- You can change which groups spawn with which weapons by adding to the lists here.
Weapons = {}
Weapons["Guest"] = {"shotgun", "crowbar", "slam"}
Weapons["Member"] = {"shotgun", "crowbar", "slam", "stun stick"}
Weapons["Respected"] = {"shotgun", "crowbar", "slam", "stun stick", "physcannon"}
Weapons["Donator"] = {"shotgun", "crowbar", "slam", "stun stick", "physcannon", "357", "ar2", "crossbow"}
Weapons["Admin"] = {"shotgun", "crowbar", "slam"}
Weapons["SuperAdmin"] = {"shotgun", "crowbar", "slam", "stun stick"}
-- The rest are straightforward to change, just change the numbers with hte corresponding group.
Health = {}
Health["Guest"] = 100
Health["Member"] = 100
Health["Respected"] = 100
Health["Donator"] = 100
Health["Admin"] = 100
Health["SuperAdmin"] = 101
Armor = {}
Armor["Guest"] = 0
Armor["Member"] = 0
Armor["Respected"] = 0
Armor["Donator"] = 50
Armor["Admin"] = 50
Armor["SuperAdmin"] = 50
WalkSpeed = {}
WalkSpeed["Guest"] = 250
WalkSpeed["Member"] = 250
WalkSpeed["Respected"] = 250
WalkSpeed["Donator"] = 300
WalkSpeed["Admin"] = 300
WalkSpeed["SuperAdmin"] = 300
RunSpeed = {}
RunSpeed["Guest"] = 500
RunSpeed["Member"] = 500
RunSpeed["Respected"] = 500
RunSpeed["Donator"] = 600
RunSpeed["Admin"] = 600
RunSpeed["SuperAdmin"] = 600
-- I kept this as it might be needed in the future.
--[[
Weapons = {}
Weapons["Guest"] = {"weapon_shotgun", "weapon_crowbar", "weapon_slam"}
Weapons["Member"] = {"weapon_shotgun", "weapon_crowbar", "weapon_slam", "weapon_stunstick"}
Weapons["Respected"] = {"weapon_shotgun", "weapon_crowbar", "weapon_slam", "weapon_stunstick", "weapon_physcannon"}
Weapons["Donator"] = {"weapon_shotgun", "weapon_crowbar", "weapon_slam", "weapon_stunstick", "weapon_physcannon", "weapon_357", "weapon_ar2", "weapon_crossbow"}
Weapons["Admin"] = {"weapon_shotgun", "weapon_crowbar", "weapon_slam"}
Weapons["SuperAdmin"] = {"weapon_shotgun", "weapon_crowbar", "weapon_slam", "weapon_stunstick"}
--]]
-- lua_openscript autorun/shared_loadoutaddon.lua
-- lua_openscript_cl autorun/shared_loadoutaddon.lua