• Problems That Don't Need Their Own Thread v5
    4,111 replies, posted
[QUOTE=bigdogmat;51794413]Look at the wiki page, [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Simple]timer.Simple[/url]. It takes 2 arguments, the delay, and the function to call.[/QUOTE] Could you fix it? I completly understand if you dont want but i would be really great full
[QUOTE=RasmusG5;51795314]Could you fix it? I completly understand if you dont want but i would be really great full[/QUOTE] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Simple]timer.Simple[/url] expects 2 arguments, the time to delay, and the function to call once the delay is up. In this code [code] timer.Simple( 4, time, function() RunConsoleCommand("-attack") end) [/code] You are passing 3 arguments, 4, `time`, and the function. You're getting the error [quote] bad argument #2 to 'Simple' (function expected, got nil) [/quote] because argument 2 (the variable `time` in your code) is nil, and [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Simple]timer.Simple[/url] expects argument 2, to be a function. So, remove the `time` argument. And the code if you're still confused [code] timer.Simple( 4, function() RunConsoleCommand("-attack") end) [/code]
[QUOTE=Rocket;51795398]Well, think about who "yourself" is. Do you want to always address [i]you[/i], as in the person playing on your Steam account? Or would it be the first player to join the server, or someone with a specific name?[/QUOTE] In the context of what I'm doing, it should be the person dealing damage to the prop_ragdoll. I'll show what I have: [CODE] local OurHealth = 25 local function TakeDamage(self, target, dmg) if target != self then return end if (dmg:GetDamageType() == 8194) then if(OurHealth <= 0) then return; end OurHealth = OurHealth - dmg:GetDamage(); if(OurHealth <= 0) then LocalPlayer():SetHealth(50) end end end hook.Add("EntityTakeDamage", Corpse, TakeDamage) [/CODE] I'm doing a Nutscript thing so I'll keep that mumbo jumbo out, but LocalPlayer():SetHealth(50) is a placeholder for where I am supposed to be getting something. (In this example, health).
this code crashes my game why? repeat RunConsoleCommand("+attack") timer.Simple( 4, function() RunConsoleCommand("-attack") end) until false
You are creating infinite timers -- "until false" will never break.
[QUOTE=Spamppa2;51797877]this code crashes my game why? repeat RunConsoleCommand("+attack") timer.Simple( 4, function() RunConsoleCommand("-attack") end) until false[/QUOTE] sounds like you want to use timer.Create instead of repeat until with timer.Simple.
[QUOTE=Spamppa2;51797877]-snip-[/QUOTE] Your [code] until false [/code] will loop [i]forever[/i] and just keep trying to run +attack creating timers.
Anyone know why the model for the skull gib, along with all other HGIBs can't be picked up with the gravity gun? I've tried changing the mass, and that has no bearing as I can see. models/Gibs/HGIBS.mdl Edit: If I use ent:SetModel() on a prop_physics soda can it can be picked up. What the fuck, richard.
[QUOTE=a1steaksa;51798202]Anyone know why the model for the skull gib, along with all other HGIBs can't be picked up with the gravity gun? I've tried changing the mass, and that has no bearing as I can see. models/Gibs/HGIBS.mdl Edit: If I use ent:SetModel() on a prop_physics soda can it can be picked up. What the fuck, richard.[/QUOTE] iirc the HL:S gib models do not have any physics, so you'd need to manually create a physics object for them
[QUOTE=bizzclaw;51791900]I'm working on a paired player animation system, this means that both players involved need to be at the exact position and angle. This is problematic however because you can't just set the angle of a player's body, as setting their view angle just turns their head in that direction, resulting in misaligned animtions. Does anone know a way to reset the player's model too make their body line up with their view angle? I thought you could reset their model, but that doens't seem to work anymore. Semi-Properly Aligned: :snip: Compltely misaligned: :snip: [/QUOTE] I ran into the same problem recently and the solution I found was to use SetRenderAngles inside of an UpdateAnimation hook. You may also want to clear the player's pose parameters, particularly [I]aim_yaw[/I], [I]aim_pitch[/I], [I]head_yaw[/I], and [I]head_pitch[/I] because they can make the model misaligned too.
[QUOTE]you're mixing client-only and server-only functions here -- ENT:Use() is a serverside hook and ply:SetHealth() only has an effect serverside, but the chat lib and LocalPlayer() only exist on the client. use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/PrintMessage]Player:PrintMessage[/url] instead.[/QUOTE] lol the rotate part was my fault, I had ito rewrite it to make it slower lol and I guess I didn't realize wtf I was doing with the chat. lol thank you very much [CODE] [ERROR] lua/entities/testent/init.lua:15: Tried to use a NULL entity! 1. GetPhysicsObject - [C]:-1 2. unknown - lua/entities/testent/init.lua:15 3. Spawn - [C]:-1 4. SpawnFunction - gamemodes/base/entities/entities/base_entity/init.lua:70 5. Spawn_SENT - gamemodes/sandbox/gamemode/commands.lua:651 6. unknown - gamemodes/sandbox/gamemode/commands.lua:716 7. unknown - lua/includes/modules/concommand.lua:54 [/CODE] Getting this error w/ this code. [CODE]include("shared.lua") function ENT:Draw() self:DrawModel() local lasttime = self.lasttime || 0; local rotate = self.rotate || 0; local Pos = self:GetPos() local Ang1 = Angle(0,0,90) local Ang2 = Angle(0,0,90) Ang1:RotateAroundAxis(Ang1:Right(), rotate) Ang2:RotateAroundAxis(Ang2:Right(), rotate + 180) cam.Start3D2D( Pos + Ang1:Up() * 0, Ang1, 0.2) draw.DrawText("A gift from the gods. Use it wisely.", "Default", 0,-50, Color(0,0,0), TEXT_ALIGN_CENTER) cam.End3D2D() cam.Start3D2D(Pos + Ang2:Up() * 0, Ang2, 0.2) draw.DrawText("A gift from the gods. Use it wisely.", "Default",0,-50, Color(0,0,0), TEXT_ALIGN_CENTER) cam.End3D2D() if (rotate > 360) then rotate = 0 end self.rotate = rotate-(2/ ( RealTime()-(lasttime))) lasttime = RealTime() end[/CODE]
[QUOTE=Meninist;51799289]lol the rotate part was my fault, I had ito rewrite it to make it slower lol and I guess I didn't realize wtf I was doing with the chat. lol thank you very much [CODE] [ERROR] lua/entities/testent/init.lua:15: Tried to use a NULL entity! 1. GetPhysicsObject - [C]:-1 2. unknown - lua/entities/testent/init.lua:15 3. Spawn - [C]:-1 4. SpawnFunction - gamemodes/base/entities/entities/base_entity/init.lua:70 5. Spawn_SENT - gamemodes/sandbox/gamemode/commands.lua:651 6. unknown - gamemodes/sandbox/gamemode/commands.lua:716 7. unknown - lua/includes/modules/concommand.lua:54 [/CODE] Getting this error w/ this code. [CODE]include("shared.lua") function ENT:Draw() self:DrawModel() local lasttime = self.lasttime || 0; local rotate = self.rotate || 0; local Pos = self:GetPos() local Ang1 = Angle(0,0,90) local Ang2 = Angle(0,0,90) Ang1:RotateAroundAxis(Ang1:Right(), rotate) Ang2:RotateAroundAxis(Ang2:Right(), rotate + 180) cam.Start3D2D( Pos + Ang1:Up() * 0, Ang1, 0.2) draw.DrawText("A gift from the gods. Use it wisely.", "Default", 0,-50, Color(0,0,0), TEXT_ALIGN_CENTER) cam.End3D2D() cam.Start3D2D(Pos + Ang2:Up() * 0, Ang2, 0.2) draw.DrawText("A gift from the gods. Use it wisely.", "Default",0,-50, Color(0,0,0), TEXT_ALIGN_CENTER) cam.End3D2D() if (rotate > 360) then rotate = 0 end self.rotate = rotate-(2/ ( RealTime()-(lasttime))) lasttime = RealTime() end[/CODE][/QUOTE] Your error is in init.lua but you pasted clientside code :v:
For some fock'n reason my function is not returning a table for a recursive directory. I can't figure out what the problem is. It works for every directory which does not have sub directories. [code] function loading.getFilesInFolder(path, _folder, _file) collectedFiles = {}; local files, folders = file.Find( path.."*", "LUA" ); table.foreach(files, function(file) table.insert(collectedFiles, path..file) if isfunction(_file) then _file(file) end end) table.foreach(folders, function(folder) table.Add(collectedFiles, loading.getFilesInFolder(path..folder..'/', _folder, _file)) if isfunction(_folder) then _folder(path, folder) end end) return collectedFiles; end [/code] Does anyone have an idea?
collectedFiles is a global, when it should be local
Even when it is local it still doesn't return the merged array from subdirectories. I tried that before.
[QUOTE=Darrell;51800492]For some fock'n reason my function is not returning a table for a recursive directory. I can't figure out what the problem is. It works for every directory which does not have sub directories. [code] function loading.getFilesInFolder(path, _folder, _file) collectedFiles = {}; local files, folders = file.Find( path.."*", "LUA" ); table.foreach(files, function(file) table.insert(collectedFiles, path..file) if isfunction(_file) then _file(file) end end) table.foreach(folders, function(folder) table.Add(collectedFiles, loading.getFilesInFolder(path..folder..'/', _folder, _file)) if isfunction(_folder) then _folder(path, folder) end end) return collectedFiles; end [/code] Does anyone have an idea?[/QUOTE] path.."*" should be path.."/*" I've tidied up the rest as well. [lua]function loading.getFilesInFolder(path, _folder, _file) local collectedFiles = {} local files, folders = file.Find(path .. "/*", "LUA") for _, file in ipairs(files) do table.insert(collectedFiles, file) if _file then _file(file) end end for _, folder in ipairs(folders) do table.Add(collectedFiles, loading.getFilesInFolder(path .. "/" .. folder, _folder, _file)) if _folder then _folder(folder) end end return collectedFiles end[/lua]
So finally I got this semi-working script: (This is part of a VJ SNPC) [CODE]function ENT:CustomOnKilled(dmginfo,hitgroup) Corpse = ents.Create("prop_ragdoll") Corpse:SetModel(self:GetModel()) Corpse:SetPos(self:GetPos()) Corpse:SetAngles(self:GetAngles()) Corpse:Spawn() Corpse:Activate() Corpse:SetColor(self:GetColor()) Corpse:SetMaterial(self:GetMaterial()) end local function TakeDamage(self, target, dmg) if target != self then return end if (dmg:GetDamageType() == 8194) then nut.item.spawn("meat", self:GetPos()) Corpse:Remove() end end hook.Add("EntityTakeDamage", Corpse, TakeDamage) [/CODE] As you can see what it's supposed to do is spawn meat [CODE]nut.item.spawn("meat", self:GetPos())[/CODE] when it get's this damage [CODE]dmg:GetDamageType() == 8194[/CODE] which all works if I refresh the script AFTER the corpse has already spawned. Which is the strangest thing ever because if I try to do this without refreshing the script the TakeDamage function is like not even in existence. Any suggestions? Or reasons for it doing this? My inkling is that function TakeDamage isn't being called when the corpse is spawned only until I refresh the script where it's like "oh right, ok, the corpse is there now, now we can do this."
[QUOTE=pilot;51802243]:snip:[/QUOTE] Your hook id is the `Corpse` variable, however that's not set until it's created, so you're setting it to a nil value, which will be ignored by the hook system. Reason it works after you refresh is because the `Corpse` variable is no longer nil. Don't use `Corpse` as the id at all, just check if target is equal to the global `Corpse`. Or put a variable on the entity instead of comparing them to global variables inside that hook. [editline]10th February 2017[/editline] Also, for the benefit of yourself and anyone who reads your scripts, use the [URL="http://wiki.garrysmod.com/page/Enums/DMG"]DMG Enums[/URL] and not the raw decimal values.
[QUOTE=bigdogmat;51802258]Your hook id is the `Corpse` variable, however that's not set until it's created, so you're setting it to a nil value, which will be ignored by the hook system. Reason it works after you refresh is because the `Corpse` variable is no longer nil. Don't use `Corpse` as the id at all, just check if target is equal to the global `Corpse`. Or put a variable on the entity instead of comparing them to global variables inside that hook. [editline]10th February 2017[/editline] Also, for the benefit of yourself and anyone who reads your scripts, use the [URL="http://wiki.garrysmod.com/page/Enums/DMG"]DMG Enums[/URL] and not the raw decimal values.[/QUOTE] Okay, I understand the problem. Excuse my lack of coding skills, but how exactly would I go about assigning a variable to the entity in a way that it would be able to check if the entity exists after it's spawned?
[QUOTE=sannys;51800991]path.."*" should be path.."/*" -snip- [/QUOTE] I fixed it now. I made the recursive function act a little bit diffrent. By including a table it uses to compile a table and returning that. Anyay, path always ends with a forwardslash. Why would you remove isfunction though? This means if someone runs this function and puts in a variable, it will trough a error and stop executing?
[QUOTE=Darrell;51803064]Why would you remove isfunction though? This means if someone runs this function and puts in a variable, it will trough a error and stop executing?[/QUOTE] Which is what [I]should[/I] happen. If someone puts in a dumb parameter, they should get an error. This is how you introduce subtle bugs into scripts. Consider what would happen if you put something in that [B]wasn't[/B] a function, but was a variable you [B]thought[/B] was one. You'd be left wondering why your function isn't being called. There would be no error thrown. All that would happen is your variable would be silently ignored. If you want to check for something like that, you'd probably want to use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/assert]assert[/url], but then that brings into question if it's even worth it to do that. It's a lot easier to just assume that the person calling your function knows what each parameter does, which is a safe assumption to make, because if they don't even know what the parameter does they only have themselves to blame when shit starts breaking. It's not your responsibility to make people smart when it comes to typing in a dynamic language like lua. I'm not saying to never type check, but for something like this, it's unnecessary. You're gonna want to make the parameter names clearer, though. fileCallback and folderCallback would be good.
[QUOTE=sannys;51803097] -snip- [/QUOTE] It's very confusing at this point. My brother (a Wishful Programming & PHP Teacher) tells me that it's your responsibility to make sure your code doesn't break when someone put in a not expected variable type. Ofcourse in PHP there is a lot more error handling, which I am trying to mimic in Lua. You're right that I would have to give my variable a more descriptive name. Thanks for the help. Even though I'm very experienced in Lua, I seek to learn new things every day. And I like discussing what the best is.
[QUOTE=pilot;51802508]Okay, I understand the problem. Excuse my lack of coding skills, but how exactly would I go about assigning a variable to the entity in a way that it would be able to check if the entity exists after it's spawned?[/QUOTE] Actually, your only problem is that hook.Add would only run once, when the lua code is loaded. Instead, you should use hook.Add every time you create a new corpse. This would also make things work when there's more than one corpse. [lua]local function TakeDamage(self, target, dmg) if target != self then return end if (dmg:GetDamageType() == 8194) then nut.item.spawn("meat", self:GetPos()) self:Remove() end end function ENT:CustomOnKilled(dmginfo,hitgroup) local Corpse = ents.Create("prop_ragdoll") Corpse:SetModel(self:GetModel()) Corpse:SetPos(self:GetPos()) Corpse:SetAngles(self:GetAngles()) Corpse:Spawn() Corpse:Activate() Corpse:SetColor(self:GetColor()) Corpse:SetMaterial(self:GetMaterial()) hook.Add("EntityTakeDamage", Corpse, TakeDamage) end[/lua] The DMG_ enum thing is right though, you really should use the enum.
[CODE] function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end self.Weapon:EmitSound( "weapons/ttt l96a1/awpf.wav" ) self:ShootBullet( 72, 1, 0.01 ) self:TakePrimaryAmmo( 1 ) self.Owner:ViewPunch( Angle( -1, 0, 0 ) ) timer.Simple(0.7,function() self.Weapon:EmitSound("weapons/ttt l96a1/l96_boltup.wav") end) timer.Simple(0.89,function() self.Weapon:EmitSound("weapons/ttt l96a1/l96_boltback.wav") end) timer.Simple(1,function() self.Weapon:EmitSound("weapons/ttt l96a1/l96_boltforward.wav") end) timer.Simple(1.2,function() self.Weapon:EmitSound("weapons/ttt l96a1/l96_boltdown.wav") end) end [/CODE] The problem is, when I shoot, the gun sound emits but gets overwritten with the first timer, how can I emit 2 sounds at the "same" time?
[QUOTE=Deadalus3010;51803454][CODE] function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end self.Weapon:EmitSound( "weapons/ttt l96a1/awpf.wav" ) self:ShootBullet( 72, 1, 0.01 ) self:TakePrimaryAmmo( 1 ) self.Owner:ViewPunch( Angle( -1, 0, 0 ) ) timer.Simple(0.7,function() self.Weapon:EmitSound("weapons/ttt l96a1/l96_boltup.wav") end) timer.Simple(0.89,function() self.Weapon:EmitSound("weapons/ttt l96a1/l96_boltback.wav") end) timer.Simple(1,function() self.Weapon:EmitSound("weapons/ttt l96a1/l96_boltforward.wav") end) timer.Simple(1.2,function() self.Weapon:EmitSound("weapons/ttt l96a1/l96_boltdown.wav") end) end [/CODE] The problem is, when I shoot, the gun sound emits but gets overwritten with the first timer, how can I emit 2 sounds at the "same" time?[/QUOTE] [QUOTE]It is recommended to use sound scripts ( see sound.Add ) over direct file paths. There are many inconsistencies, especially when the sound is played on a Weapon[/QUOTE] Could be something to do with those "inconsistencies." Try [URL="https://wiki.garrysmod.com/page/sound/Add"]sound.Add[/URL] and see if anything changes.
Don't use timers in PrimaryAttack (or any other [url=http://wiki.garrysmod.com/page/Category:Predicted_Hooks]Predicted Hooks[/url]) In this instance use SWEP:Think() to do your sounds. Also using self.Weapon is not advised, as self is the same as self.Weapon in Garry's Mod now. To answer your question you are probably not putting enough delay or the prediction is off because you are using timers. Also, according to the wiki using [url=http://wiki.garrysmod.com/page/sound/Add]sound.Add[/url] is preferred when playing sounds on weapon and using the name field from the structure passed to it. If you need to play two sounds on top of each other you can change the CHAN_ enumeration in sound.Add's structure: [url=http://wiki.garrysmod.com/page/Enums/CHAN]CHAN_ enums[/url]. Use CHAN_USER_BASE + x for the channel where x is the x-th sound to be played on top of each other
Is there a clean way to undo what [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/Droppable]Panel:Droppable[/url] does? I'd rather not remove then re-make the panel.
[QUOTE=MeepDarknessM;51804804]Don't use timers in PrimaryAttack (or any other [url=http://wiki.garrysmod.com/page/Category:Predicted_Hooks]Predicted Hooks[/url]) In this instance use SWEP:Think() to do your sounds. Also using self.Weapon is not advised, as self is the same as self.Weapon in Garry's Mod now. To answer your question you are probably not putting enough delay or the prediction is off because you are using timers. Also, according to the wiki using [url=http://wiki.garrysmod.com/page/sound/Add]sound.Add[/url] is preferred when playing sounds on weapon and using the name field from the structure passed to it. If you need to play two sounds on top of each other you can change the CHAN_ enumeration in sound.Add's structure: [url=http://wiki.garrysmod.com/page/Enums/CHAN]CHAN_ enums[/url]. Use CHAN_USER_BASE + x for the channel where x is the x-th sound to be played on top of each other[/QUOTE] I created a sniper and just wanted to get sounds after you shoot (The bolt sounds). Im not that advanced in GLua that I can fully understand your message. Im sorry. And another thing is, [CODE] sound.Add( { name = "enzo_engine_idle", channel = CHAN_STATIC, volume = 1.0, level = 80, pitch = { 95, 110 }, sound = "vehicles/enzo/idle.wav" } ) [/CODE] How does this code knows when it should be played? This is why I tried to use timers and Emitsound.
[QUOTE=Deadalus3010;51805447]I created a sniper and just wanted to get sounds after you shoot (The bolt sounds). Im not that advanced in GLua that I can fully understand your message. Im sorry. And another thing is, [CODE] sound.Add( { name = "enzo_engine_idle", channel = CHAN_STATIC, volume = 1.0, level = 80, pitch = { 95, 110 }, sound = "vehicles/enzo/idle.wav" } ) [/CODE] How does this code knows when it should be played? This is why I tried to use timers and Emitsound.[/QUOTE] You should be able to use any of the sound functions to play that sound by passing the name of your sound to said functions.
Stupid question, but is it possible to make the skybox have a [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/render/RenderView]render.RenderView[/url] texture?
Sorry, you need to Log In to post a reply to this thread.