• NPC Information
    8 replies, posted
This is something that has been on workshop for awhile, but finally decided to post it here. It's an addon that displays an NPC's information and has a few settings. It started originally off as a project to work with cam.2d3d but then I decided to keep working on it. [video=youtube;uIcO8Dlm8zQ]http://www.youtube.com/watch?v=uIcO8Dlm8zQ&feature=youtu.be[/video] [b]Settings Menu[/b] [t]http://cloud-4.steampowered.com/ugc/720870441740539149/5AEA283D100E1B33E4789FCCA284497F013AE9BE/[/t] [b]Random levels, HP based on levels[/b] [t]http://cloud-2.steampowered.com/ugc/919022918562247794/D63CEA2570AFBDAA33D1AD89AC5579793F2AE461/637x358.resizedimage[/t] [b]Size based on level[/b] [t]http://cloud-2.steampowered.com/ugc/919022918562192628/51E6A59B83FDF3440F0E11C437D90321CBDB8AEF/637x358.resizedimage[/t] It can be found on the workshop here: [url]http://steamcommunity.com/sharedfiles/filedetails/?id=172254388[/url] [B]Inferno, Eh?[/B] Joined a couple days back with working on the addon. He helped by cleaning up my code, with the checkboxes on the settings menu and the size based on level. Without him, I would not have had this latest version released. He also helped me with creating a bar that worked like an actual one, and for that I am heavily grateful. [b]Here is the code.[/b] [lua]NPC_STATS = NPC_STATS or {} NPC_STATS.NPCS = NPC_STATS.NPCS or {} if SERVER then AddCSLuaFile() resource.AddFile("materials/nook/npc_information/HP_Bar.png") local NPCLevels = CreateConVar("NPC_STATS_Enable_Levels", "true", {FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE}) local NPCHealth = CreateConVar("NPC_STATS_SetCHealth", 0, {FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE}) local NPCSize = CreateConVar("NPC_STATS_Size", "true", {FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE}) local NPCLook = CreateConVar("NPC_STATS_LookAt", "true", {FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE}) local NPCShow = CreateConVar("NPC_STATS_Show", "true", {FCVAR_REPLICATED, FCVAR_SERVER_CAN_EXECUTE}) util.AddNetworkString("NPC_STATS_send_Info") hook.Add("PlayerInitialSpawn", "NPC_STATS.PlayerInitialSpawn", function(ply) for k,v in pairs(NPC_STATS.NPCS) do net.Start("NPC_STATS_send_Info") net.WriteInt(k, 16) net.WriteTable(NPC_STATS.NPCS[k]) net.Send(ply) end end) hook.Add("OnEntityCreated", "NPC_STATS.OnEntityCreated", function(ent) if !ent:IsNPC() then return end timer.Simple(0.1, function() if !IsValid(ent) then return end local NPC_Level = math.random(1,100) local NPC_MaxHealth if tonumber(NPCHealth:GetString()) >= 1 then NPC_MaxHealth = tonumber(NPCHealth:GetString()) elseif tonumber(NPCHealth:GetString()) == 0 then if tobool(NPCLevels:GetString()) then NPC_MaxHealth = math.Round((NPC_Level * ent:Health())/10) else NPC_MaxHealth = ent:Health() end end ent:SetHealth(NPC_MaxHealth) local entID = ent:EntIndex() NPC_STATS.NPCS[entID] = {MaxHealth = NPC_MaxHealth, Level = NPC_Level} net.Start("NPC_STATS_send_Info") net.WriteInt(entID, 16) net.WriteTable(NPC_STATS.NPCS[entID]) net.Broadcast() end) end) hook.Add("ShowSpare1", "NPC_STATS.ShowSpare1", function(ply) ply:ConCommand("NPC_STATS_configMenu") end) else surface.CreateFont("InfoText", { font = "MenuLarge", size = 30, weight = 500, blursize = 0, scanlines = 0, shadow = true, outline = true }) surface.CreateFont("HPText", { font = "MenuLarge", size = 15, weight = 500, blursize = 0, scanlines = 0, shadow = true }) local NPCLevels = GetConVar("NPC_STATS_Enable_Levels") local NPCHealth = GetConVar("NPC_STATS_SetCHealth") local NPCSize = GetConVar("NPC_STATS_Size") local NPCLook = GetConVar("NPC_STATS_LookAt") local NPCShow = GetConVar("NPC_STATS_Show") function NPC_STATS:ConfigMenu() if !LocalPlayer():IsSuperAdmin() then return end local DMain = vgui.Create("DFrame") DMain:SetSize(500, 150) DMain:SetPos(ScrW()/2 - 200, ScrH()/2 - 100) DMain:MakePopup() DMain:SetTitle("NPC Config Menu") local CLevels = vgui.Create( "DCheckBoxLabel", DMain) CLevels:SetPos(5, 32) CLevels:SetText("Random Levels (Disables HP based on Levels)") CLevels:SetChecked(tobool(NPCLevels:GetString())) CLevels.OnChange = function(self, val) RunConsoleCommand("NPC_STATS_Enable_Levels", tostring(!tobool(NPCLevels:GetString()))) end CLevels:SizeToContents() local CHealth local CHS = vgui.Create("DCheckBoxLabel", DMain) CHS:SetText("Custom Health for all NPCs") CHS:SetChecked(NPCHealth:GetInt() >= 1) CHS:CopyPos(CLevels) CHS:MoveBelow(CLevels, 1) CHS:SizeToContents() CHS.OnChange = function(self, val) CHealth:SetDisabled(!val) if val then RunConsoleCommand("NPC_STATS_SetCHealth", 100) CHealth:SetText(100) else RunConsoleCommand("NPC_STATS_SetCHealth", 0) CHealth:SetText(0) end end CHealth = vgui.Create("DTextEntry", DMain) CHealth:CopyPos(CHS) CHealth:MoveRightOf(CHS, 5) CHealth:MoveBelow(CLevels, -2) CHealth:SetTall(20) CHealth:SetWide(37) CHealth:SetEnterAllowed(true) CHealth:SetText(NPCHealth:GetInt()) CHealth:SetDisabled(!CHS:GetChecked()) CHealth.OnEnter = function(self) local val = self:GetValue() local CHealthE = tonumber(val) if !CHealthE then CHealthE = 100 self:SetText(CHealthE) end RunConsoleCommand("NPC_STATS_SetCHealth", CHealthE) end local CSize = vgui.Create( "DCheckBoxLabel", DMain) CSize:SetText("Size Based on NPC's Level") CSize:CopyPos(CHS) CSize:MoveBelow(CHS, 1) CSize:SizeToContents() CSize:SetChecked(tobool(NPCSize:GetString())) CSize.OnChange = function(self, val) RunConsoleCommand("NPC_STATS_Size", tostring(!tobool(NPCSize:GetString()))) end local CLook = vgui.Create( "DCheckBoxLabel", DMain) CLook:SetText("Show when not looking at NPC") CLook:CopyPos(CSize) CLook:MoveBelow(CSize, 1) CLook:SizeToContents() CLook:SetChecked(tobool(NPCLook:GetString())) CLook.OnChange = function(self, val) RunConsoleCommand("NPC_STATS_LookAt", tostring(!tobool(NPCLook:GetString()))) end local CShow = vgui.Create( "DCheckBoxLabel", DMain) CShow:SetText("Show the information") CShow:CopyPos(CLook) CShow:MoveBelow(CLook, 1) CShow:SizeToContents() CShow:SetChecked(tobool(NPCShow:GetString())) CShow.OnChange = function(self, val) RunConsoleCommand("NPC_STATS_Show", tostring(!tobool(NPCShow:GetString()))) end end concommand.Add("NPC_STATS_configMenu", NPC_STATS.ConfigMenu) hook.Add("OnPlayerChat", "NPC_STATS.PlayerChat", function(ply, mes) if mes == "/npcinfo" then ply:ConCommand("NPC_STATS_configMenu") end end) local hpBarMat = Material("nook/npc_information/HP_Bar.png") local hpBarW, hpBarH = 155, 29 local hpBarPadding = 12 local zOffset = 75 hook.Add("PostDrawOpaqueRenderables", "NPC_STATS.PostDrawOpaqueRenderables", function() for _,npc in ipairs(ents.FindByClass("npc_*")) do if !IsValid(npc) or npc:Health() <= 0 then continue end local npcID = npc:EntIndex() local NPC_Stats = NPC_STATS.NPCS[npcID] if !NPC_Stats then continue end local npcHP = npc:Health() local npcMaxHP = NPC_Stats.MaxHealth local npcLevel = NPC_Stats.Level local npcInfo = npc.Name or (language.GetPhrase(npc:GetClass())) local ply = LocalPlayer() local hpBarLen = (npcHP/npcMaxHP) * hpBarW npc.InfoPos = ((npc:LocalToWorld(npc:OBBCenter()*2)) + (vector_up * 34)) if (!npc.Alpha) then npc.Alpha = 0 end if tobool(NPCLook:GetString()) then npc.Alpha = 255 end if (ply:GetEyeTrace().Entity == npc) then if npc.Alpha < 255 then npc.Alpha = npc.Alpha + 1 elseif npc.Alpha >= 255 then npc.Alpha = 255 end else if npc.Alpha <= 0 then npc.Alpha = 0 elseif npc.Alpha > 0 then npc.Alpha = npc.Alpha - 1 end end if npcHP <= 0 then continue end if tobool(NPCShow:GetString()) then cam.Start3D2D(npc
This is pretty neat.
Could you get a better screenshot of the first picture, I can't really read it
[QUOTE=smithy285;42322904]Could you get a better screenshot of the first picture, I can't really read it[/QUOTE] Sure. When I get home I'll get a better screenshot and do a video.
You should make the addon enabled for specific entities only like npc_zombie ect. This would be awesome for any zombie server however say if one made NPC Shops there is a random bar that shouldn't go there. :/
I'll look into adding a specific setting, shouldn't be too hard.
[QUOTE=Luni;42321717]This is pretty neat.[/QUOTE] I tried to read it and this is what I have :D 1.Random Levels(Disable HP based on Levels) 2.Custom Health for all NPCs 3.---------
[QUOTE=BoowmanTech;42357023]I tried to read it and this is what I have :D 1.Random Levels(Disable HP based on Levels) 2.Custom Health for all NPCs 3.---------[/QUOTE] Gah, completely forgot to get a video going and a new screenshot. I apologize! I'm getting on that RIGHT now. [b]EDIT:[/b] Added the video to the OP, apologies for not doing this sooner.
Just added in two new options due to players asking, one is to show the information only if they look at the NPC and the other is to hide information alltogether. Updated source code as well. I do have a question though, is there a way around the fact that it seems Garry's Mod likes to reset the model scaling?
Sorry, you need to Log In to post a reply to this thread.