├── .gitignore ├── LICENSE.txt ├── README.md ├── content ├── materials │ └── nutscript │ │ └── gui │ │ └── vignette.png └── resource │ └── fonts │ └── fontello.ttf ├── entities ├── entities │ ├── nut_item.lua │ ├── nut_money.lua │ └── nut_shipment.lua └── weapons │ ├── nut_hands.lua │ └── nut_poshelper.lua ├── gamemode ├── cl_init.lua ├── config │ ├── sh_config.lua │ └── sv_database.lua ├── core │ ├── cl_skin.lua │ ├── derma │ │ ├── cl_attribute.lua │ │ ├── cl_business.lua │ │ ├── cl_character.lua │ │ ├── cl_charcreate.lua │ │ ├── cl_classes.lua │ │ ├── cl_contextmenu.lua │ │ ├── cl_dev_icon.lua │ │ ├── cl_helps.lua │ │ ├── cl_information.lua │ │ ├── cl_intro.lua │ │ ├── cl_inventory.lua │ │ ├── cl_menu.lua │ │ ├── cl_menubutton.lua │ │ ├── cl_modelpanel.lua │ │ ├── cl_notice.lua │ │ ├── cl_noticebar.lua │ │ ├── cl_quick.lua │ │ ├── cl_scoreboard.lua │ │ ├── cl_shipment.lua │ │ ├── cl_spawnicon.lua │ │ └── cl_tooltip.lua │ ├── hooks │ │ ├── cl_hooks.lua │ │ ├── sh_hooks.lua │ │ └── sv_hooks.lua │ ├── libs │ │ ├── cl_bar.lua │ │ ├── cl_hud.lua │ │ ├── cl_markup.lua │ │ ├── cl_menu.lua │ │ ├── cl_networking.lua │ │ ├── sh_anims.lua │ │ ├── sh_attribs.lua │ │ ├── sh_business.lua │ │ ├── sh_character.lua │ │ ├── sh_chatbox.lua │ │ ├── sh_class.lua │ │ ├── sh_command.lua │ │ ├── sh_currency.lua │ │ ├── sh_date.lua │ │ ├── sh_faction.lua │ │ ├── sh_flag.lua │ │ ├── sh_item.lua │ │ ├── sh_language.lua │ │ ├── sh_log.lua │ │ ├── sh_notice.lua │ │ ├── sh_player.lua │ │ ├── sh_plugin.lua │ │ ├── sv_database.lua │ │ ├── sv_networking.lua │ │ ├── sv_player.lua │ │ └── thirdparty │ │ │ ├── cl_ikon.lua │ │ │ ├── sh_netstream2.lua │ │ │ ├── sh_pon.lua │ │ │ └── sh_utf8.lua │ ├── meta │ │ ├── sh_character.lua │ │ ├── sh_inventory.lua │ │ └── sh_item.lua │ ├── sh_commands.lua │ ├── sh_config.lua │ ├── sh_util.lua │ └── sv_data.lua ├── init.lua ├── items │ ├── ammo │ │ ├── sh_357ammo.txt │ │ ├── sh_ar2ammo.txt │ │ ├── sh_crossbowammo.txt │ │ ├── sh_pistolammo.txt │ │ ├── sh_rocketammo.txt │ │ ├── sh_shotgunammo.txt │ │ └── sh_smg1ammo.txt │ ├── bags │ │ ├── sh_large.txt │ │ └── sh_small.txt │ ├── base │ │ ├── sh_ammo.lua │ │ ├── sh_bags.lua │ │ ├── sh_outfit.lua │ │ ├── sh_pacoutfit.lua │ │ └── sh_weapons.lua │ ├── pacoutfit │ │ └── sh_skullmask.txt │ ├── sh_defaultitem.txt │ └── weapons │ │ ├── sh_357.txt │ │ ├── sh_ar2.txt │ │ ├── sh_crowbar.txt │ │ ├── sh_pistol.txt │ │ └── sh_smg1.txt ├── languages │ ├── sh_dutch.lua │ ├── sh_english.lua │ ├── sh_french.lua │ ├── sh_korean.lua │ ├── sh_norwegian.lua │ ├── sh_polish.lua │ ├── sh_russian.lua │ └── sh_spanish.lua └── shared.lua ├── nutscript.txt └── plugins ├── 3dpanel.lua ├── 3dtext.lua ├── act ├── sh_plugin.lua └── sh_setup.lua ├── ammosave.lua ├── area ├── derma │ └── cl_areamanager.lua ├── entities │ └── weapons │ │ └── nut_areahelper.lua ├── languages │ ├── sh_english.lua │ └── sh_russian └── sh_plugin.lua ├── chatbox ├── derma │ ├── cl_chatbox.lua │ └── cl_markup.lua └── sh_plugin.lua ├── crosshair.lua ├── doors ├── cl_plugin.lua ├── derma │ └── cl_door.lua ├── entities │ └── weapons │ │ └── nut_keys.lua ├── sh_commands.lua ├── sh_plugin.lua └── sv_plugin.lua ├── logging.lua ├── mapscene.lua ├── observer.lua ├── pac.lua ├── permakill.lua ├── propprotect.lua ├── recognition.lua ├── saveitems.lua ├── sh_scash_abuse.lua ├── spawns.lua ├── spawnsaver.lua ├── stamina ├── attributes │ ├── sh_end.lua │ └── sh_stm.lua └── sh_plugin.lua ├── storage ├── entities │ └── entities │ │ └── nut_storage.lua ├── sh_definitions.lua └── sh_plugin.lua ├── strength ├── attributes │ └── sh_str.lua └── sh_plugin.lua ├── thirdperson.lua ├── typing.lua ├── vendor ├── derma │ ├── cl_vendor.lua │ ├── cl_vendoreditor.lua │ └── cl_vendorfaction.lua ├── entities │ └── entities │ │ └── nut_vendor.lua └── sh_plugin.lua └── wepselect.lua /.gitignore: -------------------------------------------------------------------------------- 1 | gamemode/config/sv_database.lua 2 | 3 | # vscode 4 | .vscode/* 5 | .history 6 | 7 | # swap 8 | [._]*.s[a-v][a-z] 9 | [._]*.sw[a-p] 10 | [._]s[a-v][a-z] 11 | [._]sw[a-p] 12 | 13 | # session 14 | Session.vim 15 | 16 | # temporary 17 | .netrwhist 18 | *~ 19 | 20 | # auto-generated tag files 21 | tags 22 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Brian Hang, Kyu Yeon Lee 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![NutScript Logo](https://static.miraheze.org/nutscriptwiki/2/26/Nutscript.png) 2 | >NutScript is a DRM-free, and open source framework created by Chessnut and Black Tea for Garry's Mod. 3 | 4 | # READ: 5 | ## NutScript development has been transferred to another repository. Use https://github.com/NutScript/NutScript/ 6 | 7 | ## NutScript 1.1 8 | NutScript 1.1 is a complete re-write of the old version [1.0](https://github.com/rebel1324/NutScript/tree/master) 9 | 10 | Schemas: 11 | - [Sample Schema](https://github.com/rebel1324/Sample-Schema-1.1) 12 | - [HL2RP](https://github.com/Chessnut/hl2rp) 13 | - [CityRP](https://github.com/rebel1324/CityRP) 14 | - [NutsZ](https://github.com/rebel1324/NutsZ) 15 | - [Respite](https://github.com/Chancerawr/respite) 16 | - [FalloutRP](https://github.com/vingard/falloutrp) (Broken) 17 | 18 | ## NutScript 1.1-beta 19 | 1.1-beta is an improved version of NutScript 1.1. Some libraries have been rewritten using the Promises Lib, like the JavaScript ones. 20 | 21 | Schemas: 22 | - [CityRP](https://github.com/rebel1324/CityRP/tree/1.1-beta) 23 | - [Sample Schema](https://github.com/ts-co/sample-schema) 24 | - [Metro 2033](https://github.com/ts-co/Metro-2033) 25 | - [Respite](https://github.com/Chancerawr/respite/tree/Beta) 26 | 27 | ###### Documentation 28 | Check out the NutScript wiki at https://nutscript.miraheze.org/wiki/Main_Page 29 | 30 | ###### Community Discord 31 | NutScript's official Discord server: https://discord.gg/QUbmYuD 32 | -------------------------------------------------------------------------------- /content/materials/nutscript/gui/vignette.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rebel1324/NutScript/b626c68753b5b144501f49d4a975a890b810a693/content/materials/nutscript/gui/vignette.png -------------------------------------------------------------------------------- /content/resource/fonts/fontello.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rebel1324/NutScript/b626c68753b5b144501f49d4a975a890b810a693/content/resource/fonts/fontello.ttf -------------------------------------------------------------------------------- /entities/entities/nut_item.lua: -------------------------------------------------------------------------------- 1 | AddCSLuaFile() 2 | 3 | ENT.Base = "base_entity" 4 | ENT.Type = "anim" 5 | ENT.PrintName = "Item" 6 | ENT.Category = "NutScript" 7 | ENT.Spawnable = false 8 | ENT.RenderGroup = RENDERGROUP_BOTH 9 | 10 | if (SERVER) then 11 | function ENT:Initialize() 12 | self:SetModel("models/props_junk/watermelon01.mdl") 13 | self:SetSolid(SOLID_VPHYSICS) 14 | self:PhysicsInit(SOLID_VPHYSICS) 15 | self.health = 50 16 | 17 | local physObj = self:GetPhysicsObject() 18 | 19 | if (IsValid(physObj)) then 20 | physObj:EnableMotion(true) 21 | physObj:Wake() 22 | end 23 | 24 | hook.Run("OnItemSpawned", self) 25 | end 26 | 27 | function ENT:setHealth(amount) 28 | self.health = amount 29 | end 30 | 31 | function ENT:OnTakeDamage(dmginfo) 32 | local damage = dmginfo:GetDamage() 33 | self:setHealth(self.health - damage) 34 | 35 | if (self.health < 0 and !self.onbreak) then 36 | self.onbreak = true 37 | self:Remove() 38 | end 39 | end 40 | 41 | function ENT:setItem(itemID) 42 | local itemTable = nut.item.instances[itemID] 43 | 44 | if (itemTable) then 45 | local model = itemTable.onGetDropModel and itemTable:onGetDropModel(self) or itemTable.model 46 | 47 | self:SetSkin(itemTable.skin or 0) 48 | if (itemTable.worldModel) then 49 | self:SetModel(itemTable.worldModel == true and "models/props_junk/cardboard_box004a.mdl" or itemTable.worldModel) 50 | else 51 | self:SetModel(model) 52 | end 53 | self:SetModel(model) 54 | self:PhysicsInit(SOLID_VPHYSICS) 55 | self:SetSolid(SOLID_VPHYSICS) 56 | self:setNetVar("id", itemTable.uniqueID) 57 | self.nutItemID = itemID 58 | 59 | if (table.Count(itemTable.data) > 0) then 60 | self:setNetVar("data", itemTable.data) 61 | end 62 | 63 | local physObj = self:GetPhysicsObject() 64 | 65 | if (!IsValid(physObj)) then 66 | local min, max = Vector(-8, -8, -8), Vector(8, 8, 8) 67 | 68 | self:PhysicsInitBox(min, max) 69 | self:SetCollisionBounds(min, max) 70 | end 71 | 72 | if (IsValid(physObj)) then 73 | physObj:EnableMotion(true) 74 | physObj:Wake() 75 | end 76 | 77 | if (itemTable.onEntityCreated) then 78 | itemTable:onEntityCreated(self) 79 | end 80 | end 81 | end 82 | 83 | function ENT:OnRemove() 84 | if (!nut.shuttingDown and !self.nutIsSafe and self.nutItemID) then 85 | local itemTable = nut.item.instances[self.nutItemID] 86 | 87 | if (self.onbreak) then 88 | self:EmitSound("physics/cardboard/cardboard_box_break"..math.random(1, 3)..".wav") 89 | local position = self:LocalToWorld(self:OBBCenter()) 90 | 91 | local effect = EffectData() 92 | effect:SetStart(position) 93 | effect:SetOrigin(position) 94 | effect:SetScale(3) 95 | util.Effect("GlassImpact", effect) 96 | 97 | if (itemTable.onDestoryed) then 98 | itemTable:onDestoryed(self) 99 | end 100 | end 101 | 102 | if (itemTable) then 103 | if (itemTable.onRemoved) then 104 | itemTable:onRemoved() 105 | end 106 | 107 | nut.db.query("DELETE FROM nut_items WHERE _itemID = "..self.nutItemID) 108 | end 109 | end 110 | end 111 | 112 | function ENT:Think() 113 | local itemTable = self:getItemTable() 114 | 115 | if (itemTable.think) then 116 | itemTable:think(self) 117 | end 118 | 119 | return true 120 | end 121 | else 122 | ENT.DrawEntityInfo = true 123 | 124 | local toScreen = FindMetaTable("Vector").ToScreen 125 | local colorAlpha = ColorAlpha 126 | 127 | function ENT:onDrawEntityInfo(alpha) 128 | local itemTable = self.getItemTable(self) 129 | 130 | if (itemTable) then 131 | local oldData = itemTable.data 132 | itemTable.data = self.getNetVar(self, "data", {}) 133 | itemTable.entity = self 134 | 135 | local position = toScreen(self.LocalToWorld(self, self.OBBCenter(self))) 136 | local x, y = position.x, position.y 137 | local description = itemTable.getDesc(itemTable) 138 | 139 | if (description != self.desc) then 140 | self.desc = description 141 | self.markup = nut.markup.parse("" .. description .. "", ScrW() * 0.7) 142 | end 143 | 144 | nut.util.drawText(itemTable.getName and itemTable:getName() or L(itemTable.name), x, y, colorAlpha(nut.config.get("color"), alpha), 1, 1, nil, alpha * 0.65) 145 | 146 | y = y + 12 147 | if (self.markup) then 148 | self.markup:draw(x, y, TEXT_ALIGN_CENTER, TEXT_ALIGN_TOP) 149 | end 150 | 151 | x, y = hook.Run("DrawItemDescription", self, x, y, colorAlpha(color_white, alpha), alpha * 0.65) 152 | 153 | itemTable.entity = nil 154 | itemTable.data = oldData 155 | end 156 | end 157 | 158 | function ENT:DrawTranslucent() 159 | local itemTable = self:getItemTable() 160 | 161 | if (itemTable and itemTable.drawEntity) then 162 | itemTable:drawEntity(self) 163 | end 164 | end 165 | 166 | function ENT:Draw() 167 | self:DrawModel() 168 | end 169 | end 170 | 171 | function ENT:getItemID() 172 | return self:getNetVar("id", "") 173 | end 174 | 175 | function ENT:getItemTable() 176 | return nut.item.list[self:getItemID()] 177 | end 178 | 179 | function ENT:getData(key, default) 180 | local data = self:getNetVar("data", {}) 181 | 182 | return data[key] or default 183 | end 184 | -------------------------------------------------------------------------------- /entities/entities/nut_money.lua: -------------------------------------------------------------------------------- 1 | AddCSLuaFile() 2 | 3 | ENT.Type = "anim" 4 | ENT.PrintName = "Money" 5 | ENT.Category = "NutScript" 6 | ENT.Spawnable = false 7 | 8 | if (SERVER) then 9 | function ENT:Initialize() 10 | self:SetModel("models/props_lab/box01a.mdl") 11 | self:SetSolid(SOLID_VPHYSICS) 12 | self:PhysicsInit(SOLID_VPHYSICS) 13 | self:SetUseType(SIMPLE_USE) 14 | 15 | local physObj = self:GetPhysicsObject() 16 | 17 | if (IsValid(physObj)) then 18 | physObj:EnableMotion(true) 19 | physObj:Wake() 20 | else 21 | local min, max = Vector(-8, -8, -8), Vector(8, 8, 8) 22 | 23 | self:PhysicsInitBox(min, max) 24 | self:SetCollisionBounds(min, max) 25 | end 26 | end 27 | 28 | function ENT:Use(activator) 29 | if (self.client and self.charID) then 30 | local char = activator:getChar() 31 | 32 | if (char) then 33 | if (self.charID != char:getID() and self.client == activator) then 34 | activator:notifyLocalized("logged") 35 | 36 | return false 37 | end 38 | end 39 | end 40 | 41 | if (hook.Run("OnPickupMoney", activator, self) != false) then 42 | self:Remove() 43 | end 44 | end 45 | else 46 | ENT.DrawEntityInfo = true 47 | 48 | local toScreen = FindMetaTable("Vector").ToScreen 49 | local colorAlpha = ColorAlpha 50 | local drawText = nut.util.drawText 51 | local configGet = nut.config.get 52 | 53 | function ENT:onDrawEntityInfo(alpha) 54 | local position = toScreen(self.LocalToWorld(self, self.OBBCenter(self))) 55 | local x, y = position.x, position.y 56 | 57 | drawText(nut.currency.get(self.getAmount(self)), x, y, colorAlpha(configGet("color"), alpha), 1, 1, nil, alpha * 0.65) 58 | end 59 | end 60 | 61 | function ENT:setAmount(amount) 62 | self:setNetVar("amount", amount) 63 | end 64 | 65 | function ENT:getAmount() 66 | return self:getNetVar("amount", 0) 67 | end 68 | -------------------------------------------------------------------------------- /entities/entities/nut_shipment.lua: -------------------------------------------------------------------------------- 1 | AddCSLuaFile() 2 | 3 | ENT.Type = "anim" 4 | ENT.PrintName = "Shipment" 5 | ENT.Category = "NutScript" 6 | ENT.Spawnable = false 7 | 8 | if (SERVER) then 9 | function ENT:Initialize() 10 | self:SetModel("models/Items/item_item_crate.mdl") 11 | self:SetSolid(SOLID_VPHYSICS) 12 | self:PhysicsInit(SOLID_VPHYSICS) 13 | self:SetUseType(SIMPLE_USE) 14 | self:PrecacheGibs() 15 | 16 | local physObj = self:GetPhysicsObject() 17 | 18 | if (IsValid(physObj)) then 19 | physObj:EnableMotion(true) 20 | physObj:Wake() 21 | end 22 | 23 | self:setNetVar("delTime", CurTime() + 120) 24 | 25 | timer.Simple(120, function() 26 | if (IsValid(self)) then 27 | self:Remove() 28 | end 29 | end) 30 | end 31 | 32 | function ENT:Use(activator) 33 | if (activator:getChar() and activator:getChar():getID() == self:getNetVar("owner", 0) and hook.Run("PlayerCanOpenShipment", activator, self) != false) then 34 | activator.nutShipment = self 35 | netstream.Start(activator, "openShp", self, self.items) 36 | end 37 | end 38 | 39 | function ENT:setItems(items) 40 | self.items = items 41 | end 42 | 43 | function ENT:getItemCount() 44 | local count = 0 45 | 46 | for k, v in pairs(self.items) do 47 | count = count + math.max(v, 0) 48 | end 49 | 50 | return count 51 | end 52 | 53 | function ENT:OnRemove() 54 | self:EmitSound("physics/cardboard/cardboard_box_break"..math.random(1, 3)..".wav") 55 | 56 | local position = self:LocalToWorld(self:OBBCenter()) 57 | 58 | local effect = EffectData() 59 | effect:SetStart(position) 60 | effect:SetOrigin(position) 61 | effect:SetScale(3) 62 | util.Effect("GlassImpact", effect) 63 | end 64 | else 65 | ENT.DrawEntityInfo = true 66 | 67 | local toScreen = FindMetaTable("Vector").ToScreen 68 | local colorAlpha = ColorAlpha 69 | local drawText = nut.util.drawText 70 | 71 | local cir = {} 72 | local cir2= setmetatable({},{__index=function(self,key) 73 | local t = {} 74 | self[key]=t 75 | return t 76 | end}) 77 | 78 | local function drawCircle( x, y, radius, seg,angle,offset ) 79 | for i = 1, seg+1 do 80 | cir[i] = cir2[i] 81 | end 82 | 83 | for i=#cir,seg+2,-1 do 84 | cir[i]=nil 85 | end 86 | 87 | for i = 0, seg do 88 | local a = math.rad( ( i / seg ) * angle + offset ) 89 | local sa = math.sin( a ) 90 | local ca = math.cos( a ) 91 | local t = cir[i+1] 92 | t.x = x + sa * radius 93 | t.y = y + ca * radius 94 | t.u = sa * 0.5 + 0.5 95 | t.v = ca * 0.5 + 0.5 96 | end 97 | 98 | surface.DrawPoly( cir ) 99 | end 100 | 101 | local size = 150 102 | local tempMat = Material("particle/warp1_warp", "alphatest") 103 | function ENT:Draw() 104 | local pos, ang = self:GetPos(), self:GetAngles() 105 | 106 | self:DrawModel() 107 | 108 | pos = pos + self:GetUp()*25 109 | pos = pos + self:GetForward()*1 110 | pos = pos + self:GetRight()*3 111 | 112 | local delTime = math.max(math.ceil(self:getNetVar("delTime", 0) - CurTime()), 0) 113 | 114 | local func = function() 115 | surface.SetMaterial(tempMat) 116 | surface.SetDrawColor(0, 0, 0, 200) 117 | surface.DrawTexturedRect(-size/2, -size/2 - 10, size, size) 118 | 119 | nut.util.drawText("k", 0, 0, color_white, 1, 4, "nutIconsBig") 120 | nut.util.drawText(delTime, 0, -10, color_white, 1, 5, "nutBigFont") 121 | end 122 | 123 | cam.Start3D2D(pos, ang, .15) 124 | func() 125 | cam.End3D2D() 126 | 127 | ang:RotateAroundAxis(ang:Right(), 180) 128 | pos = pos - self:GetUp()*26 129 | 130 | cam.Start3D2D(pos, ang, .15) 131 | func() 132 | cam.End3D2D() 133 | end 134 | 135 | function ENT:onDrawEntityInfo(alpha) 136 | local position = toScreen(self.LocalToWorld(self, self.OBBCenter(self))) 137 | local x, y = position.x, position.y 138 | local owner = nut.char.loaded[self.getNetVar(self, "owner", 0)] 139 | 140 | drawText(L"shipment", x, y, colorAlpha(nut.config.get("color"), alpha), 1, 1, nil, alpha * 0.65) 141 | 142 | if (owner) then 143 | drawText(L("shipmentDesc", owner.getName(owner)), x, y + 16, colorAlpha(color_white, alpha), 1, 1, "nutSmallFont", alpha * 0.65) 144 | end 145 | end 146 | end -------------------------------------------------------------------------------- /gamemode/cl_init.lua: -------------------------------------------------------------------------------- 1 | -- Include features from the Sandbox gamemode. 2 | DeriveGamemode("sandbox") 3 | -- Define a global shared table to store NutScript information. 4 | nut = nut or {util = {}, gui = {}, meta = {}} 5 | 6 | -- Include core files. 7 | include("core/sh_util.lua") 8 | include("shared.lua") 9 | 10 | -- Sandbox stuff 11 | CreateConVar("cl_weaponcolor", "0.30 1.80 2.10", {FCVAR_ARCHIVE, FCVAR_USERINFO, FCVAR_DONTRECORD}, "The value is a Vector - so between 0-1 - not between 0-255") 12 | 13 | timer.Remove("HintSystem_OpeningMenu") 14 | timer.Remove("HintSystem_Annoy1") 15 | timer.Remove("HintSystem_Annoy2") -------------------------------------------------------------------------------- /gamemode/config/sv_database.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Welcome to the NutScript database configuration. 3 | Here, you can change what method of data storage you would prefer. 4 | 5 | The following methods are available: 6 | - tmysql4 7 | - https://code.google.com/p/blackawps-glua-modules/source/browse/gm_tmysql4_boost/Release/ 8 | - Includes both Windows and Linux 9 | - Requires setup (see below) 10 | - mysqloo 11 | - http://facepunch.com/showthread.php?t=1357773 12 | - Includes both Windows and Linux 13 | - Requires setup (see below) 14 | - sqlite 15 | - No download needed 16 | - No setup required 17 | 18 | If you want to use an external database (tmysql4 and mysqloo) then 19 | you will need to place the included .dll files into your server's 20 | lua/bin folder. Then place the libmysql files (tmysql's website says libs.rar and 21 | the mysqloo thread contains a link labeled libmysql) in the folder that contains 22 | srcds. 23 | 24 | The benefits of using an external database: 25 | - You can display stats on your website. 26 | - Can share data between servers. 27 | - Each to access data than with SQLite (SQLite data is stored in the sv.db file) 28 | Cons: 29 | - Requires setup 30 | - Some server providers do not allow the uploading of .dll files so you may need 31 | to ask them for support. 32 | - Is not as instant as SQLite (but the delay should be barely noticable) 33 | 34 | The following configurations are ONLY needed if you are going to be using an 35 | external database for your NutScript installation. 36 | --]] 37 | 38 | 39 | function GM:SetupDatabase() 40 | -- Which method of storage: sqlite, tmysql4, mysqloo 41 | nut.db.module = "sqlite" 42 | -- The hostname for the MySQL server. 43 | nut.db.hostname = "127.0.0.1" 44 | -- The username to login to the database. 45 | nut.db.username = "root" 46 | -- The password that is associated with the username. 47 | nut.db.password = "" 48 | -- The database that the user should login to. 49 | nut.db.database = "nutscript" 50 | -- The port for the database, you shouldn't need to change this. 51 | nut.db.port = 3306 52 | end -------------------------------------------------------------------------------- /gamemode/core/cl_skin.lua: -------------------------------------------------------------------------------- 1 | local SKIN = {} 2 | SKIN.fontFrame = "BudgetLabel" 3 | SKIN.fontTab = "nutSmallFont" 4 | SKIN.fontButton = "nutSmallFont" 5 | SKIN.Colours = table.Copy(derma.SkinList.Default.Colours) 6 | SKIN.Colours.Window.TitleActive = Color(0, 0, 0) 7 | SKIN.Colours.Window.TitleInactive = Color(255, 255, 255) 8 | 9 | SKIN.Colours.Button.Normal = Color(80, 80, 80) 10 | SKIN.Colours.Button.Hover = Color(255, 255, 255) 11 | SKIN.Colours.Button.Down = Color(180, 180, 180) 12 | SKIN.Colours.Button.Disabled = Color(0, 0, 0, 100) 13 | 14 | function SKIN:PaintFrame(panel) 15 | nut.util.drawBlur(panel, 10) 16 | 17 | surface.SetDrawColor(45, 45, 45, 200) 18 | surface.DrawRect(0, 0, panel:GetWide(), panel:GetTall()) 19 | 20 | surface.SetDrawColor(nut.config.get("color")) 21 | surface.DrawRect(0, 0, panel:GetWide(), 24) 22 | 23 | surface.SetDrawColor(nut.config.get("color")) 24 | surface.DrawOutlinedRect(0, 0, panel:GetWide(), panel:GetTall()) 25 | 26 | end 27 | 28 | function SKIN:DrawGenericBackground(x, y, w, h) 29 | surface.SetDrawColor(45, 45, 45, 240) 30 | surface.DrawRect(x, y, w, h) 31 | 32 | surface.SetDrawColor(0, 0, 0, 180) 33 | surface.DrawOutlinedRect(x, y, w, h) 34 | 35 | surface.SetDrawColor(100, 100, 100, 25) 36 | surface.DrawOutlinedRect(x + 1, y + 1, w - 2, h - 2) 37 | end 38 | 39 | function SKIN:PaintPanel(panel) 40 | if (panel:GetPaintBackground()) then 41 | local w, h = panel:GetWide(), panel:GetTall() 42 | 43 | surface.SetDrawColor(0, 0, 0, 100) 44 | surface.DrawRect(0, 0, w, h) 45 | surface.DrawOutlinedRect(0, 0, w, h) 46 | end 47 | end 48 | 49 | function SKIN:PaintButton(panel) 50 | if (panel:GetPaintBackground()) then 51 | local w, h = panel:GetWide(), panel:GetTall() 52 | local alpha = 50 53 | 54 | if (panel:GetDisabled()) then 55 | alpha = 10 56 | elseif (panel.Depressed) then 57 | alpha = 180 58 | elseif (panel.Hovered) then 59 | alpha = 75 60 | end 61 | 62 | surface.SetDrawColor(30, 30, 30, alpha) 63 | surface.DrawRect(0, 0, w, h) 64 | 65 | surface.SetDrawColor(0, 0, 0, 180) 66 | surface.DrawOutlinedRect(0, 0, w, h) 67 | 68 | surface.SetDrawColor(180, 180, 180, 2) 69 | surface.DrawOutlinedRect(1, 1, w - 2, h - 2) 70 | end 71 | end 72 | 73 | -- I don't think we gonna need minimize button and maximize button. 74 | function SKIN:PaintWindowMinimizeButton( panel, w, h ) 75 | end 76 | 77 | function SKIN:PaintWindowMaximizeButton( panel, w, h ) 78 | end 79 | 80 | derma.DefineSkin("nutscript", "The base skin for the NutScript framework.", SKIN) 81 | derma.RefreshSkins() -------------------------------------------------------------------------------- /gamemode/core/derma/cl_attribute.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | local gradient = nut.util.getMaterial("vgui/gradient-u") 3 | local gradient2 = nut.util.getMaterial("vgui/gradient-d") 4 | 5 | function PANEL:Init() 6 | self:SetTall(20) 7 | 8 | self.add = self:Add("DImageButton") 9 | self.add:SetSize(16, 16) 10 | self.add:Dock(RIGHT) 11 | self.add:DockMargin(2, 2, 2, 2) 12 | self.add:SetImage("icon16/add.png") 13 | self.add.OnMousePressed = function() 14 | self.pressing = 1 15 | self:doChange() 16 | self.add:SetAlpha(150) 17 | end 18 | self.add.OnMouseReleased = function() 19 | if (self.pressing) then 20 | self.pressing = nil 21 | self.add:SetAlpha(255) 22 | end 23 | end 24 | self.add.OnCursorExited = self.add.OnMouseReleased 25 | 26 | self.sub = self:Add("DImageButton") 27 | self.sub:SetSize(16, 16) 28 | self.sub:Dock(LEFT) 29 | self.sub:DockMargin(2, 2, 2, 2) 30 | self.sub:SetImage("icon16/delete.png") 31 | self.sub.OnMousePressed = function() 32 | self.pressing = -1 33 | self:doChange() 34 | self.sub:SetAlpha(150) 35 | end 36 | self.sub.OnMouseReleased = function() 37 | if (self.pressing) then 38 | self.pressing = nil 39 | self.sub:SetAlpha(255) 40 | end 41 | end 42 | self.sub.OnCursorExited = self.sub.OnMouseReleased 43 | 44 | self.value = 0 45 | self.deltaValue = self.value 46 | self.max = 10 47 | 48 | self.bar = self:Add("DPanel") 49 | self.bar:Dock(FILL) 50 | self.bar.Paint = function(this, w, h) 51 | surface.SetDrawColor(35, 35, 35, 250) 52 | surface.DrawRect(0, 0, w, h) 53 | 54 | w, h = w - 4, h - 4 55 | 56 | local value = self.deltaValue / self.max 57 | 58 | if (value > 0) then 59 | local color = nut.config.get("color") 60 | local boostedValue = self.boostValue or 0 61 | local add = 0 62 | 63 | if (self.deltaValue != self.value) then 64 | add = 35 65 | end 66 | 67 | -- your stat 68 | do 69 | if !(boostedValue < 0 and math.abs(boostedValue) > self.value) then 70 | surface.SetDrawColor(color.r + add, color.g + add, color.b + add, 230) 71 | surface.DrawRect(2, 2, w * value, h) 72 | 73 | surface.SetDrawColor(255, 255, 255, 35) 74 | surface.SetMaterial(gradient) 75 | surface.DrawTexturedRect(2, 2, w * value, h) 76 | end 77 | end 78 | 79 | -- boosted stat 80 | do 81 | if (boostedValue != 0) then 82 | 83 | if (boostedValue < 0) then 84 | local please = math.min(self.value, math.abs(boostedValue)) 85 | boostValue = ((please or 0) / self.max) * (self.deltaValue / self.value) 86 | else 87 | boostValue = ((boostedValue or 0) / self.max) * (self.deltaValue / self.value) 88 | end 89 | 90 | if (boostedValue < 0) then 91 | surface.SetDrawColor(200, 40, 40, 230) 92 | 93 | local bWidth = math.abs(w * boostValue) 94 | surface.DrawRect(2 + w * value - bWidth, 2, bWidth, h) 95 | 96 | surface.SetDrawColor(255, 255, 255, 35) 97 | surface.SetMaterial(gradient) 98 | surface.DrawTexturedRect(2 + w * value - bWidth, 2, bWidth, h) 99 | else 100 | surface.SetDrawColor(40, 200, 40, 230) 101 | surface.DrawRect(2 + w * value, 2, w * boostValue, h) 102 | 103 | surface.SetDrawColor(255, 255, 255, 35) 104 | surface.SetMaterial(gradient) 105 | surface.DrawTexturedRect(2 + w * value, 2, w * boostValue, h) 106 | end 107 | end 108 | end 109 | end 110 | 111 | surface.SetDrawColor(255, 255, 255, 5) 112 | surface.SetMaterial(gradient2) 113 | surface.DrawTexturedRect(2, 2, w, h) 114 | end 115 | 116 | self.label = self.bar:Add("DLabel") 117 | self.label:Dock(FILL) 118 | self.label:SetExpensiveShadow(1, Color(0, 0, 60)) 119 | self.label:SetContentAlignment(5) 120 | end 121 | 122 | function PANEL:Think() 123 | if (self.pressing) then 124 | if ((self.nextPress or 0) < CurTime()) then 125 | self:doChange() 126 | end 127 | end 128 | 129 | self.deltaValue = math.Approach(self.deltaValue, self.value, FrameTime() * 15) 130 | end 131 | 132 | function PANEL:doChange() 133 | if ((self.value == 0 and self.pressing == -1) or (self.value == self.max and self.pressing == 1)) then 134 | return 135 | end 136 | 137 | self.nextPress = CurTime() + 0.2 138 | 139 | if (self:onChanged(self.pressing) != false) then 140 | self.value = math.Clamp(self.value + self.pressing, 0, self.max) 141 | end 142 | end 143 | 144 | function PANEL:onChanged(difference) 145 | end 146 | 147 | function PANEL:getValue() 148 | return self.value 149 | end 150 | 151 | function PANEL:setValue(value) 152 | self.value = value 153 | end 154 | 155 | function PANEL:setBoost(value) 156 | self.boostValue = value 157 | end 158 | 159 | function PANEL:setMax(max) 160 | self.max = max 161 | end 162 | 163 | function PANEL:setText(text) 164 | self.label:SetText(text) 165 | end 166 | 167 | function PANEL:setReadOnly() 168 | self.sub:Remove() 169 | self.add:Remove() 170 | end 171 | vgui.Register("nutAttribBar", PANEL, "DPanel") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_charcreate.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | function PANEL:Init() 3 | if (IsValid(nut.gui.charCreate)) then 4 | nut.gui.charCreate:Remove() 5 | end 6 | 7 | nut.gui.charCreate = self 8 | 9 | self:SetSize(ScrW() * 0.45, ScrH() * 0.55) 10 | self:SetPos(ScrW() * 0.3, ScrH() * 0.3 + 16) 11 | 12 | self.notice = self:Add("nutNoticeBar") 13 | self.notice:setType(4) 14 | self.notice:setText(L"charCreateTip") 15 | self.notice:SetWide(self:GetWide()) 16 | 17 | self.payload = {} 18 | self.lastY = self.notice:GetTall() + 8 19 | end 20 | 21 | function PANEL:addLabel(text) 22 | local label = self:Add("DLabel") 23 | label:SetPos(0, self.lastY) 24 | label:SetFont("nutMenuButtonFont") 25 | label:SetText(L(text)) 26 | label:SizeToContents() 27 | label:SetTextColor(color_white) 28 | label:SetExpensiveShadow(2, Color(0, 0, 0, 200)) 29 | 30 | self.lastY = self.lastY + label:GetTall() + 8 31 | 32 | return label 33 | end 34 | 35 | function PANEL:addTextBox() 36 | local textBox = self:Add("DTextEntry") 37 | textBox:SetFont("nutMenuButtonLightFont") 38 | textBox:SetWide(self:GetWide()) 39 | textBox:SetPos(0, self.lastY) 40 | textBox:SetTall(36) 41 | 42 | self.lastY = self.lastY + textBox:GetTall() + 8 43 | 44 | return textBox 45 | end 46 | 47 | function PANEL:setUp(faction) 48 | self.faction = faction 49 | self.payload.faction = self.faction 50 | 51 | for k, v in SortedPairsByMemberValue(nut.char.vars, "index") do 52 | if (!v.noDisplay and k != "__SortedIndex") then 53 | if (v.shouldDisplay) then 54 | if (v.shouldDisplay(self) == false) then 55 | continue 56 | end 57 | end 58 | 59 | self:addLabel(k) 60 | 61 | if (v.onDisplay) then 62 | local panel = v.onDisplay(self, self.lastY) 63 | 64 | if (IsValid(panel)) then 65 | self.lastY = self.lastY + panel:GetTall() + 8 66 | 67 | if (v.onPostSetup) then 68 | v.onPostSetup(panel, faction, self.payload) 69 | end 70 | end 71 | elseif (type(v.default) == "string") then 72 | local textBox = self:addTextBox() 73 | textBox.OnTextChanged = function(this) 74 | self.payload[k] = this:GetText() 75 | end 76 | 77 | if (v.onPostSetup) then 78 | v.onPostSetup(textBox, faction, self.payload) 79 | end 80 | end 81 | end 82 | end 83 | end 84 | vgui.Register("nutCharCreate", PANEL, "DScrollPanel") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_classes.lua: -------------------------------------------------------------------------------- 1 | 2 | local PANEL = {} 3 | function PANEL:Init() 4 | self:SetTall(64) 5 | 6 | local function assignClick(panel) 7 | panel.OnMousePressed = function() 8 | self.pressing = -1 9 | self:onClick() 10 | end 11 | panel.OnMouseReleased = function() 12 | if (self.pressing) then 13 | self.pressing = nil 14 | --self:onClick() 15 | end 16 | end 17 | end 18 | 19 | 20 | self.icon = self:Add("SpawnIcon") 21 | self.icon:SetSize(128, 64) 22 | self.icon:InvalidateLayout(true) 23 | self.icon:Dock(LEFT) 24 | self.icon.PaintOver = function(this, w, h) 25 | /* 26 | if (panel.payload.model == k) then 27 | local color = nut.config.get("color", color_white) 28 | 29 | surface.SetDrawColor(color.r, color.g, color.b, 200) 30 | 31 | for i = 1, 3 do 32 | local i2 = i * 2 33 | 34 | surface.DrawOutlinedRect(i, i, w - i2, h - i2) 35 | end 36 | 37 | surface.SetDrawColor(color.r, color.g, color.b, 75) 38 | surface.SetMaterial(gradient) 39 | surface.DrawTexturedRect(0, 0, w, h) 40 | end 41 | */ 42 | end 43 | assignClick(self.icon) 44 | 45 | self.limit = self:Add("DLabel") 46 | self.limit:Dock(RIGHT) 47 | self.limit:SetMouseInputEnabled(true) 48 | self.limit:SetCursor("hand") 49 | self.limit:SetExpensiveShadow(1, Color(0, 0, 60)) 50 | self.limit:SetContentAlignment(5) 51 | self.limit:SetFont("nutMediumFont") 52 | self.limit:SetWide(64) 53 | assignClick(self.limit) 54 | 55 | self.label = self:Add("DLabel") 56 | self.label:Dock(FILL) 57 | self.label:SetMouseInputEnabled(true) 58 | self.label:SetCursor("hand") 59 | self.label:SetExpensiveShadow(1, Color(0, 0, 60)) 60 | self.label:SetContentAlignment(5) 61 | self.label:SetFont("nutMediumFont") 62 | assignClick(self.label) 63 | end 64 | 65 | function PANEL:onClick() 66 | nut.command.send("beclass", self.class) 67 | end 68 | 69 | function PANEL:setNumber(number) 70 | local limit = self.data.limit 71 | 72 | if (limit > 0) then 73 | self.limit:SetText(Format("%s/%s", number, limit)) 74 | else 75 | self.limit:SetText("∞") 76 | end 77 | end 78 | 79 | function PANEL:setClass(data) 80 | if (data.model) then 81 | local model = data.model 82 | if (type(model):lower() == "table") then 83 | model = table.Random(model) 84 | end 85 | 86 | self.icon:SetModel(model) 87 | else 88 | local char = LocalPlayer():getChar() 89 | local model = LocalPlayer():GetModel() 90 | 91 | if (char) then 92 | model = char:getModel() 93 | end 94 | 95 | self.icon:SetModel(model) 96 | end 97 | 98 | self.label:SetText(L(data.name)) 99 | self.data = data 100 | self.class = data.index 101 | 102 | self:setNumber(#nut.class.getPlayers(data.index)) 103 | end 104 | vgui.Register("nutClassPanel", PANEL, "DPanel") 105 | 106 | PANEL = {} 107 | function PANEL:Init() 108 | nut.gui.classes = self 109 | 110 | self:SetSize(self:GetParent():GetSize()) 111 | 112 | self.list = vgui.Create("DPanelList", self) 113 | self.list:Dock(FILL) 114 | self.list:EnableVerticalScrollbar() 115 | self.list:SetSpacing(5) 116 | self.list:SetPadding(5) 117 | 118 | self.classPanels = {} 119 | self:loadClasses() 120 | end 121 | 122 | function PANEL:loadClasses() 123 | self.list:Clear() 124 | 125 | for k, v in ipairs(nut.class.list) do 126 | local no, why = nut.class.canBe(LocalPlayer(), k) 127 | local itsFull = ("class is full" == why) 128 | 129 | if (no or itsFull) then 130 | local panel = vgui.Create("nutClassPanel", self.list) 131 | panel:setClass(v) 132 | table.insert(self.classPanels, panel) 133 | 134 | self.list:AddItem(panel) 135 | end 136 | end 137 | end 138 | vgui.Register("nutClasses", PANEL, "EditablePanel") 139 | 140 | hook.Add("CreateMenuButtons", "nutClasses", function(tabs) 141 | local cnt = table.Count(nut.class.list) 142 | 143 | if (cnt <= 1) then return end 144 | 145 | for k, v in ipairs(nut.class.list) do 146 | if (!nut.class.canBe(LocalPlayer(), k)) then 147 | continue 148 | else 149 | tabs["classes"] = function(panel) 150 | panel:Add("nutClasses") 151 | end 152 | 153 | return 154 | end 155 | end 156 | end) 157 | 158 | netstream.Hook("classUpdate", function(joinedClient) 159 | if (nut.gui.classes and nut.gui.classes:IsVisible()) then 160 | if (joinedClient == LocalPlayer()) then 161 | nut.gui.classes:loadClasses() 162 | else 163 | for k, v in ipairs(nut.gui.classes.classPanels) do 164 | local data = v.data 165 | 166 | v:setNumber(#nut.class.getPlayers(data.index)) 167 | end 168 | end 169 | end 170 | end) -------------------------------------------------------------------------------- /gamemode/core/derma/cl_helps.lua: -------------------------------------------------------------------------------- 1 | if (CLIENT) then 2 | local HELP_DEFAULT 3 | 4 | hook.Add("CreateMenuButtons", "nutHelpMenu", function(tabs) 5 | HELP_DEFAULT = [[ 6 |
7 |
8 | 9 |
]] .. L"helpDefault" .. [[ 10 |
11 |
12 | ]] 13 | 14 | tabs["help"] = function(panel) 15 | local html 16 | local header = [[ 17 | 18 | 39 | 40 | 41 | ]] 42 | 43 | local tree = panel:Add("DTree") 44 | tree:SetPadding(5) 45 | tree:Dock(LEFT) 46 | tree:SetWide(180) 47 | tree:DockMargin(0, 0, 15, 0) 48 | tree.OnNodeSelected = function(this, node) 49 | if (node.onGetHTML) then 50 | local source = node:onGetHTML() 51 | 52 | if (source:sub(1, 4) == "http") then 53 | html:OpenURL(source) 54 | else 55 | html:SetHTML(header..node:onGetHTML().."") 56 | end 57 | end 58 | end 59 | 60 | html = panel:Add("DHTML") 61 | html:Dock(FILL) 62 | html:SetHTML(header..HELP_DEFAULT) 63 | 64 | local tabs = {} 65 | hook.Run("BuildHelpMenu", tabs) 66 | 67 | for k, v in SortedPairs(tabs) do 68 | if (type(v) != "function") then 69 | local source = v 70 | 71 | v = function() return tostring(source) end 72 | end 73 | 74 | tree:AddNode(L(k)).onGetHTML = v or function() return "" end 75 | end 76 | end 77 | end) 78 | end 79 | 80 | hook.Add("BuildHelpMenu", "nutBasicHelp", function(tabs) 81 | tabs["commands"] = function(node) 82 | local body = "" 83 | 84 | for k, v in SortedPairs(nut.command.list) do 85 | local allowed = false 86 | 87 | if (v.adminOnly and !LocalPlayer():IsAdmin()or v.superAdminOnly and !LocalPlayer():IsSuperAdmin()) then 88 | continue 89 | end 90 | 91 | if (v.group) then 92 | if (type(v.group) == "table") then 93 | for k, v in pairs(v.group) do 94 | if (LocalPlayer():IsUserGroup(v)) then 95 | allowed = true 96 | 97 | break 98 | end 99 | end 100 | elseif (LocalPlayer():IsUserGroup(v.group)) then 101 | return true 102 | end 103 | else 104 | allowed = true 105 | end 106 | 107 | if (allowed) then 108 | body = body.."

/"..k.."

Syntax: "..v.syntax.."

" 109 | end 110 | end 111 | 112 | return body 113 | end 114 | 115 | tabs["plugins"] = function(node) 116 | local body = "" 117 | 118 | for k, v in SortedPairsByMemberValue(nut.plugin.list, "name") do 119 | body = (body..[[ 120 |

121 | %s
122 | 123 | %s: %s
124 | %s: %s 125 | ]]):format(v.name or "Unknown", L"desc", v.desc or L"noDesc", L"author", v.author) 126 | 127 | if (v.version) then 128 | body = body.."
"..L"version"..": "..v.version 129 | end 130 | 131 | body = body.."

" 132 | end 133 | 134 | return body 135 | end 136 | 137 | tabs["flags"] = function(node) 138 | local body = [[]] 139 | 140 | for k, v in SortedPairs(nut.flag.list) do 141 | local icon 142 | 143 | if (LocalPlayer():getChar():hasFlags(k)) then 144 | icon = [[]] 145 | else 146 | icon = [[]] 147 | end 148 | 149 | body = body..Format([[ 150 | 151 | 152 | 153 | 154 | 155 | ]], icon, k, v.desc) 156 | end 157 | 158 | return body.."
%s%s%s
" 159 | end 160 | end) -------------------------------------------------------------------------------- /gamemode/core/derma/cl_intro.lua: -------------------------------------------------------------------------------- 1 | local gradient = nut.util.getMaterial("vgui/gradient-r.vtf") 2 | local glow = surface.GetTextureID("particle/Particle_Glow_04_Additive") 3 | 4 | local PANEL = {} 5 | function PANEL:Init() 6 | 7 | if (IsValid(nut.gui.intro)) then 8 | nut.gui.intro:Remove() 9 | end 10 | 11 | nut.gui.intro = self 12 | 13 | self:SetSize(ScrW(), ScrH()) 14 | self:SetZPos(9999) 15 | 16 | timer.Simple(0.1, function() 17 | if (!IsValid(self)) then 18 | return 19 | end 20 | 21 | self.sound = CreateSound(LocalPlayer(), "music/hl1_song20.mp3") 22 | self.sound:Play() 23 | self.sound:ChangePitch(80, 0) 24 | end) 25 | 26 | self.authors = self:Add("DLabel") 27 | self.authors:SetText(GAMEMODE.Author.." Presents") 28 | self.authors:SetFont("nutIntroMediumFont") 29 | self.authors:SetTextColor(color_white) 30 | self.authors:SetAlpha(0) 31 | self.authors:AlphaTo(255, 5, 1.5, function() 32 | self.authors:AlphaTo(0, 5, 3, function() 33 | self.authors:SetText("In collaboration with "..SCHEMA.author) 34 | self.authors:SizeToContents() 35 | self.authors:CenterHorizontal() 36 | 37 | self.authors:AlphaTo(255, 3, 0.5, function() 38 | if (self.sound) then 39 | self.sound:FadeOut(8) 40 | self.sound:FadeOut(8) 41 | end 42 | 43 | self.authors:AlphaTo(0, 3, 1, function() 44 | LocalPlayer():EmitSound("music/hl2_song10.mp3", 150, 70) 45 | 46 | self.cover:MoveTo(self.name:GetWide(), 0, 7.5, 5, nil, function() 47 | self.glow = true 48 | self.delta = 0 49 | 50 | self.schema:AlphaTo(255, 5, 1) 51 | end) 52 | end) 53 | end) 54 | end) 55 | end) 56 | self.authors:SizeToContents() 57 | self.authors:Center() 58 | self.authors:SetZPos(99) 59 | 60 | self.name = self:Add("DLabel") 61 | self.name:SetText(GAMEMODE.Name) 62 | self.name:SetFont("nutIntroTitleFont") 63 | self.name:SetTextColor(color_white) 64 | self.name:SizeToContents() 65 | self.name:Center() 66 | self.name:SetPos(self.name.x, ScrH() * 0.4) 67 | self.name:SetExpensiveShadow(2, color_black) 68 | 69 | self.schema = self:Add("DLabel") 70 | self.schema:SetText(SCHEMA.introName and L(SCHEMA.introName) or L(SCHEMA.name)) 71 | self.schema:SetFont("nutIntroBigFont") 72 | self.schema:SizeToContents() 73 | self.schema:Center() 74 | self.schema:MoveBelow(self.name, 10) 75 | self.schema:SetAlpha(0) 76 | self.schema:SetExpensiveShadow(2, color_black) 77 | 78 | self.cover = self.name:Add("DPanel") 79 | self.cover:SetSize(ScrW(), self.name:GetTall()) 80 | self.cover.Paint = function(this, w, h) 81 | surface.SetDrawColor(0, 0, 0) 82 | surface.SetMaterial(gradient) 83 | surface.DrawTexturedRect(0, 0, 100, h) 84 | 85 | surface.DrawRect(100, 0, ScrW(), h) 86 | end 87 | self.cover:SetPos(-100, 0) 88 | 89 | timer.Simple(5, function() 90 | if (IsValid(self)) then 91 | self:addContinue() 92 | end 93 | end) 94 | end 95 | 96 | function PANEL:addContinue() 97 | self.info = self:Add("DLabel") 98 | self.info:Dock(BOTTOM) 99 | self.info:SetTall(36) 100 | self.info:DockMargin(0, 0, 0, 32) 101 | self.info:SetText("Press Space to continue...") 102 | self.info:SetFont("nutIntroSmallFont") 103 | self.info:SetContentAlignment(2) 104 | self.info:SetAlpha(0) 105 | self.info:AlphaTo(255, 1, 0, function() 106 | self.info.Paint = function(this) 107 | this:SetAlpha(math.abs(math.cos(RealTime() * 0.8) * 255)) 108 | end 109 | end) 110 | self.info:SetExpensiveShadow(1, color_black) 111 | end 112 | 113 | function PANEL:Think() 114 | if (IsValid(self.info) and input.IsKeyDown(KEY_SPACE) and !self.closing) then 115 | self.closing = true 116 | self:AlphaTo(0, 2.5, 0, function() 117 | self:Remove() 118 | end) 119 | end 120 | end 121 | 122 | function PANEL:OnRemove() 123 | if (self.sound) then 124 | self.sound:Stop() 125 | self.sound = nil 126 | 127 | if (IsValid(nut.gui.char)) then 128 | nut.gui.char:playMusic() 129 | end 130 | end 131 | end 132 | 133 | function PANEL:Paint(w, h) 134 | surface.SetDrawColor(0, 0, 0) 135 | surface.DrawRect(0, 0, w, h) 136 | 137 | if (self.glow) then 138 | self.delta = math.Approach(self.delta, 100, FrameTime() * 10) 139 | 140 | local x, y = ScrW()*0.5 - 700, ScrH()*0.5 - 340 141 | 142 | surface.SetDrawColor(self.delta, self.delta, self.delta, self.delta + math.sin(RealTime() * 0.7)*10) 143 | surface.SetTexture(glow) 144 | surface.DrawTexturedRect(x, y, 1400, 680) 145 | end 146 | end 147 | vgui.Register("nutIntro", PANEL, "EditablePanel") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_menu.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | local gradient = nut.util.getMaterial("vgui/gradient-u") 3 | local gradient2 = nut.util.getMaterial("vgui/gradient-d") 4 | local alpha = 80 5 | 6 | function PANEL:Init() 7 | if (IsValid(nut.gui.menu)) then 8 | nut.gui.menu:Remove() 9 | end 10 | 11 | nut.gui.menu = self 12 | 13 | self:SetSize(ScrW(), ScrH()) 14 | self:SetAlpha(0) 15 | self:AlphaTo(255, 0.25, 0) 16 | self:SetPopupStayAtBack(true) 17 | 18 | self.tabs = self:Add("DHorizontalScroller") 19 | self.tabs:SetWide(0) 20 | self.tabs:SetTall(86) 21 | 22 | self.panel = self:Add("EditablePanel") 23 | self.panel:SetSize(ScrW() * 0.6, ScrH() * 0.65) 24 | self.panel:Center() 25 | self.panel:SetPos(self.panel.x, self.panel.y + 72) 26 | self.panel:SetAlpha(0) 27 | 28 | self.title = self:Add("DLabel") 29 | self.title:SetPos(self.panel.x, self.panel.y - 80) 30 | self.title:SetTextColor(color_white) 31 | self.title:SetExpensiveShadow(1, Color(0, 0, 0, 150)) 32 | self.title:SetFont("nutTitleFont") 33 | self.title:SetText("") 34 | self.title:SetAlpha(0) 35 | self.title:SetSize(self.panel:GetWide(), 72) 36 | 37 | local tabs = {} 38 | 39 | hook.Run("CreateMenuButtons", tabs) 40 | 41 | self.tabList = {} 42 | 43 | for name, callback in SortedPairs(tabs) do 44 | if (type(callback) == "string") then 45 | local body = callback 46 | 47 | if (body:sub(1, 4) == "http") then 48 | callback = function(panel) 49 | local html = panel:Add("DHTML") 50 | html:Dock(FILL) 51 | html:OpenURL(body) 52 | end 53 | else 54 | callback = function(panel) 55 | local html = panel:Add("DHTML") 56 | html:Dock(FILL) 57 | html:SetHTML(body) 58 | end 59 | end 60 | end 61 | 62 | local tab = self:addTab(L(name), callback, name) 63 | self.tabList[name] = tab 64 | end 65 | 66 | self.noAnchor = CurTime() + .4 67 | self.anchorMode = true 68 | self:MakePopup() 69 | 70 | self.info = vgui.Create("nutCharInfo", self) 71 | self.info:setup() 72 | self.info:SetAlpha(0) 73 | self.info:AlphaTo(255, 0.5) 74 | end 75 | 76 | function PANEL:OnKeyCodePressed(key) 77 | self.noAnchor = CurTime() + .5 78 | 79 | if (key == KEY_F1) then 80 | self:remove() 81 | end 82 | end 83 | 84 | function PANEL:Think() 85 | local key = input.IsKeyDown(KEY_F1) 86 | if (key and (self.noAnchor or CurTime()+.4) < CurTime() and self.anchorMode == true) then 87 | self.anchorMode = false 88 | surface.PlaySound("buttons/lightswitch2.wav") 89 | end 90 | 91 | if (!self.anchorMode) then 92 | if (IsValid(self.info) and self.info.desc:IsEditing()) then 93 | return 94 | end 95 | 96 | if (!key) then 97 | self:remove() 98 | end 99 | end 100 | end 101 | 102 | local color_bright = Color(240, 240, 240, 180) 103 | 104 | function PANEL:Paint(w, h) 105 | nut.util.drawBlur(self, 12) 106 | 107 | surface.SetDrawColor(0, 0, 0) 108 | surface.SetMaterial(gradient) 109 | surface.DrawTexturedRect(0, 0, w, h) 110 | 111 | surface.SetDrawColor(30, 30, 30, alpha) 112 | surface.DrawRect(0, 0, w, 78) 113 | 114 | surface.SetDrawColor(color_bright) 115 | surface.DrawRect(0, 78, w, 8) 116 | end 117 | 118 | function PANEL:addTab(name, callback, uniqueID) 119 | name = L(name) 120 | 121 | local function paintTab(tab, w, h) 122 | if (self.activeTab == tab) then 123 | surface.SetDrawColor(ColorAlpha(nut.config.get("color"), 200)) 124 | surface.DrawRect(0, h - 8, w, 8) 125 | elseif (tab.Hovered) then 126 | surface.SetDrawColor(0, 0, 0, 50) 127 | surface.DrawRect(0, h - 8, w, 8) 128 | end 129 | end 130 | 131 | surface.SetFont("nutMenuButtonLightFont") 132 | local w = surface.GetTextSize(name) 133 | 134 | local tab = self.tabs:Add("DButton") 135 | tab:SetSize(0, self.tabs:GetTall()) 136 | tab:SetText(name) 137 | tab:SetPos(self.tabs:GetWide(), 0) 138 | tab:SetTextColor(Color(250, 250, 250)) 139 | tab:SetFont("nutMenuButtonLightFont") 140 | tab:SetExpensiveShadow(1, Color(0, 0, 0, 150)) 141 | tab:SizeToContentsX() 142 | tab:SetWide(w + 32) 143 | tab.Paint = paintTab 144 | tab.DoClick = function(this) 145 | if (IsValid(nut.gui.info)) then 146 | nut.gui.info:Remove() 147 | end 148 | 149 | self.panel:Clear() 150 | 151 | self.title:SetText(this:GetText()) 152 | self.title:SizeToContentsY() 153 | self.title:AlphaTo(255, 0.5) 154 | self.title:MoveAbove(self.panel, 8) 155 | 156 | self.panel:AlphaTo(255, 0.5, 0.1) 157 | self.activeTab = this 158 | lastMenuTab = uniqueID 159 | 160 | if (callback) then 161 | callback(self.panel, this) 162 | end 163 | end 164 | self.tabs:AddPanel(tab) 165 | 166 | self.tabs:SetWide(math.min(self.tabs:GetWide() + tab:GetWide(), ScrW())) 167 | self.tabs:SetPos((ScrW() * 0.5) - (self.tabs:GetWide() * 0.5), 0) 168 | 169 | return tab 170 | end 171 | 172 | function PANEL:setActiveTab(key) 173 | if (IsValid(self.tabList[key])) then 174 | self.tabList[key]:DoClick() 175 | end 176 | end 177 | 178 | function PANEL:OnRemove() 179 | end 180 | 181 | function PANEL:remove() 182 | CloseDermaMenus() 183 | 184 | if (!self.closing) then 185 | self:AlphaTo(0, 0.25, 0, function() 186 | self:Remove() 187 | end) 188 | self.closing = true 189 | end 190 | end 191 | vgui.Register("nutMenu", PANEL, "EditablePanel") 192 | 193 | if (IsValid(nut.gui.menu)) then 194 | vgui.Create("nutMenu") 195 | end -------------------------------------------------------------------------------- /gamemode/core/derma/cl_menubutton.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | function PANEL:Init() 3 | self:SetFont("nutMenuButtonFont") 4 | self:SetExpensiveShadow(2, Color(0, 0, 0, 200)) 5 | self:SetTextColor(color_white) 6 | self:SetDrawBackground(false) 7 | self.OldSetTextColor = self.SetTextColor 8 | self.SetTextColor = function(this, color) 9 | this:OldSetTextColor(color) 10 | this:SetFGColor(color) 11 | end 12 | end 13 | 14 | function PANEL:setText(text, noTranslation) 15 | surface.SetFont("nutMenuButtonFont") 16 | 17 | self:SetText(noTranslation and text:upper() or L(text):upper()) 18 | 19 | if (!noTranslation) then 20 | self:SetToolTip(L(text.."Tip")) 21 | end 22 | 23 | local w, h = surface.GetTextSize(self:GetText()) 24 | self:SetSize(w + 64, h + 32) 25 | end 26 | 27 | function PANEL:OnCursorEntered() 28 | local color = self:GetTextColor() 29 | self:SetTextColor(Color(math.max(color.r - 25, 0), math.max(color.g - 25, 0), math.max(color.b - 25, 0))) 30 | 31 | surface.PlaySound("ui/buttonrollover.wav") 32 | end 33 | 34 | function PANEL:OnCursorExited() 35 | if (self.color) then 36 | self:SetTextColor(self.color) 37 | else 38 | self:SetTextColor(color_white) 39 | end 40 | end 41 | 42 | function PANEL:OnMousePressed(code) 43 | if (self.color) then 44 | self:SetTextColor(self.color) 45 | else 46 | self:SetTextColor(nut.config.get("color")) 47 | end 48 | 49 | surface.PlaySound("ui/buttonclickrelease.wav") 50 | 51 | if (code == MOUSE_LEFT and self.DoClick) then 52 | self:DoClick(self) 53 | end 54 | end 55 | 56 | function PANEL:OnMouseReleased(key) 57 | if (self.color) then 58 | self:SetTextColor(self.color) 59 | else 60 | self:SetTextColor(color_white) 61 | end 62 | end 63 | vgui.Register("nutMenuButton", PANEL, "DButton") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_modelpanel.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | local MODEL_ANGLE = Angle(0, 45, 0) 3 | 4 | function PANEL:Init() 5 | self.brightness = 1 6 | 7 | self:SetCursor("none") 8 | self.OldSetModel = self.SetModel 9 | self.SetModel = function(self, model) 10 | self:OldSetModel(model) 11 | 12 | local entity = self.Entity 13 | 14 | if (IsValid(entity)) then 15 | local sequence = entity:SelectWeightedSequence(ACT_IDLE) 16 | 17 | if (sequence <= 0) then 18 | sequence = entity:LookupSequence("idle_unarmed") 19 | end 20 | 21 | if (sequence > 0) then 22 | entity:ResetSequence(sequence) 23 | else 24 | local found = false 25 | 26 | for k, v in ipairs(entity:GetSequenceList()) do 27 | if ((v:lower():find("idle") or v:lower():find("fly")) and v != "idlenoise") then 28 | entity:ResetSequence(v) 29 | found = true 30 | 31 | break 32 | end 33 | end 34 | 35 | if (!found) then 36 | entity:ResetSequence(4) 37 | end 38 | end 39 | 40 | entity:SetIK(false) 41 | end 42 | end 43 | end 44 | 45 | function PANEL:LayoutEntity() 46 | local scrW, scrH = ScrW(), ScrH() 47 | local xRatio = gui.MouseX() / scrW 48 | local yRatio = gui.MouseY() / scrH 49 | local x, y = self:LocalToScreen(self:GetWide() / 2) 50 | local xRatio2 = x / scrW 51 | local entity = self.Entity 52 | 53 | entity:SetPoseParameter("head_pitch", yRatio*90 - 30) 54 | entity:SetPoseParameter("head_yaw", (xRatio - xRatio2)*90 - 5) 55 | entity:SetAngles(MODEL_ANGLE) 56 | entity:SetIK(false) 57 | 58 | if (self.copyLocalSequence) then 59 | entity:SetSequence(LocalPlayer():GetSequence()) 60 | entity:SetPoseParameter("move_yaw", 360 * LocalPlayer():GetPoseParameter("move_yaw") - 180) 61 | end 62 | 63 | self:RunAnimation() 64 | end 65 | 66 | function PANEL:DrawModel() 67 | local brightness = self.brightness * 0.4 68 | local brightness2 = self.brightness * 1.5 69 | 70 | render.SetModelLighting(0, brightness2, brightness2, brightness2) 71 | 72 | for i = 1, 4 do 73 | render.SetModelLighting(i, brightness, brightness, brightness) 74 | end 75 | 76 | local fraction = (brightness / 1) * 0.1 77 | 78 | render.SetModelLighting(5, fraction, fraction, fraction) 79 | 80 | -- Excecute Some stuffs 81 | if (self.enableHook) then 82 | hook.Run("DrawNutModelView", self, self.Entity) 83 | end 84 | 85 | self.Entity:DrawModel() 86 | end 87 | 88 | function PANEL:OnMousePressed() 89 | end 90 | vgui.Register("nutModelPanel", PANEL, "DModelPanel") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_notice.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | local gradient = nut.util.getMaterial("vgui/gradient-d") 3 | 4 | function PANEL:Init() 5 | self:SetSize(256, 36) 6 | self:SetContentAlignment(5) 7 | self:SetExpensiveShadow(1, Color(0, 0, 0, 150)) 8 | self:SetFont("nutMediumFont") 9 | self:SetTextColor(color_white) 10 | self:SetDrawOnTop(true) 11 | end 12 | 13 | function PANEL:Paint(w, h) 14 | nut.util.drawBlur(self, 10) 15 | 16 | surface.SetDrawColor(230, 230, 230, 10) 17 | surface.DrawRect(0, 0, w, h) 18 | 19 | if (self.start) then 20 | local w2 = math.TimeFraction(self.start, self.endTime, CurTime()) * w 21 | 22 | surface.SetDrawColor(nut.config.get("color")) 23 | surface.DrawRect(w2, 0, w - w2, h) 24 | end 25 | 26 | surface.SetDrawColor(0, 0, 0, 45) 27 | surface.DrawOutlinedRect(0, 0, w, h) 28 | end 29 | vgui.Register("nutNotice", PANEL, "DLabel") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_noticebar.lua: -------------------------------------------------------------------------------- 1 | hook.Add("LoadFonts", "nutNoticeFont", function(font, genericFont) 2 | surface.CreateFont("nutNoticeFont", { 3 | font = genericFont, 4 | size = 16, 5 | weight = 500, 6 | extended = true, 7 | antialias = true 8 | }) 9 | end) 10 | 11 | local PANEL = {} 12 | 13 | PANEL.pnlTypes = { 14 | [1] = { -- NOT ALLOWED 15 | col = Color(200, 60, 60), 16 | icon = "icon16/exclamation.png" 17 | }, 18 | [2] = { -- COULD BE CANCELED 19 | col = Color(255, 100, 100), 20 | icon = "icon16/cross.png" 21 | }, 22 | [3] = { -- WILL BE CANCELED 23 | col = Color(255, 100, 100), 24 | icon = "icon16/cancel.png" 25 | }, 26 | [4] = { -- TUTORIAL/GUIDE 27 | col = Color(100, 185, 255), 28 | icon = "icon16/book.png" 29 | }, 30 | [5] = { -- ERROR 31 | col = Color(220, 200, 110), 32 | icon = "icon16/error.png" 33 | }, 34 | [6] = { -- YES 35 | col = Color(64, 185, 85), 36 | icon = "icon16/accept.png" 37 | }, 38 | [7] = { -- TUTORIAL/GUIDE 39 | col = Color(100, 185, 255), 40 | icon = "icon16/information.png" 41 | }, 42 | } 43 | 44 | function PANEL:Init() 45 | self.type = 1 46 | self.text = self:Add("DLabel") 47 | self.text:SetFont("nutNoticeFont") 48 | self.text:SetContentAlignment(5) 49 | self.text:SetTextColor(color_white) 50 | self.text:SizeToContents() 51 | self.text:Dock(FILL) 52 | self.text:DockMargin(2, 2, 2, 2) 53 | self.text:SetExpensiveShadow(1, Color(25, 25, 25, 120)) 54 | 55 | self:SetTall(28) 56 | end 57 | 58 | function PANEL:setType(value) 59 | self.type = value 60 | return 61 | end 62 | 63 | function PANEL:setText(value) 64 | self.text:SetText(value) 65 | end 66 | 67 | function PANEL:setFont(value) 68 | self.text:SetFont(value) 69 | end 70 | 71 | function PANEL:Paint() 72 | self.material = nut.util.getMaterial(self.pnlTypes[self.type].icon) 73 | 74 | local col = self.pnlTypes[self.type].col 75 | local mat = self.material 76 | local size = self:GetTall()*.6 77 | local marg = 3 78 | 79 | draw.RoundedBox(4, 0, 0, self:GetWide(), self:GetTall(), col) 80 | 81 | if (mat) then 82 | surface.SetDrawColor(color_white) 83 | surface.SetMaterial(mat) 84 | surface.DrawTexturedRect(size/2, self:GetTall()/2-size/2 + 1, size, size) 85 | end 86 | end 87 | 88 | vgui.Register("nutNoticeBar", PANEL, "DPanel") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_quick.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | function PANEL:Init() 3 | nut.gui.quick = self 4 | 5 | self:SetSize(400, 36) 6 | self:SetPos(ScrW() - 36, -36) 7 | self:MakePopup() 8 | self:SetKeyBoardInputEnabled(false) 9 | self:SetZPos(999) 10 | self:SetMouseInputEnabled(true) 11 | 12 | self.title = self:Add("DLabel") 13 | self.title:SetTall(36) 14 | self.title:Dock(TOP) 15 | self.title:SetFont("nutMediumFont") 16 | self.title:SetText(L"quickSettings") 17 | self.title:SetContentAlignment(4) 18 | self.title:SetTextInset(44, 0) 19 | self.title:SetTextColor(Color(250, 250, 250)) 20 | self.title:SetExpensiveShadow(1, Color(0, 0, 0, 175)) 21 | self.title.Paint = function(this, w, h) 22 | surface.SetDrawColor(nut.config.get("color")) 23 | surface.DrawRect(0, 0, w, h) 24 | end 25 | 26 | self.expand = self:Add("DButton") 27 | self.expand:SetContentAlignment(5) 28 | self.expand:SetText("`") 29 | self.expand:SetFont("nutIconsMedium") 30 | self.expand:SetDrawBackground(false) 31 | self.expand:SetTextColor(color_white) 32 | self.expand:SetExpensiveShadow(1, Color(0, 0, 0, 150)) 33 | self.expand:SetSize(36, 36) 34 | self.expand.DoClick = function(this) 35 | if (self.expanded) then 36 | self:SizeTo(self:GetWide(), 36, 0.15, nil, nil, function() 37 | self:MoveTo(ScrW() - 36, 0, 0.15) 38 | end) 39 | 40 | self.expanded = false 41 | else 42 | self:MoveTo(ScrW() - 400, 0, 0.15, nil, nil, function() 43 | local height = 0 44 | 45 | for k, v in pairs(self.items) do 46 | if (IsValid(v)) then 47 | height = height + v:GetTall() + 1 48 | end 49 | end 50 | 51 | self:SizeTo(self:GetWide(), 36 + height, 0.15) 52 | end) 53 | 54 | self.expanded = true 55 | end 56 | end 57 | 58 | self.scroll = self:Add("DScrollPanel") 59 | self.scroll:SetPos(0, 36) 60 | self.scroll:SetSize(self:GetWide(), ScrH() * 0.5) 61 | 62 | self:MoveTo(self.x, 0, 0.05) 63 | 64 | self.items = {} 65 | 66 | hook.Run("SetupQuickMenu", self) 67 | end 68 | 69 | local function paintButton(button, w, h) 70 | local alpha = 0 71 | 72 | if (button.Depressed or button.m_bSelected) then 73 | alpha = 5 74 | elseif (button.Hovered) then 75 | alpha = 2 76 | end 77 | 78 | surface.SetDrawColor(255, 255, 255, alpha) 79 | surface.DrawRect(0, 0, w, h) 80 | end 81 | 82 | function PANEL:addButton(text, callback) 83 | local button = self.scroll:Add("DButton") 84 | button:SetText(text) 85 | button:SetTall(36) 86 | button:Dock(TOP) 87 | button:DockMargin(0, 1, 0, 0) 88 | button:SetFont("nutMediumLightFont") 89 | button:SetExpensiveShadow(1, Color(0, 0, 0, 150)) 90 | button:SetContentAlignment(4) 91 | button:SetTextInset(8, 0) 92 | button:SetTextColor(color_white) 93 | button.Paint = paintButton 94 | 95 | if (callback) then 96 | button.DoClick = callback 97 | end 98 | 99 | self.items[#self.items + 1] = button 100 | 101 | return button 102 | end 103 | 104 | function PANEL:addSpacer() 105 | local panel = self.scroll:Add("DPanel") 106 | panel:SetTall(1) 107 | panel:Dock(TOP) 108 | panel:DockMargin(0, 1, 0, 0) 109 | panel.Paint = function(this, w, h) 110 | surface.SetDrawColor(255, 255, 255, 10) 111 | surface.DrawRect(0, 0, w, h) 112 | end 113 | 114 | self.items[#self.items + 1] = panel 115 | 116 | return panel 117 | end 118 | 119 | local color_dark = Color(255, 255, 255, 5) 120 | 121 | function PANEL:addCheck(text, callback, checked) 122 | local x, y 123 | local color 124 | 125 | local button = self:addButton(text, function(panel) 126 | panel.checked = !panel.checked 127 | 128 | if (callback) then 129 | callback(panel, panel.checked) 130 | end 131 | end) 132 | button.PaintOver = function(this, w, h) 133 | x, y = w - 8, h * 0.5 134 | 135 | if (this.checked) then 136 | color = nut.config.get("color") 137 | else 138 | color = color_dark 139 | end 140 | 141 | draw.SimpleText(self.icon or "F", "nutIconsSmall", x, y, color, 2, 1) 142 | end 143 | button.checked = checked 144 | 145 | return button 146 | end 147 | 148 | function PANEL:setIcon(char) 149 | self.icon = char 150 | end 151 | 152 | function PANEL:Paint(w, h) 153 | nut.util.drawBlur(self) 154 | 155 | surface.SetDrawColor(nut.config.get("color")) 156 | surface.DrawRect(0, 0, w, 36) 157 | 158 | surface.SetDrawColor(255, 255, 255, 5) 159 | surface.DrawRect(0, 0, w, h) 160 | end 161 | vgui.Register("nutQuick", PANEL, "EditablePanel") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_shipment.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | function PANEL:Init() 3 | self:SetSize(460, 360) 4 | self:SetTitle(L"shipment") 5 | self:Center() 6 | self:MakePopup() 7 | 8 | self.scroll = self:Add("DScrollPanel") 9 | self.scroll:Dock(FILL) 10 | 11 | self.list = self.scroll:Add("DListLayout") 12 | self.list:Dock(FILL) 13 | end 14 | 15 | function PANEL:setItems(entity, items) 16 | self.entity = entity 17 | self.items = true 18 | self.itemPanels = {} 19 | 20 | for k, v in SortedPairs(items) do 21 | local itemTable = nut.item.list[k] 22 | 23 | if (itemTable) then 24 | local item = self.list:Add("DPanel") 25 | item:SetTall(36) 26 | item:Dock(TOP) 27 | item:DockMargin(4, 4, 4, 0) 28 | 29 | item.icon = item:Add("SpawnIcon") 30 | item.icon:SetPos(2, 2) 31 | item.icon:SetSize(32, 32) 32 | item.icon:SetModel(itemTable.model) 33 | item.icon:SetToolTip(itemTable:getDesc()) 34 | 35 | item.quantity = item.icon:Add("DLabel") 36 | item.quantity:SetSize(32, 32) 37 | item.quantity:SetContentAlignment(3) 38 | item.quantity:SetTextInset(0, 0) 39 | item.quantity:SetText(v) 40 | item.quantity:SetFont("DermaDefaultBold") 41 | item.quantity:SetExpensiveShadow(1, Color(0, 0, 0, 150)) 42 | 43 | item.name = item:Add("DLabel") 44 | item.name:SetPos(38, 0) 45 | item.name:SetSize(200, 36) 46 | item.name:SetFont("nutSmallFont") 47 | item.name:SetText(L(itemTable.name)) 48 | item.name:SetContentAlignment(4) 49 | item.name:SetTextColor(color_white) 50 | 51 | item.take = item:Add("DButton") 52 | item.take:Dock(RIGHT) 53 | item.take:SetText(L"take") 54 | item.take:SetWide(48) 55 | item.take:DockMargin(3, 3, 3, 3) 56 | item.take.DoClick = function(this) 57 | netstream.Start("shpUse", k) 58 | items[k] = items[k] - 1 59 | 60 | item.quantity:SetText(items[k]) 61 | 62 | if (items[k] <= 0) then 63 | item:Remove() 64 | items[k] = nil 65 | end 66 | 67 | if (table.Count(items) == 0) then 68 | self:Remove() 69 | end 70 | end 71 | 72 | item.drop = item:Add("DButton") 73 | item.drop:Dock(RIGHT) 74 | item.drop:SetText(L"drop") 75 | item.drop:SetWide(48) 76 | item.drop:DockMargin(3, 3, 0, 3) 77 | item.drop.DoClick = function(this) 78 | netstream.Start("shpUse", k, 1) 79 | items[k] = items[k] - 1 80 | 81 | item.quantity:SetText(items[k]) 82 | 83 | if (items[k] <= 0) then 84 | item:Remove() 85 | end 86 | end 87 | 88 | self.itemPanels[k] = item 89 | end 90 | end 91 | end 92 | 93 | function PANEL:Think() 94 | if (self.items and !IsValid(self.entity)) then 95 | self:Remove() 96 | end 97 | end 98 | vgui.Register("nutShipment", PANEL, "DFrame") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_spawnicon.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | local MODEL_ANGLE = Angle(0, 45, 0) 3 | 4 | function PANEL:Init() 5 | self:setHidden(false) 6 | 7 | for i = 0, 5 do 8 | if (i == 1 or i == 5) then 9 | self:SetDirectionalLight(i, Color(155, 155, 155)) 10 | else 11 | self:SetDirectionalLight(i, Color(255, 255, 255)) 12 | end 13 | end 14 | 15 | self.OldSetModel = self.SetModel 16 | self.SetModel = function(self, model, skin, hidden) 17 | self:OldSetModel(model) 18 | 19 | local entity = self.Entity 20 | 21 | if (skin) then 22 | entity:SetSkin(skin) 23 | end 24 | 25 | local sequence = entity:SelectWeightedSequence(ACT_IDLE) 26 | 27 | if (sequence <= 0) then 28 | sequence = entity:LookupSequence("idle_unarmed") 29 | end 30 | 31 | if (sequence > 0) then 32 | entity:ResetSequence(sequence) 33 | else 34 | local found = false 35 | 36 | for k, v in ipairs(entity:GetSequenceList()) do 37 | if ((v:lower():find("idle") or v:lower():find("fly")) and v != "idlenoise") then 38 | entity:ResetSequence(v) 39 | found = true 40 | 41 | break 42 | end 43 | end 44 | 45 | if (!found) then 46 | entity:ResetSequence(4) 47 | end 48 | end 49 | 50 | local data = PositionSpawnIcon(entity, entity:GetPos()) 51 | 52 | if (data) then 53 | self:SetFOV(data.fov) 54 | self:SetCamPos(data.origin) 55 | self:SetLookAng(data.angles) 56 | end 57 | 58 | entity:SetIK(false) 59 | entity:SetEyeTarget(Vector(0, 0, 64)) 60 | end 61 | end 62 | 63 | function PANEL:setHidden(hidden) 64 | if (hidden) then 65 | self:SetAmbientLight(color_black) 66 | self:SetColor(Color(0, 0, 0)) 67 | 68 | for i = 0, 5 do 69 | self:SetDirectionalLight(i, color_black) 70 | end 71 | else 72 | self:SetAmbientLight(Color(20, 20, 20)) 73 | self:SetAlpha(255) 74 | 75 | for i = 0, 5 do 76 | if (i == 1 or i == 5) then 77 | self:SetDirectionalLight(i, Color(155, 155, 155)) 78 | else 79 | self:SetDirectionalLight(i, Color(255, 255, 255)) 80 | end 81 | end 82 | end 83 | end 84 | 85 | function PANEL:LayoutEntity() 86 | self:RunAnimation() 87 | end 88 | 89 | function PANEL:OnMousePressed() 90 | if (self.DoClick) then 91 | self:DoClick() 92 | end 93 | end 94 | vgui.Register("nutSpawnIcon", PANEL, "DModelPanel") -------------------------------------------------------------------------------- /gamemode/core/derma/cl_tooltip.lua: -------------------------------------------------------------------------------- 1 | if (SERVER) then return end 2 | 3 | TOOLTIP_GENERIC = 0 4 | TOOLTIP_ITEM = 1 5 | 6 | local tooltip_delay = 0.01 7 | 8 | local PANEL = {} 9 | 10 | function PANEL:Init() 11 | 12 | self:SetDrawOnTop( true ) 13 | self.DeleteContentsOnClose = false 14 | self:SetText( "" ) 15 | self:SetFont( "nutToolTipText" ) 16 | 17 | end 18 | 19 | function PANEL:UpdateColours( skin ) 20 | return self:SetTextStyleColor(color_black) 21 | end 22 | 23 | function PANEL:SetContents( panel, bDelete ) 24 | panel:SetParent( self ) 25 | 26 | self.Contents = panel 27 | self.DeleteContentsOnClose = bDelete or false 28 | self.Contents:SizeToContents() 29 | self:InvalidateLayout( true ) 30 | 31 | self.Contents:SetVisible( false ) 32 | end 33 | 34 | function PANEL:PerformLayout() 35 | if (self.iconMode != TOOLTIP_ITEM) then 36 | if ( self.Contents ) then 37 | self:SetWide( self.Contents:GetWide() + 8 ) 38 | self:SetTall( self.Contents:GetTall() + 8 ) 39 | self.Contents:SetPos( 4, 4 ) 40 | else 41 | local w, h = self:GetContentSize() 42 | self:SetSize( w + 8, h + 6 ) 43 | self:SetContentAlignment( 5 ) 44 | end 45 | end 46 | end 47 | 48 | local Mat = Material( "vgui/arrow" ) 49 | 50 | function PANEL:DrawArrow( x, y ) 51 | self.Contents:SetVisible( true ) 52 | 53 | surface.SetMaterial( Mat ) 54 | surface.DrawTexturedRect( self.ArrowPosX + x, self.ArrowPosY + y, self.ArrowWide, self.ArrowTall ) 55 | end 56 | 57 | local itemWidth = ScrW()*.15 58 | function PANEL:PositionTooltip() 59 | if ( !IsValid( self.TargetPanel ) ) then 60 | self:Remove() 61 | return 62 | end 63 | 64 | self:PerformLayout() 65 | 66 | local x, y = input.GetCursorPos() 67 | local w, h = self:GetSize() 68 | 69 | local lx, ly = self.TargetPanel:LocalToScreen( 0, 0 ) 70 | 71 | y = y - 50 72 | 73 | y = math.min( y, ly - h * 1.5 ) 74 | if ( y < 2 ) then y = 2 end 75 | 76 | -- Fixes being able to be drawn off screen 77 | self:SetPos( math.Clamp( x - w * 0.5, 0, ScrW() - self:GetWide() ), math.Clamp( y, 0, ScrH() - self:GetTall() ) ) 78 | end 79 | 80 | function PANEL:Paint( w, h ) 81 | self:PositionTooltip() 82 | 83 | if (self.iconMode == TOOLTIP_ITEM) then 84 | nut.util.drawBlur(self, 10) 85 | surface.SetDrawColor(55, 55, 55, 120) 86 | surface.DrawRect(0, 0, w, h) 87 | surface.SetDrawColor(255, 255, 255, 120) 88 | surface.DrawOutlinedRect(1, 1, w - 2, h - 2) 89 | 90 | if (self.markupObject) then 91 | self.markupObject:draw(15, 10) 92 | end 93 | else 94 | derma.SkinHook( "Paint", "Tooltip", self, w, h ) 95 | end 96 | end 97 | 98 | function PANEL:OpenForPanel( panel ) 99 | self.TargetPanel = panel 100 | self:PositionTooltip() 101 | 102 | if (panel.itemID) then 103 | self.iconMode = TOOLTIP_ITEM 104 | end 105 | 106 | if (self.iconMode == TOOLTIP_ITEM) then 107 | self.markupObject = nut.markup.parse(self:GetText(), itemWidth) 108 | self:SetText("") 109 | self:SetWide(math.max(itemWidth, 200) + 15) 110 | self:SetHeight(self.markupObject:getHeight() + 20) 111 | end 112 | 113 | if ( tooltip_delay > 0 ) then 114 | 115 | self:SetVisible( false ) 116 | timer.Simple( tooltip_delay, function() 117 | if ( !IsValid( self ) ) then return end 118 | if ( !IsValid( panel ) ) then return end 119 | 120 | self:PositionTooltip() 121 | self:SetVisible( true ) 122 | end ) 123 | end 124 | 125 | end 126 | 127 | function PANEL:Close() 128 | 129 | if ( !self.DeleteContentsOnClose && self.Contents ) then 130 | 131 | self.Contents:SetVisible( false ) 132 | self.Contents:SetParent( nil ) 133 | 134 | end 135 | 136 | self:Remove() 137 | 138 | end 139 | 140 | function PANEL:GenerateExample( ClassName, PropertySheet, Width, Height ) 141 | 142 | local ctrl = vgui.Create( "DButton" ) 143 | ctrl:SetText( "Hover me" ) 144 | ctrl:SetWide( 200 ) 145 | ctrl:SetTooltip( "This is a tooltip" ) 146 | 147 | PropertySheet:AddSheet( ClassName, ctrl, nil, true, true ) 148 | 149 | end 150 | 151 | derma.DefineControl( "DTooltip", "", PANEL, "DLabel" ) 152 | -------------------------------------------------------------------------------- /gamemode/core/libs/cl_bar.lua: -------------------------------------------------------------------------------- 1 | nut.bar = nut.bar or {} 2 | nut.bar.list = {} 3 | nut.bar.delta = nut.bar.delta or {} 4 | nut.bar.actionText = "" 5 | nut.bar.actionStart = 0 6 | nut.bar.actionEnd = 0 7 | 8 | function nut.bar.get(identifier) 9 | for i = 1, #nut.bar.list do 10 | local bar = nut.bar.list[i] 11 | 12 | if (bar and bar.identifier == identifier) then 13 | return bar 14 | end 15 | end 16 | end 17 | nut.bar.Get = nut.bar.get 18 | 19 | function nut.bar.add(getValue, color, priority, identifier) 20 | if (identifier) then 21 | local oldBar = nut.bar.get(identifier) 22 | 23 | if (oldBar) then 24 | table.remove(nut.bar.list, oldBar.priority) 25 | end 26 | end 27 | 28 | priority = priority or table.Count(nut.bar.list) + 1 29 | 30 | local info = nut.bar.list[priority] 31 | 32 | nut.bar.list[priority] = { 33 | getValue = getValue, 34 | color = color or info.color or Color(math.random(150, 255), math.random(150, 255), math.random(150, 255)), 35 | priority = priority, 36 | lifeTime = 0, 37 | identifier = identifier 38 | } 39 | 40 | return priority 41 | end 42 | nut.bar.Add = nut.bar.add 43 | 44 | function nut.bar.remove(identifier) 45 | local bar 46 | for k, v in ipairs(nut.bar.list) do 47 | if v.identifier == identifier then 48 | bar = v 49 | 50 | break 51 | end 52 | end 53 | 54 | if (bar) then 55 | table.remove(nut.bar.list, bar.priority) 56 | end 57 | end 58 | nut.bar.Remove = nut.bar.remove 59 | 60 | local color_dark = Color(0, 0, 0, 225) 61 | local gradient = nut.util.getMaterial("vgui/gradient-u") 62 | local gradient2 = nut.util.getMaterial("vgui/gradient-d") 63 | local surface = surface 64 | 65 | function nut.bar.draw(x, y, w, h, value, color) 66 | nut.util.drawBlurAt(x, y, w, h) 67 | 68 | surface.SetDrawColor(255, 255, 255, 15) 69 | surface.DrawRect(x, y, w, h) 70 | surface.DrawOutlinedRect(x, y, w, h) 71 | 72 | x, y, w, h = x + 2, y + 2, (w - 4) * math.min(value, 1), h - 4 73 | 74 | surface.SetDrawColor(color.r, color.g, color.b, 250) 75 | surface.DrawRect(x, y, w, h) 76 | 77 | surface.SetDrawColor(255, 255, 255, 8) 78 | surface.SetMaterial(gradient) 79 | surface.DrawTexturedRect(x, y, w, h) 80 | end 81 | nut.bar.Draw = nut.bar.draw 82 | 83 | local TEXT_COLOR = Color(240, 240, 240) 84 | local SHADOW_COLOR = Color(20, 20, 20) 85 | 86 | function nut.bar.drawAction() 87 | local start, finish = nut.bar.actionStart, nut.bar.actionEnd 88 | local curTime = CurTime() 89 | local scrW, scrH = ScrW(), ScrH() 90 | 91 | if (finish > curTime) then 92 | local fraction = 1 - math.TimeFraction(start, finish, curTime) 93 | local alpha = fraction * 255 94 | 95 | if (alpha > 0) then 96 | local w, h = scrW * 0.35, 28 97 | local x, y = (scrW * 0.5) - (w * 0.5), (scrH * 0.725) - (h * 0.5) 98 | 99 | nut.util.drawBlurAt(x, y, w, h) 100 | 101 | surface.SetDrawColor(35, 35, 35, 100) 102 | surface.DrawRect(x, y, w, h) 103 | 104 | surface.SetDrawColor(0, 0, 0, 120) 105 | surface.DrawOutlinedRect(x, y, w, h) 106 | 107 | surface.SetDrawColor(nut.config.get("color")) 108 | surface.DrawRect(x + 4, y + 4, (w * fraction) - 8, h - 8) 109 | 110 | surface.SetDrawColor(200, 200, 200, 20) 111 | surface.SetMaterial(gradient2) 112 | surface.DrawTexturedRect(x + 4, y + 4, (w * fraction) - 8, h - 8) 113 | 114 | draw.SimpleText(nut.bar.actionText, "nutMediumFont", x + 2, y - 22, SHADOW_COLOR) 115 | draw.SimpleText(nut.bar.actionText, "nutMediumFont", x, y - 24, TEXT_COLOR) 116 | end 117 | end 118 | end 119 | nut.bar.DrawAction = nut.bar.drawAction 120 | 121 | local Approach = math.Approach 122 | 123 | BAR_HEIGHT = 10 124 | 125 | function nut.bar.drawAll() 126 | if (hook.Run("ShouldHideBars")) then 127 | return 128 | end 129 | 130 | local w, h = surface.ScreenWidth() * 0.35, BAR_HEIGHT 131 | local x, y = 4, 4 132 | local deltas = nut.bar.delta 133 | local frameTime = FrameTime() 134 | local curTime = CurTime() 135 | local updateValue = frameTime * 0.6 136 | 137 | for i = 1, #nut.bar.list do 138 | local bar = nut.bar.list[i] 139 | 140 | if (bar) then 141 | local realValue = bar.getValue() 142 | local value = Approach(deltas[i] or 0, realValue, updateValue) 143 | 144 | deltas[i] = value 145 | 146 | if (deltas[i] != realValue) then 147 | bar.lifeTime = curTime + 5 148 | end 149 | 150 | if (bar.lifeTime >= curTime or bar.visible or hook.Run("ShouldBarDraw", bar)) then 151 | nut.bar.draw(x, y, w, h, value, bar.color, bar) 152 | y = y + h + 2 153 | end 154 | end 155 | end 156 | 157 | nut.bar.drawAction() 158 | end 159 | nut.bar.DrawAll = nut.bar.drawAll 160 | 161 | do 162 | nut.bar.add(function() 163 | return LocalPlayer():Health() / LocalPlayer():GetMaxHealth() 164 | end, Color(200, 50, 40), nil, "health") 165 | 166 | nut.bar.add(function() 167 | return math.min(LocalPlayer():Armor() / 100, 1) 168 | end, Color(30, 70, 180), nil, "armor") 169 | end 170 | 171 | netstream.Hook("actBar", function(start, finish, text) 172 | if (!text) then 173 | nut.bar.actionStart = 0 174 | nut.bar.actionEnd = 0 175 | else 176 | if (text:sub(1, 1) == "@") then 177 | text = L2(text:sub(2)) or text 178 | end 179 | 180 | nut.bar.actionStart = start 181 | nut.bar.actionEnd = finish 182 | nut.bar.actionText = text:upper() 183 | end 184 | end) 185 | -------------------------------------------------------------------------------- /gamemode/core/libs/cl_hud.lua: -------------------------------------------------------------------------------- 1 | nut.hud = {} 2 | 3 | local owner, w, h, ceil, ft, clmp 4 | ceil = math.ceil 5 | clmp = math.Clamp 6 | local aprg, aprg2 = 0, 0 7 | function nut.hud.drawDeath() 8 | owner = LocalPlayer() 9 | ft = FrameTime() 10 | w, h = ScrW(), ScrH() 11 | 12 | if (owner:getChar()) then 13 | if (owner:Alive()) then 14 | if (aprg != 0) then 15 | aprg2 = clmp(aprg2 - ft*1.3, 0, 1) 16 | if (aprg2 == 0) then 17 | aprg = clmp(aprg - ft*.7, 0, 1) 18 | end 19 | end 20 | else 21 | if (aprg2 != 1) then 22 | aprg = clmp(aprg + ft*.5, 0, 1) 23 | if (aprg == 1) then 24 | aprg2 = clmp(aprg2 + ft*.4, 0, 1) 25 | end 26 | end 27 | end 28 | end 29 | 30 | if (IsValid(nut.char.gui) and nut.gui.char:IsVisible() or !owner:getChar()) then 31 | return 32 | end 33 | 34 | surface.SetDrawColor(0, 0, 0, ceil((aprg^.5) * 255)) 35 | surface.DrawRect(-1, -1, w+2, h+2) 36 | local tx, ty = nut.util.drawText(L"youreDead", w/2, h/2, ColorAlpha(color_white, aprg2 * 255), 1, 1, "nutDynFontMedium", aprg2 * 255) 37 | end 38 | 39 | hook.Add("GetCrosshairAlpha", "nutCrosshair", function(alpha) 40 | return alpha * (1 - aprg) 41 | end) 42 | 43 | function nut.hud.drawAll(postHook) 44 | if (postHook) then 45 | nut.hud.drawDeath() 46 | end 47 | end -------------------------------------------------------------------------------- /gamemode/core/libs/cl_networking.lua: -------------------------------------------------------------------------------- 1 | local entityMeta = FindMetaTable("Entity") 2 | local playerMeta = FindMetaTable("Player") 3 | 4 | nut.net = nut.net or {} 5 | nut.net.globals = nut.net.globals or {} 6 | 7 | netstream.Hook("nVar", function(index, key, value) 8 | nut.net[index] = nut.net[index] or {} 9 | nut.net[index][key] = value 10 | end) 11 | 12 | netstream.Hook("nDel", function(index) 13 | nut.net[index] = nil 14 | end) 15 | 16 | netstream.Hook("nLcl", function(key, value) 17 | nut.net[LocalPlayer():EntIndex()] = nut.net[LocalPlayer():EntIndex()] or {} 18 | nut.net[LocalPlayer():EntIndex()][key] = value 19 | end) 20 | 21 | netstream.Hook("gVar", function(key, value) 22 | nut.net.globals[key] = value 23 | end) 24 | 25 | function getNetVar(key, default) 26 | local value = nut.net.globals[key] 27 | 28 | return value != nil and value or default 29 | end 30 | GetNetVar = getNetVar 31 | 32 | function entityMeta:getNetVar(key, default) 33 | local index = self:EntIndex() 34 | 35 | if (nut.net[index] and nut.net[index][key] != nil) then 36 | return nut.net[index][key] 37 | end 38 | 39 | return default 40 | end 41 | entityMeta.GetNetVar = entityMeta.getNetVar 42 | 43 | playerMeta.getLocalVar = entityMeta.getNetVar 44 | playerMeta.GetLocalVar = playerMeta.getLocalVar 45 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_attribs.lua: -------------------------------------------------------------------------------- 1 | if (!nut.char) then include("sh_character.lua") end 2 | 3 | nut.attribs = nut.attribs or {} 4 | nut.attribs.list = nut.attribs.list or {} 5 | 6 | function nut.attribs.loadFromDir(directory) 7 | for k, v in ipairs(file.Find(directory.."/*.lua", "LUA")) do 8 | local niceName = v:sub(4, -5) 9 | 10 | ATTRIBUTE = nut.attribs.list[niceName] or {} 11 | if (PLUGIN) then 12 | ATTRIBUTE.plugin = PLUGIN.uniqueID 13 | end 14 | 15 | nut.util.include(directory.."/"..v) 16 | 17 | ATTRIBUTE.name = ATTRIBUTE.name or "Unknown" 18 | ATTRIBUTE.desc = ATTRIBUTE.desc or "No description availalble." 19 | 20 | nut.attribs.list[niceName] = ATTRIBUTE 21 | ATTRIBUTE = nil 22 | end 23 | end 24 | nut.attribs.LoadFromDir = nut.attribs.loadFromDir 25 | 26 | function nut.attribs.setup(client) 27 | local character = client:getChar() 28 | 29 | if (character) then 30 | for k, v in pairs(nut.attribs.list) do 31 | if (v.onSetup) then 32 | v:onSetup(client, character:getAttrib(k, 0)) 33 | end 34 | end 35 | end 36 | end 37 | nut.attribs.Setup = nut.attribs.setup 38 | 39 | -- Add updating of attributes to the character metatable. 40 | do 41 | local charMeta = nut.meta.character 42 | 43 | if (SERVER) then 44 | function charMeta:updateAttrib(key, value) 45 | local attribute = nut.attribs.list[key] 46 | 47 | if (attribute) then 48 | local attrib = self:getAttribs() 49 | local client = self:getPlayer() 50 | 51 | attrib[key] = math.min((attrib[key] or 0) + value, attribute.maxValue or nut.config.get("maxAttribs", 30)) 52 | 53 | if (IsValid(client)) then 54 | netstream.Start(client, "attrib", self:getID(), key, attrib[key]) 55 | 56 | if (attribute.setup) then 57 | attribute.setup(attrib[key]) 58 | end 59 | end 60 | end 61 | 62 | hook.Run("OnCharAttribUpdated", client, self, key, value) 63 | end 64 | charMeta.UpdateAttrib = charMeta.updateAttrib 65 | 66 | function charMeta:setAttrib(key, value) 67 | local attribute = nut.attribs.list[key] 68 | 69 | if (attribute) then 70 | local attrib = self:getAttribs() 71 | local client = self:getPlayer() 72 | 73 | attrib[key] = value 74 | 75 | if (IsValid(client)) then 76 | netstream.Start(client, "attrib", self:getID(), key, attrib[key]) 77 | 78 | if (attribute.setup) then 79 | attribute.setup(attrib[key]) 80 | end 81 | end 82 | end 83 | 84 | hook.Run("OnCharAttribUpdated", client, self, key, value) 85 | end 86 | charMeta.SetAttrib = charMeta.setAttrib 87 | 88 | function charMeta:addBoost(boostID, attribID, boostAmount) 89 | local boosts = self:getVar("boosts", {}) 90 | 91 | boosts[attribID] = boosts[attribID] or {} 92 | boosts[attribID][boostID] = boostAmount 93 | 94 | hook.Run("OnCharAttribBoosted", self:getPlayer(), self, attribID, boostID, boostAmount) 95 | 96 | return self:setVar("boosts", boosts, nil, self:getPlayer()) 97 | end 98 | charMeta.AddBoost = charMeta.addBoost 99 | 100 | function charMeta:removeBoost(boostID, attribID) 101 | local boosts = self:getVar("boosts", {}) 102 | 103 | boosts[attribID] = boosts[attribID] or {} 104 | boosts[attribID][boostID] = nil 105 | 106 | hook.Run("OnCharAttribBoosted", self:getPlayer(), self, attribID, boostID, true) 107 | 108 | return self:setVar("boosts", boosts, nil, self:getPlayer()) 109 | end 110 | charMeta.RemoveBoost = charMeta.removeBoost 111 | else 112 | netstream.Hook("attrib", function(id, key, value) 113 | local character = nut.char.loaded[id] 114 | 115 | if (character) then 116 | character:getAttribs()[key] = value 117 | end 118 | end) 119 | end 120 | 121 | function charMeta:getBoost(attribID) 122 | local boosts = self:getBoosts() 123 | 124 | return boosts[attribID] 125 | end 126 | charMeta.GetBoost = charMeta.getBoost 127 | 128 | function charMeta:getBoosts() 129 | return self:getVar("boosts", {}) 130 | end 131 | charMeta.GetBoosts = charMeta.getBoosts 132 | 133 | function charMeta:getAttrib(key, default) 134 | local att = self:getAttribs()[key] or default 135 | local boosts = self:getBoosts()[key] 136 | 137 | if (boosts) then 138 | for k, v in pairs(boosts) do 139 | att = att + v 140 | end 141 | end 142 | 143 | return att 144 | end 145 | charMeta.GetAttrib = charMeta.getAttrib 146 | end 147 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_business.lua: -------------------------------------------------------------------------------- 1 | if (SERVER) then 2 | netstream.Hook("bizBuy", function(client, items) 3 | if (client.nextBiz and client.nextBiz > CurTime()) then 4 | client:notifyLocalized("tooFast") 5 | return 6 | end 7 | 8 | local char = client:getChar() 9 | 10 | if (!char) then 11 | return 12 | end 13 | 14 | if (table.Count(items) < 1) then 15 | return 16 | end 17 | 18 | local cost = 0 19 | 20 | for k, v in pairs(items) do 21 | local itemTable = nut.item.list[k] 22 | 23 | if (itemTable and hook.Run("CanPlayerUseBusiness", client, k) != false) then 24 | local amount = math.Clamp(tonumber(v) or 0, 0, 10) 25 | 26 | if (amount == 0) then 27 | items[k] = nil 28 | else 29 | cost = cost + (amount * (itemTable.price or 0)) 30 | end 31 | else 32 | items[k] = nil 33 | end 34 | end 35 | 36 | if (table.Count(items) < 1) then 37 | return 38 | end 39 | 40 | if (char:hasMoney(cost)) then 41 | char:takeMoney(cost) 42 | 43 | local entity = ents.Create("nut_shipment") 44 | entity:SetPos(client:getItemDropPos()) 45 | entity:Spawn() 46 | entity:setItems(items) 47 | entity:setNetVar("owner", char:getID()) 48 | 49 | local shipments = char:getVar("charEnts") or {} 50 | table.insert(shipments, entity) 51 | char:setVar("charEnts", shipments, true) 52 | 53 | netstream.Start(client, "bizResp") 54 | hook.Run("OnCreateShipment", client, entity) 55 | client.nextBiz = CurTime() + 0.5 56 | end 57 | end) 58 | 59 | netstream.Hook("shpUse", function(client, uniqueID, drop) 60 | local entity = client.nutShipment 61 | local itemTable = nut.item.list[uniqueID] 62 | 63 | if (itemTable and IsValid(entity)) then 64 | if (entity:GetPos():Distance(client:GetPos()) > 128) then 65 | client.nutShipment = nil 66 | 67 | return 68 | end 69 | 70 | local amount = entity.items[uniqueID] 71 | 72 | if (amount and amount > 0) then 73 | if (entity.items[uniqueID] <= 0) then 74 | entity.items[uniqueID] = nil 75 | end 76 | 77 | if (drop) then 78 | nut.item.spawn(uniqueID, entity:GetPos() + Vector(0, 0, 16)) 79 | else 80 | local status, fault = client:getChar():getInv():add(uniqueID) 81 | 82 | if (!status) then 83 | return client:notifyLocalized("noFit") 84 | end 85 | end 86 | 87 | hook.Run("OnTakeShipmentItem", client, uniqueID, amount) 88 | 89 | entity.items[uniqueID] = entity.items[uniqueID] - 1 90 | 91 | if (entity:getItemCount() < 1) then 92 | entity:GibBreakServer(Vector(0, 0, 0.5)) 93 | entity:Remove() 94 | end 95 | end 96 | end 97 | end) 98 | else 99 | netstream.Hook("openShp", function(entity, items) 100 | nut.gui.shipment = vgui.Create("nutShipment") 101 | nut.gui.shipment:setItems(entity, items) 102 | end) 103 | 104 | netstream.Hook("updtShp", function(entity, items) 105 | if (nut.gui.shipment and nut.gui.shipment:IsVisible()) then 106 | end 107 | end) 108 | 109 | netstream.Hook("takeShp", function(name, amount) 110 | if (nut.gui.shipment and nut.gui.shipment:IsVisible()) then 111 | local item = nut.gui.shipment.itemPanel[name] 112 | 113 | if (item) then 114 | item.amount = item.amount - 1 115 | item:Update(item.amount) 116 | 117 | if (item.amount <= 0) then 118 | item:Remove() 119 | end 120 | end 121 | end 122 | end) 123 | end -------------------------------------------------------------------------------- /gamemode/core/libs/sh_class.lua: -------------------------------------------------------------------------------- 1 | nut.class = nut.class or {} 2 | nut.class.list = {} 3 | 4 | local charMeta = nut.meta.character 5 | 6 | -- Register classes from a directory. 7 | function nut.class.loadFromDir(directory) 8 | -- Search the directory for .lua files. 9 | for k, v in ipairs(file.Find(directory.."/*.lua", "LUA")) do 10 | -- Get the name without the "sh_" prefix and ".lua" suffix. 11 | local niceName = v:sub(4, -5) 12 | -- Determine a numeric identifier for this class. 13 | local index = #nut.class.list + 1 14 | 15 | local halt 16 | for k, v in ipairs(nut.class.list) do 17 | if (v.uniqueID == niceName) then 18 | halt = true 19 | end 20 | end 21 | 22 | if (halt == true) then 23 | continue 24 | end 25 | 26 | -- Set up a global table so the file has access to the class table. 27 | CLASS = {index = index, uniqueID = niceName} 28 | -- Define some default variables. 29 | CLASS.name = "Unknown" 30 | CLASS.desc = "No description available." 31 | CLASS.limit = 0 32 | 33 | -- For future use with plugins. 34 | if (PLUGIN) then 35 | CLASS.plugin = PLUGIN.uniqueID 36 | end 37 | 38 | -- Include the file so data can be modified. 39 | nut.util.include(directory.."/"..v, "shared") 40 | 41 | -- Why have a class without a faction? 42 | if (!CLASS.faction or !team.Valid(CLASS.faction)) then 43 | ErrorNoHalt("Class '"..niceName.."' does not have a valid faction!\n") 44 | CLASS = nil 45 | 46 | continue 47 | end 48 | 49 | -- Allow classes to be joinable by default. 50 | if (!CLASS.onCanBe) then 51 | CLASS.onCanBe = function(client) 52 | return true 53 | end 54 | end 55 | 56 | -- Add the class to the list of classes. 57 | nut.class.list[index] = CLASS 58 | -- Remove the global variable to prevent conflict. 59 | CLASS = nil 60 | end 61 | end 62 | nut.class.LoadFromDir = nut.class.loadFromDir 63 | 64 | -- Determines if a player is allowed to join a specific class. 65 | function nut.class.canBe(client, class) 66 | -- Get the class table by its numeric identifier. 67 | local info = nut.class.list[class] 68 | 69 | -- See if the class exists. 70 | if (!info) then 71 | return false, "no info" 72 | end 73 | 74 | -- If the player's faction matches the class's faction. 75 | if (client:Team() != info.faction) then 76 | return false, "not correct team" 77 | end 78 | 79 | if (client:getChar():getClass() == class) then 80 | return false, "same class request" 81 | end 82 | 83 | if (info.limit > 0) then 84 | if (#nut.class.getPlayers(info.index) >= info.limit) then 85 | return false, "class is full" 86 | end 87 | end 88 | 89 | hook.Run("CanPlayerJoinClass", client, class, info) 90 | 91 | -- See if the class allows the player to join it. 92 | return info:onCanBe(client) 93 | end 94 | nut.class.CanBe = nut.class.canBe 95 | 96 | function nut.class.get(identifier) 97 | return nut.class.list[identifier] 98 | end 99 | nut.class.Get = nut.class.get 100 | 101 | function nut.class.getPlayers(class) 102 | local players = {} 103 | for k, v in ipairs(player.GetAll()) do 104 | local char = v:getChar() 105 | 106 | if (char and char:getClass() == class) then 107 | table.insert(players, v) 108 | end 109 | end 110 | 111 | return players 112 | end 113 | nut.class.GetPlayers = nut.class.getPlayers 114 | 115 | function charMeta:joinClass(class) 116 | if (!class) then 117 | self:kickClass() 118 | 119 | return 120 | end 121 | 122 | local oldClass = self:getClass() 123 | local client = self:getPlayer() 124 | 125 | if (nut.class.canBe(client, class)) then 126 | self:setClass(class) 127 | hook.Run("OnPlayerJoinClass", client, class, oldClass) 128 | 129 | return true 130 | else 131 | return false 132 | end 133 | end 134 | nut.class.JoinClass = nut.class.joinClass 135 | 136 | function charMeta:kickClass() 137 | local client = self:getPlayer() 138 | if (!client) then return end 139 | 140 | local goClass 141 | 142 | for k, v in pairs(nut.class.list) do 143 | if (v.faction == client:Team() and v.isDefault) then 144 | goClass = k 145 | 146 | break 147 | end 148 | end 149 | 150 | self:joinClass(goClass) 151 | 152 | hook.Run("OnPlayerJoinClass", client, goClass) 153 | end 154 | charMeta.KickClass = charMeta.kickClass 155 | 156 | function GM:OnPlayerJoinClass(client, class, oldClass) 157 | local info = nut.class.list[class] 158 | local info2 = nut.class.list[oldClass] 159 | 160 | if (info.onSet) then 161 | info:onSet(client) 162 | end 163 | 164 | if (info2 and info2.onLeave) then 165 | info2:onLeave(client) 166 | end 167 | 168 | netstream.Start(nil, "classUpdate", client) 169 | end 170 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_currency.lua: -------------------------------------------------------------------------------- 1 | nut.currency = nut.currency or {} 2 | nut.currency.symbol = nut.currency.symbol or "$" 3 | nut.currency.singular = nut.currency.singular or "dollar" 4 | nut.currency.plural = nut.currency.plural or "dollars" 5 | 6 | function nut.currency.set(symbol, singular, plural) 7 | nut.currency.symbol = symbol 8 | nut.currency.singular = singular 9 | nut.currency.plural = plural 10 | end 11 | nut.currency.Set = nut.currency.set 12 | 13 | function nut.currency.get(amount) 14 | if (amount == 1) then 15 | return nut.currency.symbol.."1 "..nut.currency.singular 16 | else 17 | return nut.currency.symbol..amount.." "..nut.currency.plural 18 | end 19 | end 20 | nut.currency.Get = nut.currency.get 21 | 22 | function nut.currency.spawn(pos, amount, angle) 23 | if (!pos) then 24 | print("[Nutscript] Can't create currency entity: Invalid Position") 25 | elseif (!amount or amount < 0) then 26 | print("[Nutscript] Can't create currency entity: Invalid Amount of money") 27 | end 28 | 29 | local money = ents.Create("nut_money") 30 | money:SetPos(pos) 31 | -- double check for negative. 32 | money:setNetVar("amount", math.Round(math.abs(amount))) 33 | money:SetAngles(angle or Angle(0, 0, 0)) 34 | money:Spawn() 35 | money:Activate() 36 | 37 | return money 38 | end 39 | nut.currency.Spawn = nut.currency.spawn 40 | 41 | function GM:OnPickupMoney(client, moneyEntity) 42 | if (moneyEntity and moneyEntity:IsValid()) then 43 | local amount = moneyEntity:getAmount() 44 | 45 | client:getChar():giveMoney(amount) 46 | client:notifyLocalized("moneyTaken", nut.currency.get(amount)) 47 | end 48 | end 49 | 50 | do 51 | local character = nut.meta.character 52 | 53 | function character:hasMoney(amount) 54 | if (amount < 0) then 55 | print("Negative Money Check Received.") 56 | end 57 | 58 | return self:getMoney() >= amount 59 | end 60 | character.HasMoney = character.hasMoney 61 | 62 | function character:giveMoney(amount, kek) 63 | if (!kek) then 64 | nut.log.add(self:getPlayer(), "money", amount) 65 | end 66 | 67 | self:setMoney(self:getMoney() + amount) 68 | 69 | return true 70 | end 71 | character.GiveMoney = character.giveMoney 72 | 73 | function character:takeMoney(amount) 74 | nut.log.add(self:getPlayer(), "money", -amount) 75 | amount = math.abs(amount) 76 | self:giveMoney(-amount, true) 77 | 78 | return true 79 | end 80 | character.TakeMoney = character.takeMoney 81 | end 82 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_date.lua: -------------------------------------------------------------------------------- 1 | nut.date = nut.date or {} 2 | nut.date.cache = nut.date.cache or {} 3 | nut.date.start = nut.date.start or os.time() 4 | 5 | if (!nut.config) then 6 | include("nutscript/gamemode/core/sh_config.lua") 7 | end 8 | 9 | nut.config.add("year", 2015, "The starting year of the schema.", nil, { 10 | data = {min = 0, max = 4000}, 11 | category = "date" 12 | }) 13 | nut.config.add("month", 1, "The starting month of the schema.", nil, { 14 | data = {min = 1, max = 12}, 15 | category = "date" 16 | }) 17 | nut.config.add("day", 1, "The starting day of the schema.", nil, { 18 | data = {min = 1, max = 31}, 19 | category = "date" 20 | }) 21 | 22 | if (SERVER) then 23 | function nut.date.get() 24 | local unixTime = os.time() 25 | 26 | return (unixTime - (nut.date.start or unixTime)) + os.time({ 27 | year = nut.config.get("year"), 28 | month = nut.config.get("month"), 29 | day = nut.config.get("day") 30 | }) 31 | end 32 | nut.date.Get = nut.date.get 33 | 34 | function nut.date.send(client) 35 | netstream.Start(client, "dateSync", CurTime(), os.time() - nut.date.start) 36 | end 37 | nut.date.Send = nut.date.send 38 | else 39 | function nut.date.get() 40 | local realTime = RealTime() 41 | 42 | -- Add the starting time + offset + current time played. 43 | return nut.date.start + os.time({ 44 | year = nut.config.get("year"), 45 | month = nut.config.get("month"), 46 | day = nut.config.get("day") 47 | }) + (realTime - (nut.joinTime or realTime)) 48 | end 49 | nut.date.Get = nut.date.get 50 | 51 | netstream.Hook("dateSync", function(curTime, offset) 52 | offset = offset + (CurTime() - curTime) 53 | 54 | nut.date.start = offset 55 | end) 56 | end 57 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_faction.lua: -------------------------------------------------------------------------------- 1 | nut.faction = nut.faction or {} 2 | nut.faction.teams = nut.faction.teams or {} 3 | nut.faction.indices = nut.faction.indices or {} 4 | 5 | local CITIZEN_MODELS = { 6 | "models/humans/group01/male_01.mdl", 7 | "models/humans/group01/male_02.mdl", 8 | "models/humans/group01/male_04.mdl", 9 | "models/humans/group01/male_05.mdl", 10 | "models/humans/group01/male_06.mdl", 11 | "models/humans/group01/male_07.mdl", 12 | "models/humans/group01/male_08.mdl", 13 | "models/humans/group01/male_09.mdl", 14 | "models/humans/group02/male_01.mdl", 15 | "models/humans/group02/male_03.mdl", 16 | "models/humans/group02/male_05.mdl", 17 | "models/humans/group02/male_07.mdl", 18 | "models/humans/group02/male_09.mdl", 19 | "models/humans/group01/female_01.mdl", 20 | "models/humans/group01/female_02.mdl", 21 | "models/humans/group01/female_03.mdl", 22 | "models/humans/group01/female_06.mdl", 23 | "models/humans/group01/female_07.mdl", 24 | "models/humans/group02/female_01.mdl", 25 | "models/humans/group02/female_03.mdl", 26 | "models/humans/group02/female_06.mdl", 27 | "models/humans/group01/female_04.mdl" 28 | } 29 | 30 | function nut.faction.loadFromDir(directory) 31 | for k, v in ipairs(file.Find(directory.."/*.lua", "LUA")) do 32 | local niceName = v:sub(4, -5) 33 | 34 | FACTION = nut.faction.teams[niceName] or {index = table.Count(nut.faction.teams) + 1, isDefault = true} 35 | if (PLUGIN) then 36 | FACTION.plugin = PLUGIN.uniqueID 37 | end 38 | 39 | nut.util.include(directory.."/"..v, "shared") 40 | 41 | if (!FACTION.name) then 42 | FACTION.name = "Unknown" 43 | ErrorNoHalt("Faction '"..niceName.."' is missing a name. You need to add a FACTION.name = \"Name\"\n") 44 | end 45 | 46 | if (!FACTION.desc) then 47 | FACTION.desc = "noDesc" 48 | ErrorNoHalt("Faction '"..niceName.."' is missing a description. You need to add a FACTION.desc = \"Description\"\n") 49 | end 50 | 51 | if (!FACTION.color) then 52 | FACTION.color = Color(150, 150, 150) 53 | ErrorNoHalt("Faction '"..niceName.."' is missing a color. You need to add FACTION.color = Color(1, 2, 3)\n") 54 | end 55 | 56 | team.SetUp(FACTION.index, FACTION.name or "Unknown", FACTION.color or Color(125, 125, 125)) 57 | 58 | FACTION.models = FACTION.models or CITIZEN_MODELS 59 | FACTION.uniqueID = FACTION.uniqueID or niceName 60 | 61 | for k, v in pairs(FACTION.models) do 62 | if (type(v) == "string") then 63 | util.PrecacheModel(v) 64 | elseif (type(v) == "table") then 65 | util.PrecacheModel(v[1]) 66 | end 67 | end 68 | 69 | nut.faction.indices[FACTION.index] = FACTION 70 | nut.faction.teams[niceName] = FACTION 71 | FACTION = nil 72 | end 73 | end 74 | nut.faction.LoadFromDir = nut.faction.loadFromDir 75 | 76 | function nut.faction.get(identifier) 77 | return nut.faction.indices[identifier] or nut.faction.teams[identifier] 78 | end 79 | nut.faction.Get = nut.faction.get 80 | 81 | function nut.faction.getIndex(uniqueID) 82 | for k, v in ipairs(nut.faction.indices) do 83 | if (v.uniqueID == uniqueID) then 84 | return k 85 | end 86 | end 87 | end 88 | nut.faction.GetIndex = nut.faction.getIndex 89 | 90 | if (CLIENT) then 91 | function nut.faction.hasWhitelist(faction) 92 | local data = nut.faction.indices[faction] 93 | 94 | if (data) then 95 | if (data.isDefault) then 96 | return true 97 | end 98 | 99 | local nutData = nut.localData and nut.localData.whitelists or {} 100 | 101 | return nutData[SCHEMA.folder] and nutData[SCHEMA.folder][data.uniqueID] == true or false 102 | end 103 | 104 | return false 105 | end 106 | nut.faction.HasWhitelist = nut.faction.hasWhitelist 107 | end 108 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_flag.lua: -------------------------------------------------------------------------------- 1 | nut.flag = nut.flag or {} 2 | nut.flag.list = nut.flag.list or {} 3 | 4 | -- Adds a flag that does something when set. 5 | function nut.flag.add(flag, desc, callback) 6 | -- Add the flag to a list, storing the description and callback (if there is one). 7 | nut.flag.list[flag] = {desc = desc, callback = callback} 8 | end 9 | nut.flag.Add = nut.flag.add 10 | 11 | if (SERVER) then 12 | -- Called to apply flags when a player has spawned. 13 | function nut.flag.onSpawn(client) 14 | -- Check if they have a valid character. 15 | if (client:getChar()) then 16 | -- Get all of the character's flags. 17 | local flags = client:getChar():getFlags() 18 | 19 | for i = 1, #flags do 20 | -- Get each individual flag. 21 | local flag = flags:sub(i, i) 22 | local info = nut.flag.list[flag] 23 | 24 | -- Check if the flag has a callback. 25 | if (info and info.callback) then 26 | -- Run the callback, passing the player and true so they get whatever benefits. 27 | info.callback(client, true) 28 | end 29 | end 30 | end 31 | end 32 | nut.flag.OnSpawn = nut.flag.onSpawn 33 | end 34 | 35 | do 36 | -- Extend the character metatable to allow flag giving/taking. 37 | local character = nut.meta.character 38 | 39 | -- Flags can only be set server-side. 40 | if (SERVER) then 41 | -- Set the flag data to the flag string. 42 | function character:setFlags(flags) 43 | self:setData("f", flags) 44 | end 45 | character.SetFlags = character.setFlags 46 | 47 | -- Add a flag to the flag string. 48 | function character:giveFlags(flags) 49 | local addedFlags = "" 50 | 51 | -- Get the individual flags within the flag string. 52 | for i = 1, #flags do 53 | local flag = flags:sub(i, i) 54 | local info = nut.flag.list[flag] 55 | 56 | if (info) then 57 | if (!character:hasFlags(flag)) then 58 | addedFlags = addedFlags..flag 59 | end 60 | 61 | if (info.callback) then 62 | -- Pass the player and true (true for the flag being given.) 63 | info.callback(self:getPlayer(), true) 64 | end 65 | end 66 | end 67 | 68 | -- Only change the flag string if it is different. 69 | if (addedFlags != "") then 70 | self:setFlags(self:getFlags()..addedFlags) 71 | end 72 | end 73 | character.GiveFlags = character.giveFlags 74 | 75 | -- Remove the flags from the flag string. 76 | function character:takeFlags(flags) 77 | local oldFlags = self:getFlags() 78 | local newFlags = oldFlags 79 | 80 | -- Get the individual flags within the flag string. 81 | for i = 1, #flags do 82 | local flag = flags:sub(i, i) 83 | local info = nut.flag.list[flag] 84 | 85 | -- Call the callback if the flag has been registered. 86 | if (info and info.callback) then 87 | -- Pass the player and false (false since the flag is being taken) 88 | info.callback(self:getPlayer(), false) 89 | end 90 | 91 | newFlags = newFlags:gsub(flag, "") 92 | end 93 | 94 | if (newFlags != oldFlags) then 95 | self:setFlags(newFlags) 96 | end 97 | end 98 | character.TakeFlags = character.takeFlags 99 | end 100 | 101 | -- Return the flag string. 102 | function character:getFlags() 103 | return self:getData("f", "") 104 | end 105 | character.GetFlags = character.getFlags 106 | 107 | -- Check if the flag string contains the flags specified. 108 | function character:hasFlags(flags) 109 | for i = 1, #flags do 110 | if (self:getFlags():find(flags:sub(i, i), 1, true)) then 111 | return true 112 | end 113 | end 114 | 115 | return false 116 | end 117 | character.HasFlags = character.hasFlags 118 | end 119 | 120 | do 121 | nut.flag.add("p", "Access to the physgun.", function(client, isGiven) 122 | if (isGiven) then 123 | client:Give("weapon_physgun") 124 | client:SelectWeapon("weapon_physgun") 125 | else 126 | client:StripWeapon("weapon_physgun") 127 | end 128 | end) 129 | 130 | nut.flag.add("t", "Access to the toolgun", function(client, isGiven) 131 | if (isGiven) then 132 | client:Give("gmod_tool") 133 | client:SelectWeapon("gmod_tool") 134 | else 135 | client:StripWeapon("gmod_tool") 136 | end 137 | end) 138 | 139 | nut.flag.add("c", "Access to spawn chairs.") 140 | nut.flag.add("C", "Access to spawn vehicles.") 141 | nut.flag.add("r", "Access to spawn ragdolls.") 142 | nut.flag.add("e", "Access to spawn props.") 143 | nut.flag.add("n", "Access to spawn NPCs.") 144 | end 145 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_language.lua: -------------------------------------------------------------------------------- 1 | nut.lang = nut.lang or {} 2 | nut.lang.stored = nut.lang.stored or {} 3 | nut.lang.names = nut.lang.names or {} 4 | 5 | function nut.lang.loadFromDir(directory) 6 | for k, v in ipairs(file.Find(directory.."/sh_*.lua", "LUA")) do 7 | local niceName = v:sub(4, -5):lower() 8 | 9 | nut.util.include(directory.."/"..v, "shared") 10 | 11 | if (LANGUAGE) then 12 | if (NAME) then 13 | nut.lang.names[niceName] = NAME 14 | NAME = nil 15 | end 16 | 17 | nut.lang.stored[niceName] = table.Merge(nut.lang.stored[niceName] or {}, LANGUAGE) 18 | LANGUAGE = nil 19 | end 20 | end 21 | end 22 | nut.lang.LoadFromDir = nut.lang.loadFromDir 23 | 24 | local FormatString = string.format 25 | 26 | if (SERVER) then 27 | local ClientGetInfo = FindMetaTable("Player").GetInfo 28 | 29 | function L(key, client, ...) 30 | local languages = nut.lang.stored 31 | local langKey = ClientGetInfo(client, "nut_language") 32 | local info = languages[langKey] or languages.english 33 | 34 | return FormatString(info and info[key] or key, ...) 35 | end 36 | 37 | function L2(key, client, ...) 38 | local languages = nut.lang.stored 39 | local langKey = ClientGetInfo(client, "nut_language") 40 | local info = languages[langKey] or languages.english 41 | 42 | if (info and info[key]) then 43 | return FormatString(info[key], ...) 44 | end 45 | end 46 | else 47 | NUT_CVAR_LANG = CreateClientConVar("nut_language", nut.config.language or "english", true, true) 48 | 49 | function L(key, ...) 50 | local languages = nut.lang.stored 51 | local langKey = NUT_CVAR_LANG:GetString() 52 | local info = languages[langKey] or languages.english 53 | 54 | return FormatString(info and info[key] or key, ...) 55 | end 56 | 57 | function L2(key, ...) 58 | local langKey = NUT_CVAR_LANG:GetString() 59 | local info = nut.lang.stored[langKey] 60 | 61 | if (info and info[key]) then 62 | return FormatString(info[key], ...) 63 | end 64 | end 65 | end 66 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_log.lua: -------------------------------------------------------------------------------- 1 | FLAG_NORMAL = 0 2 | FLAG_SUCCESS = 1 3 | FLAG_WARNING = 2 4 | FLAG_DANGER = 3 5 | FLAG_SERVER = 4 6 | FLAG_DEV = 5 7 | 8 | nut.log = nut.log or {} 9 | nut.log.color = { 10 | [FLAG_NORMAL] = Color(200, 200, 200), 11 | [FLAG_SUCCESS] = Color(50, 200, 50), 12 | [FLAG_WARNING] = Color(255, 255, 0), 13 | [FLAG_DANGER] = Color(255, 50, 50), 14 | [FLAG_SERVER] = Color(120, 0, 255), 15 | [FLAG_DEV] = Color(0, 160, 255), 16 | } 17 | local consoleColor = Color(50, 200, 50) 18 | 19 | -- TODO: Creating MYSQL/SQLLite Query for the logging. 20 | -- SUGG: Do I have to get Seperated Database? For ChatLog, For EventLog. 21 | 22 | if (SERVER) then 23 | if (!nut.db) then 24 | include("sv_database.lua") 25 | end 26 | 27 | function nut.log.loadTables() 28 | file.CreateDir("nutscript/logs") 29 | end 30 | nut.log.LoadTables = nut.log.loadTables 31 | 32 | function nut.log.resetTables() 33 | end 34 | nut.log.ResetTables = nut.log.resetTables 35 | 36 | nut.log.types = nut.log.types or {} 37 | function nut.log.addType(logType, func) 38 | nut.log.types[logType] = func 39 | end 40 | nut.log.AddType = nut.log.addType 41 | 42 | function nut.log.getString(client, logType, ...) 43 | local text = nut.log.types[logType] 44 | 45 | if (text) then 46 | if (isfunction(text)) then 47 | text = text(client, ...) 48 | end 49 | else 50 | text = -1 51 | end 52 | 53 | return text 54 | end 55 | nut.log.GetString = nut.log.getString 56 | 57 | function nut.log.addRaw(logString, flag) 58 | nut.log.send(nut.util.getAdmins(), logString, flag) 59 | 60 | MsgC(consoleColor, "[LOG] ", nut.log.color[flag] or color_white, logString .. "\n") 61 | 62 | if (!noSave) then 63 | file.Append("nutscript/logs/"..os.date("%x"):gsub("/", "-")..".txt", "["..os.date("%X").."]\t"..logString.."\r\n") 64 | end 65 | end 66 | nut.log.AddRaw = nut.log.addRaw 67 | 68 | function nut.log.add(client, logType, ...) 69 | local logString = nut.log.getString(client, logType, ...) 70 | if (logString == -1) then return end 71 | 72 | nut.log.send(nut.util.getAdmins(), logString) 73 | 74 | MsgC(consoleColor, "[LOG] ", color_white, logString .. "\n") 75 | 76 | if (!noSave) then 77 | file.Append("nutscript/logs/"..os.date("%x"):gsub("/", "-")..".txt", "["..os.date("%X").."]\t"..logString.."\r\n") 78 | end 79 | end 80 | nut.log.Add = nut.log.add 81 | 82 | function nut.log.open(client) 83 | local logData = {} 84 | 85 | netstream.Hook(client, "nutLogView", logData) 86 | end 87 | nut.log.Open = nut.log.open 88 | 89 | function nut.log.send(client, logString, flag) 90 | netstream.Start(client, "nutLogStream", logString, flag) 91 | end 92 | nut.log.Send = nut.log.send 93 | else 94 | netstream.Hook("nutLogStream", function(logString, flag) 95 | MsgC(consoleColor, "[SERVER] ", nut.log.color[flag] or color_white, logString .. "\n") 96 | end) 97 | end 98 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_notice.lua: -------------------------------------------------------------------------------- 1 | if (SERVER) then 2 | -- Sends a notification to a specified recipient. 3 | function nut.util.notify(message, recipient) 4 | netstream.Start(recipient, "notify", message) 5 | end 6 | nut.util.Notify = nut.util.notify 7 | 8 | -- Sends a translated notification. 9 | function nut.util.notifyLocalized(message, recipient, ...) 10 | netstream.Start(recipient, "notifyL", message, ...) 11 | end 12 | nut.util.NotifyLocalized = nut.util.notifyLocalized 13 | 14 | do 15 | local playerMeta = FindMetaTable("Player") 16 | 17 | -- Utility function to notify a player. 18 | function playerMeta:notify(message) 19 | nut.util.notify(message, self) 20 | end 21 | playerMeta.Notify = playerMeta.notify 22 | 23 | -- Utility function to notify a localized message to a player. 24 | function playerMeta:notifyLocalized(message, ...) 25 | nut.util.notifyLocalized(message, self, ...) 26 | end 27 | playerMeta.NotifyLocalized = playerMeta.notifyLocalized 28 | end 29 | else 30 | -- List of notice panels. 31 | nut.notices = nut.notices or {} 32 | 33 | -- Create a notification panel. 34 | function nut.util.notify(message) 35 | local notice = vgui.Create("nutNotice") 36 | local i = table.insert(nut.notices, notice) 37 | local scrW = ScrW() 38 | 39 | -- Set up information for the notice. 40 | notice:SetText(message) 41 | notice:SetPos(ScrW(), (i - 1) * (notice:GetTall() + 4) + 4) 42 | notice:SizeToContentsX() 43 | notice:SetWide(notice:GetWide() + 16) 44 | notice.start = CurTime() + 0.25 45 | notice.endTime = CurTime() + 7.75 46 | 47 | -- Move all notices to their proper positions. 48 | local function OrganizeNotices() 49 | for k, v in ipairs(nut.notices) do 50 | v:MoveTo(scrW - (v:GetWide() + 4), (k - 1) * (v:GetTall() + 4) + 4, 0.15, (k / #nut.notices) * 0.25, nil) 51 | end 52 | end 53 | 54 | -- Add the notice we made to the list. 55 | OrganizeNotices() 56 | 57 | -- Show the notification in the console. 58 | MsgC(Color(0, 255, 255), message.."\n") 59 | 60 | -- Once the notice appears, make a sound and message. 61 | timer.Simple(0.15, function() 62 | surface.PlaySound("buttons/button14.wav") 63 | end) 64 | 65 | -- After the notice has displayed for 7.5 seconds, remove it. 66 | timer.Simple(7.75, function() 67 | if (IsValid(notice)) then 68 | -- Search for the notice to remove. 69 | for k, v in ipairs(nut.notices) do 70 | if (v == notice) then 71 | -- Move the notice off the screen. 72 | notice:MoveTo(ScrW(), notice.y, 0.15, 0.1, nil, function() 73 | notice:Remove() 74 | end) 75 | 76 | -- Remove the notice from the list and move other notices. 77 | table.remove(nut.notices, k) 78 | OrganizeNotices() 79 | 80 | break 81 | end 82 | end 83 | end 84 | end) 85 | end 86 | nut.util.Notify = nut.util.notify 87 | 88 | -- Creates a translated notification. 89 | function nut.util.notifyLocalized(message, ...) 90 | nut.util.notify(L(message, ...)) 91 | end 92 | nut.util.NotifyLocalized = nut.util.notifyLocalized 93 | 94 | -- Receives a notification from the server. 95 | netstream.Hook("notify", nut.util.notify) 96 | 97 | -- Receives a notification from the server. 98 | netstream.Hook("notifyL", nut.util.notifyLocalized) 99 | end 100 | -------------------------------------------------------------------------------- /gamemode/core/libs/sh_player.lua: -------------------------------------------------------------------------------- 1 | local playerMeta = FindMetaTable("Player") 2 | 3 | -- nutData information for the player. 4 | do 5 | if (SERVER) then 6 | function playerMeta:getNutData(key, default) 7 | if (key == true) then 8 | return self.nutData 9 | end 10 | 11 | local data = self.nutData and self.nutData[key] 12 | 13 | if (data == nil) then 14 | return default 15 | else 16 | return data 17 | end 18 | end 19 | playerMeta.GetNutData = playerMeta.getNutData 20 | else 21 | function playerMeta:getNutData(key, default) 22 | local data = nut.localData and nut.localData[key] 23 | 24 | if (data == nil) then 25 | return default 26 | else 27 | return data 28 | end 29 | end 30 | playerMeta.GetNutData = playerMeta.getNutData 31 | 32 | netstream.Hook("nutDataSync", function(data, playTime) 33 | nut.localData = data 34 | nut.playTime = playTime 35 | end) 36 | 37 | netstream.Hook("nutData", function(key, value) 38 | nut.localData = nut.localData or {} 39 | nut.localData[key] = value 40 | end) 41 | end 42 | end 43 | 44 | -- Whitelist networking information here. 45 | do 46 | function playerMeta:hasWhitelist(faction) 47 | local data = nut.faction.indices[faction] 48 | 49 | if (data) then 50 | if (data.isDefault) then 51 | return true 52 | end 53 | 54 | local nutData = self:getNutData("whitelists", {}) 55 | 56 | return nutData[SCHEMA.folder] and nutData[SCHEMA.folder][data.uniqueID] == true or false 57 | end 58 | 59 | return false 60 | end 61 | playerMeta.HasWhitelist = playerMeta.hasWhitelist 62 | 63 | function playerMeta:getItems() 64 | local char = self:getChar() 65 | 66 | if (char) then 67 | local inv = char:getInv() 68 | 69 | if (inv) then 70 | return inv:getItems() 71 | end 72 | end 73 | end 74 | playerMeta.GetItems = playerMeta.getItems 75 | 76 | function playerMeta:getClass() 77 | local char = self:getChar() 78 | 79 | if (char) then 80 | return char:getClass() 81 | end 82 | end 83 | playerMeta.GetClass = playerMeta.getClass 84 | 85 | function playerMeta:getClassData() 86 | local char = self:getChar() 87 | 88 | if (char) then 89 | local class = char:getClass() 90 | 91 | if (class) then 92 | local classData = nut.class.list[class] 93 | 94 | return classData 95 | end 96 | end 97 | end 98 | playerMeta.GetClassData = playerMeta.getClassData 99 | end 100 | -------------------------------------------------------------------------------- /gamemode/core/libs/sv_networking.lua: -------------------------------------------------------------------------------- 1 | local entityMeta = FindMetaTable("Entity") 2 | local playerMeta = FindMetaTable("Player") 3 | 4 | nut.net = nut.net or {} 5 | nut.net.globals = nut.net.globals or {} 6 | 7 | -- Check if there is an attempt to send a function. Can't send those. 8 | local function checkBadType(name, object) 9 | local objectType = type(object) 10 | 11 | if (objectType == "function") then 12 | ErrorNoHalt("Net var '"..name.."' contains a bad object type!") 13 | 14 | return true 15 | elseif (objectType == "table") then 16 | for k, v in pairs(object) do 17 | -- Check both the key and the value for tables, and has recursion. 18 | if (checkBadType(name, k) or checkBadType(name, v)) then 19 | return true 20 | end 21 | end 22 | end 23 | end 24 | 25 | function setNetVar(key, value, receiver) 26 | if (checkBadType(key, value)) then return end 27 | if (getNetVar(key) == value) then return end 28 | 29 | nut.net.globals[key] = value 30 | netstream.Start(receiver, "gVar", key, value) 31 | end 32 | SetNetVar = setNetVar 33 | 34 | function playerMeta:syncVars() 35 | for entity, data in pairs(nut.net) do 36 | if (entity == "globals") then 37 | for k, v in pairs(data) do 38 | netstream.Start(self, "gVar", k, v) 39 | end 40 | elseif (IsValid(entity)) then 41 | for k, v in pairs(data) do 42 | netstream.Start(self, "nVar", entity:EntIndex(), k, v) 43 | end 44 | end 45 | end 46 | end 47 | playerMeta.SyncVars = playerMeta.syncVars 48 | 49 | function entityMeta:sendNetVar(key, receiver) 50 | netstream.Start(receiver, "nVar", self:EntIndex(), key, nut.net[self] and nut.net[self][key]) 51 | end 52 | entityMeta.SendNetVar = entityMeta.sendNetVar 53 | 54 | function entityMeta:clearNetVars(receiver) 55 | nut.net[self] = nil 56 | netstream.Start(receiver, "nDel", self:EntIndex()) 57 | end 58 | entityMeta.ClearNetVars = entityMeta.clearNetVars 59 | 60 | function entityMeta:setNetVar(key, value, receiver) 61 | if (checkBadType(key, value)) then return end 62 | 63 | nut.net[self] = nut.net[self] or {} 64 | 65 | if (nut.net[self][key] != value) then 66 | nut.net[self][key] = value 67 | end 68 | 69 | self:sendNetVar(key, receiver) 70 | end 71 | entityMeta.SetNetVar = entityMeta.setNetVar 72 | 73 | function entityMeta:getNetVar(key, default) 74 | if (nut.net[self] and nut.net[self][key] != nil) then 75 | return nut.net[self][key] 76 | end 77 | 78 | return default 79 | end 80 | entityMeta.GetNetVar = entityMeta.getNetVar 81 | 82 | function playerMeta:setLocalVar(key, value) 83 | if (checkBadType(key, value)) then return end 84 | 85 | nut.net[self] = nut.net[self] or {} 86 | nut.net[self][key] = value 87 | 88 | netstream.Start(self, "nLcl", key, value) 89 | end 90 | playerMeta.SetLocalVar = playerMeta.setLocalVar 91 | 92 | playerMeta.getLocalVar = entityMeta.getNetVar 93 | playerMeta.GetLocalVar = playerMeta.getLocalVar 94 | 95 | function getNetVar(key, default) 96 | local value = nut.net.globals[key] 97 | 98 | return value != nil and value or default 99 | end 100 | GetNetVar = getNetVar 101 | 102 | hook.Add("EntityRemoved", "nCleanUp", function(entity) 103 | entity:clearNetVars() 104 | end) 105 | 106 | hook.Add("PlayerInitialSpawn", "nSync", function(client) 107 | client:syncVars() 108 | end) 109 | -------------------------------------------------------------------------------- /gamemode/core/libs/sv_player.lua: -------------------------------------------------------------------------------- 1 | local playerMeta = FindMetaTable("Player") 2 | 3 | -- Player data (outside of characters) handling. 4 | do 5 | function playerMeta:loadNutData(callback) 6 | local name = self:steamName() 7 | local steamID64 = self:SteamID64() 8 | local timeStamp = math.floor(os.time()) 9 | local ip = self:IPAddress():match("%d+%.%d+%.%d+%.%d+") 10 | 11 | nut.db.query("SELECT _data, _playTime FROM nut_players WHERE _steamID = "..steamID64, function(data) 12 | if (IsValid(self) and data and data[1] and data[1]._data) then 13 | nut.db.updateTable({ 14 | _lastJoin = timeStamp, 15 | _address = ip 16 | }, nil, "players", "_steamID = "..steamID64) 17 | 18 | self.nutPlayTime = tonumber(data[1]._playTime) or 0 19 | self.nutData = util.JSONToTable(data[1]._data) 20 | 21 | if (callback) then 22 | callback(self.nutData) 23 | end 24 | else 25 | nut.db.insertTable({ 26 | _steamID = steamID64, 27 | _steamName = name, 28 | _playTime = 0, 29 | _address = ip, 30 | _lastJoin = timeStamp, 31 | _data = {} 32 | }, nil, "players") 33 | 34 | if (callback) then 35 | callback({}) 36 | end 37 | end 38 | end) 39 | end 40 | playerMeta.LoadNutData = playerMeta.loadNutData 41 | 42 | function playerMeta:saveNutData() 43 | local name = self:steamName() 44 | local steamID64 = self:SteamID64() 45 | 46 | nut.db.updateTable({ 47 | _steamName = name, 48 | _playTime = math.floor((self.nutPlayTime or 0) + (RealTime() - (self.nutJoinTime or RealTime() - 1))), 49 | _data = self.nutData 50 | }, nil, "players", "_steamID = "..steamID64) 51 | end 52 | playerMeta.SaveNutData = playerMeta.saveNutData 53 | 54 | function playerMeta:setNutData(key, value, noNetworking) 55 | self.nutData = self.nutData or {} 56 | self.nutData[key] = value 57 | 58 | if (!noNetworking) then 59 | netstream.Start(self, "nutData", key, value) 60 | end 61 | end 62 | playerMeta.SetNutData = playerMeta.setNutData 63 | end 64 | 65 | -- Whitelisting information for the player. 66 | do 67 | function playerMeta:setWhitelisted(faction, whitelisted) 68 | if (!whitelisted) then 69 | whitelisted = nil 70 | end 71 | 72 | local data = nut.faction.indices[faction] 73 | 74 | if (data) then 75 | local whitelists = self:getNutData("whitelists", {}) 76 | whitelists[SCHEMA.folder] = whitelists[SCHEMA.folder] or {} 77 | whitelists[SCHEMA.folder][data.uniqueID] = whitelisted and true or nil 78 | 79 | self:setNutData("whitelists", whitelists) 80 | self:saveNutData() 81 | 82 | return true 83 | end 84 | 85 | return false 86 | end 87 | playerMeta.SetWhitelisted = playerMeta.setWhitelisted 88 | end 89 | -------------------------------------------------------------------------------- /gamemode/core/libs/thirdparty/sh_netstream2.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | NetStream - 2.0.0 3 | 4 | Alexander Grist-Hucker 5 | http://www.revotech.org 6 | 7 | Credits to: 8 | thelastpenguin for pON. 9 | https://github.com/thelastpenguin/gLUA-Library/tree/master/pON 10 | --]] 11 | 12 | 13 | local type, error, pcall, pairs, _player = type, error, pcall, pairs, player; 14 | 15 | if (!pon) then 16 | include("sh_pon.lua"); 17 | end; 18 | 19 | AddCSLuaFile(); 20 | 21 | netstream = netstream or {}; 22 | netstream.stored = netstream.stored or {}; 23 | 24 | -- A function to split data for a data stream. 25 | function netstream.Split(data) 26 | local index = 1; 27 | local result = {}; 28 | local buffer = {}; 29 | 30 | for i = 0, string.len(data) do 31 | buffer[#buffer + 1] = string.sub(data, i, i); 32 | 33 | if (#buffer == 32768) then 34 | result[#result + 1] = table.concat(buffer); 35 | index = index + 1; 36 | buffer = {}; 37 | end; 38 | end; 39 | 40 | result[#result + 1] = table.concat(buffer); 41 | 42 | return result; 43 | end; 44 | 45 | -- A function to hook a data stream. 46 | function netstream.Hook(name, Callback) 47 | netstream.stored[name] = Callback; 48 | end; 49 | 50 | if (SERVER) then 51 | util.AddNetworkString("NetStreamDS"); 52 | 53 | -- A function to start a net stream. 54 | function netstream.Start(player, name, ...) 55 | local recipients = {}; 56 | local bShouldSend = false; 57 | local bSendPVS = false; 58 | 59 | if (type(player) != "table") then 60 | if (!player) then 61 | player = _player.GetAll(); 62 | elseif (type(player) == "Vector") then 63 | bSendPVS = true; 64 | else 65 | player = {player}; 66 | end; 67 | end; 68 | 69 | if (type(player) != "Vector") then 70 | for k, v in pairs(player) do 71 | if (type(v) == "Player") then 72 | recipients[#recipients + 1] = v; 73 | 74 | bShouldSend = true; 75 | elseif (type(k) == "Player") then 76 | recipients[#recipients + 1] = k; 77 | 78 | bShouldSend = true; 79 | end; 80 | end; 81 | else 82 | bShouldSend = true; 83 | end; 84 | 85 | local dataTable = {...}; 86 | local encodedData = pon.encode(dataTable); 87 | 88 | if (encodedData and #encodedData > 0 and bShouldSend) then 89 | net.Start("NetStreamDS"); 90 | net.WriteString(name); 91 | net.WriteUInt(#encodedData, 32); 92 | net.WriteData(encodedData, #encodedData); 93 | if (bSendPVS) then 94 | net.SendPVS(player); 95 | else 96 | net.Send(recipients); 97 | end; 98 | end; 99 | end; 100 | 101 | net.Receive("NetStreamDS", function(length, player) 102 | local NS_DS_NAME = net.ReadString(); 103 | local NS_DS_LENGTH = net.ReadUInt(32); 104 | local NS_DS_DATA = net.ReadData(NS_DS_LENGTH); 105 | 106 | if (NS_DS_NAME and NS_DS_DATA and NS_DS_LENGTH) then 107 | player.nsDataStreamName = NS_DS_NAME; 108 | player.nsDataStreamData = ""; 109 | 110 | if (player.nsDataStreamName and player.nsDataStreamData) then 111 | player.nsDataStreamData = NS_DS_DATA; 112 | 113 | if (netstream.stored[player.nsDataStreamName]) then 114 | local bStatus, value = pcall(pon.decode, player.nsDataStreamData); 115 | 116 | if (bStatus) then 117 | netstream.stored[player.nsDataStreamName](player, unpack(value)); 118 | else 119 | ErrorNoHalt("NetStream: '"..NS_DS_NAME.."'\n"..value.."\n"); 120 | end; 121 | end; 122 | 123 | player.nsDataStreamName = nil; 124 | player.nsDataStreamData = nil; 125 | end; 126 | end; 127 | 128 | NS_DS_NAME, NS_DS_DATA, NS_DS_LENGTH = nil, nil, nil; 129 | end); 130 | else 131 | -- A function to start a net stream. 132 | function netstream.Start(name, ...) 133 | local dataTable = {...}; 134 | local encodedData = pon.encode(dataTable); 135 | 136 | if (encodedData and #encodedData > 0) then 137 | net.Start("NetStreamDS"); 138 | net.WriteString(name); 139 | net.WriteUInt(#encodedData, 32); 140 | net.WriteData(encodedData, #encodedData); 141 | net.SendToServer(); 142 | end; 143 | end; 144 | 145 | net.Receive("NetStreamDS", function(length) 146 | local NS_DS_NAME = net.ReadString(); 147 | local NS_DS_LENGTH = net.ReadUInt(32); 148 | local NS_DS_DATA = net.ReadData(NS_DS_LENGTH); 149 | 150 | if (NS_DS_NAME and NS_DS_DATA and NS_DS_LENGTH) then 151 | if (netstream.stored[NS_DS_NAME]) then 152 | local bStatus, value = pcall(pon.decode, NS_DS_DATA); 153 | 154 | if (bStatus) then 155 | netstream.stored[NS_DS_NAME](unpack(value)); 156 | else 157 | ErrorNoHalt("NetStream: '"..NS_DS_NAME.."'\n"..value.."\n"); 158 | end; 159 | end; 160 | end; 161 | 162 | NS_DS_NAME, NS_DS_DATA, NS_DS_LENGTH = nil, nil, nil; 163 | end); 164 | end; -------------------------------------------------------------------------------- /gamemode/core/sv_data.lua: -------------------------------------------------------------------------------- 1 | nut.data = nut.data or {} 2 | nut.data.stored = nut.data.stored or {} 3 | 4 | -- Create a folder to store data in. 5 | file.CreateDir("nutscript") 6 | 7 | -- Set and save data in the nutscript folder. 8 | function nut.data.set(key, value, global, ignoreMap) 9 | -- Get the base path to write to. 10 | local path = "nutscript/"..(global and "" or SCHEMA.folder.."/")..(ignoreMap and "" or game.GetMap().."/") 11 | 12 | -- Create the schema folder if the data is not global. 13 | if (!global) then 14 | file.CreateDir("nutscript/"..SCHEMA.folder.."/") 15 | end 16 | 17 | -- If we're not ignoring the map, create a folder for the map. 18 | file.CreateDir(path) 19 | -- Write the data using pON encoding. 20 | file.Write(path..key..".txt", pon.encode({value})) 21 | 22 | -- Cache the data value here. 23 | nut.data.stored[key] = value 24 | 25 | return path 26 | end 27 | nut.data.Set = nut.data.set 28 | 29 | -- Gets a piece of information for NutScript. 30 | function nut.data.get(key, default, global, ignoreMap, refresh) 31 | -- If it exists in the cache, return the cached value so it is faster. 32 | if (!refresh) then 33 | local stored = nut.data.stored[key] 34 | 35 | if (stored != nil) then 36 | return stored 37 | end 38 | end 39 | 40 | -- Get the path to read from. 41 | local path = "nutscript/"..(global and "" or SCHEMA.folder.."/")..(ignoreMap and "" or game.GetMap().."/") 42 | -- Read the data from a local file. 43 | local contents = file.Read(path..key..".txt", "DATA") 44 | 45 | if (contents and contents != "") then 46 | -- Decode the contents and return the data. 47 | local status, decoded = pcall(pon.decode, contents) 48 | 49 | if (status and decoded) then 50 | local value = decoded[1] 51 | 52 | if (value != nil) then 53 | return value 54 | else 55 | return default 56 | end 57 | else 58 | return default 59 | end 60 | else 61 | -- If we provided a default, return that since we couldn't retrieve the data. 62 | return default 63 | end 64 | end 65 | nut.data.Get = nut.data.get 66 | 67 | -- Deletes existing data in nutscript framework. 68 | function nut.data.delete(key, global, ignoreMap) 69 | -- Get the path to read from. 70 | local path = "nutscript/"..(global and "" or SCHEMA.folder.."/")..(ignoreMap and "" or game.GetMap().."/") 71 | -- Read the data from a local file. 72 | local contents = file.Read(path..key..".txt", "DATA") 73 | 74 | if (contents and contents != "") then 75 | file.Delete(path..key..".txt") 76 | nut.data.stored[key] = nil 77 | return true 78 | else 79 | -- If we provided a default, return that since we couldn't retrieve the data. 80 | return false 81 | end 82 | end 83 | nut.data.Delete = nut.data.delete 84 | 85 | timer.Create("nutSaveData", 600, 0, function() 86 | hook.Run("SaveData") 87 | hook.Run("PersistenceSave") 88 | end) 89 | -------------------------------------------------------------------------------- /gamemode/init.lua: -------------------------------------------------------------------------------- 1 | -- Include NutScript content. 2 | resource.AddWorkshop("207739713") 3 | 4 | -- Include features from the Sandbox gamemode. 5 | DeriveGamemode("sandbox") 6 | -- Define a global shared table to store NutScript information. 7 | nut = nut or {util = {}, meta = {}} 8 | 9 | -- Send the following files to players. 10 | AddCSLuaFile("cl_init.lua") 11 | AddCSLuaFile("core/sh_util.lua") 12 | AddCSLuaFile("shared.lua") 13 | 14 | -- Include utility functions, data storage functions, and then shared.lua 15 | include("core/sh_util.lua") 16 | include("core/sv_data.lua") 17 | include("shared.lua") 18 | 19 | -- Connect to the database using SQLite, mysqloo, or tmysql4. 20 | timer.Simple(0, function() 21 | hook.Run("SetupDatabase") 22 | 23 | nut.db.connect(function() 24 | -- Create the SQL tables if they do not exist. 25 | nut.db.loadTables() 26 | nut.log.loadTables() 27 | 28 | hook.Run("OnDatabaseLoaded") 29 | 30 | MsgC(Color(0, 255, 0), "NutScript has connected to the database.\n") 31 | MsgC(Color(0, 255, 0), "Database Type: " .. nut.db.module .. ".\n") 32 | end) 33 | end) 34 | 35 | -- Resources that are required for players to download are here. 36 | resource.AddFile("materials/nutscript/gui/vignette.png") 37 | resource.AddFile("resource/fonts/fontello.ttf") 38 | 39 | concommand.Add("nut_setowner", function(client, command, arguments) 40 | if (!IsValid(client)) then 41 | MsgC(Color(255, 0, 0), "** 'nut_setowner' has been deprecated in NutScript 1.1\n") 42 | MsgC(Color(255, 0, 0), "** Instead, please install an admin mod and use that instead.\n") 43 | end 44 | end) 45 | 46 | cvars.AddChangeCallback( "sbox_persist", function( name, old, new ) 47 | 48 | -- A timer in case someone tries to rapily change the convar, such as addons with "live typing" or whatever 49 | timer.Create( "sbox_persist_change_timer", 1, 1, function() 50 | hook.Run( "PersistenceSave", old ) 51 | 52 | --game.CleanUpMap() -- Maybe this should be moved to PersistenceLoad? 53 | --seriously you just did this for 2 years? fuck off 54 | 55 | if ( new == "" ) then return end 56 | 57 | hook.Run( "PersistenceLoad", new ) 58 | end ) 59 | 60 | end, "sbox_persist_load" ) 61 | -------------------------------------------------------------------------------- /gamemode/items/ammo/sh_357ammo.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = ".357 Ammo" 2 | ITEM.model = "models/items/357ammo.mdl" 3 | ITEM.ammo = "357" // type of the ammo 4 | ITEM.ammoAmount = 12 // amount of the ammo 5 | ITEM.ammoDesc = "A Box that contains %s of .357 Ammo" 6 | ITEM.price = 10 -------------------------------------------------------------------------------- /gamemode/items/ammo/sh_ar2ammo.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "AR2 Cartridge" 2 | ITEM.model = "models/Items/combine_rifle_cartridge01.mdl" 3 | ITEM.ammo = "ar2" // type of the ammo 4 | ITEM.ammoAmount = 30 // amount of the ammo 5 | ITEM.ammoDesc = "A Cartridge that contains %s of AR2 Ammo" -------------------------------------------------------------------------------- /gamemode/items/ammo/sh_crossbowammo.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Crossbow Bolts" 2 | ITEM.model = "models/Items/BoxBuckshot.mdl" 3 | ITEM.ammo = "XBowRounds" // type of the ammo 4 | ITEM.ammoAmount = 5 // amount of the ammo 5 | ITEM.ammoDesc = "A Bundle of %s Crossbow Bolts" -------------------------------------------------------------------------------- /gamemode/items/ammo/sh_pistolammo.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Pistol Ammo" 2 | ITEM.model = "models/items/357ammo.mdl" 3 | ITEM.ammo = "pistol" // type of the ammo 4 | ITEM.ammoAmount = 30 // amount of the ammo 5 | ITEM.ammoDesc = "A Box that contains %s of Pistol Ammo" -------------------------------------------------------------------------------- /gamemode/items/ammo/sh_rocketammo.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "A Rocket" 2 | ITEM.model = "models/weapons/w_missile_closed.mdl" 3 | ITEM.ammo = "rpg_round" // type of the ammo 4 | ITEM.ammoAmount = 1 // amount of the ammo 5 | ITEM.width = 2 6 | ITEM.ammoDesc = "A Package of %s Rockets" 7 | ITEM.iconCam = { 8 | ang = Angle(-0.70499622821808, 268.25439453125, 0), 9 | fov = 12.085652091515, 10 | pos = Vector(7, 200, -2) 11 | } 12 | -------------------------------------------------------------------------------- /gamemode/items/ammo/sh_shotgunammo.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Shotgun Shells" 2 | ITEM.model = "models/Items/BoxBuckshot.mdl" 3 | ITEM.ammo = "buckshot" // type of the ammo 4 | ITEM.ammoAmount = 15 // amount of the ammo 5 | ITEM.ammoDesc = "A Box of %s Shotgun Shells" -------------------------------------------------------------------------------- /gamemode/items/ammo/sh_smg1ammo.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Sub Machine Gun Ammo" 2 | ITEM.model = "models/Items/BoxSRounds.mdl" 3 | ITEM.ammo = "smg1" // type of the ammo 4 | ITEM.ammoAmount = 45 // amount of the ammo 5 | ITEM.ammoDesc = "A Box that contains %s of SMG Ammo" -------------------------------------------------------------------------------- /gamemode/items/bags/sh_large.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Big Bag" 2 | ITEM.desc = "A big bag." 3 | ITEM.invWidth = 6 4 | ITEM.invHeight = 4 -------------------------------------------------------------------------------- /gamemode/items/bags/sh_small.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Small Bag" 2 | ITEM.desc = "A small bag." -------------------------------------------------------------------------------- /gamemode/items/base/sh_ammo.lua: -------------------------------------------------------------------------------- 1 | ITEM.name = "Ammo Base" 2 | ITEM.model = "models/Items/BoxSRounds.mdl" 3 | ITEM.width = 1 4 | ITEM.height = 1 5 | ITEM.ammo = "pistol" // type of the ammo 6 | ITEM.ammoAmount = 30 // amount of the ammo 7 | ITEM.desc = "A Box that contains %s of Pistol Ammo" 8 | ITEM.category = "Ammunition" 9 | 10 | function ITEM:getDesc() 11 | return Format(self.desc, self.ammoAmount) 12 | end 13 | 14 | if (CLIENT) then 15 | function ITEM:paintOver(item, w, h) 16 | draw.SimpleText(item.ammoAmount, "DermaDefault", w , h - 5, color_white, TEXT_ALIGN_RIGHT, TEXT_ALIGN_BOTTOM, 1, color_black) 17 | end 18 | end 19 | 20 | // On player uneqipped the item, Removes a weapon from the player and keep the ammo in the item. 21 | ITEM.functions.use = { -- sorry, for name order. 22 | name = "Load", 23 | tip = "useTip", 24 | icon = "icon16/add.png", 25 | onRun = function(item) 26 | item.player:GiveAmmo(item.ammoAmount, item.ammo) 27 | item.player:EmitSound("items/ammo_pickup.wav", 110) 28 | 29 | return true 30 | end, 31 | } 32 | -------------------------------------------------------------------------------- /gamemode/items/base/sh_bags.lua: -------------------------------------------------------------------------------- 1 | ITEM.name = "Bag" 2 | ITEM.desc = "A bag to hold items." 3 | ITEM.model = "models/props_c17/suitcase001a.mdl" 4 | ITEM.category = "Storage" 5 | ITEM.width = 2 6 | ITEM.height = 2 7 | ITEM.invWidth = 4 8 | ITEM.invHeight = 2 9 | ITEM.isBag = true 10 | ITEM.functions.View = { 11 | icon = "icon16/briefcase.png", 12 | onClick = function(item) 13 | local index = item:getData("id") 14 | 15 | if (index) then 16 | local panel = nut.gui["inv"..index] 17 | local parent = item.invID and nut.gui["inv"..item.invID] or nil 18 | local inventory = nut.item.inventories[index] 19 | 20 | if (IsValid(panel)) then 21 | panel:Remove() 22 | end 23 | 24 | if (inventory and inventory.slots) then 25 | panel = vgui.Create("nutInventory", parent) 26 | panel:setInventory(inventory) 27 | panel:ShowCloseButton(true) 28 | panel:SetTitle(item.getName and item:getName() or L(item.name)) 29 | 30 | nut.gui["inv"..index] = panel 31 | else 32 | ErrorNoHalt("[NutScript] Attempt to view an uninitialized inventory '"..index.."'\n") 33 | end 34 | end 35 | 36 | return false 37 | end, 38 | onCanRun = function(item) 39 | return !IsValid(item.entity) and item:getData("id") 40 | end 41 | } 42 | 43 | -- Called when a new instance of this item has been made. 44 | function ITEM:onInstanced(invID, x, y) 45 | local inventory = nut.item.inventories[invID] 46 | 47 | nut.item.newInv(inventory and inventory.owner or 0, self.uniqueID, function(inventory) 48 | inventory.vars.isBag = self.uniqueID 49 | self:setData("id", inventory:getID()) 50 | end) 51 | end 52 | 53 | function ITEM:getInv() 54 | local index = self:getData("id") 55 | 56 | if (index) then 57 | return nut.item.inventories[index] 58 | end 59 | end 60 | 61 | -- Called when the item first appears for a client. 62 | function ITEM:onSendData() 63 | local index = self:getData("id") 64 | 65 | if (index) then 66 | local inventory = nut.item.inventories[index] 67 | 68 | if (inventory) then 69 | inventory.vars.isBag = self.uniqueID 70 | inventory:sync(self.player) 71 | else 72 | local owner = self.player:getChar():getID() 73 | 74 | nut.item.restoreInv(self:getData("id"), self.invWidth, self.invHeight, function(inventory) 75 | inventory.vars.isBag = self.uniqueID 76 | inventory:setOwner(owner, true) 77 | end) 78 | end 79 | else 80 | local inventory = nut.item.inventories[self.invID] 81 | local client = self.player 82 | 83 | nut.item.newInv(self.player:getChar():getID(), self.uniqueID, function(inventory) 84 | self:setData("id", inventory:getID()) 85 | end) 86 | end 87 | end 88 | 89 | ITEM.postHooks.drop = function(item, result) 90 | local index = item:getData("id") 91 | 92 | nut.db.query("UPDATE nut_inventories SET _charID = 0 WHERE _invID = "..index) 93 | netstream.Start(item.player, "nutBagDrop", index) 94 | end 95 | 96 | if (CLIENT) then 97 | netstream.Hook("nutBagDrop", function(index) 98 | local panel = nut.gui["inv"..index] 99 | 100 | if (panel and panel:IsVisible()) then 101 | panel:Close() 102 | end 103 | end) 104 | end 105 | 106 | -- Called before the item is permanently deleted. 107 | function ITEM:onRemoved() 108 | local index = self:getData("id") 109 | 110 | if (index) then 111 | nut.db.query("DELETE FROM nut_items WHERE _invID = "..index) 112 | nut.db.query("DELETE FROM nut_inventories WHERE _invID = "..index) 113 | end 114 | end 115 | 116 | -- Called when the item should tell whether or not it can be transfered between inventories. 117 | function ITEM:onCanBeTransfered(oldInventory, newInventory) 118 | local index = self:getData("id") 119 | 120 | if (newInventory) then 121 | if (newInventory.vars and newInventory.vars.isBag) then 122 | return false 123 | end 124 | 125 | local index2 = newInventory:getID() 126 | 127 | if (index == index2) then 128 | return false 129 | end 130 | 131 | for k, v in pairs(self:getInv():getItems()) do 132 | if (v:getData("id") == index2) then 133 | return false 134 | end 135 | end 136 | end 137 | 138 | return !newInventory or newInventory:getID() != oldInventory:getID() or newInventory.vars.isBag 139 | end 140 | 141 | -- Called after the item is registered into the item tables. 142 | function ITEM:onRegistered() 143 | nut.item.registerInv(self.uniqueID, self.invWidth, self.invHeight, true) 144 | end -------------------------------------------------------------------------------- /gamemode/items/base/sh_outfit.lua: -------------------------------------------------------------------------------- 1 | ITEM.name = "Outfit" 2 | ITEM.desc = "A Outfit Base." 3 | ITEM.category = "Outfit" 4 | ITEM.model = "models/Gibs/HGIBS.mdl" 5 | ITEM.width = 1 6 | ITEM.height = 1 7 | ITEM.outfitCategory = "model" 8 | ITEM.pacData = {} 9 | 10 | /* 11 | -- This will change a player's skin after changing the model. Keep in mind it starts at 0. 12 | ITEM.newSkin = 1 13 | -- This will change a certain part of the model. 14 | ITEM.replacements = {"group01", "group02"} 15 | -- This will change the player's model completely. 16 | ITEM.replacements = "models/manhack.mdl" 17 | -- This will have multiple replacements. 18 | ITEM.replacements = { 19 | {"male", "female"}, 20 | {"group01", "group02"} 21 | } 22 | 23 | -- This will apply body groups. 24 | ITEM.bodyGroups = { 25 | ["blade"] = 1, 26 | ["bladeblur"] = 1 27 | } 28 | */ 29 | 30 | -- Inventory drawing 31 | if (CLIENT) then 32 | -- Draw camo if it is available. 33 | function ITEM:paintOver(item, w, h) 34 | if (item:getData("equip")) then 35 | surface.SetDrawColor(110, 255, 110, 100) 36 | surface.DrawRect(w - 14, h - 14, 8, 8) 37 | end 38 | end 39 | end 40 | 41 | function ITEM:removeOutfit(client) 42 | local character = client:getChar() 43 | 44 | self:setData("equip", false) 45 | 46 | if (character:getData("oldMdl")) then 47 | character:setModel(character:getData("oldMdl")) 48 | character:setData("oldMdl", nil) 49 | end 50 | 51 | if (self.newSkin) then 52 | if (character:getData("oldSkin")) then 53 | client:SetSkin(character:getData("oldSkin")) 54 | character:setData("oldSkin", nil) 55 | else 56 | client:SetSkin(0) 57 | end 58 | end 59 | 60 | for k, v in pairs(self.bodyGroups or {}) do 61 | local index = client:FindBodygroupByName(k) 62 | 63 | if (index > -1) then 64 | client:SetBodygroup(index, 0) 65 | 66 | local groups = character:getData("groups", {}) 67 | 68 | if (groups[index]) then 69 | groups[index] = nil 70 | character:setData("groups", groups) 71 | end 72 | end 73 | end 74 | 75 | if (self.attribBoosts) then 76 | for k, _ in pairs(self.attribBoosts) do 77 | character:removeBoost(self.uniqueID, k) 78 | end 79 | end 80 | end 81 | 82 | -- On item is dropped, Remove a weapon from the player and keep the ammo in the item. 83 | ITEM:hook("drop", function(item) 84 | if (item:getData("equip")) then 85 | item:removeOutfit(item.player) 86 | end 87 | end) 88 | 89 | -- On player uneqipped the item, Removes a weapon from the player and keep the ammo in the item. 90 | ITEM.functions.EquipUn = { -- sorry, for name order. 91 | name = "Unequip", 92 | tip = "equipTip", 93 | icon = "icon16/cross.png", 94 | onRun = function(item) 95 | item:removeOutfit(item.player) 96 | 97 | return false 98 | end, 99 | onCanRun = function(item) 100 | return (!IsValid(item.entity) and item:getData("equip") == true) 101 | end 102 | } 103 | 104 | -- On player eqipped the item, Gives a weapon to player and load the ammo data from the item. 105 | ITEM.functions.Equip = { 106 | name = "Equip", 107 | tip = "equipTip", 108 | icon = "icon16/tick.png", 109 | onRun = function(item) 110 | local char = item.player:getChar() 111 | local items = char:getInv():getItems() 112 | 113 | for k, v in pairs(items) do 114 | if (v.id != item.id) then 115 | local itemTable = nut.item.instances[v.id] 116 | 117 | if (itemTable.pacData and v.outfitCategory == item.outfitCategory and itemTable:getData("equip")) then 118 | item.player:notify("You're already equipping this kind of outfit") 119 | 120 | return false 121 | end 122 | end 123 | end 124 | 125 | item:setData("equip", true) 126 | 127 | if (type(item.onGetReplacement) == "function") then 128 | char:setData("oldMdl", char:getData("oldMdl", item.player:GetModel())) 129 | char:setModel(item:onGetReplacement()) 130 | elseif (item.replacement or item.replacements) then 131 | char:setData("oldMdl", char:getData("oldMdl", item.player:GetModel())) 132 | 133 | if (type(item.replacements) == "table") then 134 | if (#item.replacements == 2 and type(item.replacements[1]) == "string") then 135 | char:setModel(item.player:GetModel():gsub(item.replacements[1], item.replacements[2])) 136 | else 137 | for k, v in ipairs(item.replacements) do 138 | char:setModel(item.player:GetModel():gsub(v[1], v[2])) 139 | end 140 | end 141 | else 142 | char:setModel(item.replacement or item.replacements) 143 | end 144 | end 145 | 146 | if (item.newSkin) then 147 | char:setData("oldSkin", item.player:GetSkin()) 148 | item.player:SetSkin(item.newSkin) 149 | end 150 | 151 | if (item.bodyGroups) then 152 | local groups = {} 153 | 154 | for k, value in pairs(item.bodyGroups) do 155 | local index = item.player:FindBodygroupByName(k) 156 | 157 | if (index > -1) then 158 | groups[index] = value 159 | end 160 | end 161 | 162 | local newGroups = char:getData("groups", {}) 163 | 164 | for index, value in pairs(groups) do 165 | newGroups[index] = value 166 | item.player:SetBodygroup(index, value) 167 | end 168 | 169 | if (table.Count(newGroups) > 0) then 170 | char:setData("groups", newGroups) 171 | end 172 | end 173 | 174 | if (item.attribBoosts) then 175 | for k, v in pairs(item.attribBoosts) do 176 | char:addBoost(item.uniqueID, k, v) 177 | end 178 | end 179 | 180 | return false 181 | end, 182 | onCanRun = function(item) 183 | return (!IsValid(item.entity) and item:getData("equip") != true) 184 | end 185 | } 186 | 187 | function ITEM:onCanBeTransfered(oldInventory, newInventory) 188 | if (newInventory and self:getData("equip")) then 189 | return false 190 | end 191 | 192 | return true 193 | end 194 | -------------------------------------------------------------------------------- /gamemode/items/base/sh_pacoutfit.lua: -------------------------------------------------------------------------------- 1 | ITEM.name = "PAC Outfit" 2 | ITEM.desc = "A PAC Outfit Base." 3 | ITEM.category = "Outfit" 4 | ITEM.model = "models/Gibs/HGIBS.mdl" 5 | ITEM.width = 1 6 | ITEM.height = 1 7 | ITEM.outfitCategory = "hat" 8 | ITEM.pacData = {} 9 | 10 | --[[ 11 | ITEM.pacData = { 12 | [1] = { 13 | ["children"] = { 14 | [1] = { 15 | ["children"] = { 16 | }, 17 | ["self"] = { 18 | ["Angles"] = Angle(12.919322967529, 6.5696062847564e-006, -1.0949343050015e-005), 19 | ["Position"] = Vector(-2.099609375, 0.019973754882813, 1.0180969238281), 20 | ["UniqueID"] = "4249811628", 21 | ["Size"] = 1.25, 22 | ["Bone"] = "eyes", 23 | ["Model"] = "models/Gibs/HGIBS.mdl", 24 | ["ClassName"] = "model", 25 | }, 26 | }, 27 | }, 28 | ["self"] = { 29 | ["ClassName"] = "group", 30 | ["UniqueID"] = "907159817", 31 | ["EditorExpand"] = true, 32 | }, 33 | }, 34 | } 35 | 36 | -- This will change a player's skin after changing the model. Keep in mind it starts at 0. 37 | ITEM.newSkin = 1 38 | -- This will change a certain part of the model. 39 | ITEM.replacements = {"group01", "group02"} 40 | -- This will change the player's model completely. 41 | ITEM.replacements = "models/manhack.mdl" 42 | -- This will have multiple replacements. 43 | ITEM.replacements = { 44 | {"male", "female"}, 45 | {"group01", "group02"} 46 | } 47 | 48 | -- This will apply body groups. 49 | ITEM.bodyGroups = { 50 | ["blade"] = 1, 51 | ["bladeblur"] = 1 52 | } 53 | 54 | --]] 55 | 56 | -- Inventory drawing 57 | if (CLIENT) then 58 | -- Draw camo if it is available. 59 | function ITEM:paintOver(item, w, h) 60 | if (item:getData("equip")) then 61 | surface.SetDrawColor(110, 255, 110, 100) 62 | surface.DrawRect(w - 14, h - 14, 8, 8) 63 | end 64 | end 65 | end 66 | 67 | function ITEM:removePart(client) 68 | local char = client:getChar() 69 | 70 | self:setData("equip", false) 71 | client:removePart(self.uniqueID) 72 | 73 | if (self.attribBoosts) then 74 | for k, _ in pairs(self.attribBoosts) do 75 | char:removeBoost(self.uniqueID, k) 76 | end 77 | end 78 | end 79 | 80 | -- On item is dropped, Remove a weapon from the player and keep the ammo in the item. 81 | ITEM:hook("drop", function(item) 82 | if (item:getData("equip")) then 83 | item:removePart(item.player) 84 | end 85 | end) 86 | 87 | -- On player uneqipped the item, Removes a weapon from the player and keep the ammo in the item. 88 | ITEM.functions.EquipUn = { -- sorry, for name order. 89 | name = "Unequip", 90 | tip = "equipTip", 91 | icon = "icon16/cross.png", 92 | onRun = function(item) 93 | item:removePart(item.player) 94 | 95 | return false 96 | end, 97 | onCanRun = function(item) 98 | return (!IsValid(item.entity) and item:getData("equip") == true) 99 | end 100 | } 101 | 102 | -- On player eqipped the item, Gives a weapon to player and load the ammo data from the item. 103 | ITEM.functions.Equip = { 104 | name = "Equip", 105 | tip = "equipTip", 106 | icon = "icon16/tick.png", 107 | onRun = function(item) 108 | local char = item.player:getChar() 109 | local items = char:getInv():getItems() 110 | 111 | for k, v in pairs(items) do 112 | if (v.id != item.id) then 113 | local itemTable = nut.item.instances[v.id] 114 | 115 | if (itemTable.pacData and v.outfitCategory == item.outfitCategory and itemTable:getData("equip")) then 116 | item.player:notify("You're already equipping this kind of outfit") 117 | 118 | return false 119 | end 120 | end 121 | end 122 | 123 | item:setData("equip", true) 124 | item.player:addPart(item.uniqueID, item) 125 | 126 | if (item.attribBoosts) then 127 | for k, v in pairs(item.attribBoosts) do 128 | char:addBoost(item.uniqueID, k, v) 129 | end 130 | end 131 | 132 | return false 133 | end, 134 | onCanRun = function(item) 135 | return (!IsValid(item.entity) and item:getData("equip") != true) 136 | end 137 | } 138 | 139 | function ITEM:onCanBeTransfered(oldInventory, newInventory) 140 | if (newInventory and self:getData("equip")) then 141 | return false 142 | end 143 | 144 | return true 145 | end 146 | 147 | function ITEM:onRemoved() 148 | local inv = nut.item.inventories[self.invID] 149 | local receiver = inv.getReceiver and inv:getReceiver() 150 | 151 | if (IsValid(receiver) and receiver:IsPlayer()) then 152 | if (self:getData("equip")) then 153 | self:removePart(receiver) 154 | end 155 | end 156 | end 157 | -------------------------------------------------------------------------------- /gamemode/items/pacoutfit/sh_skullmask.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Skull Mask" 2 | ITEM.desc = "It's a skull mask." 3 | ITEM.model = "models/Gibs/HGIBS.mdl" 4 | ITEM.width = 1 5 | ITEM.height = 1 6 | ITEM.outfitCategory = "hat" 7 | ITEM.pacData = { 8 | [1] = { 9 | ["children"] = { 10 | [1] = { 11 | ["children"] = { 12 | }, 13 | ["self"] = { 14 | ["Angles"] = Angle(12.919322967529, 6.5696062847564e-006, -1.0949343050015e-005), 15 | ["Position"] = Vector(-2.099609375, 0.019973754882813, 1.3180969238281), 16 | ["UniqueID"] = "4249811628", 17 | ["Size"] = 1.25, 18 | ["Bone"] = "eyes", 19 | ["Model"] = "models/Gibs/HGIBS.mdl", 20 | ["ClassName"] = "model", 21 | }, 22 | }, 23 | }, 24 | ["self"] = { 25 | ["ClassName"] = "group", 26 | ["UniqueID"] = "907159817", 27 | ["EditorExpand"] = true, 28 | }, 29 | }, 30 | } -------------------------------------------------------------------------------- /gamemode/items/sh_defaultitem.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Test Item" 2 | ITEM.desc = "A test item!" 3 | ITEM.model = "models/props_c17/oildrum001.mdl" -------------------------------------------------------------------------------- /gamemode/items/weapons/sh_357.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "357" 2 | ITEM.desc = "A sidearm utilising .357 Caliber ammunition." 3 | ITEM.model = "models/weapons/w_357.mdl" 4 | ITEM.class = "weapon_357" 5 | ITEM.weaponCategory = "sidearm" 6 | ITEM.width = 2 7 | ITEM.height = 1 8 | ITEM.iconCam = { 9 | ang = Angle(-17.581502914429, 250.7974395752, 0), 10 | fov = 5.412494001838, 11 | pos = Vector(57.109928131104, 181.7945098877, -60.738327026367) 12 | } 13 | -------------------------------------------------------------------------------- /gamemode/items/weapons/sh_ar2.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "AR2" 2 | ITEM.desc = "A Weapon." 3 | ITEM.model = "models/weapons/w_IRifle.mdl" 4 | ITEM.class = "weapon_ar2" 5 | ITEM.weaponCategory = "primary" 6 | ITEM.width = 4 7 | ITEM.height = 2 8 | ITEM.iconCam = { 9 | ang = Angle(-0.70499622821808, 268.25439453125, 0), 10 | fov = 12.085652091515, 11 | pos = Vector(0, 200, 0) 12 | } -------------------------------------------------------------------------------- /gamemode/items/weapons/sh_crowbar.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Crowbar" 2 | ITEM.desc = "A slightly rusty looking crowbar." 3 | ITEM.model = "models/weapons/w_crowbar.mdl" 4 | ITEM.class = "weapon_crowbar" 5 | ITEM.weaponCategory = "melee" 6 | ITEM.width = 2 7 | ITEM.height = 1 8 | ITEM.iconCam = { 9 | ang = Angle(-0.23955784738064, 270.44906616211, 0), 10 | fov = 10.780103254469, 11 | pos = Vector(0, 200, 0) 12 | } 13 | -------------------------------------------------------------------------------- /gamemode/items/weapons/sh_pistol.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "9MM Pistol" 2 | ITEM.desc = "A sidearm utilising 9mm Ammunition." 3 | ITEM.model = "models/weapons/w_pistol.mdl" 4 | ITEM.class = "weapon_pistol" 5 | ITEM.weaponCategory = "sidearm" 6 | ITEM.width = 2 7 | ITEM.height = 1 8 | ITEM.iconCam = { 9 | ang = Angle(0.33879372477531, 270.15808105469, 0), 10 | fov = 5.0470897275697, 11 | pos = Vector(0, 200, -1) 12 | } 13 | -------------------------------------------------------------------------------- /gamemode/items/weapons/sh_smg1.txt: -------------------------------------------------------------------------------- 1 | ITEM.name = "Sub Machine Gun" 2 | ITEM.desc = "A Weapon." 3 | ITEM.model = "models/weapons/w_smg1.mdl" 4 | ITEM.class = "weapon_smg1" 5 | ITEM.weaponCategory = "primary" 6 | ITEM.width = 3 7 | ITEM.height = 2 8 | ITEM.iconCam = { 9 | ang = Angle(-0.020070368424058, 270.40155029297, 0), 10 | fov = 7.2253324508038, 11 | pos = Vector(0, 200, -1) 12 | } -------------------------------------------------------------------------------- /gamemode/shared.lua: -------------------------------------------------------------------------------- 1 | -- Define gamemode information. 2 | GM.Name = "NutScript 1.1" 3 | GM.Author = "Chessnut and Black Tea" 4 | GM.Website = "http://chessnut.info" 5 | 6 | -- Fix for client:SteamID64() returning nil when in single-player. 7 | do 8 | local playerMeta = FindMetaTable("Player") 9 | playerMeta.nutSteamID64 = playerMeta.nutSteamID64 or playerMeta.SteamID64 10 | 11 | -- Overwrite the normal SteamID64 method. 12 | function playerMeta:SteamID64() 13 | -- Return 0 if the SteamID64 could not be found. 14 | return self:nutSteamID64() or 0 15 | end 16 | 17 | NutTranslateModel = NutTranslateModel or player_manager.TranslateToPlayerModelName 18 | 19 | function player_manager.TranslateToPlayerModelName(model) 20 | model = model:lower():gsub("\\", "/") 21 | local result = NutTranslateModel(model) 22 | 23 | if (result == "kleiner" and !model:find("kleiner")) then 24 | local model2 = model:gsub("models/", "models/player/") 25 | result = NutTranslateModel(model2) 26 | 27 | if (result != "kleiner") then 28 | return result 29 | end 30 | 31 | model2 = model:gsub("models/humans", "models/player") 32 | result = NutTranslateModel(model2) 33 | 34 | if (result != "kleiner") then 35 | return result 36 | end 37 | 38 | model2 = model:gsub("models/zombie/", "models/player/zombie_") 39 | result = NutTranslateModel(model2) 40 | 41 | if (result != "kleiner") then 42 | return result 43 | end 44 | end 45 | 46 | return result 47 | end 48 | end 49 | 50 | -- Include core framework files. 51 | nut.util.include("core/cl_skin.lua") 52 | nut.util.includeDir("core/libs/thirdparty") 53 | nut.util.include("core/sh_config.lua") 54 | nut.util.includeDir("core/libs") 55 | nut.util.includeDir("core/derma") 56 | nut.util.includeDir("core/hooks") 57 | 58 | -- Include language and default base items. 59 | nut.lang.loadFromDir("nutscript/gamemode/languages") 60 | nut.item.loadFromDir("nutscript/gamemode/items") 61 | 62 | -- Called after the gamemode has loaded. 63 | function GM:Initialize() 64 | -- Load all of the NutScript plugins. 65 | nut.plugin.initialize() 66 | -- Restore the configurations from earlier if applicable. 67 | nut.config.load() 68 | end 69 | 70 | ITSTIMETOSTOP = false 71 | -- Called when a file has been modified. 72 | function GM:OnReloaded() 73 | 74 | -- Reload the default fonts. 75 | if (CLIENT) then 76 | hook.Run("LoadFonts", nut.config.get("font"), nut.config.get("genericFont")) 77 | 78 | -- Reload the scoreboard. 79 | if (IsValid(nut.gui.score)) then 80 | nut.gui.score:Remove() 81 | end 82 | else 83 | -- Auto-reload support for faction pay timers. 84 | for index, faction in ipairs(nut.faction.indices) do 85 | for k, v in ipairs(team.GetPlayers(index)) do 86 | if (faction.pay and faction.pay > 0) then 87 | timer.Adjust("nutSalary"..v:UniqueID(), faction.payTime or 300, 0, function() 88 | local pay = hook.Run("GetSalaryAmount", v, faction) or faction.pay 89 | 90 | v:getChar():giveMoney(pay) 91 | v:notifyLocalized("salary", nut.currency.get(pay)) 92 | end) 93 | else 94 | timer.Remove("nutSalary"..v:UniqueID()) 95 | end 96 | end 97 | end 98 | end 99 | 100 | if (!ITSTIMETOSTOP) then 101 | -- Load all of the NutScript plugins. 102 | nut.plugin.initialize() 103 | -- Restore the configurations from earlier if applicable. 104 | nut.config.load() 105 | 106 | ITSTIMETOSTOP = true 107 | end 108 | 109 | end 110 | 111 | -- Include default NutScript chat commands. 112 | nut.util.include("core/sh_commands.lua") 113 | 114 | if (SERVER and game.IsDedicated()) then 115 | concommand.Remove("gm_save") 116 | 117 | concommand.Add("gm_save", function(client, command, arguments) 118 | client:ChatPrint("You are not allowed to do that, administrators have been notified.") 119 | 120 | if ((client.nutNextWarn or 0) < CurTime()) then 121 | local message = client:Name().." ["..client:SteamID().."] has possibly attempted to crash the server with 'gm_save'" 122 | 123 | for k, v in ipairs(player.GetAll()) do 124 | if (v:IsAdmin()) then 125 | v:ChatPrint(message) 126 | end 127 | end 128 | 129 | MsgC(Color(255, 255, 0), message.."\n") 130 | client.nutNextWarn = CurTime() + 60 131 | end 132 | end) 133 | end 134 | -------------------------------------------------------------------------------- /nutscript.txt: -------------------------------------------------------------------------------- 1 | "nutscript" 2 | { 3 | "base" "sandbox" 4 | "title" "NutScript 1.1" 5 | "author" "Chessnut and Black Tea" 6 | } -------------------------------------------------------------------------------- /plugins/act/sh_plugin.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Acts" 2 | PLUGIN.author = "Chessnut" 3 | PLUGIN.desc = "Adds acts that can be performed." 4 | PLUGIN.acts = PLUGIN.acts or {} 5 | 6 | nut.util.include("sh_setup.lua") 7 | 8 | for k, v in pairs(PLUGIN.acts) do 9 | local data = {} 10 | local multiple = false 11 | 12 | for k2, v2 in pairs(v) do 13 | if (type(v2.sequence) == "table" and #v2.sequence > 1) then 14 | multiple = true 15 | 16 | break 17 | end 18 | end 19 | 20 | if (multiple) then 21 | data.syntax = "[number type]" 22 | end 23 | 24 | data.onRun = function(client, arguments) 25 | if (client.nutSeqUntimed) then 26 | client:setNetVar("actAng") 27 | client:leaveSequence() 28 | client.nutSeqUntimed = nil 29 | 30 | return 31 | end 32 | 33 | if (!client:Alive() or 34 | client:setLocalVar("ragdoll")) then 35 | return 36 | end 37 | 38 | if ((client.nutNextAct or 0) < CurTime()) then 39 | local class = nut.anim.getModelClass(client:GetModel()) 40 | local info = v[class] 41 | 42 | if (info) then 43 | if (info.onCheck) then 44 | local result = info.onCheck(client) 45 | 46 | if (result) then 47 | return result 48 | end 49 | end 50 | 51 | local sequence 52 | 53 | if (type(info.sequence) == "table") then 54 | local index = math.Clamp(math.floor(tonumber(arguments[1]) or 1), 1, #info.sequence) 55 | 56 | sequence = info.sequence[index] 57 | else 58 | sequence = info.sequence 59 | end 60 | 61 | local duration = client:forceSequence(sequence, nil, info.untimed and 0 or nil) 62 | 63 | client.nutSeqUntimed = info.untimed 64 | client.nutNextAct = CurTime() + (info.untimed and 4 or duration) + 1 65 | client:setNetVar("actAng", client:GetAngles()) 66 | else 67 | return "@modelNoSeq" 68 | end 69 | end 70 | end 71 | nut.command.add("act"..k, data) 72 | end 73 | 74 | function PLUGIN:UpdateAnimation(client, moveData) 75 | local angles = client:getNetVar("actAng") 76 | 77 | if (angles) then 78 | client:SetRenderAngles(angles) 79 | end 80 | end 81 | 82 | function PLUGIN:OnPlayerLeaveSequence(client) 83 | client:setNetVar("actAng") 84 | end 85 | 86 | function PLUGIN:PlayerDeath(client) 87 | if (client.nutSeqUntimed) then 88 | client:setNetVar("actAng") 89 | client:leaveSequence() 90 | client.nutSeqUntimed = nil 91 | end 92 | end 93 | 94 | function PLUGIN:OnCharFallover(client) 95 | if (client.nutSeqUntimed) then 96 | client:setNetVar("actAng") 97 | client:leaveSequence() 98 | client.nutSeqUntimed = nil 99 | end 100 | end 101 | 102 | function PLUGIN:ShouldDrawLocalPlayer(client) 103 | if (client:getNetVar("actAng")) then 104 | return true 105 | end 106 | end 107 | 108 | local GROUND_PADDING = Vector(0, 0, 8) 109 | local PLAYER_OFFSET = Vector(0, 0, 72) 110 | 111 | function PLUGIN:CalcView(client, origin, angles, fov) 112 | if (client:getNetVar("actAng")) then 113 | local view = {} 114 | local data = {} 115 | data.start = client:GetPos() + PLAYER_OFFSET 116 | data.endpos = data.start - client:EyeAngles():Forward()*72 117 | view.origin = util.TraceLine(data).HitPos + GROUND_PADDING 118 | view.angles = client:EyeAngles() 119 | return view 120 | end 121 | end 122 | 123 | function PLUGIN:PlayerBindPress(client, bind, pressed) 124 | if (client:getNetVar("actAng")) then 125 | bind = bind:lower() 126 | 127 | if (bind:find("+jump") and pressed) then 128 | nut.command.send("actsit") 129 | 130 | return true 131 | end 132 | end 133 | end -------------------------------------------------------------------------------- /plugins/act/sh_setup.lua: -------------------------------------------------------------------------------- 1 | local function facingWall(client) 2 | local data = {} 3 | data.start = client:GetPos() 4 | data.endpos = data.start + client:GetAimVector()*54 5 | data.filter = client 6 | 7 | if (!util.TraceLine(data).HitWorld) then 8 | return "@faceWall" 9 | end 10 | end 11 | 12 | local function facingWallBack(client) 13 | local data = {} 14 | data.start = client:GetPos() 15 | data.endpos = data.start - client:GetAimVector()*54 16 | data.filter = client 17 | 18 | if (!util.TraceLine(data).HitWorld) then 19 | return "@faceWallBack" 20 | end 21 | end 22 | 23 | ACT_ENDSEQ = 0 24 | ACT_STARTSEQ = 1 25 | 26 | PLUGIN.acts["sit"] = { 27 | ["citizen_male"] = {sequence = "sit_ground", untimed = true, transition = { [ACT_STARTSEQ] = "Idle_to_Sit_Ground", [ACT_ENDSEQ] = "Sit_Ground_to_Idle" }}, 28 | ["citizen_female"] = {sequence = "sit_ground", untimed = true} 29 | } 30 | PLUGIN.acts["injured"] = { 31 | ["citizen_male"] = {sequence = {"d1_town05_wounded_idle_1", "d1_town05_wounded_idle_2", "d1_town05_winston_down"}, untimed = true}, 32 | ["citizen_female"] = {sequence = "d1_town05_wounded_idle_1", untimed = true} 33 | } 34 | PLUGIN.acts["arrest"] = { 35 | ["citizen_male"] = {sequence = "apcarrestidle", untimed = true, onCheck = facingWall} 36 | } 37 | PLUGIN.acts["cheer"] = { 38 | ["citizen_male"] = {sequence = {"cheer1", "cheer2", "wave_smg1"}}, 39 | ["citizen_female"] = {sequence = {"cheer1", "wave_smg1"}} 40 | } 41 | PLUGIN.acts["here"] = { 42 | ["citizen_male"] = {sequence = {"wave_close", "wave"}}, 43 | ["citizen_female"] = {sequence = {"wave_close", "wave"}} 44 | } 45 | PLUGIN.acts["sitwall"] = { 46 | ["citizen_male"] = {sequence = {"plazaidle4", "injured1"}, untimed = true, onCheck = facingWallBack}, 47 | ["citizen_female"] = {sequence = {"plazaidle4", "injured1", "injured2"}, untimed = true, onCheck = facingWallBack} 48 | } 49 | PLUGIN.acts["stand"] = { 50 | ["citizen_male"] = {sequence = {"lineidle01", "lineidle02", "lineidle03", "lineidle04"}, untimed = true}, 51 | ["citizen_female"] = {sequence = {"lineidle01", "lineidle02", "lineidle03"}, untimed = true}, 52 | ["metrocop"] = {sequence = "plazathreat2", untimed = true} 53 | } -------------------------------------------------------------------------------- /plugins/ammosave.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Ammo Saver" 2 | PLUGIN.author = "Black Tea" 3 | PLUGIN.desc = "Saves the ammo of a character." 4 | PLUGIN.ammoList = {} 5 | nut.ammo = nut.ammo or {} 6 | 7 | 8 | function nut.ammo.register(name) 9 | table.insert(PLUGIN.ammoList, name) 10 | end 11 | 12 | -- Register Default HL2 Ammunition. 13 | nut.ammo.register("ar2") 14 | nut.ammo.register("pistol") 15 | nut.ammo.register("357") 16 | nut.ammo.register("smg1") 17 | nut.ammo.register("xbowbolt") 18 | nut.ammo.register("buckshot") 19 | nut.ammo.register("rpg_round") 20 | nut.ammo.register("smg1_grenade") 21 | nut.ammo.register("grenade") 22 | nut.ammo.register("ar2altfire") 23 | nut.ammo.register("slam") 24 | 25 | -- Register Cut HL2 Ammunition. 26 | nut.ammo.register("alyxgun") 27 | nut.ammo.register("sniperround") 28 | nut.ammo.register("sniperpenetratedround") 29 | nut.ammo.register("thumper") 30 | nut.ammo.register("gravity") 31 | nut.ammo.register("battery") 32 | nut.ammo.register("gaussenergy") 33 | nut.ammo.register("combinecannon") 34 | nut.ammo.register("airboatgun") 35 | nut.ammo.register("striderminigun") 36 | nut.ammo.register("helicoptergun") 37 | 38 | -- Called right before the character has its information save. 39 | function PLUGIN:CharacterPreSave(character) 40 | -- Get the player from the character. 41 | local client = character:getPlayer() 42 | 43 | -- Check to see if we can get the player's ammo. 44 | if (IsValid(client)) then 45 | local ammoTable = {} 46 | 47 | for k, v in ipairs(self.ammoList) do 48 | local ammo = client:GetAmmoCount(v) 49 | 50 | if (ammo > 0) then 51 | ammoTable[v] = ammo 52 | end 53 | end 54 | 55 | character:setData("ammo", ammoTable) 56 | end 57 | end 58 | 59 | -- Called after the player's loadout has been set. 60 | function PLUGIN:PlayerLoadedChar(client) 61 | timer.Simple(0.25, function() 62 | if (!IsValid(client)) then 63 | return 64 | end 65 | 66 | -- Get the saved ammo table from the character data. 67 | local character = client:getChar() 68 | 69 | if (!character) then 70 | return 71 | end 72 | 73 | local ammoTable = character:getData("ammo") 74 | 75 | -- Check if the ammotable is exists. 76 | if (ammoTable) then 77 | for k, v in pairs(ammoTable) do 78 | client:SetAmmo(v, tostring(k)) 79 | end 80 | end 81 | end) 82 | end 83 | -------------------------------------------------------------------------------- /plugins/area/derma/cl_areamanager.lua: -------------------------------------------------------------------------------- 1 | local PLUGIN = PLUGIN 2 | local PANEL = {} 3 | 4 | function PANEL:Init() 5 | self:SetTitle(L("areaManager")) 6 | self:SetSize(500, 400) 7 | self:Center() 8 | self:MakePopup() 9 | 10 | local noticeBar = self:Add("nutNoticeBar") 11 | noticeBar:Dock(TOP) 12 | noticeBar:setType(4) 13 | noticeBar:setText(L("areaManagerTip")) 14 | 15 | self.list = self:Add("PanelList") 16 | self.list:Dock(FILL) 17 | self.list:DockMargin(0, 5, 0, 0) 18 | self.list:SetSpacing(5) 19 | self.list:SetPadding(5) 20 | self.list:EnableVerticalScrollbar() 21 | 22 | self:loadBusinesses() 23 | end 24 | 25 | function PANEL:loadBusinesses() 26 | for class, data in pairs(PLUGIN.areaTable) do 27 | local panel = self.list:Add("DButton") 28 | panel:SetText(data.name) 29 | panel:SetFont("ChatFont") 30 | panel:SetTextColor(color_white) 31 | panel:SetTall(30) 32 | local onConfirm = function(newName) 33 | netstream.Start("areaEdit", class, {name = newName}) 34 | self:Close() 35 | end 36 | panel.OnMousePressed = function(this, code) 37 | if (code == MOUSE_LEFT) then 38 | surface.PlaySound("buttons/blip1.wav") 39 | Derma_StringRequest( 40 | L("enterAreaName"), 41 | L("enterAreaName"), 42 | data.name, 43 | onConfirm 44 | ) 45 | elseif (code == MOUSE_RIGHT) then 46 | surface.PlaySound("buttons/blip2.wav") 47 | 48 | local menu = DermaMenu() 49 | menu:AddOption(L"renameArea", function() 50 | Derma_StringRequest( 51 | L("enterAreaName"), 52 | L("enterAreaName"), 53 | data.name, 54 | onConfirm 55 | ) 56 | end):SetImage("icon16/comment.png") 57 | menu:AddOption(L"moveToArea", function() 58 | netstream.Start("areaTeleport", class) 59 | end):SetImage("icon16/door_in.png") 60 | menu:AddOption(L"deleteArea", function() 61 | netstream.Start("areaRemove", class) 62 | self:Close() 63 | end):SetImage("icon16/cross.png") 64 | menu:Open() 65 | end 66 | end 67 | self.list:AddItem(panel) 68 | end 69 | end 70 | 71 | vgui.Register("nutAreaManager", PANEL, "DFrame") 72 | 73 | netstream.Hook("nutAreaManager", function(areaList) 74 | PLUGIN.areaTable = areaList 75 | areaManager = vgui.Create("nutAreaManager") 76 | end) -------------------------------------------------------------------------------- /plugins/area/entities/weapons/nut_areahelper.lua: -------------------------------------------------------------------------------- 1 | AddCSLuaFile() 2 | 3 | if( CLIENT ) then 4 | SWEP.PrintName = "Area Helper"; 5 | SWEP.Slot = 0; 6 | SWEP.SlotPos = 0; 7 | SWEP.CLMode = 0 8 | end 9 | SWEP.HoldType = "fists" 10 | 11 | SWEP.Category = "Nutscript" 12 | SWEP.Spawnable = true 13 | SWEP.AdminSpawnable = true 14 | 15 | SWEP.ViewModel = "models/weapons/v_pistol.mdl" 16 | SWEP.WorldModel = "models/weapons/w_pistol.mdl" 17 | 18 | SWEP.Primary.Delay = 1 19 | SWEP.Primary.Recoil = 0 20 | SWEP.Primary.Damage = 0 21 | SWEP.Primary.NumShots = 0 22 | SWEP.Primary.Cone = 0 23 | SWEP.Primary.ClipSize = -1 24 | SWEP.Primary.DefaultClip = -1 25 | SWEP.Primary.Automatic = false 26 | SWEP.Primary.Ammo = "none" 27 | 28 | SWEP.Secondary.Delay = 0.9 29 | SWEP.Secondary.Recoil = 0 30 | SWEP.Secondary.Damage = 0 31 | SWEP.Secondary.NumShots = 1 32 | SWEP.Secondary.Cone = 0 33 | SWEP.Secondary.ClipSize = -1 34 | SWEP.Secondary.DefaultClip = -1 35 | SWEP.Secondary.Automatic = true 36 | SWEP.Secondary.Ammo = "none" 37 | 38 | function SWEP:Initialize() 39 | self:SetWeaponHoldType("knife") 40 | end 41 | 42 | function SWEP:Deploy() 43 | return true 44 | end 45 | 46 | function SWEP:Think() 47 | end 48 | 49 | local gridsize = 1 50 | 51 | if SERVER then 52 | function SWEP:PrimaryAttack() 53 | end 54 | 55 | function SWEP:Reload() 56 | end 57 | 58 | function SWEP:SecondaryAttack() 59 | end 60 | end 61 | 62 | if CLIENT then 63 | areaPoint = areaPoint or {} 64 | 65 | function SWEP:PrimaryAttack() 66 | if IsFirstTimePredicted() then 67 | local trace = LocalPlayer():GetEyeTraceNoCursor() 68 | local pos = trace.HitPos 69 | 70 | if (areaPoint.startVector) then 71 | areaPoint.endVector = pos 72 | surface.PlaySound("buttons/button15.wav") 73 | else 74 | areaPoint.startVector = pos 75 | surface.PlaySound("buttons/button3.wav") 76 | end 77 | end 78 | end 79 | 80 | function SWEP:openAreaManager() 81 | end 82 | 83 | function SWEP:Reload() 84 | if (!self.ohWow and areaPoint.startVector and areaPoint.endVector) then 85 | self.ohWow = true 86 | Derma_StringRequest("Area Name?", "Area Name?", "", function(text) 87 | self.ohWow = false 88 | netstream.Start("areaAdd", text, areaPoint.startVector, areaPoint.endVector) 89 | end, function() 90 | self.ohWow = false 91 | end) 92 | end 93 | end 94 | 95 | function SWEP:SecondaryAttack() 96 | if (IsFirstTimePredicted()) then 97 | areaPoint = {} 98 | 99 | if (!self.rSnd) then 100 | surface.PlaySound("buttons/button2.wav") 101 | self.rSnd = true 102 | 103 | timer.Simple(.5, function() 104 | self.rSnd = false 105 | end) 106 | end 107 | end 108 | 109 | return false 110 | end 111 | 112 | function SWEP:Deploy() 113 | end 114 | 115 | function SWEP:Holster() 116 | return true 117 | end 118 | 119 | function SWEP:OnRemove() 120 | end 121 | 122 | function SWEP:Think() 123 | end 124 | 125 | function SWEP:DrawHUD() 126 | local w, h = ScrW(), ScrH() 127 | local cury = h/4*3 128 | local tx, ty = draw.SimpleText("Left Click: Set Area Point", "nutMediumFont", w/2, cury, color_white, 1, 1) 129 | cury = cury + ty 130 | local tx, ty = draw.SimpleText("Right Click: Reset Area Point", "nutMediumFont", w/2, cury, color_white, 1, 1) 131 | cury = cury + ty 132 | local tx, ty = draw.SimpleText("Reload: Register Area", "nutMediumFont", w/2, cury, color_white, 1, 1) 133 | 134 | local trace = LocalPlayer():GetEyeTraceNoCursor() 135 | local pos = trace.HitPos 136 | 137 | surface.SetDrawColor(255, 0, 0) 138 | local aimPos = pos:ToScreen() 139 | if (pos and aimPos) then 140 | surface.DrawLine(aimPos.x, aimPos.y - 10, aimPos.x, aimPos.y + 10) 141 | surface.DrawLine(aimPos.x - 10, aimPos.y, aimPos.x + 10, aimPos.y) 142 | end 143 | end 144 | 145 | hook.Add("PostDrawOpaqueRenderables", "helperDraw", function() 146 | if (areaPoint) then 147 | local sPos, ePos 148 | if (areaPoint.startVector and areaPoint.endVector) then 149 | sPos = areaPoint.startVector 150 | ePos = areaPoint.endVector 151 | elseif (areaPoint.startVector and !areaPoint.endVector) then 152 | sPos = areaPoint.startVector 153 | local trace = LocalPlayer():GetEyeTraceNoCursor() 154 | ePos = trace.HitPos 155 | end 156 | 157 | if (sPos and ePos) then 158 | local c1, c2, c3, c4 159 | --render.DrawLine(sPos, ePos, color_white) 160 | c1 = Vector(sPos[1], ePos[2], sPos[3]) 161 | render.DrawLine(sPos, c1, color_white) 162 | c2 = Vector(ePos[1], sPos[2], sPos[3]) 163 | render.DrawLine(sPos, c2, color_white) 164 | c3 = Vector(ePos[1], ePos[2], sPos[3]) 165 | render.DrawLine(c3, c1, color_white) 166 | c4 = Vector(ePos[1], ePos[2], sPos[3]) 167 | render.DrawLine(c3, c2, color_white) 168 | 169 | c1 = Vector(sPos[1], ePos[2], ePos[3]) 170 | render.DrawLine(ePos, c1, color_white) 171 | c2 = Vector(ePos[1], sPos[2], ePos[3]) 172 | render.DrawLine(ePos, c2, color_white) 173 | c3 = Vector(sPos[1], sPos[2], ePos[3]) 174 | render.DrawLine(c3, c1, color_white) 175 | c4 = Vector(sPos[1], sPos[2], ePos[3]) 176 | render.DrawLine(c3, c2, color_white) 177 | 178 | local c5, c6, c7, c8 179 | c5 = Vector(sPos[1], ePos[2], sPos[3]) 180 | render.DrawLine(c1, c5, color_white) 181 | c6 = Vector(ePos[1], sPos[2], sPos[3]) 182 | render.DrawLine(c2, c6, color_white) 183 | c7 = Vector(sPos[1], sPos[2], sPos[3]) 184 | render.DrawLine(c3, c7, color_white) 185 | c4 = Vector(ePos[1], ePos[2], ePos[3]) 186 | c8 = Vector(ePos[1], ePos[2], sPos[3]) 187 | render.DrawLine(c4, c8, color_white) 188 | end 189 | end 190 | end) 191 | end -------------------------------------------------------------------------------- /plugins/area/languages/sh_english.lua: -------------------------------------------------------------------------------- 1 | LANGUAGE = { 2 | areaPlugin = "Plugin: Area Display", 3 | areaFontSize = "Area Display Font Size", 4 | areaDispSpeed = "Area Display Speed", 5 | areaCommand = "Run the command again at a different position to set a maximum point.", 6 | areaRemoved = "You removed '%s' Area.", 7 | areaAdded = "You added '%s' Area.", 8 | areaChanged = "You changed area's name to '%s' from '%s'.", 9 | areaModified = "You changed '%s' Area's Property.", 10 | areaManager = "Area Manager", 11 | areaManagerTip = "Click or Right Click to interact with area.", 12 | enterAreaName = "Enter Area's New Name.", 13 | moveToArea = "Move to Area", 14 | renameArea = "Rename Area", 15 | deleteArea = "Delete Area", 16 | } -------------------------------------------------------------------------------- /plugins/area/languages/sh_russian: -------------------------------------------------------------------------------- 1 | -- Written by kirukiru (http://steamcommunity.com/profiles/76561198155438309/) 2 | 3 | LANGUAGE = { 4 | areaPlugin = "Плагин: Зонирование", 5 | areaFontSize = "Размер Шрифта Зоны", 6 | areaDispSpeed = "Скорость Отображения Зоны", 7 | areaCommand = "Вызовите команду снова в другом месте чтобы назначить конечную точку.", 8 | areaRemoved = "Вы удалили Зону '%s'.", 9 | areaAdded = "Вы добавили Зону '%s'.", 10 | areaChanged = "Вы изменили название Зоны с '%s' на '%s'.", 11 | areaModified = "Вы изменили свойство Зоны '%s'.", 12 | areaManager = "Управление Зонами", 13 | areaManagerTip = "Кликните чтобы взаимодействовать с Зоной.", 14 | enterAreaName = "Введите новое название Зоны.", 15 | moveToArea = "Переместиться к Зоне", 16 | renameArea = "Переименовать Зону", 17 | deleteArea = "Удалить Зону", 18 | } 19 | -------------------------------------------------------------------------------- /plugins/chatbox/derma/cl_markup.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | function PANEL:Init() 3 | self:SetDrawBackground(false) 4 | end 5 | 6 | function PANEL:setMarkup(text, onDrawText) 7 | local object = nut.markup.parse(text, self:GetWide()) 8 | object.onDrawText = onDrawText 9 | 10 | self:SetTall(object:getHeight()) 11 | self.Paint = function(this, w, h) 12 | object:draw(0, 0) 13 | end 14 | end 15 | vgui.Register("nutMarkupPanel", PANEL, "DPanel") -------------------------------------------------------------------------------- /plugins/chatbox/sh_plugin.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Chatbox" 2 | PLUGIN.author = "Chessnut" 3 | PLUGIN.desc = "Adds a chatbox that replaces the default one." 4 | 5 | if (CLIENT) then 6 | NUT_CVAR_CHATFILTER = CreateClientConVar("nut_chatfilter", "", true, false) 7 | 8 | function PLUGIN:createChat() 9 | if (IsValid(self.panel)) then 10 | return 11 | end 12 | 13 | self.panel = vgui.Create("nutChatBox") 14 | end 15 | 16 | function PLUGIN:InitPostEntity() 17 | self:createChat() 18 | end 19 | 20 | function PLUGIN:PlayerBindPress(client, bind, pressed) 21 | bind = bind:lower() 22 | 23 | if (bind:find("messagemode") and pressed) then 24 | if (!self.panel.active) then 25 | self.panel:setActive(true) 26 | end 27 | return true 28 | end 29 | end 30 | 31 | function PLUGIN:HUDShouldDraw(element) 32 | if (element == "CHudChat") then 33 | return false 34 | end 35 | end 36 | 37 | chat.nutAddText = chat.nutAddText or chat.AddText 38 | 39 | local PLUGIN = PLUGIN 40 | 41 | function chat.AddText(...) 42 | local show = true 43 | 44 | if (IsValid(PLUGIN.panel)) then 45 | show = PLUGIN.panel:addText(...) 46 | end 47 | 48 | if (show) then 49 | chat.nutAddText(...) 50 | chat.PlaySound() 51 | end 52 | end 53 | 54 | function PLUGIN:ChatText(index, name, text, messageType) 55 | if (messageType == "none" and IsValid(self.panel)) then 56 | self.panel:addText(text) 57 | chat.PlaySound() 58 | end 59 | end 60 | 61 | concommand.Add("fixchatplz", function() 62 | if (IsValid(PLUGIN.panel)) then 63 | PLUGIN.panel:Remove() 64 | PLUGIN:createChat() 65 | end 66 | end) 67 | else 68 | netstream.Hook("msg", function(client, text) 69 | if ((client.nutNextChat or 0) < CurTime() and text:find("%S")) then 70 | hook.Run("PlayerSay", client, text) 71 | client.nutNextChat = CurTime() + math.max(#text / 250, 0.4) 72 | end 73 | end) 74 | end 75 | -------------------------------------------------------------------------------- /plugins/crosshair.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Crosshair" 2 | PLUGIN.author = "Black Tea" 3 | PLUGIN.desc = "A Crosshair." 4 | 5 | if (CLIENT) then 6 | local function drawdot( pos, size, col ) 7 | local color = col[2] 8 | surface.SetDrawColor(color.r, color.g, color.b, color.a) 9 | surface.DrawRect(pos[1] - size/2, pos[2] - size/2, size, size) 10 | 11 | local color = col[1] 12 | surface.SetDrawColor(color.r, color.g, color.b, color.a) 13 | surface.DrawOutlinedRect(pos[1] - size/2, pos[2] - size/2 , size, size) 14 | end 15 | 16 | local w, h, aimVector, punchAngle, ft, screen, scaleFraction, distance, entity 17 | local math_round = math.Round 18 | local curGap = 0 19 | local curAlpha = 0 20 | local maxDistance = 1000 ^ 2 21 | local crossSize = 4 22 | local crossGap = 0 23 | local colors = {color_black} 24 | local filter = {} 25 | 26 | function PLUGIN:PostDrawHUD() 27 | local client = LocalPlayer() 28 | if (!client:getChar() or !client:Alive()) then 29 | return 30 | end 31 | 32 | local entity = Entity(client:getLocalVar("ragdoll", 0)) 33 | if (entity:IsValid()) then 34 | return 35 | end 36 | 37 | local wep = client:GetActiveWeapon() 38 | if (wep and wep:IsValid() and wep.HUDPaint) then 39 | return 40 | end 41 | 42 | if (hook.Run("ShouldDrawCrosshair") == false or g_ContextMenu:IsVisible() or nut.gui.char:IsVisible()) then 43 | return 44 | end 45 | 46 | aimVector = client:EyeAngles() 47 | punchAngle = client:GetPunchAngle() 48 | w, h = ScrW(), ScrH() 49 | ft = FrameTime() 50 | filter = {client} 51 | 52 | local vehicle = client:GetVehicle() 53 | if (vehicle and IsValid(vehicle)) then 54 | aimVector = aimVector + vehicle:GetAngles() 55 | table.insert(filter, vehicle) 56 | end 57 | 58 | local data = {} 59 | data.start = client:GetShootPos() 60 | data.endpos = data.start + (aimVector + punchAngle):Forward()*65535 61 | data.filter = filter 62 | local trace = util.TraceLine(data) 63 | 64 | entity = trace.Entity 65 | distance = trace.StartPos:DistToSqr(trace.HitPos) 66 | scaleFraction = 1 - math.Clamp(distance / maxDistance, 0, .5) 67 | screen = trace.HitPos:ToScreen() 68 | crossSize = 4 69 | crossGap = 25 * (scaleFraction - (client:isWepRaised() and 0 or .1)) 70 | 71 | if (IsValid(entity) and entity:GetClass() == "nut_item" and 72 | entity:GetPos():DistToSqr(data.start) <= 16384) then 73 | crossGap = 0 74 | crossSize = 5 75 | end 76 | 77 | curGap = Lerp(ft * 2, curGap, crossGap) 78 | curAlpha = Lerp(ft * 2, curAlpha, (!client:isWepRaised() and 255 or 150)) 79 | curAlpha = hook.Run("GetCrosshairAlpha", curAlpha) or curAlpha 80 | colors[2] = Color(255, curAlpha, curAlpha, curAlpha) 81 | 82 | drawdot( {math_round(screen.x), math_round(screen.y)}, crossSize, colors) 83 | drawdot( {math_round(screen.x + curGap), math_round(screen.y)}, crossSize, colors) 84 | drawdot( {math_round(screen.x - curGap), math_round(screen.y)}, crossSize, colors) 85 | drawdot( {math_round(screen.x), math_round(screen.y + curGap * .8)}, crossSize, colors) 86 | drawdot( {math_round(screen.x), math_round(screen.y - curGap * .8)}, crossSize, colors) 87 | end 88 | end -------------------------------------------------------------------------------- /plugins/doors/cl_plugin.lua: -------------------------------------------------------------------------------- 1 | ACCESS_LABELS = {} 2 | ACCESS_LABELS[DOOR_OWNER] = "owner" 3 | ACCESS_LABELS[DOOR_TENANT] = "tenant" 4 | ACCESS_LABELS[DOOR_GUEST] = "guest" 5 | ACCESS_LABELS[DOOR_NONE] = "none" 6 | 7 | function PLUGIN:ShouldDrawEntityInfo(entity) 8 | if (entity.isDoor(entity) and !entity.getNetVar(entity, "disabled")) then 9 | return true 10 | end 11 | end 12 | 13 | local toScreen = FindMetaTable("Vector").ToScreen 14 | local colorAlpha = ColorAlpha 15 | local drawText = nut.util.drawText 16 | local configGet = nut.config.get 17 | local teamGetColor = team.GetColor 18 | 19 | function PLUGIN:DrawEntityInfo(entity, alpha) 20 | if (entity.isDoor(entity) and !entity:getNetVar("hidden") and hook.Run("CanDrawDoorInfo") != false) then 21 | local position = toScreen(entity.LocalToWorld(entity, entity.OBBCenter(entity))) 22 | local x, y = position.x, position.y 23 | local owner = entity.GetDTEntity(entity, 0) 24 | local name = entity.getNetVar(entity, "title", entity.getNetVar(entity, "name", IsValid(owner) and L"dTitleOwned" or L"dTitle")) 25 | local faction = entity.getNetVar(entity, "faction") 26 | local class = entity.getNetVar(entity, "class") 27 | local color 28 | 29 | if (faction) then 30 | color = teamGetColor(faction) 31 | else 32 | color = configGet("color") 33 | end 34 | 35 | local classData 36 | if (class) then 37 | classData = nut.class.list[class] 38 | 39 | if (classData) then 40 | color = classData.color 41 | else 42 | color = configGet("color") 43 | end 44 | else 45 | color = configGet("color") 46 | end 47 | 48 | drawText(name, x, y, colorAlpha(color, alpha), 1, 1) 49 | 50 | if (IsValid(owner)) then 51 | drawText(L("dOwnedBy", owner.Name(owner)), x, y + 16, colorAlpha(color_white, alpha), 1, 1) 52 | elseif (faction) then 53 | local info = nut.faction.indices[faction] 54 | 55 | if (info) then 56 | drawText(L("dOwnedBy", L2(info.name) or info.name), x, y + 16, colorAlpha(color_white, alpha), 1, 1) 57 | end 58 | elseif (class) then 59 | if (classData) then 60 | drawText(L("dOwnedBy", L2(classData.name) or classData.name), x, y + 16, colorAlpha(color_white, alpha), 1, 1) 61 | end 62 | else 63 | drawText(entity.getNetVar(entity, "noSell") and L"dIsNotOwnable" or L"dIsOwnable", x, y + 16, colorAlpha(color_white, alpha), 1, 1) 64 | end 65 | end 66 | end 67 | 68 | netstream.Hook("doorMenu", function(entity, access, door2) 69 | if (IsValid(nut.gui.door)) then 70 | return nut.gui.door:Remove() 71 | end 72 | 73 | if (IsValid(entity)) then 74 | nut.gui.door = vgui.Create("nutDoorMenu") 75 | nut.gui.door:setDoor(entity, access, door2) 76 | end 77 | end) 78 | 79 | netstream.Hook("doorPerm", function(door, client, access) 80 | local panel = door.nutPanel 81 | 82 | if (IsValid(panel) and IsValid(client)) then 83 | panel.access[client] = access 84 | 85 | for k, v in ipairs(panel.access:GetLines()) do 86 | if (v.player == client) then 87 | v:SetColumnText(2, L(ACCESS_LABELS[access or 0])) 88 | 89 | return 90 | end 91 | end 92 | end 93 | end) -------------------------------------------------------------------------------- /plugins/doors/derma/cl_door.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | function PANEL:Init() 3 | self:SetSize(280, 240) 4 | self:SetTitle(L"doorSettings") 5 | self:Center() 6 | self:MakePopup() 7 | 8 | self.access = self:Add("DListView") 9 | self.access:Dock(FILL) 10 | self.access:AddColumn(L"name").Header:SetTextColor(Color(25, 25, 25)) 11 | self.access:AddColumn(L"access").Header:SetTextColor(Color(25, 25, 25)) 12 | self.access.OnClickLine = function(this, line, selected) 13 | if (IsValid(line.player)) then 14 | local menu = DermaMenu() 15 | menu:AddOption(L"tenant", function() 16 | if (self.accessData and self.accessData[line.player] != DOOR_TENANT) then 17 | netstream.Start("doorPerm", self.door, line.player, DOOR_TENANT) 18 | end 19 | end):SetImage("icon16/user_add.png") 20 | menu:AddOption(L"guest", function() 21 | if (self.accessData and self.accessData[line.player] != DOOR_GUEST) then 22 | netstream.Start("doorPerm", self.door, line.player, DOOR_GUEST) 23 | end 24 | end):SetImage("icon16/user_green.png") 25 | menu:AddOption(L"none", function() 26 | if (self.accessData and self.accessData[line.player] != DOOR_NONE) then 27 | netstream.Start("doorPerm", self.door, line.player, DOOR_NONE) 28 | end 29 | end):SetImage("icon16/user_red.png") 30 | menu:Open() 31 | end 32 | end 33 | end 34 | 35 | function PANEL:setDoor(door, access, door2) 36 | door.nutPanel = self 37 | 38 | self.accessData = access 39 | self.door = door 40 | 41 | for k, v in ipairs(player.GetAll()) do 42 | if (v != LocalPlayer() and v:getChar()) then 43 | self.access:AddLine(v:Name(), L(ACCESS_LABELS[access[v] or 0])).player = v 44 | end 45 | end 46 | 47 | if (self:checkAccess(DOOR_OWNER)) then 48 | self.sell = self:Add("DButton") 49 | self.sell:Dock(BOTTOM) 50 | self.sell:SetText(L"sell") 51 | self.sell:SetTextColor(color_white) 52 | self.sell:DockMargin(0, 5, 0, 0) 53 | self.sell.DoClick = function(this) 54 | self:Remove() 55 | nut.command.send("doorsell") 56 | end 57 | end 58 | 59 | if (self:checkAccess(DOOR_TENANT)) then 60 | self.name = self:Add("DTextEntry") 61 | self.name:Dock(TOP) 62 | self.name:DockMargin(0, 0, 0, 5) 63 | self.name.Think = function(this) 64 | if (!this:IsEditing()) then 65 | local entity = IsValid(door2) and door2 or door 66 | 67 | self.name:SetText(entity:getNetVar("title", L"dTitleOwned")) 68 | end 69 | end 70 | self.name.OnEnter = function(this) 71 | nut.command.send("doorsettitle", this:GetText()) 72 | end 73 | end 74 | end 75 | 76 | function PANEL:checkAccess(access) 77 | access = access or DOOR_GUEST 78 | 79 | if ((self.accessData[LocalPlayer()] or 0) >= access) then 80 | return true 81 | end 82 | 83 | return false 84 | end 85 | 86 | function PANEL:Think() 87 | if (self.accessData and !IsValid(self.door) and self:checkAccess()) then 88 | self:Remove() 89 | end 90 | end 91 | vgui.Register("nutDoorMenu", PANEL, "DFrame") -------------------------------------------------------------------------------- /plugins/doors/sh_plugin.lua: -------------------------------------------------------------------------------- 1 | if (engine.ActiveGamemode() == "dayz") then 2 | return 3 | end 4 | 5 | PLUGIN.name = "Doors" 6 | PLUGIN.author = "Chessnut" 7 | PLUGIN.desc = "A simple door system." 8 | 9 | DOOR_OWNER = 3 10 | DOOR_TENANT = 2 11 | DOOR_GUEST = 1 12 | DOOR_NONE = 0 13 | 14 | nut.util.include("sv_plugin.lua") 15 | nut.util.include("cl_plugin.lua") 16 | nut.util.include("sh_commands.lua") 17 | 18 | do 19 | local entityMeta = FindMetaTable("Entity") 20 | 21 | function entityMeta:checkDoorAccess(client, access) 22 | if (!self:isDoor()) then 23 | return false 24 | end 25 | 26 | access = access or DOOR_GUEST 27 | 28 | local parent = self.nutParent 29 | 30 | if (IsValid(parent)) then 31 | return parent:checkDoorAccess(client, access) 32 | end 33 | 34 | if (hook.Run("CanPlayerAccessDoor", client, self, access)) then 35 | return true 36 | end 37 | 38 | if (self.nutAccess and (self.nutAccess[client] or 0) >= access) then 39 | return true 40 | end 41 | 42 | return false 43 | end 44 | 45 | if (SERVER) then 46 | function entityMeta:removeDoorAccessData() 47 | -- Don't ask why. This happened with 60 player servers. 48 | if (IsValid(self)) then 49 | for k, v in pairs(self.nutAccess or {}) do 50 | netstream.Start(k, "doorMenu") 51 | end 52 | 53 | self.nutAccess = {} 54 | self:SetDTEntity(0, nil) 55 | end 56 | end 57 | end 58 | end 59 | 60 | -- Configurations for door prices. 61 | nut.config.add("doorCost", 10, "The price to purchase a door.", nil, { 62 | data = {min = 0, max = 500}, 63 | category = "dConfigName" 64 | }) 65 | nut.config.add("doorSellRatio", 0.5, "How much of the door price is returned when selling a door.", nil, { 66 | form = "Float", 67 | data = {min = 0, max = 1.0}, 68 | category = "dConfigName" 69 | }) 70 | nut.config.add("doorLockTime", 1, "How long it takes to (un)lock a door.", nil, { 71 | form = "Float", 72 | data = {min = 0, max = 10.0}, 73 | category = "dConfigName" 74 | }) -------------------------------------------------------------------------------- /plugins/logging.lua: -------------------------------------------------------------------------------- 1 | local PLUGIN = PLUGIN 2 | PLUGIN.name = "Logging" 3 | PLUGIN.author = "Black Tea" 4 | PLUGIN.desc = "You can modfiy the logging text/lists on this plugin." 5 | 6 | if (SERVER) then 7 | local L, type, IsValid = Format, type, IsValid 8 | 9 | nut.log.addType("chat", function(client, ...) 10 | local arg = {...} 11 | return (L("[%s] %s: %s", arg[1], client:Name(), arg[2])) 12 | end) 13 | nut.log.addType("command", function(client, ...) 14 | local arg = {...} 15 | return (L("%s used command '%s'", client:Name(), arg[1])) 16 | end) 17 | nut.log.addType("charLoad", function(client, ...) 18 | local arg = {...} 19 | return (L("%s loaded the character #%s (%s)", client:steamName(), arg[1], arg[2])) 20 | end) 21 | nut.log.addType("charDelete", function(client, ...) 22 | local arg = {...} 23 | return (L("%s(%s) deleted character (%s)", client:steamName(), client:SteamID(), arg[1])) 24 | end) 25 | nut.log.addType("itemUse", function(client, ...) 26 | local arg = {...} 27 | local item = arg[2] 28 | return (L("%s tried '%s' to item '%s'(#%s)", client:Name(), arg[1], item.name, item.id)) 29 | end) 30 | nut.log.addType("shipment", function(client, ...) 31 | local arg = {...} 32 | return (L("%s took '%s' from the shipment", client:Name(), arg[1])) 33 | end) 34 | nut.log.addType("shipmentO", function(client, ...) 35 | local arg = {...} 36 | return (L("%s ordered a shipment", client:Name())) 37 | end) 38 | nut.log.addType("buy", function(client, ...) 39 | local arg = {...} 40 | return (L("%s purchased '%s' from the NPC", client:Name(), arg[1])) 41 | end) 42 | nut.log.addType("buydoor", function(client, ...) 43 | local arg = {...} 44 | return (L("%s purchased the door", client:Name())) 45 | end) 46 | 47 | function PLUGIN:CharacterLoaded(id) 48 | local character = nut.char.loaded[id] 49 | local client = character:getPlayer() 50 | nut.log.add(client, "charLoad", id, character:getName()) 51 | end 52 | 53 | function PLUGIN:OnCharDelete(client, id) 54 | nut.log.add(client, "charDelete", id) 55 | end 56 | 57 | function PLUGIN:OnTakeShipmentItem(client, itemClass, amount) 58 | local itemTable = nut.item.list[itemClass] 59 | nut.log.add(client, "shipment", itemTable.name) 60 | end 61 | 62 | function PLUGIN:OnCreateShipment(client, shipmentEntity) 63 | nut.log.add(client, "shipmentO") 64 | end 65 | 66 | function PLUGIN:OnCharTradeVendor(client, vendor, x, y, invID, price, isSell) 67 | end 68 | 69 | function PLUGIN:OnPlayerInteractItem(client, action, item) 70 | if (type(item) == "Entity") then 71 | if (IsValid(item)) then 72 | local itemID = item.nutItemID 73 | item = nut.item.instances[itemID] 74 | else 75 | return 76 | end 77 | elseif (type(item) == "number") then 78 | item = nut.item.instances[item] 79 | end 80 | 81 | if (!item) then 82 | return 83 | end 84 | 85 | nut.log.add(client, "itemUse", action, item) 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /plugins/observer.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Observer" 2 | PLUGIN.author = "Chessnut" 3 | PLUGIN.desc = "Adds on to the no-clip mode to prevent instrusion." 4 | 5 | if (CLIENT) then 6 | -- Create a setting to see if the player will teleport back after noclipping. 7 | NUT_CVAR_OBSTPBACK = CreateClientConVar("nut_obstpback", 0, true, true) 8 | NUT_CVAR_ADMINESP = CreateClientConVar("nut_obsesp", 1, true, true) 9 | NUT_CVAR_ADMINESPAVANCED = CreateClientConVar("nut_obsespadvanced", 1, true, true) 10 | 11 | local client, sx, sy, scrPos, marginx, marginy, x, y, teamColor, distance, factor, size, alpha 12 | local dimDistance = 1024 13 | function PLUGIN:HUDPaint() 14 | client = LocalPlayer() 15 | 16 | if (client:IsAdmin() and client:GetMoveType() == MOVETYPE_NOCLIP and !client:InVehicle() and NUT_CVAR_ADMINESP:GetBool()) then 17 | sx, sy = surface.ScreenWidth(), surface.ScreenHeight() 18 | 19 | for k, v in ipairs(player.GetAll()) do 20 | if (v == client) then continue end 21 | 22 | scrPos = v:GetPos():ToScreen() 23 | marginx, marginy = sy*.1, sy*.1 24 | x, y = math.Clamp(scrPos.x, marginx, sx - marginx), math.Clamp(scrPos.y, marginy, sy - marginy) 25 | teamColor = team.GetColor(v:Team()) 26 | distance = client:GetPos():Distance(v:GetPos()) 27 | factor = 1 - math.Clamp(distance/dimDistance, 0, 1) 28 | size = math.max(10, 32*factor) 29 | alpha = math.Clamp(255*factor, 80, 255) 30 | 31 | surface.SetDrawColor(teamColor.r, teamColor.g, teamColor.b, alpha) 32 | if (NUT_CVAR_ADMINESPAVANCED:GetBool()) then 33 | surface.DrawLine(sx * 0.5, sy * 0.5, x, y) 34 | surface.DrawRect(x - size/2, y - size/2, size, size) 35 | end 36 | 37 | nut.util.drawText(v:Name(), x, y - size, ColorAlpha(teamColor, alpha), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER, nil, alpha) 38 | end 39 | end 40 | end 41 | 42 | function PLUGIN:SetupQuickMenu(menu) 43 | if (LocalPlayer():IsAdmin()) then 44 | local buttonESP = menu:addCheck(L"toggleESP", function(panel, state) 45 | if (state) then 46 | RunConsoleCommand("nut_obsesp", "1") 47 | else 48 | RunConsoleCommand("nut_obsesp", "0") 49 | end 50 | end, NUT_CVAR_ADMINESP:GetBool()) 51 | 52 | local buttonESPAdvanced = menu:addCheck(L"toggleESPAdvanced", function(panel, state) 53 | if (state) then 54 | RunConsoleCommand("nut_obsespadvanced", "1") 55 | else 56 | RunConsoleCommand("nut_obsespadvanced", "0") 57 | end 58 | end, NUT_CVAR_ADMINESPAVANCED:GetBool()) 59 | 60 | local buttonTP = menu:addCheck(L"toggleObserverTP", function(panel, state) 61 | if (state) then 62 | RunConsoleCommand("nut_obstpback", "1") 63 | else 64 | RunConsoleCommand("nut_obstpback", "0") 65 | end 66 | end, NUT_CVAR_OBSTPBACK:GetBool()) 67 | 68 | menu:addSpacer() 69 | end 70 | end 71 | 72 | function PLUGIN:ShouldDrawEntityInfo(entity) 73 | if (IsValid(entity)) then 74 | if (entity:IsPlayer() or IsValid(entity:getNetVar("player"))) then 75 | if (entity.IsAdmin and entity:IsAdmin() and entity:GetMoveType() == MOVETYPE_NOCLIP) then 76 | return false 77 | end 78 | end 79 | end 80 | end 81 | else 82 | function PLUGIN:PlayerNoClip(client, state) 83 | -- Observer mode is reserved for administrators. 84 | if (client:IsAdmin()) then 85 | -- Check if they are entering noclip. 86 | if (state) then 87 | -- Store their old position and looking at angle. 88 | client.nutObsData = {client:GetPos(), client:EyeAngles()} 89 | -- Hide them so they are not visible. 90 | client:SetNoDraw(true) 91 | client:SetNotSolid(true) 92 | client:DrawWorldModel(false) 93 | client:DrawShadow(false) 94 | -- Don't allow the player to get hurt. 95 | client:GodEnable() 96 | -- Don't allow npcs to target the player. 97 | client:SetNoTarget(true) 98 | hook.Run("OnPlayerObserve", client, state) 99 | else 100 | if (client.nutObsData) then 101 | -- Move they player back if they want. 102 | if (client:GetInfoNum("nut_obstpback", 0) > 0) then 103 | local position, angles = client.nutObsData[1], client.nutObsData[2] 104 | 105 | -- Do it the next frame since the player can not be moved right now. 106 | timer.Simple(0, function() 107 | client:SetPos(position) 108 | client:SetEyeAngles(angles) 109 | -- Make sure they stay still when they get back. 110 | client:SetVelocity(Vector(0, 0, 0)) 111 | end) 112 | end 113 | 114 | -- Delete the old data. 115 | client.nutObsData = nil 116 | end 117 | 118 | -- Make the player visible again. 119 | client:SetNoDraw(false) 120 | client:SetNotSolid(false) 121 | client:DrawWorldModel(true) 122 | client:DrawShadow(true) 123 | -- Let the player take damage again. 124 | client:GodDisable() 125 | -- Let npcs target the player again. 126 | client:SetNoTarget(false) 127 | hook.Run("OnPlayerObserve", client, state) 128 | end 129 | end 130 | end 131 | end 132 | -------------------------------------------------------------------------------- /plugins/permakill.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Permakill" 2 | PLUGIN.author = "Thadah Denyse" 3 | PLUGIN.desc = "Adds permanent death in the server options." 4 | 5 | nut.config.add("pkActive", false, "Whether or not permakill is activated on the server.", nil, { 6 | category = "Permakill" 7 | }) 8 | 9 | nut.config.add("pkWorld", false, "Whether or not world and self damage produce permanent death.", nil, { 10 | category = "Permakill" 11 | }) 12 | 13 | function PLUGIN:PlayerDeath(client, inflictor, attacker) 14 | local character = client:getChar() 15 | 16 | if (nut.config.get("pkActive")) then 17 | if !(nut.config.get("pkWorld") and (client == attacker or inflictor:IsWorld())) then 18 | return 19 | end 20 | character:setData("permakilled", true) 21 | end 22 | end 23 | 24 | function PLUGIN:PlayerSpawn(client) 25 | local character = client:getChar() 26 | if (nut.config.get("pkActive") and character and character:getData("permakilled")) then 27 | character:ban() 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /plugins/propprotect.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Basic Prop Protection" 2 | PLUGIN.author = "Chessnut" 3 | PLUGIN.desc = "Adds a simple prop protection system." 4 | 5 | local PROP_BLACKLIST = { 6 | ["models/props_combine/combinetrain02b.mdl"] = true, 7 | ["models/props_combine/combinetrain02a.mdl"] = true, 8 | ["models/props_combine/combinetrain01.mdl"] = true, 9 | ["models/cranes/crane_frame.mdl"] = true, 10 | ["models/props_wasteland/cargo_container01.mdl"] = true, 11 | ["models/props_junk/trashdumpster02.mdl"] = true, 12 | ["models/props_c17/oildrum001_explosive.mdl"] = true, 13 | ["models/props_canal/canal_bridge02.mdl"] = true, 14 | ["models/props_canal/canal_bridge01.mdl"] = true, 15 | ["models/props_canal/canal_bridge03a.mdl"] = true, 16 | ["models/props_canal/canal_bridge03b.mdl"] = true, 17 | ["models/props_wasteland/cargo_container01.mdl"] = true, 18 | ["models/props_wasteland/cargo_container01c.mdl"] = true, 19 | ["models/props_wasteland/cargo_container01b.mdl"] = true, 20 | ["models/props_combine/combine_mine01.mdl"] = true, 21 | ["models/props_junk/glassjug01.mdl"] = true, 22 | ["models/props_c17/paper01.mdl"] = true, 23 | ["models/props_junk/garbage_takeoutcarton001a.mdl"] = true, 24 | ["models/props_c17/trappropeller_engine.mdl"] = true, 25 | ["models/props/cs_office/microwave.mdl"] = true, 26 | ["models/items/item_item_crate.mdl"] = true, 27 | ["models/props_junk/gascan001a.mdl"] = true, 28 | ["models/props_c17/consolebox01a.mdl"] = true, 29 | ["models/props_buildings/building_002a.mdl"] = true, 30 | ["models/props_phx/mk-82.mdl"] = true, 31 | ["models/props_phx/cannonball.mdl"] = true, 32 | ["models/props_phx/ball.mdl"] = true, 33 | ["models/props_phx/amraam.mdl"] = true, 34 | ["models/props_phx/misc/flakshell_big.mdl"] = true, 35 | ["models/props_phx/ww2bomb.mdl"] = true, 36 | ["models/props_phx/torpedo.mdl"] = true, 37 | ["models/props/de_train/biohazardtank.mdl"] = true, 38 | ["models/props_buildings/project_building01.mdl"] = true, 39 | ["models/props_combine/prison01c.mdl"] = true, 40 | ["models/props/cs_militia/silo_01.mdl"] = true, 41 | ["models/props_phx/huge/evildisc_corp.mdl"] = true, 42 | ["models/props_phx/misc/potato_launcher_explosive.mdl"] = true, 43 | ["models/props_combine/combine_citadel001.mdl"] = true, 44 | ["models/props_phx/oildrum001_explosive.mdl"] = true 45 | } 46 | 47 | if (SERVER) then 48 | local function getLogName(entity) 49 | local class = entity:GetClass():lower() 50 | 51 | if (class:find("prop")) then 52 | local propType = class:sub(6) 53 | 54 | if (propType == "physics") then 55 | propType = "prop" 56 | end 57 | 58 | class = propType.." ("..entity:GetModel()..")" 59 | end 60 | 61 | return class 62 | end 63 | 64 | function PLUGIN:PlayerSpawnObject(client, model, skin) 65 | if ((client.nutNextSpawn or 0) < CurTime()) then 66 | client.nutNextSpawn = CurTime() + 0.75 67 | else 68 | if(client.AdvDupe2 and client.AdvDupe2.Pasting) then 69 | return true 70 | end 71 | 72 | return false 73 | end 74 | 75 | if (!client:IsAdmin() and PROP_BLACKLIST[model:lower()]) then 76 | return false 77 | end 78 | end 79 | 80 | function PLUGIN:PhysgunPickup(client, entity) 81 | if (entity:GetCreator() == client) then 82 | return true 83 | end 84 | end 85 | 86 | function PLUGIN:CanProperty(client, property, entity) 87 | if (entity:GetCreator() == client and (property == "remover" or property == "collision")) then 88 | --nut.log.add(client, property, getLogName(entity)) 89 | 90 | return true 91 | end 92 | end 93 | 94 | function PLUGIN:CanTool(client, trace, tool) 95 | local entity = trace.Entity 96 | 97 | if (IsValid(entity) and entity:GetCreator() == client) then 98 | return true 99 | end 100 | end 101 | 102 | function PLUGIN:PlayerSpawnedEntity(client, entity) 103 | entity:SetCreator(client) 104 | --nut.log.add(client, getLogName(entity)) 105 | end 106 | 107 | function PLUGIN:PlayerSpawnedProp(client, model, entity) 108 | hook.Run("PlayerSpawnedEntity", client, entity) 109 | end 110 | 111 | PLUGIN.PlayerSpawnedEffect = PLUGIN.PlayerSpawnedProp 112 | PLUGIN.PlayerSpawnedRagdoll = PLUGIN.PlayerSpawnedProp 113 | 114 | function PLUGIN:PlayerSpawnedNPC(client, entity) 115 | hook.Run("PlayerSpawnedEntity", client, entity) 116 | end 117 | 118 | PLUGIN.PlayerSpawnedSENT = PLUGIN.PlayerSpawnedNPC 119 | PLUGIN.PlayerSpawnedVehicle = PLUGIN.PlayerSpawnedNPC 120 | end 121 | -------------------------------------------------------------------------------- /plugins/recognition.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Recognition" 2 | PLUGIN.author = "Chessnut" 3 | PLUGIN.desc = "Adds the ability to recognize people." 4 | 5 | do 6 | local character = nut.meta.character 7 | 8 | if (SERVER) then 9 | function character:recognize(id) 10 | if (type(id) != "number" and id.getID) then 11 | id = id:getID() 12 | end 13 | 14 | local recognized = self:getData("rgn", "") 15 | 16 | if (recognized != "" and recognized:find(","..id..",")) then 17 | return false; 18 | end; 19 | 20 | self:setData("rgn", recognized..","..id..",") 21 | 22 | return true 23 | end 24 | end 25 | 26 | function character:doesRecognize(id) 27 | if (type(id) != "number" and id.getID) then 28 | id = id:getID() 29 | end 30 | 31 | return hook.Run("IsCharRecognised", self, id) != false 32 | end 33 | 34 | function PLUGIN:IsCharRecognised(char, id) 35 | local other = nut.char.loaded[id] 36 | 37 | if (other) then 38 | local faction = nut.faction.indices[other:getFaction()] 39 | 40 | if (faction and faction.isGloballyRecognized) then 41 | return 42 | end 43 | end 44 | 45 | local recognized = char:getData("rgn", "") 46 | 47 | if (recognized == "") then 48 | return false 49 | end 50 | 51 | if (!recognized:find(","..id..",")) then 52 | return false 53 | end 54 | end 55 | end 56 | 57 | if (CLIENT) then 58 | CHAT_RECOGNIZED = CHAT_RECOGNIZED or {} 59 | CHAT_RECOGNIZED["ic"] = true 60 | CHAT_RECOGNIZED["y"] = true 61 | CHAT_RECOGNIZED["w"] = true 62 | CHAT_RECOGNIZED["me"] = true 63 | 64 | function PLUGIN:IsRecognizedChatType(chatType) 65 | return CHAT_RECOGNIZED[chatType] 66 | end 67 | 68 | function PLUGIN:GetDisplayedDescription(client) 69 | if (client:getChar() and client != LocalPlayer() and LocalPlayer():getChar() and !LocalPlayer():getChar():doesRecognize(client:getChar()) and !hook.Run("IsPlayerRecognized", client)) then 70 | return L"noRecog" 71 | end 72 | end 73 | 74 | function PLUGIN:ShouldAllowScoreboardOverride(client) 75 | if (nut.config.get("sbRecog")) then 76 | return true 77 | end 78 | end 79 | 80 | function PLUGIN:GetDisplayedName(client, chatType) 81 | if (client != LocalPlayer()) then 82 | local character = client:getChar() 83 | local ourCharacter = LocalPlayer():getChar() 84 | 85 | if (ourCharacter and character and !ourCharacter:doesRecognize(character) and !hook.Run("IsPlayerRecognized", client)) then 86 | if (chatType and hook.Run("IsRecognizedChatType", chatType)) then 87 | local description = character:getDesc() 88 | 89 | if (#description > 40) then 90 | description = description:utf8sub(1, 37).."..." 91 | end 92 | 93 | return "["..description.."]" 94 | elseif (!chatType) then 95 | return L"unknown" 96 | end 97 | end 98 | end 99 | end 100 | 101 | netstream.Hook("rgnMenu", function() 102 | local menu = DermaMenu() 103 | menu:AddOption(L"rgnLookingAt", function() 104 | netstream.Start("rgn", 1) 105 | end) 106 | menu:AddOption(L"rgnWhisper", function() 107 | netstream.Start("rgn", 2) 108 | end) 109 | menu:AddOption(L"rgnTalk", function() 110 | netstream.Start("rgn", 3) 111 | end) 112 | menu:AddOption(L"rgnYell", function() 113 | netstream.Start("rgn", 4) 114 | end) 115 | menu:Open() 116 | menu:MakePopup() 117 | menu:Center() 118 | end) 119 | 120 | netstream.Hook("rgnDone", function() 121 | hook.Run("OnCharRecognized", client, id) 122 | end) 123 | 124 | function PLUGIN:OnCharRecognized(client, recogCharID) 125 | surface.PlaySound("buttons/button17.wav") 126 | end 127 | else 128 | function PLUGIN:ShowSpare1(client) 129 | if (client:getChar()) then 130 | netstream.Start(client, "rgnMenu") 131 | end 132 | end 133 | 134 | netstream.Hook("rgn", function(client, level) 135 | local targets = {} 136 | 137 | if (level < 2) then 138 | local entity = client:GetEyeTraceNoCursor().Entity 139 | 140 | if (IsValid(entity) and entity:IsPlayer() and entity:getChar() and nut.chat.classes.ic.onCanHear(client, entity)) then 141 | targets[1] = entity 142 | end 143 | else 144 | local class = "w" 145 | 146 | if (level == 3) then 147 | class = "ic" 148 | elseif (level == 4) then 149 | class = "y" 150 | end 151 | 152 | class = nut.chat.classes[class] 153 | 154 | for k, v in ipairs(player.GetAll()) do 155 | if (client != v and v:getChar() and class.onCanHear(client, v)) then 156 | targets[#targets + 1] = v 157 | end 158 | end 159 | end 160 | 161 | if (#targets > 0) then 162 | local id = client:getChar():getID() 163 | local i = 0 164 | 165 | for k, v in ipairs(targets) do 166 | if (v:getChar():recognize(id)) then 167 | i = i + 1 168 | end 169 | end 170 | 171 | if (i > 0) then 172 | netstream.Start(client, "rgnDone") 173 | hook.Run("OnCharRecognized", client, id) 174 | end 175 | end 176 | end) 177 | end 178 | -------------------------------------------------------------------------------- /plugins/saveitems.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Save Items" 2 | PLUGIN.author = "Chessnut" 3 | PLUGIN.desc = "Saves items that were dropped." 4 | 5 | /* 6 | function PLUGIN:OnSavedItemLoaded(items) 7 | for k, v in ipairs(items) do 8 | -- do something 9 | end 10 | end 11 | 12 | function PLUGIN:ShouldDeleteSavedItems() 13 | return true 14 | end 15 | */ 16 | 17 | -- as title says. 18 | 19 | function PLUGIN:LoadData() 20 | local items = self:getData() 21 | 22 | if (items) then 23 | local idRange = {} 24 | local positions = {} 25 | 26 | for k, v in ipairs(items) do 27 | idRange[#idRange + 1] = v[1] 28 | positions[v[1]] = v[2] 29 | end 30 | 31 | if (#idRange > 0) then 32 | local range = "("..table.concat(idRange, ", ")..")" 33 | 34 | if (hook.Run("ShouldDeleteSavedItems") == true) then 35 | -- don't spawn saved item and just delete them. 36 | nut.db.query("DELETE FROM nut_items WHERE _itemID IN " .. range) 37 | print("Server Deleted Server Items (does not includes Logical Items)") 38 | print(range) 39 | else 40 | nut.db.query("SELECT _itemID, _uniqueID, _data FROM nut_items WHERE _itemID IN "..range, function(data) 41 | if (data) then 42 | local loadedItems = {} 43 | 44 | for k, v in ipairs(data) do 45 | local itemID = tonumber(v._itemID) 46 | local data = util.JSONToTable(v._data or "[]") 47 | local uniqueID = v._uniqueID 48 | local itemTable = nut.item.list[uniqueID] 49 | local position = positions[itemID] 50 | 51 | if (itemTable and itemID) then 52 | local position = positions[itemID] 53 | local item = nut.item.new(uniqueID, itemID) 54 | item.data = data or {} 55 | item:spawn(position).nutItemID = itemID 56 | 57 | item.invID = 0 58 | table.insert(loadedItems, item) 59 | end 60 | end 61 | 62 | hook.Run("OnSavedItemLoaded", loadedItems) -- when you have something in the dropped item. 63 | end 64 | end) 65 | end 66 | end 67 | end 68 | end 69 | 70 | function PLUGIN:SaveData() 71 | local items = {} 72 | 73 | for k, v in ipairs(ents.FindByClass("nut_item")) do 74 | if (v.nutItemID and !v.temp) then 75 | items[#items + 1] = {v.nutItemID, v:GetPos()} 76 | end 77 | end 78 | 79 | self:setData(items) 80 | end -------------------------------------------------------------------------------- /plugins/sh_scash_abuse.lua: -------------------------------------------------------------------------------- 1 | /* Due to the amount of servers that have been absolutely braindead in their configuration, allowing assholes like me to write a nice little script to infinitely spawn money, I thought it's high time people used their brains. */ 2 | 3 | PLUGIN.name = "Spawning money Anti-Abuse" 4 | PLUGIN.author = "Rusty" 5 | PLUGIN.desc = "Prevent people from using ye-olde classic money maker." 6 | 7 | function PLUGIN:CanDeleteChar(ply, char) 8 | if char:getMoney() < nut.config.get("defMoney", 0) then 9 | return true 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /plugins/spawns.lua: -------------------------------------------------------------------------------- 1 | local PLUGIN = PLUGIN 2 | 3 | PLUGIN.name = "Spawns" 4 | PLUGIN.desc = "Spawn points for factions and classes." 5 | PLUGIN.author = "Chessnut" 6 | PLUGIN.spawns = PLUGIN.spawns or {} 7 | 8 | function PLUGIN:PostPlayerLoadout(client) 9 | if (self.spawns and table.Count(self.spawns) > 0 and client:getChar()) then 10 | local class = client:getChar():getClass() 11 | local points 12 | local className = "" 13 | 14 | for k, v in ipairs(nut.faction.indices) do 15 | if (k == client:Team()) then 16 | points = self.spawns[v.uniqueID] or {} 17 | 18 | break 19 | end 20 | end 21 | 22 | if (points) then 23 | for k, v in ipairs(nut.class.list) do 24 | if (class == v.index) then 25 | className = v.uniqueID 26 | 27 | break 28 | end 29 | end 30 | 31 | points = points[className] or points[""] 32 | 33 | if (points and table.Count(points) > 0) then 34 | local position = table.Random(points) 35 | 36 | client:SetPos(position) 37 | end 38 | end 39 | end 40 | end 41 | 42 | function PLUGIN:LoadData() 43 | self.spawns = self:getData() or {} 44 | end 45 | 46 | function PLUGIN:SaveSpawns() 47 | self:setData(self.spawns) 48 | end 49 | 50 | nut.command.add("spawnadd", { 51 | adminOnly = true, 52 | syntax = " [string class]", 53 | onRun = function(client, arguments) 54 | local faction 55 | local name = arguments[1] 56 | local class = table.concat(arguments, " ", 2) 57 | local info 58 | local info2 59 | 60 | if (name) then 61 | info = nut.faction.indices[name:lower()] 62 | 63 | if (!info) then 64 | for k, v in ipairs(nut.faction.indices) do 65 | if (nut.util.stringMatches(v.uniqueID, name) or nut.util.stringMatches(L(v.name, client), name)) then 66 | faction = v.uniqueID 67 | info = v 68 | 69 | break 70 | end 71 | end 72 | end 73 | 74 | if (info) then 75 | if (class and class != "") then 76 | local found = false 77 | 78 | for k, v in ipairs(nut.class.list) do 79 | if (v.faction == info.index and (v.uniqueID:lower() == class:lower() or nut.util.stringMatches(L(v.name, client), class))) then 80 | class = v.uniqueID 81 | info2 = v 82 | found = true 83 | 84 | break 85 | end 86 | end 87 | 88 | if (!found) then 89 | return L("invalidClass", client) 90 | end 91 | else 92 | class = "" 93 | end 94 | 95 | PLUGIN.spawns[faction] = PLUGIN.spawns[faction] or {} 96 | PLUGIN.spawns[faction][class] = PLUGIN.spawns[faction][class] or {} 97 | 98 | table.insert(PLUGIN.spawns[faction][class], client:GetPos()) 99 | 100 | PLUGIN:SaveSpawns() 101 | 102 | local name = L(info.name, client) 103 | 104 | if (info2) then 105 | name = name.." ("..L(info2.name, client)..")" 106 | end 107 | 108 | return L("spawnAdded", client, name) 109 | else 110 | return L("invalidFaction", client) 111 | end 112 | else 113 | return L("invalidArg", client, 1) 114 | end 115 | end 116 | }) 117 | 118 | nut.command.add("spawnremove", { 119 | adminOnly = true, 120 | syntax = "[number radius]", 121 | onRun = function(client, arguments) 122 | local position = client:GetPos() 123 | local radius = tonumber(arguments[1]) or 120 124 | local i = 0 125 | 126 | for k, v in pairs(PLUGIN.spawns) do 127 | for k2, v in pairs(v) do 128 | for k3, v3 in pairs(v) do 129 | if (v3:Distance(position) <= radius) then 130 | v[k3] = nil 131 | i = i + 1 132 | end 133 | end 134 | end 135 | end 136 | 137 | if (i > 0) then 138 | PLUGIN:SaveSpawns() 139 | end 140 | 141 | return L("spawnDeleted", client, i) 142 | end 143 | }) -------------------------------------------------------------------------------- /plugins/spawnsaver.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Spawn Saver" 2 | PLUGIN.author = "Chessnut" 3 | PLUGIN.desc = "Saves the position of a character." 4 | 5 | -- Called right before the character has its information save. 6 | function PLUGIN:CharacterPreSave(character) 7 | -- Get the player from the character. 8 | local client = character:getPlayer() 9 | 10 | -- Check to see if we can get the player's position. 11 | if (IsValid(client)) then 12 | -- Store the position in the character's data. 13 | character:setData("pos", {client:GetPos(), client:EyeAngles(), game.GetMap()}) 14 | end 15 | end 16 | 17 | -- Called after the player's loadout has been set. 18 | function PLUGIN:PlayerLoadedChar(client, character, lastChar) 19 | timer.Simple(0, function() 20 | if (IsValid(client)) then 21 | -- Get the saved position from the character data. 22 | local position = character:getData("pos") 23 | 24 | -- Check if the position was set. 25 | if (position) then 26 | if (position[3] and position[3]:lower() == game.GetMap():lower()) then 27 | -- Restore the player to that position. 28 | client:SetPos(position[1].x and position[1] or client:GetPos()) 29 | client:SetEyeAngles(position[2].p and position[2] or Angle(0, 0, 0)) 30 | end 31 | 32 | -- Remove the position data since it is no longer needed. 33 | character:setData("pos", nil) 34 | end 35 | end 36 | end) 37 | end -------------------------------------------------------------------------------- /plugins/stamina/attributes/sh_end.lua: -------------------------------------------------------------------------------- 1 | ATTRIBUTE.name = "Endurance" 2 | ATTRIBUTE.desc = "Affects how long you can run for." -------------------------------------------------------------------------------- /plugins/stamina/attributes/sh_stm.lua: -------------------------------------------------------------------------------- 1 | ATTRIBUTE.name = "Stamina" 2 | ATTRIBUTE.desc = "Affects how fast you can run." 3 | 4 | function ATTRIBUTE:onSetup(client, value) 5 | client:SetRunSpeed(nut.config.get("runSpeed") + value) 6 | end -------------------------------------------------------------------------------- /plugins/stamina/sh_plugin.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Stamina" 2 | PLUGIN.author = "Chessnut" 3 | PLUGIN.desc = "Adds a stamina system to limit running." 4 | 5 | if (SERVER) then 6 | function PLUGIN:PostPlayerLoadout(client) 7 | client:setLocalVar("stm", 100) 8 | 9 | local uniqueID = "nutStam"..client:SteamID() 10 | local offset = 0 11 | local velocity 12 | local length2D = 0 13 | local runSpeed = client:GetRunSpeed() - 5 14 | 15 | timer.Create(uniqueID, 0.25, 0, function() 16 | if (IsValid(client)) then 17 | local character = client:getChar() 18 | 19 | if (client:GetMoveType() != MOVETYPE_NOCLIP and character) then 20 | velocity = client:GetVelocity() 21 | length2D = velocity:Length2D() 22 | runSpeed = nut.config.get("runSpeed") + character:getAttrib("stm", 0) 23 | 24 | if (client:WaterLevel() > 1) then 25 | runSpeed = runSpeed * 0.775 26 | end 27 | 28 | if (client:KeyDown(IN_SPEED) and length2D >= (runSpeed - 10)) then 29 | offset = -2 + (character:getAttrib("end", 0) / 60) 30 | elseif (offset > 0.5) then 31 | offset = 1 32 | else 33 | offset = 1.75 34 | end 35 | 36 | if (client:Crouching()) then 37 | offset = offset + 1 38 | end 39 | 40 | local current = client:getLocalVar("stm", 0) 41 | local value = math.Clamp(current + offset, 0, 100) 42 | 43 | if (current != value) then 44 | client:setLocalVar("stm", value) 45 | 46 | if (value == 0 and !client:getNetVar("brth", false)) then 47 | client:SetRunSpeed(nut.config.get("walkSpeed")) 48 | client:setNetVar("brth", true) 49 | 50 | --character:updateAttrib("end", 0.1) 51 | --character:updateAttrib("stm", 0.01) 52 | 53 | hook.Run("PlayerStaminaLost", client) 54 | elseif (value >= 50 and client:getNetVar("brth", false)) then 55 | client:SetRunSpeed(runSpeed) 56 | client:setNetVar("brth", nil) 57 | end 58 | end 59 | end 60 | else 61 | timer.Remove(uniqueID) 62 | end 63 | end) 64 | end 65 | 66 | local playerMeta = FindMetaTable("Player") 67 | 68 | function playerMeta:restoreStamina(amount) 69 | local current = self:getLocalVar("stm", 0) 70 | local value = math.Clamp(current + amount, 0, 100) 71 | 72 | self:setLocalVar("stm", value) 73 | end 74 | else 75 | nut.bar.add(function() 76 | return LocalPlayer():getLocalVar("stm", 0) / 100 77 | end, Color(200, 200, 40), nil, "stm") 78 | end -------------------------------------------------------------------------------- /plugins/storage/entities/entities/nut_storage.lua: -------------------------------------------------------------------------------- 1 | local PLUGIN = PLUGIN 2 | 3 | ENT.Type = "anim" 4 | ENT.PrintName = "Storage" 5 | ENT.Category = "NutScript" 6 | ENT.Spawnable = false 7 | 8 | if (SERVER) then 9 | function ENT:Initialize() 10 | self:SetModel("models/props_junk/watermelon01.mdl") 11 | self:SetSolid(SOLID_VPHYSICS) 12 | self:PhysicsInit(SOLID_VPHYSICS) 13 | self:SetUseType(SIMPLE_USE) 14 | self.receivers = {} 15 | 16 | local physObj = self:GetPhysicsObject() 17 | 18 | if (IsValid(physObj)) then 19 | physObj:EnableMotion(true) 20 | physObj:Wake() 21 | end 22 | end 23 | 24 | function ENT:setInventory(inventory) 25 | if (inventory) then 26 | self:setNetVar("id", inventory:getID()) 27 | 28 | inventory.onAuthorizeTransfer = function(inventory, client, oldInventory, item) 29 | if (IsValid(client) and IsValid(self) and self.receivers[client]) then 30 | return true 31 | end 32 | end 33 | inventory.getReceiver = function(inventory) 34 | local receivers = {} 35 | 36 | for k, v in pairs(self.receivers) do 37 | if (IsValid(k)) then 38 | receivers[#receivers + 1] = k 39 | end 40 | end 41 | 42 | return #receivers > 0 and receivers or nil 43 | end 44 | inventory.onCanTransfer = function(inventory, client, oldX, oldY, x, y, newInvID) 45 | return hook.Run("StorageCanTransfer", inventory, client, oldX, oldY, x, y, newInvID) 46 | end 47 | end 48 | end 49 | 50 | function ENT:OnRemove() 51 | local index = self:getNetVar("id") 52 | 53 | if (!nut.shuttingDown and !self.nutIsSafe and nut.entityDataLoaded and index) then 54 | local item = nut.item.inventories[index] 55 | 56 | if (item) then 57 | nut.item.inventories[index] = nil 58 | 59 | nut.db.query("DELETE FROM nut_items WHERE _invID = "..index) 60 | nut.db.query("DELETE FROM nut_inventories WHERE _invID = "..index) 61 | 62 | hook.Run("StorageItemRemoved", self, item) 63 | end 64 | end 65 | end 66 | 67 | local OPEN_TIME = .7 68 | function ENT:OpenInv(activator) 69 | local inventory = self:getInv() 70 | local def = PLUGIN.definitions[self:GetModel():lower()] 71 | 72 | if (def.onOpen) then 73 | def.onOpen(self, activator) 74 | end 75 | 76 | activator:setAction("Opening...", OPEN_TIME, function() 77 | if (activator:GetPos():Distance(self:GetPos()) <= 100) then 78 | self.receivers[activator] = true 79 | activator.nutBagEntity = self 80 | 81 | inventory:sync(activator) 82 | netstream.Start(activator, "invOpen", self, inventory:getID()) 83 | self:EmitSound(def.opensound or "items/ammocrate_open.wav") 84 | end 85 | end) 86 | end 87 | 88 | function ENT:Use(activator) 89 | local inventory = self:getInv() 90 | 91 | if (inventory and (activator.nutNextOpen or 0) < CurTime()) then 92 | if (activator:getChar()) then 93 | local def = PLUGIN.definitions[self:GetModel():lower()] 94 | 95 | if (self:getNetVar("locked")) then 96 | self:EmitSound(def.locksound or "doors/default_locked.wav") 97 | if (!self.keypad) then 98 | netstream.Start(activator, "invLock", self) 99 | end 100 | else 101 | self:OpenInv(activator) 102 | end 103 | end 104 | 105 | activator.nutNextOpen = CurTime() + OPEN_TIME * 1.5 106 | end 107 | end 108 | else 109 | ENT.DrawEntityInfo = true 110 | 111 | local COLOR_LOCKED = Color(242, 38, 19) 112 | local COLOR_UNLOCKED = Color(135, 211, 124) 113 | local toScreen = FindMetaTable("Vector").ToScreen 114 | local colorAlpha = ColorAlpha 115 | local drawText = nut.util.drawText 116 | local configGet = nut.config.get 117 | 118 | function ENT:onDrawEntityInfo(alpha) 119 | local locked = self.getNetVar(self, "locked", false) 120 | local position = toScreen(self.LocalToWorld(self, self.OBBCenter(self))) 121 | local x, y = position.x, position.y 122 | 123 | y = y - 20 124 | local tx, ty = nut.util.drawText(locked and "P" or "Q", x, y, colorAlpha(locked and COLOR_LOCKED or COLOR_UNLOCKED, alpha), 1, 1, "nutIconsMedium", alpha * 0.65) 125 | y = y + ty*.9 126 | 127 | local def = PLUGIN.definitions[self.GetModel(self):lower()] 128 | local tx, ty = drawText("Storage", x, y, colorAlpha(configGet("color"), alpha), 1, 1, nil, alpha * 0.65) 129 | if (def) then 130 | y = y + ty + 1 131 | drawText(def.desc, x, y, colorAlpha(color_white, alpha), 1, 1, nil, alpha * 0.65) 132 | end 133 | end 134 | end 135 | 136 | function ENT:getInv() 137 | return nut.item.inventories[self:getNetVar("id", 0)] 138 | end -------------------------------------------------------------------------------- /plugins/storage/sh_definitions.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | PLUGIN.definitions[model's name(lowercase)] = { 3 | name = "Crate", 4 | desc = "A simple wooden create.", 5 | width = 4, 6 | height = 4, 7 | locksound = "", 8 | opensound = "", 9 | } 10 | --]] 11 | 12 | PLUGIN.definitions["models/props_junk/wood_crate001a.mdl"] = { 13 | name = "Crate", 14 | desc = "A simple wooden crate.", 15 | width = 4, 16 | height = 4, 17 | } 18 | 19 | PLUGIN.definitions["models/props_c17/lockers001a.mdl"] = { 20 | name = "Locker", 21 | desc = "A white locker.", 22 | width = 3, 23 | height = 5, 24 | } 25 | 26 | PLUGIN.definitions["models/props_wasteland/controlroom_storagecloset001a.mdl"] = { 27 | name = "Metal Cabinet", 28 | desc = "A green metal cabinet.", 29 | width = 4, 30 | height = 5, 31 | } 32 | 33 | PLUGIN.definitions["models/props_wasteland/controlroom_filecabinet002a.mdl"] = { 34 | name = "File Cabinet", 35 | desc = "A metal filing cabinet.", 36 | width = 2, 37 | height = 4, 38 | } 39 | PLUGIN.definitions["models/props_c17/furniturefridge001a.mdl"] = { 40 | name = "Refrigerator", 41 | desc = "A metal box for keeping food in.", 42 | width = 2, 43 | height = 3, 44 | } 45 | 46 | PLUGIN.definitions["models/props_wasteland/kitchen_fridge001a.mdl"] = { 47 | name = "Large Refrigerator", 48 | desc = "A large metal box for storing even more food in.", 49 | width = 4, 50 | height = 5, 51 | } 52 | PLUGIN.definitions["models/props_junk/trashbin01a.mdl"] = { 53 | name = "Trash Bin", 54 | desc = "What do you expect to find in here?", 55 | width = 1, 56 | height = 2, 57 | } 58 | PLUGIN.definitions["models/items/ammocrate_smg1.mdl"] = { 59 | name = "Ammo Crate", 60 | desc = "A heavy crate that stores ammo", 61 | width = 5, 62 | height = 3, 63 | onOpen = function(entity, activator) 64 | local seq = entity:LookupSequence("Close") 65 | entity:ResetSequence(seq) 66 | 67 | timer.Simple(2, function() 68 | if (entity and IsValid(entity)) then 69 | local seq = entity:LookupSequence("Open") 70 | entity:ResetSequence(seq) 71 | end 72 | end) 73 | end, 74 | } 75 | -------------------------------------------------------------------------------- /plugins/strength/attributes/sh_str.lua: -------------------------------------------------------------------------------- 1 | ATTRIBUTE.name = "Strength" 2 | ATTRIBUTE.desc = "A measure of how strong you are." -------------------------------------------------------------------------------- /plugins/strength/sh_plugin.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Strength" 2 | PLUGIN.author = "Chessnut" 3 | PLUGIN.desc = "Adds a strength attribute." 4 | 5 | if (SERVER) then 6 | function PLUGIN:PlayerGetFistDamage(client, damage, context) 7 | if (client:getChar()) then 8 | -- Add to the total fist damage. 9 | context.damage = context.damage + (client:getChar():getAttrib("str", 0) * nut.config.get("strMultiplier")) 10 | end 11 | end 12 | 13 | function PLUGIN:PlayerThrowPunch(client, hit) 14 | if (client:getChar()) then 15 | client:getChar():updateAttrib("str", 0.001) 16 | end 17 | end 18 | end 19 | 20 | -- Configuration for the plugin 21 | nut.config.add("strMultiplier", 0.3, "The strength multiplier scale", nil, { 22 | form = "Float", 23 | data = {min=0, max=1.0}, 24 | category = "Strength" 25 | }) 26 | -------------------------------------------------------------------------------- /plugins/typing.lua: -------------------------------------------------------------------------------- 1 | PLUGIN.name = "Typing Indicator" 2 | PLUGIN.desc = "Shows some text when someone types." 3 | PLUGIN.author = "Chessnut" 4 | 5 | if (CLIENT) then 6 | local TYPE_OFFSET = Vector(0, 0, 80) 7 | local TYPE_OFFSET_CROUCHED = Vector(0, 0, 48) 8 | local TYPE_COLOR = Color(250, 250, 250) 9 | 10 | function PLUGIN:StartChat() 11 | netstream.Start("typeStatus", 1) 12 | end 13 | 14 | function PLUGIN:FinishChat() 15 | netstream.Start("typeStatus") 16 | end 17 | 18 | local data = {} 19 | 20 | function PLUGIN:HUDPaint() 21 | local ourPos = LocalPlayer():GetPos() 22 | local localPlayer = LocalPlayer() 23 | 24 | data.start = localPlayer:EyePos() 25 | 26 | for k, v in ipairs(player.GetAll()) do 27 | if (v != localPlayer and v:getNetVar("typing") and v:GetMoveType() == MOVETYPE_WALK) then 28 | data.endpos = v:EyePos() 29 | 30 | if (util.TraceLine(data).Entity == v) then 31 | local position = v:GetPos() 32 | local alpha = (1 - (ourPos:DistToSqr(position) / 65536)) * 255 33 | 34 | if (alpha > 0) then 35 | local screen = (position + (v:Crouching() and TYPE_OFFSET_CROUCHED or TYPE_OFFSET)):ToScreen() 36 | 37 | nut.util.drawText("(Typing)", screen.x, screen.y - 18, ColorAlpha(TYPE_COLOR, alpha), 1, 1, "nutChatFontItalics", alpha) 38 | end 39 | end 40 | end 41 | end 42 | end 43 | else 44 | netstream.Hook("typeStatus", function(client, state) 45 | if (state) then 46 | state = true 47 | else 48 | state = nil 49 | end 50 | 51 | client:setNetVar("typing", state) 52 | end) 53 | end -------------------------------------------------------------------------------- /plugins/vendor/derma/cl_vendorfaction.lua: -------------------------------------------------------------------------------- 1 | local PANEL = {} 2 | function PANEL:Init() 3 | self:SetSize(256, 280) 4 | self:Center() 5 | self:MakePopup() 6 | self:SetTitle(L"vendorFaction") 7 | self.scroll = self:Add("DScrollPanel") 8 | self.scroll:Dock(FILL) 9 | self.scroll:DockPadding(0, 0, 0, 4) 10 | 11 | self.factions = {} 12 | self.classes = {} 13 | 14 | for k, v in ipairs(nut.faction.indices) do 15 | local panel = self.scroll:Add("DPanel") 16 | panel:Dock(TOP) 17 | panel:DockPadding(4, 4, 4, 4) 18 | panel:DockMargin(0, 0, 0, 4) 19 | 20 | local faction = panel:Add("DCheckBoxLabel") 21 | faction:Dock(TOP) 22 | faction:SetText(L(v.name)) 23 | faction:DockMargin(0, 0, 0, 4) 24 | faction.OnChange = function(this, state) 25 | self:updateVendor("faction", v.uniqueID) 26 | end 27 | 28 | self.factions[v.uniqueID] = faction 29 | 30 | for k2, v2 in ipairs(nut.class.list) do 31 | if (v2.faction == k) then 32 | local class = panel:Add("DCheckBoxLabel") 33 | class:Dock(TOP) 34 | class:DockMargin(16, 0, 0, 4) 35 | class:SetText(L(v2.name)) 36 | class.OnChange = function(this, state) 37 | self:updateVendor("class", v2.uniqueID) 38 | end 39 | 40 | self.classes[v2.uniqueID] = class 41 | 42 | panel:SetTall(panel:GetTall() + class:GetTall() + 4) 43 | end 44 | end 45 | end 46 | end 47 | 48 | function PANEL:setup() 49 | for k, v in pairs(self.entity.factions or {}) do 50 | self.factions[k]:SetChecked(true) 51 | end 52 | 53 | for k, v in pairs(self.entity.classes or {}) do 54 | self.classes[k]:SetChecked(true) 55 | end 56 | end 57 | vgui.Register("nutVendorFactionEditor", PANEL, "DFrame") --------------------------------------------------------------------------------