• Lua Error! My SWEP won't even show up :(
    6 replies, posted
I want to make a SWEP that lowers the gravity of the target, sends them upwards, and then explodes them. The problem could be that ExplodeSubject is not being called right. In that case I could do timer.Simple( 2, function(ento) blah blah end ) but I am unsure. Anybody have advice? [CODE] function SWEP:PrimaryAttack() ento = self.Owner:GetEyeTrace().Entity if ento:IsValid() then ento.SetGravity( -450 ) ento:SetVelocity( Vector( 0, 0, 250 ) ) self.Owner:EmitSound( "gravitywobble.mp3" ) timer.Simple( 2, ExplodeSubject(ento) ) else self.Owner:EmitSound( "notarget.wav" ) end end function SWEP:ExplodeSubject(subject) local explode = ents.Create("env_explosion") explode:SetPos( subject:GetPos() ) explode:SetOwner( self.Owner ) explode:Spawn() explode:SetKeyValue("iMagnitude","175") explode:Fire("Explode", 0, 0 ) explode:EmitSound("weapon_AWP.Single", 400, 400 ) if subject:IsPlayer() then subject:Kill() else subject:Remove() end end [/CODE] [editline]22nd April 2017[/editline] Oops. It doesn't look like I saw this mistake. I'll be back... [CODE] ento.SetGravity( -450 ) [/CODE] Should be a colon, yes? Nope. Still the same. [editline]22nd April 2017[/editline] It seems I should run a [CODE] Entity:IsWorld() [/CODE] test, yes? Still doesn't work! HEEEEEEELP The console is neutral... Here is a pastebin of my script: [url]https://pastebin.com/AU9bF3NM[/url]
[CODE] timer.Simple( 2, function() if IsValid(self) and IsValid(ento) then -- After the two seconds delay the weapon or entity might be invalid (somebody removed the entity, ...) -- Use IsValid checks to avoid "Tried to use a NULL entity!" errors self:ExplodeSubject(ento) end end) [/CODE]
[QUOTE=zoox;52139897][CODE] timer.Simple( 2, function() if IsValid(self) and IsValid(ento) then -- After the two seconds delay the weapon or entity might be invalid (somebody removed the entity, ...) -- Use IsValid checks to avoid "Tried to use a NULL entity!" errors self:ExplodeSubject(ento) end end) [/CODE][/QUOTE] I'll try it when I get home. The fact that surprises me is that the weapon does not even show up, yet produces no console errors. I should also try the folder itself instead of the .gma Good point tho.
That's odd -- I put your script in lua/weapons/weapon_test.lua and it showed up right away
[QUOTE=zoox;52140973]That's odd -- I put your script in lua/weapons/weapon_test.lua and it showed up right away[/QUOTE] I'm adding this snippet now and trying the folder instead of the gma- will be back soon. [CODE] function SWEP:ExplodeSubject(subject) if IsValid(self) and IsValid(subject) then local explode = ents.Create("env_explosion") explode:SetPos( subject:GetPos() ) explode:SetOwner( self.Owner ) explode:Spawn() explode:SetKeyValue("iMagnitude","175") explode:Fire("Explode", 0, 0 ) explode:EmitSound("weapon_AWP.Single", 400, 400 ) if subject:IsPlayer() then subject:Kill() else subject:Remove() end end end [/CODE] [editline][/editline] The problem is mostly solved, yet the target still does not explode. The script cannot call global ExplodeSubject() and identifies it as a nil value. What exactly defines a function as global, though? [URL="https://vid.me/rIZe"]Here's a video.[/URL]
Did you replace [CODE]timer.Simple( 2, ExplodeSubject(ento) )[/CODE] with the snippet I posted earlier?
And that concludes it! I have resolved it myself. Here's the new script on pastebin: [url]https://pastebin.com/M3aFG4Sn[/url] I have another problem but I'll make a new thread because this seems dead. [editline]23rd April 2017[/editline] [QUOTE=zoox;52141426]Did you replace [CODE]timer.Simple( 2, ExplodeSubject(ento) )[/CODE] with the snippet I posted earlier?[/QUOTE] Oops, sorry zoox. Check out the pastebin. I'm sure I did.
Sorry, you need to Log In to post a reply to this thread.