Need some advice for this code:

Hey guys,

A friend of mine made this custom TTT weapon (Flashbang) For traitors for me, but it dont seem to work.
By question is, maybe you guys can advice me what is wrong with this code.

BKU (Made TTT) Posted this tutorial:

My friend told me he downloaded the flashbang from here:

Then he sended me this Shared.lua what comes in

/terrortown/entities/weapons/weapon_ttt_flashbang/shared.lua

[lua]
if SERVER then
AddCSLuaFile( “shared.lua” )

end

SWEP.HoldType = “grenade”

if CLIENT then
SWEP.PrintName = “Flashbang”
SWEP.Slot = 2

SWEP.Icon = “VGUI/ttt/icon_nades”
end

SWEP.Base = “weapon_tttbasegrenade”
SWEP.Spawnable = true
SWEP.AdminSpawnable = true

SWEP.ViewModel = “models/weapons/v_eq_flashbang.mdl”
SWEP.WorldModel = “models/weapons/w_eq_flashbang.mdl”
SWEP.Weight = 5
SWEP.AutoSpawnable = true
– really the only difference between grenade weapons: the model and the thrown
– ent.

function SWEP:GetGrenadeName()
return “ttt_flashbang”
end
[/lua]

Then in: /terrortown/entities/entities/ttt_flashbang

There is a Init.lua and a Shared.lua

He merged the Shared + Init together like this:

[lua]
if SERVER then
AddCSLuaFile( “shared.lua” )
include(“shared.lua”)
end

ENT.Type = “anim”
ENT.Base = “ttt_basegrenade_proj”
ENT.Model = Model(“models/weapons/w_eq_flashbang_thrown.mdl”)

local FLASH_INTENSITY = 3000

/---------------------------------------------------------
Initialize
---------------------------------------------------------
/
function ENT:Initialize()

self.Entity:SetModel("models/weapons/w_eq_flashbang_thrown.mdl")
self.Entity:PhysicsInit( SOLID_VPHYSICS )
self.Entity:SetMoveType( MOVETYPE_VPHYSICS )
self.Entity:SetSolid( SOLID_VPHYSICS )
self.Entity:DrawShadow( false )

-- Don't collide with the player
self.Entity:SetCollisionGroup( COLLISION_GROUP_WEAPON )
self.Entity:SetNetworkedString("Owner", "World")

local phys = self.Entity:GetPhysicsObject()

if (phys:IsValid()) then
	phys:Wake()
end

timer.Simple(2,
function()
	if self.Entity then 
		self:Explode() 
	end
end)

end

/---------------------------------------------------------
Explode
---------------------------------------------------------
/
function ENT:Explode()

self.Entity:EmitSound(Sound("Flashbang.Explode"));

for _,pl in pairs(player.GetAll()) do

	local ang = (self.Entity:GetPos() - pl:GetShootPos()):Normalize():Angle()

	local tracedata = {};

	tracedata.start = pl:GetShootPos();
	tracedata.endpos = self.Entity:GetPos();
	tracedata.filter = pl;
	local tr = util.TraceLine(tracedata);

	if (!tr.HitWorld) then
		local dist = pl:GetShootPos():Distance( self.Entity:GetPos() )  
		local endtime = FLASH_INTENSITY / (dist * 2);

		if (endtime > 6) then
			endtime = 6;
		elseif (endtime < 1) then
			endtime = 0;
		end

		simpendtime = math.floor(endtime);
		tenthendtime = math.floor((endtime - simpendtime) * 10);

– if (pl:GetNetworkedFloat(“FLASHED_END”) > CurTime()) then
– pl:SetNetworkedFloat(“FLASHED_END”, endtime + pl:GetNetworkedFloat(“FLASHED_END”) + CurTime() - pl:GetNetworkedFloat(“FLASHED_START”));
– else
pl:SetNetworkedFloat(“FLASHED_END”, endtime + CurTime());
– end

		pl:SetNetworkedFloat("FLASHED_END_START", CurTime());
	end
end
self.Entity:Remove();

end

/---------------------------------------------------------
Think
---------------------------------------------------------
/
function ENT:Think()
end

/---------------------------------------------------------
OnTakeDamage
---------------------------------------------------------
/
function ENT:OnTakeDamage()
end

/---------------------------------------------------------
Use
---------------------------------------------------------
/
function ENT:Use()
end

/---------------------------------------------------------
StartTouch
---------------------------------------------------------
/
function ENT:StartTouch()
end

/---------------------------------------------------------
EndTouch
---------------------------------------------------------
/
function ENT:EndTouch()
end

/---------------------------------------------------------
Touch
---------------------------------------------------------
/
function ENT:Touch()
end

/*---------------------------------------------------------
Think
---------------------------------------------------------*/
function ENT:Think()
end

/*---------------------------------------------------------
Draw
---------------------------------------------------------*/
function ENT:Draw()

	self.Entity:DrawModel()
end

/*---------------------------------------------------------
IsTranslucent
---------------------------------------------------------*/
function ENT:IsTranslucent()

	return true
end

function FlashEffect() if LocalPlayer():GetNetworkedFloat("FLASHED_END") > CurTime() then

	local pl 			= LocalPlayer();
	local FlashedEnd 		= pl:GetNetworkedFloat("FLASHED_END")
	local FlashedStart 	= pl:GetNetworkedFloat("FLASHED_START")
	
	local Alpha

	if(FlashedEnd - CurTime() > FLASHTIMER) then
		Alpha = 150;
	else
		local FlashAlpha = 1 - (CurTime() - (FlashedEnd - FLASHTIMER)) / (FlashedEnd - (FlashedEnd - FLASHTIMER));
		Alpha = FlashAlpha * 150;
	end
	
		surface.SetDrawColor(255, 255, 255, math.Round(Alpha))
		surface.DrawRect(0, 0, surface.ScreenWidth(), surface.ScreenHeight())
	end 
end

hook.Add("HUDPaint", "FlashEffect", FlashEffect);

	local function StunEffect()
	local pl 			= LocalPlayer();
	local FlashedEnd 		= pl:GetNetworkedFloat("FLASHED_END")
	local FlashedStart 	= pl:GetNetworkedFloat("FLASHED_START")

	if (FlashedEnd > CurTime() and FlashedEnd - EFFECT_DELAY - CurTime() <= FLASHTIMER) then
		local FlashAlpha = 1 - (CurTime() - (FlashedEnd - FLASHTIMER)) / (FLASHTIMER);
		DrawMotionBlur( 0, FlashAlpha / ((FLASHTIMER + EFFECT_DELAY) / (FLASHTIMER * 4)), 0);

	elseif (FlashedEnd > CurTime()) then
		DrawMotionBlur( 0, 0.01, 0);
	else
		DrawMotionBlur( 0, 0, 0);
	end
end

hook.Add( "RenderScreenspaceEffects", "StunEffect", StunEffect )

end

ENT.Type = “anim”

/---------------------------------------------------------
OnRemove
---------------------------------------------------------
/
function ENT:OnRemove()
end

/---------------------------------------------------------
PhysicsUpdate
---------------------------------------------------------
/
function ENT:PhysicsUpdate()
end

/---------------------------------------------------------
PhysicsCollide
---------------------------------------------------------
/
function ENT:PhysicsCollide(data,phys)
if data.Speed > 50 then
self.Entity:EmitSound(Sound(“Flashbang.Bounce”))
end

local impulse = -data.Speed * data.HitNormal * .4 + (data.OurOldVelocity * -.6)
phys:ApplyForceCenter(impulse)

end
[/lua]

I hope you guys can understand this long post.

If you guys need to see the orig Init and shared.lua i can post them

By question basicly is, what makes TTT not see that this is a flashbang?

Help please? :frowning:

You show us hundreds of lines of code and you don’t even have an error or a clue to what’s wrong?
All I can do in this situation is to rate you optimistic.

Well it doesnt give a specific error cuz the code is good. You should only look at the first code, the last 3 are the original code’s from the file itself.

The problem actolly is that it still explodes as incendiary (sorry for the fail spelling) while it should explode as flashbang but for some reason TTT dont see it as a flashbang so thats my question,
What is the problem that TTT dont see this nade to explode as a flashbang?

I really need some help with this code please… ?

Why did you post all of the code you did if only one section is used?

yeah alright ill change it

Ok changed the code, I hope its more Clear now.

Never mind made it myself working already, Thx anyways :slight_smile:

Is this flashbang now working, because i want a flashbang for my server too :smiley:

No, it’s outdated.

Okay :frowning: