• What do you need help with? V3
    6,419 replies, posted
[QUOTE=Turtle95;38729437]Hello, I'm trying to make my SWEP kill any NPC, but only if I'm looking at the NPC. However, my code seems to not work as I intend. [CODE]function SWEP:Think() local tr = self.Owner:GetEyeTrace(); if tr.Entity:IsPlayer() or tr.Entity:IsNPC() then timer.Simple(3, function () if tr.Entity:IsValid() then tr.Entity:TakeDamage(tr.Entity:Health(), self, self.Owner) end end) else end print(tr.Entity:GetClass()) end[/CODE][/QUOTE] you have your args mixed up try [lua] //entity:TakeDamage = (amt, attacker, inflictor) timer.Simple(3, function() if tr.Entity:IsValid() then tr.Entity:TakeDamage(tr.Entity:Health(), self.Owner, self.Weapon) end end) [/lua] Anyways, try that, I haven't tested but i know that your 2nd and 3rd args should have been swapped. Good luck
[QUOTE=M0dSe7en;38730091]you have your args mixed up try [lua] //entity:TakeDamage = (amt, attacker, inflictor) timer.Simple(3, function() if tr.Entity:IsValid() then tr.Entity:TakeDamage(tr.Entity:Health(), self.Owner, self.Weapon) end end) [/lua] Anyways, try that, I haven't tested but i know that your 2nd and 3rd args should have been swapped. Good luck[/QUOTE] You didn't read what I said did you? I want the NPC to die ONLY IF I LOOK AT IT. Please help me!
Okay so I've found out that SetRenderMode( RENDERMODE_TRANSALPHA ) works on prop_physics but when I'm spawning my own sent to handle props like this it doesn't work: [code] ent = ents.Create("sent_prop") ent:SetAngles(ang) ent:SetPos(tr.HitPos) ent:SetModel(model) ent:Spawn() ent:SetRenderMode( RENDERMODE_TRANSALPHA ) ent:Activate() [/code] Inside the entity: [code]function ENT:Initialize() self.Entity:SetModel(self.Model) self.Entity:PhysicsInit(SOLID_VPHYSICS) self.Entity:SetMoveType(MOVETYPE_VPHYSICS) self.Entity:SetSolid(SOLID_VPHYSICS) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() phys:EnableMotion(false) self:SetUnFreezable(true) end end[/code] Not sure if this is a bug or just something wrong with my code.
I have a spawnlist for NPCs, but it isn't appearing in-game, what is wrong with it? [code] local Category = "Okibi's NPCs" local NPC = { Name = "HybridHunter", Class = "sent_hhunter", KeyValues = { citizentype = 4 }, Category = Category } list.Set( "NPC", "npc_hybrid_hunter", NPC ) [/code]
[QUOTE=Turtle95;38730220]You didn't read what I said did you? I want the NPC to die ONLY IF I LOOK AT IT. Please help me![/QUOTE] Oh, ok i see what you mean. Sorry, I'm having an off day. I see why your code wasn't working too. You put a timer in a think hook which will never work since think gets called every frame. If your looking to time it though than use this [lua] killTimer = CurTime() delay = 3 function SWEP:Think() if CurTime() >= killTimer then local tr = self.Owner:GetEyeTrace(); if tr.HitNonWorld && (tr.Entity:IsPlayer() || tr.Entity:IsNPC()) then timer.Simple(3, function () if tr.Entity:IsValid() then tr.Entity:TakeDamage(tr.Entity:Health(), self, self.Owner) end end) end killTimer = CurTime() + delay end end [/lua] just get rid of the if statement and variables if you don't want a timer.
[QUOTE=Drakehawke;38728423]The scripted tools system is purely created in Lua, have a poke around the [url=http://glua.me/bin/?path=/gamemodes/sandbox/entities/weapons/gmod_tool/stool.lua]source[/url] and you might find a way.[/QUOTE] Here's my findings for the day; I tried overriding elements of the toolmode using this code; [lua] AddCSLuaFile() local modifyACFMenuTable // modification of the tool's serverside component if SERVER then modifyACFMenuTable = function( toolobj ) toolobj.LeftClick = function() print("XCFTool!") end toolobj.RightClick = function() print("XCFTool2!") end toolobj.BubWozEre = true Msg("Modified acfmenu serverside!\n") end end // modification of the tool's clientside component if CLIENT then modifyACFMenuTable = function( toolobj ) toolobj.LeftClick = function() print("XCFTool!") end toolobj.RightClick = function() print("XCFTool2!") end toolobj.BuildCPanel = function(CPanel) local pnldef_ACFmenu = vgui.RegisterFile( "cl_XCFMenu_gui.lua" ) local DPanel = vgui.CreateFromTable( pnldef_ACFmenu ) CPanel:AddPanel( DPanel ) end toolobj.BubWozEre = true Msg("Modified acfmenu clientside!\n") end end // check every second to see if we can modify the tool timer.Create("XCF_CheckACFMenu", 1, 0, function() local toollist = weapons.GetStored("gmod_tool").Tool if !toollist.acfmenu then Msg("acfmenu was not found!\n") timer.Simple(1, doACFOverrides) return end if !toollist.acfmenu.BubWozEre then modifyACFMenuTable(toollist.acfmenu) timer.Remove("XCF_CheckACFMenu") end end) [/lua] It uses weapons.GetStored to get the toolgun's "real weapon table", and then it makes amendments to the toolmode's table. But it doesn't work. I'm going to guess that the table weapons.GetStored returns is not actually the table that the weapon uses. That'd explain why none of my changes are taking hold. Has anyone done something like this before, who can give me some tips? :)
-snip- Used engine.LightStyle(int, string)
[QUOTE=M0dSe7en;38730526]Oh, ok i see what you mean. Sorry, I'm having an off day. I see why your code wasn't working too. You put a timer in a think hook which will never work since think gets called every frame. If your looking to time it though than use this [lua] killTimer = CurTime() delay = 3 function SWEP:Think() if CurTime() >= killTimer then local tr = self.Owner:GetEyeTrace(); if tr.HitNonWorld && (tr.Entity:IsPlayer() || tr.Entity:IsNPC()) then timer.Simple(3, function () if tr.Entity:IsValid() then tr.Entity:TakeDamage(tr.Entity:Health(), self, self.Owner) end end) end killTimer = CurTime() + delay end end [/lua] just get rid of the if statement and variables if you don't want a timer.[/QUOTE] Thanks, though this is the only problem: [CODE][ERROR] addons/slenderman/lua/weapons/slenderman/shared.lua:71: attempt to call method 'TakeDamage' (a nil value) 1. unknown - addons/slenderman/lua/weapons/slenderman/shared.lua:71 Timer Failed! [Simple][@addons/slenderman/lua/weapons/slenderman/shared.lua (line 71)][/CODE]
Seeing as though my questions usually go un-answered, I'll post again....... Does this function no longer work client-side? [lua] function TabAdd() spawnmenu.AddToolTab("Name of the tab", "Unique Name") end -- Hook the Tab to the Menu hook.Add( "AddToolMenuTabs", "Unique Name", TabAdd) [/lua] I can not for the life of me getting a tab to show in q-menu...
my bad, copied and pasted forgot about original change. I'm really tired btw, just change to [lua] killTimer = CurTime() delay = 3 function SWEP:Think() if CurTime() >= killTimer then local tr = self.Owner:GetEyeTrace(); if tr.HitNonWorld && (tr.Entity:IsPlayer() || tr.Entity:IsNPC()) then tr.Entity:TakeDamage(tr.Entity:Health(), self.Owner, self.Weapon) end killTimer = CurTime() + delay end end [/lua]
is there anyone really experienced with ApplyForce/AddAngleVelocity/physics in general that would be available for me to ask a bunch of questions? I keep getting stuck and I don't know why and it's really frustrating
Dedicated sever gamemode as spacebuild 3 and not being able to noclip through owners props. Can anyone help. I'll give admin rights if you want to join and help with other stuff.
Anyone know how to enable shading on entities rather than brushes? This is for editing the map lighting: [code] // Setup light animation tables. 'a' is total darkness, 'z' is maxbright. engine.LightStyle(0, "b") [/code]
is there a way to make draw.roundedbox hook clicks and perform a function? i thought you could use it for buttons and i made an insane interface but couldnt figure out how to hook mousepress on it :-(
Nevermind, I have solved the Blur thing, though I have another question, how do I edit volume on this code here? [lua] local tab = { "amb/Dungeon_01.mp3", "amb/Dungeon_02.mp3", "amb/Dungeon_03.mp3", "amb/Dungeon_04.mp3", "amb/Dungeon_05.mp3", "amb/Dungeon_06.mp3", "amb/Dungeon_07.mp3", "amb/Dungeon_08.mp3", "amb/Dungeon_10.mp3", "amb/Dungeon_11.mp3", "amb/Dungeon_12.mp3", "amb/Dungeon_13.mp3", "amb/Dungeon_14.mp3" } local function AmbientSounds() local sound, plytab = table.Random(tab), player.GetAll() for k = 1, #plytab do plytab[k]:SendLua("surface.PlaySound(\"".. sound .."\")") end; end; timer.Create("AmbientSoundsEmit", 210, 0, AmbientSounds) [/lua] Though I remember surface.PlaySound not having a volume option, so how would I change this? I still want to keep the sounds played on the client not serverside.
I need help with a project im working on. k so im make a sign "minecraft sign". I need it to change model when i look at the wall but i keep getting an error. [CODE]local model1 = "models/mcmodelpack/entities/sign.mdl" local model2 = "models/mcmodelpack/entities/wallsign.mdl" function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos + tr.HitNormal * -.5 local ent = ents.Create( ClassName or "mc_sign" ) ent:SetModel( model ) ent:SetPos( SpawnPos ) ent:Spawn() ent:Activate() return ent if ( !self.Entity:IsOnGround() ) then local model = model1 else local model = model2 end end[/CODE] and i dont know wat im doing wrong all i get is an error saying that i need a end to close it
[QUOTE=Splambob;38730774]Here's my findings for the day; I tried overriding elements of the toolmode using this code; [lua] AddCSLuaFile() local modifyACFMenuTable // modification of the tool's serverside component if SERVER then modifyACFMenuTable = function( toolobj ) toolobj.LeftClick = function() print("XCFTool!") end toolobj.RightClick = function() print("XCFTool2!") end toolobj.BubWozEre = true Msg("Modified acfmenu serverside!\n") end end // modification of the tool's clientside component if CLIENT then modifyACFMenuTable = function( toolobj ) toolobj.LeftClick = function() print("XCFTool!") end toolobj.RightClick = function() print("XCFTool2!") end toolobj.BuildCPanel = function(CPanel) local pnldef_ACFmenu = vgui.RegisterFile( "cl_XCFMenu_gui.lua" ) local DPanel = vgui.CreateFromTable( pnldef_ACFmenu ) CPanel:AddPanel( DPanel ) end toolobj.BubWozEre = true Msg("Modified acfmenu clientside!\n") end end // check every second to see if we can modify the tool timer.Create("XCF_CheckACFMenu", 1, 0, function() local toollist = weapons.GetStored("gmod_tool").Tool if !toollist.acfmenu then Msg("acfmenu was not found!\n") timer.Simple(1, doACFOverrides) return end if !toollist.acfmenu.BubWozEre then modifyACFMenuTable(toollist.acfmenu) timer.Remove("XCF_CheckACFMenu") end end) [/lua] It uses weapons.GetStored to get the toolgun's "real weapon table", and then it makes amendments to the toolmode's table. But it doesn't work. I'm going to guess that the table weapons.GetStored returns is not actually the table that the weapon uses. That'd explain why none of my changes are taking hold. Has anyone done something like this before, who can give me some tips? :)[/QUOTE] You should be able to get somewhere with it, if all else fails there's always the debug library. There's definitely a better way of doing it than that timer though.
Working on 3d person view. But I don't know how set shoot pos ... [url]http://d.pr/i/Mr3m[/url]
[QUOTE=Dark Herald;38736610]Working on 3d person view. But I don't know how set shoot pos ... [url]http://d.pr/i/Mr3m[/url][/QUOTE] Well, I've updated the cringerpants over shoulder view thing, if only I could figure out where/how to upload it somewhere. Only thing that was wrong with it was player:GetScriptedVehicle() should've been changed to player:GetVehicle(). lol And yes, there was only one mention of it in the .lua Anyway, onto my question. What's with all these player models lua code adding in this AddCSLuaFile( 'assassin.lua' ) all the time? What's with the assassin.lua? O.o I'm stumped... Plus my console was picking it up as an error. <.<
[QUOTE=Splambob;38730774]I'm going to guess that the table weapons.GetStored returns is not actually the table that the weapon uses. That'd explain why none of my changes are taking hold. Has anyone done something like this before, who can give me some tips? :)[/QUOTE] try editing the table at weapons.GetStored("classname").t
Is there a way to enable the vertical scrollbar for a [B]DListLayout[/B]? It's undocumented, but the wiki suggests to use it. :/ local SheetList = vgui.Create("DListLayout") SheetList:EnableVerticalScrollbar(true) [CODE][ERROR] ... attempt to call method 'EnableVerticalScrollbar' (a nil value)[/CODE]
i'm attempting derma for the first time, trying to make it toggle the frame when you press menu bind: [lua] local d_user_settings = vgui.Create( "DFrame" ) d_user_settings:SetPos( ScrW() / 2 - 100,ScrH() - 320 ) d_user_settings:SetSize( 200, 250 ) d_user_settings:SetVisible( true ) d_user_settings:SetDraggable( false ) d_user_settings:ShowCloseButton( false ) -- makepopup makes the bind not work to hide the menu, ie i can open it, but then it gains focus and keybinds do not work? --d_user_settings:MakePopup() local d_user_settings_b = vgui.Create("DButton") d_user_settings_b:SetParent( d_user_settings ) d_user_settings_b:SetText( "spectate mode" ) d_user_settings_b:SetPos(25, 50) d_user_settings_b:SetSize( 150, 175 ) d_user_settings_b.DoClick = function ( btn ) local d_user_settings_b_options = DermaMenu() d_user_settings_b_options:AddOption("single", function() Msg("single") end ) d_user_settings_b_options:AddOption("double", function() Msg("split screen") end ) d_user_settings_b_options:AddOption("quad", function() Msg("quad screen") end ) d_user_settings_b_options:Open() end qmenu = false d_user_settings:SetVisible(false) function QMPress() -- toggle the derma frame, it is already out of focus so don't worry about clicking it accidently... if !qmenu then d_user_settings:SetVisible(false) qmenu = true else d_user_settings:SetVisible(true) qmenu = false end end concommand.Add( "qmenu",QMPress ) [/lua] i need makepopup to make the button clickable afaik, but doing that disables the ability for my keybind function to hide the derma frame again. if someone could tell me how to both be able to toggle with keyboard and click on buttons it would be great :v: edit: d_user_settings:[highlight]SetKeyBoardInputEnabled()[/highlight] has fixed it, (i can now have it in focus and register keys) i'll leave this up just for reference
[QUOTE=itkuitkzhji;38737323]Is there a way to enable the vertical scrollbar for a [B]DListLayout[/B]? It's undocumented, but the wiki suggests to use it. :/ local SheetList = vgui.Create("DListLayout") SheetList:EnableVerticalScrollbar(true) [CODE][ERROR] ... attempt to call method 'EnableVerticalScrollbar' (a nil value)[/CODE][/QUOTE] It doesn't have one anymore. Have a look here how to add one. It's for DIconLayout but should work the same. [url]https://github.com/adamdburton/pointshop/blob/master/lua/vgui/DPointShopMenu.lua#L35[/url]
Thanks, it worked. :D
[QUOTE=itkuitkzhji;38737323]Is there a way to enable the vertical scrollbar for a [B]DListLayout[/B]? It's undocumented, but the wiki suggests to use it. :/ local SheetList = vgui.Create("DListLayout") SheetList:EnableVerticalScrollbar(true) [CODE][ERROR] ... attempt to call method 'EnableVerticalScrollbar' (a nil value)[/CODE][/QUOTE] DListLayout would need to be parented to a DScrollPanel. [editline]7th December 2012[/editline] Ninja'd!
[QUOTE=KatNotDinner;38712401]I'm having a problem. I set some models' render origin and angles via the SetRenderOrigin|Angles. It works great. The models are drawing at a specified player's head pos and angles. The problem is that when this player turns at a specified angle, the model stops drawing until he turns at some other specified angle. Ideas?[/QUOTE] Please help.
[QUOTE=KatNotDinner;38738953]Please help.[/QUOTE] Post the code
how do i change where the shell ejection effects throw the shells? they all fly in a fixed direction
Well, when it comes to scripted entities. i dont know anything about making them. Console: [code]Attempted to create unknown entity type zco_zombiepoint! Can't init zco_zombiepoint Attempted to create unknown entity type zco_zombiepoint! Can't init zco_zombiepoint[/code] Scripted entity codes (files are located at gamemode/entities/zco_zombiepoint/) init.lua [code]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function ENT:Initialize() self.Entity:SetModel("models/props_interiors/BathTub01a.mdl") self.Entity:SetName("zco_zombiepoint") end function Ent:Think() -- nope end[/code] shared.lua [code]ENT.Type = "point" ENT.Base = "base_gmodentity" ENT.PrintName = "Zombie Spawnpoint" ENT.Author = "Zode"[/code] cl_init.lua [code]include("shared.lua") function ENT:Draw() self.Entity:DrawModel() end[/code] Trying to learn some lua by making basic wave-based gamemode (npcs vs players)
Anyone know how to enable shading on entities rather than brushes? This is for editing the map lighting: [code] // Setup light animation tables. 'a' is total darkness, 'z' is maxbright. engine.LightStyle(0, "b") [/code] I need something to enable it on entities also because once the brightness of the map is turned down, entities are highly visible due to their brightness.
Sorry, you need to Log In to post a reply to this thread.