Emp 2.0

Hey,
I have some weird problems with my EMP SWEP. The SWEP includes a HUD. The HUD should always appear if I reload the weapon. But this won’t works.

So here is my code:

[lua]
if ( SERVER ) then

AddCSLuaFile( “shared.lua” )

SWEP.Weight = 5
SWEP.AutoSwitchTo = true
SWEP.AutoSwitchFrom = true

end

if ( CLIENT ) then

SWEP.PrintName = “EMP”;
SWEP.Slot = 3;
SWEP.SlotPos = 1;
SWEP.DrawAmmo = true;
SWEP.DrawCrosshair = true;

end

SWEP.Author = “Pennerlord”;
SWEP.Contact = “”;
SWEP.Purpose = “Paralyzing Cars”;
SWEP.Instructions = “Left click to paralyze a car!”;

SWEP.Spawnable = false
SWEP.AdminSpawnable = true

SWEP.ViewModel = “models/weapons/v_pistol.mdl”
SWEP.WorldModel = “models/weapons/w_pistol.mdl”
SWEP.HoldType = “pistol”

SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 10
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = “357”

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “”

//SWEP.isReloading = true

/----------------------------------------------------------
Name: SWEP:Initialize()
Desc: Called when the weapon is first loaded
----------------------------------------------------------
/

function SWEP:Initialize( )
self.TimeReload = 15
// self.StartReload = CurTime()
// self.EndReload = CurTime() + self.TimeReload
// self.isReloading = true
end

/--------------------------
Reload
--------------------------
/

function SWEP:Reload()
if ( self.Weapon:Clip1() > 0 ) then return end
if self.isReloading then return end

self.Owner:PrintMessage( HUD_PRINTCENTER, "Reloading...")
timer.Create("ReloadTimer", 15, 1, self.DelayReload, self)

self.isReloading = true
self.StartReload = CurTime()
self.EndReload = CurTime() + self.TimeReload

if self.isReloading then
	player.GetByID( 1 ):PrintMessage( HUD_PRINTTALK, "WHAZ UP?" )
end

end

/--------------------------
Primary Attack
--------------------------
/

function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
local eyetrace = self.Owner:GetEyeTrace();
if !eyetrace.Entity:IsVehicle() then return end
local Dist = (self:GetPos() - eyetrace.Entity:GetPos()):Length()
if (Dist > 300) then return end

self.Weapon:EmitSound("Weapon_StunStick.Activate")
self.BaseClass.ShootEffects( self )
self:TakePrimaryAmmo(1)

if (!SERVER) then return end

if eyetrace.Entity:IsVehicle() then
	self.Owner:PrintMessage( HUD_PRINTCENTER, "Car is paralyzed now!")
	self:taseVehicle(eyetrace.Entity)
end

end

/--------------------------
Paralyze the car
--------------------------
/

function SWEP:taseVehicle(eyetrace)
eyetrace:EmitSound(“vehicles/apc/apc_shutdown.wav”)
eyetrace:SetColor(0,0,255,255)
eyetrace:Fire(“TurnOff”, “1”, 0)
eyetrace:Fire(“HandBrakeOn”, “1”, 0)
timer.Create(“TaseTimer”, 10, 1, self.retrieve, self, eyetrace)
end

/--------------------------
Bring the car back
--------------------------
/

function SWEP:retrieve(eyetrace)
eyetrace:SetColor(255,255,255,255)
eyetrace:Fire(“TurnOn”, “1”, 0)
eyetrace:Fire(“HandBrakeOff”, “1”, 0)
end

/-------------------------------------------------------------------------
Reload the SWEP and set “self.isReloading” to false after 15 seconds
-------------------------------------------------------------------------
/

function SWEP:DelayReload()
self.Weapon:DefaultReload( ACT_VM_RELOAD )
self.isReloading = false
end

/--------------------------
The EMP HUD
--------------------------
/

function SWEP:DrawHUD()
if self.isReloading then
local time = self.EndReload - self.StartReload
local curtime = CurTime() - self.StartReload
local status = curtime/time
local BarWidth = status * 20

	draw.RoundedBox(0, 5, ScrH() - 15 - 100, BarWidth, 15, Color(255,0,0,255))
	draw.SimpleText("Test", "default", 10, ScrH() - 15 - 120, Color(255,255,255,255))
end

end
[/lua]

I will be glad if somebody could help me.

This belongs in the Questions subforum. Please read the sticky before posting.

Oh sry, I hadn’t seen the sub forums because they are on the bottom of the page.

You need to initialize self.IsReloading, otherwise it will try to do the if statement right away and fail. So initialize it to false.

Well the rules sticky has links to all of them and explains that. You probably should have read it.

It’s still not working.