• Print

Author Topic: Seeking a Little Help  (Read 4956 times)

0 Members and 1 Guest are viewing this topic.

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Seeking a Little Help
« on: December 11, 2016, 12:21:50 am »
So I took the original shock command, author I forgot the name of (sorry), and played with it a little to make it suit my tastes a bit more. Yet whenever I execute the command it gives me the following error in the server side console:

Quote
03:18:38 Lua Error: [ERROR] gamemodes/base/gamemode/player.lua:205: Tried to use a NULL entity!
1. GetClass - [C]:-1
 2. old_hook_call - gamemodes/base/gamemode/player.lua:205
  3. unknown - addons/pills/lua/includes/modules/momo/compat.lua:23
   4. TakeDamageInfo - [C]:-1
    5. call - addons/ulx/lua/ulx/modules/sh/bluenova-custom.lua:818
     6. __fn - addons/ulib/lua/ulib/shared/commands.lua:943
      7. unknown - addons/ulib/lua/ulib/shared/commands.lua:1306
       8. pcall - [C]:-1
        9. pcallError - addons/ulib/lua/ulib/shared/util.lua:570
        10. fn - addons/ulib/lua/ulib/server/concommand.lua:67
         11. old_hook_call - addons/ulib/lua/ulib/shared/hook.lua:109
           12. unknown - addons/pills/lua/includes/modules/momo/compat.lua:23

The modified version is the following:

Code: [Select]
local zaptable = {
"ambient/energy/zap1.wav",
"ambient/energy/weld2.wav",
"ambient/levels/labs/electric_explosion3.wav",
"ambient/levels/labs/electric_explosion1.wav"
}

function ulx.shock( calling_ply, target_plys, damage )
for k,v in ipairs( target_plys ) do
local fx = EffectData()
fx:SetEntity( v )
fx:SetOrigin( v:GetPos() )
fx:SetStart( v:GetPos() )
fx:SetScale( 1 )
fx:SetMagnitude( 15 )
util.Effect( "TeslaHitboxes", fx )
v:EmitSound( tostring( table.Random( zaptable ) ) )
local dmginfo = DamageInfo()
dmginfo:SetDamage( damage )
dmginfo:SetDamageType( DMG_DISSOLVE )
v:TakeDamageInfo( dmginfo )

end
ulx.fancyLogAdmin( calling_ply, "#A has shocked #T", target_plys )
end
local shock = ulx.command( CATEGORY_NAME, "ulx shock", ulx.shock, "!shock" )
shock:addParam{ type=ULib.cmds.PlayersArg }
shock:addParam{ type=ULib.cmds.NumArg, default=1000, ULib.cmds.optional }
shock:defaultAccess( ULib.ACCESS_ADMIN )
shock:help( "Shock players" )

I tried everything I could think of and everything either ended with no changed results or the desired outcome of the command (basically a more fun version of slay) being changed.

Thanks for any help, advice, etc.

BlueNova,
« Last Edit: December 11, 2016, 09:52:27 am by JamminR »

Offline Timmy

  • Ulysses Team Member
  • Sr. Member
  • *****
  • Posts: 252
  • Karma: 168
  • Code monkey
Re: Seeking a Little Help
« Reply #1 on: December 12, 2016, 11:56:45 am »
Let's have a closer look at the first error:
Code: [Select]
[ERROR] gamemodes/base/gamemode/player.lua:205: Tried to use a NULL entity!
Right... A bit of code from the base gamemode is trying to use a non-existent entity. Let's check out player.lua:205:
Code: Lua
  1. function GM:PlayerDeath( ply, inflictor, attacker )
  2.     -- ...
  3.     net.WriteString( inflictor:GetClass() ) -- line 205
  4.     -- ...
  5. end

The PlayerDeath hook function is failing because one of its arguments, inflictor, is NULL. The function didn't expect that... it really needs this information! Therefore, we must always tell Garry's Mod who/what inflicted damage on a player.

The part of your script that's responsible for dealing damage:
Code: Lua
  1. local dmginfo = DamageInfo()
  2. dmginfo:SetDamage( damage )
  3. dmginfo:SetDamageType( DMG_DISSOLVE )

Must also include who caused the attack:
Code: Lua
  1. dmginfo:SetAttacker( v )

Giving information about the attacker should fix the error. The PlayerDeath function is smart enough to figure out that the attacker is also the inflictor.
« Last Edit: December 12, 2016, 12:58:37 pm by Timmy »

Offline BlueNova

  • Full Member
  • ***
  • Posts: 113
  • Karma: 13
  • The most powerful force in the universe.
Re: Seeking a Little Help
« Reply #2 on: December 12, 2016, 11:57:06 pm »
Right, missed that somehow, thanks for the help. Works as intended now.

  • Print