Author Topic: Making the Gravity Gun more "functional".  (Read 2143 times)

0 Members and 3 Guests are viewing this topic.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Making the Gravity Gun more "functional".
« on: September 28, 2013, 05:07:14 PM »
Code: [Select]
rpmods = {}
rpmods.tool = {}
rpmods.jobs = {}

function rpmods.tool.func( ply, ent )
if tobool(FPP.Settings.FPP_GRAVGUN1.noshooting) then
if( !ply or !ply:IsValid() ) then return false end

if( SERVER ) then
ply:GetActiveWeapon().Charges = ply:GetActiveWeapon().Charges or 0
local ammo = ply:GetActiveWeapon().Charges
if( ammo <= 0 ) then
ply:SendLua([[LocalPlayer():GetActiveWeapon().CanShoot = false]])
else
ply:SendLua([[LocalPlayer():GetActiveWeapon().CanShoot = true]])
end
end

if( CLIENT ) then
if( !ply:GetActiveWeapon().CanShoot ) then
return false
end
end

if( !ply:GetActiveWeapon().BeenShot ) then
rpmods.jobs[ply:Team()].func(ply,ent)
ply:GetActiveWeapon().BeenShot = true
timer.Simple(0.5, function() ply:GetActiveWeapon().BeenShot = false end)
if( SERVER ) then DropEntityIfHeld(ent) return false elseif( CLIENT ) then return true end
end

if( SERVER ) then DropEntityIfHeld(ent) end
return false -- ...and return false
end
end
hook.Add("GravGunPunt", "PuntFunction", rpmods.tool.func)

-- Quick and dirty job fix --
-- Example: local TEAM_CITIZEN = TEAM_CITIZEN or <The number returened from player:Team()>
local TEAM_CITIZEN = TEAM_CITIZEN or 1


-- Add Jobs Below This Line --
-- Example: rpmods.jobs[TEAM_CITIZEN] = {func = function( ply ) ply:ChatPrint("Hello World") end} )
rpmods.jobs[TEAM_CITIZEN] = {func = function( ply, ent ) ply:ChatPrint("Hello World") end}

I have made the code above, but I can not figure out why it is not working, and by not working I mean it is not even throwing errors (I wish it was, would make my life easier...).

If any one can help me debug it that would help me out allot. ( Currently I am putting this directly in lua/autorun. )
« Last Edit: September 28, 2013, 05:23:38 PM by HeLLFox_15 »
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Making the Gravity Gun more "functional".
« Reply #1 on: September 28, 2013, 05:37:06 PM »
If you're trying to override another function, you're probably hooking it first (so the original is overriding you).
Experiencing God's grace one day at a time.

Offline LuaTenshi

  • Hero Member
  • *****
  • Posts: 545
  • Karma: 47
  • Just your ordinary moon angel!
    • Mirai.Red
Re: Making the Gravity Gun more "functional".
« Reply #2 on: September 28, 2013, 07:43:20 PM »
If you're trying to override another function, you're probably hooking it first (so the original is overriding you).

I am not really sure what is executed first, or last... so how would I make sure that my script runs last.
I cry every time I see that I am not a respected member of this community.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: Making the Gravity Gun more "functional".
« Reply #3 on: September 29, 2013, 05:42:38 AM »
Create your hook inside an initialization hook and verify the hook timings with print statements.
Experiencing God's grace one day at a time.