• Print

Author Topic: [Solved] Help with code  (Read 4791 times)

0 Members and 1 Guest are viewing this topic.

Offline The Asian Aimbot

  • Jr. Member
  • **
  • Posts: 74
  • Karma: 2
  • Rise and shine, Mr. Freeman, rise... and shine...
    • Asian Domain GMod Sandbox Server
[Solved] Help with code
« on: April 01, 2017, 09:48:41 am »
I'm trying to make an overpowered SWEP and I've encountered an error:

[Rodrigo Sanchez|2|STEAM_0:0:91442540] Lua Error:

[ERROR] addons/one_paunch_modified/lua/weapons/weapon_one_paunch_modified.lua:97: attempt to call field 'Create' (a nil value)
  1. unknown - addons/one_paunch_modified/lua/weapons/weapon_one_paunch_modified.lua:97

Here's the code:

Code: Lua
  1. function SWEP:SecondaryAttack()
  2.  
  3.         self:EmitSound("punch.wav", 100, 100, 1, CHAN_WEAPON )
  4.         self:PrimaryAttack( true )
  5.         local explode = ents.Create( "env_explosion" )
  6.         if ( SERVER && IsValid( explode ) ) then
  7.         explode:SetPos( ( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 32 ) ) )
  8.         explode:SetOwner( self.Owner )
  9.         explode:Spawn()
  10.         explode:SetKeyValue( "iMagnitude", "2000" )
  11.         explode:Fire( "Explode", 0, 0 )
  12.         end
  13.        
  14.  
  15. end

Any tips/help would be greatly appreciated!  ;) (I'm kinda new to Lua)

Edit: Problem has been solved, I made it check if it was client and valid:

Code: Lua
  1.         self:EmitSound("punch.wav", 100, 100, 1, CHAN_WEAPON )
  2.         self:PrimaryAttack( true )
  3.                 if ( CLIENT ) then return end
  4.         local explode = ents.Create( "env_explosion" )
  5.                 if ( !IsValid( explode ) ) then return end
  6.         explode:SetPos( ( self.Owner:EyePos() + ( self.Owner:GetAimVector() * 32 ) ) )
  7.         explode:SetOwner( self.Owner )
  8.         explode:Spawn()
  9.         explode:SetKeyValue( "iMagnitude", "600" )
  10.         explode:Fire( "Explode", 0, 0 )
  11.         end
« Last Edit: April 01, 2017, 10:32:56 am by The Asian Aimbot »
The Asian Toaster man who escaped the Great Martian Coup of '69, hid in Beijing for 9 months, and was cast away by the FSM. Flew away w/ GoombasTasteGood and hid in Addis Ababa after fleeing to Botswana, then to Canada.

http://www.downloadmorewam.com

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: Help with code
« Reply #1 on: April 01, 2017, 10:06:50 am »
Perhaps this...

Code: Lua
  1. local explode = EffectData()
  2.  
  3. --Your other stuff here
  4.  
  5. util.Effect( "Explosion", explode )
  6.  

If you're going for the explosion effect that is, which I think you are.

Offline The Asian Aimbot

  • Jr. Member
  • **
  • Posts: 74
  • Karma: 2
  • Rise and shine, Mr. Freeman, rise... and shine...
    • Asian Domain GMod Sandbox Server
Re: Help with code
« Reply #2 on: April 01, 2017, 10:13:35 am »
I'll try that, thanks!

I'll need help rigging some other damage system though. point_hurt works, but I want the player's name to appear in the killfeed rather than "Point Hurt"
« Last Edit: April 01, 2017, 10:16:26 am by The Asian Aimbot »
The Asian Toaster man who escaped the Great Martian Coup of '69, hid in Beijing for 9 months, and was cast away by the FSM. Flew away w/ GoombasTasteGood and hid in Addis Ababa after fleeing to Botswana, then to Canada.

http://www.downloadmorewam.com

  • Print