I'm trying to make a drug gun for ttt but it wont work, just says its a null entity. Could someone please tell me where I've gone wrong.
[lua]
if SERVER then
AddCSLuaFile( "shared.lua" )
SWEP.HoldType = "pistol"
end
if ( CLIENT ) then
SWEP.PrintName = "Poison Gun"
SWEP.Author = "Jolly Monkey"
SWEP.Slot = 6
SWEP.SlotPos = 0
SWEP.ViewModelFOV = 54
SWEP.ViewModelFlip = false
end
SWEP.Base = "weapon_tttbase"
SWEP.Primary.Recoil = 4
SWEP.Primary.Damage = 5
SWEP.Primary.Delay = 1.0
SWEP.Primary.Cone = 0.01
SWEP.Primary.ClipSize = 4
SWEP.Primary.Automatic = false
SWEP.Primary.DefaultClip = 4
SWEP.Primary.ClipMax = 4
-- if I run out of ammo types, this weapon is one I could move to a custom ammo
-- handling strategy, because you never need to pick up ammo for it
SWEP.Primary.Ammo = "AR2AltFire"
SWEP.IsEquipment = true
SWEP.ViewModel = "models/weapons/v_357.mdl"
SWEP.WorldModel = "models/weapons/w_357.mdl"
SWEP.Primary.Sound = Sound( "Weapon_USP.SilencedShot" )
SWEP.Tracer = "AR2Tracer"
-- models\weapons\flare.mdl
function PoisonTarget(att, path, dmginfo)
if SERVER and path.Hit and path.HitNonWorld and ValidEntity(path.Entity) then
local ent = path.Entity
local dur = ent:IsPlayer() and 5 or 10
if ent:IsPlayer() then
ent:SetNWFloat("drugs_start", CurTime())
ent:SetNetworkedFloat("drugs_end", CurTime())
ent.ignite_info = {att=dmginfo:GetAttacker(), infl=dmginfo:GetInflictor()}
timer.Simple(dur + 0.1, function()
if ValidEntity(ent) then
ent.ignite_info = nil
end
end)
end
if ent:GetClass() == "prop_ragdoll" then
local mid = ent:LocalToWorld(ent:OBBCenter())
mid.z = mid.z + 25
util.PaintDown(mid, "Scorch", ent)
SafeRemoveEntityDelayed(ent, 5)
end
end
end
function SWEP:ShootFlare()
local cone = self.Primary.Cone
local bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( cone, cone, 0 )
bullet.Tracer = 1
bullet.Force = 2
bullet.Damage = self.Primary.Damage
bullet.TracerName = self.Tracer
bullet.Callback = PoisonTarget
self.Owner:FireBullets( bullet )
end
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
if not self:CanPrimaryAttack() then return end
self.Weapon:EmitSound( self.Primary.Sound )
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self:ShootFlare()
self:TakePrimaryAmmo( 1 )
if ValidEntity(self.Owner) then
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
end
if ( (SinglePlayer() && SERVER) || CLIENT ) then
self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
end
end
function SWEP:SecondaryAttack()
end
TRANSITION_TIME = 6
if(CLIENT)then
function GotDruggedByAHippy()
if( pl:GetNetworkedFloat("drugs_start") + TRANSITION_TIME > CurTime() ) then
local s = ply:GetNetworkedFloat("drugs_start");
local e = s + TRANSITION_TIME;
local c = CurTime();
local pf = (c-s) / (e-s);
tab[ "$pp_colour_colour" ] = 1 + pf*3
tab[ "$pp_colour_brightness" ] = -pf*0.19
tab[ "$pp_colour_contrast" ] = 1 + pf*5.31
DrawBloom(0.65, (pf^2)*0.1, 9, 9, 4, 7.7,255,255,255)
DrawColorModify( tab )
elseif( pl:GetNetworkedFloat("drugs_end") - TRANSITION_TIME < CurTime() )then
local e = pl:GetNetworkedFloat("drugs_end");
local s = e - TRANSITION_TIME;
local c = CurTime();
local pf = 1 - (c-s) / (e-s);
tab[ "$pp_colour_colour" ] = 1 + pf*3
tab[ "$pp_colour_brightness" ] = -pf*0.19
tab[ "$pp_colour_contrast" ] = 1 + pf*5.31
DrawBloom(0.65, (pf^2)*0.1, 9, 9, 4, 7.7,255,255,255)
DrawColorModify( tab )
else
tab[ "$pp_colour_colour" ] = 1 + 3
tab[ "$pp_colour_brightness" ] = -0.19
tab[ "$pp_colour_contrast" ] = 1 + 5.31
DrawBloom(0.65, 0.1, 9, 9, 4, 7.7,255,255,255)
DrawColorModify( tab )
end
end
end
hook.Add("RenderScreenspaceEffects", "DruggedUpArentIDickHead", GotDruggedByAHippy)
-- lua_openscript \terrortown\entities\weapons\weapon_ttt_drug/shared.lua
[/lua]
Fuck if anyone wants to look through all that for errors, however plentiful they may be.
Just look through your console for errors and go from there.
Lol, it says cannot index global "SWEP" when I try openscript, but then it said that when I tried to do the same for working guns. And by that do u mean I'm an epic fail?
P.S if you did get it working I would be very grateful and maybe give u a cookie.
Of course you are going to get that error, the SWEP table is long gone by the time you get a chance to lua_openscript it. Just check for errors in the console.
Aye aye captain.
[editline]10:18PM[/editline]
Hook 'DruggedUpArentIDickHead' Failed: weapons/weapon_ttt_drug/shared.lua:122: attempt to index global 'ply' (a nil value)
:S
[lua]
if SERVER then
AddCSLuaFile( "shared.lua" )
SWEP.HoldType = "pistol"
end
if ( CLIENT ) then
SWEP.PrintName = "Poison Gun"
SWEP.Author = "Jolly Monkey"
SWEP.Slot = 6
SWEP.SlotPos = 0
SWEP.ViewModelFOV = 54
SWEP.ViewModelFlip = false
end
SWEP.Base = "weapon_tttbase"
SWEP.Primary.Recoil = 4
SWEP.Primary.Damage = 5
SWEP.Primary.Delay = 1.0
SWEP.Primary.Cone = 0.01
SWEP.Primary.ClipSize = 4
SWEP.Primary.Automatic = false
SWEP.Primary.DefaultClip = 4
SWEP.Primary.ClipMax = 4
-- if I run out of ammo types, this weapon is one I could move to a custom ammo
-- handling strategy, because you never need to pick up ammo for it
SWEP.Primary.Ammo = "AR2AltFire"
SWEP.IsEquipment = true
SWEP.ViewModel = "models/weapons/v_357.mdl"
SWEP.WorldModel = "models/weapons/w_357.mdl"
SWEP.Primary.Sound = Sound( "Weapon_USP.SilencedShot" )
SWEP.Tracer = "AR2Tracer"
-- models\weapons\flare.mdl
function PoisonTarget(att, path, dmginfo)
if SERVER and path.Hit and path.HitNonWorld and ValidEntity(path.Entity) then
local ent = path.Entity
local dur = ent:IsPlayer() and 5 or 10
if ent:IsPlayer() then
ent:SetNWFloat("drugs_start", CurTime())
ent:SetNetworkedFloat("drugs_end", CurTime())
ent.ignite_info = {att=dmginfo:GetAttacker(), infl=dmginfo:GetInflictor()}
timer.Simple(dur + 0.1, function()
if ValidEntity(ent) then
ent.ignite_info = nil
end
end)
end
if ent:GetClass() == "prop_ragdoll" then
local mid = ent:LocalToWorld(ent:OBBCenter())
mid.z = mid.z + 25
util.PaintDown(mid, "Scorch", ent)
SafeRemoveEntityDelayed(ent, 5)
end
end
end
function SWEP:ShootFlare()
local cone = self.Primary.Cone
local bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( cone, cone, 0 )
bullet.Tracer = 1
bullet.Force = 2
bullet.Damage = self.Primary.Damage
bullet.TracerName = self.Tracer
bullet.Callback = PoisonTarget
self.Owner:FireBullets( bullet )
end
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
if not self:CanPrimaryAttack() then return end
self.Weapon:EmitSound( self.Primary.Sound )
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self:ShootFlare()
self:TakePrimaryAmmo( 1 )
if ValidEntity(self.Owner) then
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
end
if ( (SinglePlayer() && SERVER) || CLIENT ) then
self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
end
end
function SWEP:SecondaryAttack()
end
TRANSITION_TIME = 6
if(CLIENT)then
function GotDruggedByAHippy()
if( pl:GetNetworkedFloat("drugs_start") + TRANSITION_TIME > CurTime() ) then
local s = pl:GetNetworkedFloat("drugs_start");
local e = s + TRANSITION_TIME;
local c = CurTime();
local pf = (c-s) / (e-s);
tab[ "$pp_colour_colour" ] = 1 + pf*3
tab[ "$pp_colour_brightness" ] = -pf*0.19
tab[ "$pp_colour_contrast" ] = 1 + pf*5.31
DrawBloom(0.65, (pf^2)*0.1, 9, 9, 4, 7.7,255,255,255)
DrawColorModify( tab )
elseif( pl:GetNetworkedFloat("drugs_end") - TRANSITION_TIME < CurTime() )then
local e = pl:GetNetworkedFloat("drugs_end");
local s = e - TRANSITION_TIME;
local c = CurTime();
local pf = 1 - (c-s) / (e-s);
tab[ "$pp_colour_colour" ] = 1 + pf*3
tab[ "$pp_colour_brightness" ] = -pf*0.19
tab[ "$pp_colour_contrast" ] = 1 + pf*5.31
DrawBloom(0.65, (pf^2)*0.1, 9, 9, 4, 7.7,255,255,255)
DrawColorModify( tab )
else
tab[ "$pp_colour_colour" ] = 1 + 3
tab[ "$pp_colour_brightness" ] = -0.19
tab[ "$pp_colour_contrast" ] = 1 + 5.31
DrawBloom(0.65, 0.1, 9, 9, 4, 7.7,255,255,255)
DrawColorModify( tab )
end
end
end
hook.Add("RenderScreenspaceEffects", "DruggedUpArentIDickHead", GotDruggedByAHippy)
-- lua_openscript \terrortown\entities\weapons\weapon_ttt_drug/shared.lua
[/lua]
Try that.
I'm sorry to say it, but it still doesn't work and you don't win the cookie :'(.
I win cookie?
[lua]if SERVER then
AddCSLuaFile( "shared.lua" )
SWEP.HoldType = "pistol"
end
if ( CLIENT ) then
SWEP.PrintName = "Poison Gun"
SWEP.Author = "Jolly Monkey"
SWEP.Slot = 6
SWEP.SlotPos = 0
SWEP.ViewModelFOV = 54
SWEP.ViewModelFlip = false
end
SWEP.Base = "weapon_tttbase"
SWEP.Primary.Recoil = 4
SWEP.Primary.Damage = 5
SWEP.Primary.Delay = 1.0
SWEP.Primary.Cone = 0.01
SWEP.Primary.ClipSize = 4
SWEP.Primary.Automatic = false
SWEP.Primary.DefaultClip = 4
SWEP.Primary.ClipMax = 4
-- if I run out of ammo types, this weapon is one I could move to a custom ammo
-- handling strategy, because you never need to pick up ammo for it
SWEP.Primary.Ammo = "AR2AltFire"
SWEP.IsEquipment = true
SWEP.ViewModel = "models/weapons/v_357.mdl"
SWEP.WorldModel = "models/weapons/w_357.mdl"
SWEP.Primary.Sound = Sound( "Weapon_USP.SilencedShot" )
SWEP.Tracer = "AR2Tracer"
-- models\weapons\flare.mdl
function PoisonTarget(att, path, dmginfo)
if SERVER and path.Hit and path.HitNonWorld and ValidEntity(path.Entity) then
local ent = path.Entity
local dur = ent:IsPlayer() and 5 or 10
if ent:IsPlayer() then
ent:SetNWFloat("drugs_start", CurTime())
ent:SetNetworkedFloat("drugs_end", CurTime())
ent.ignite_info = {att=dmginfo:GetAttacker(), infl=dmginfo:GetInflictor()}
timer.Simple(dur + 0.1, function()
if ValidEntity(ent) then
ent.ignite_info = nil
end
end)
end
if ent:GetClass() == "prop_ragdoll" then
local mid = ent:LocalToWorld(ent:OBBCenter())
mid.z = mid.z + 25
util.PaintDown(mid, "Scorch", ent)
SafeRemoveEntityDelayed(ent, 5)
end
end
end
function SWEP:ShootFlare()
local cone = self.Primary.Cone
local bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( cone, cone, 0 )
bullet.Tracer = 1
bullet.Force = 2
bullet.Damage = self.Primary.Damage
bullet.TracerName = self.Tracer
bullet.Callback = PoisonTarget
self.Owner:FireBullets( bullet )
end
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
if not self:CanPrimaryAttack() then return end
self.Weapon:EmitSound( self.Primary.Sound )
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
self:ShootFlare()
self:TakePrimaryAmmo( 1 )
if ValidEntity(self.Owner) then
self.Owner:SetAnimation( PLAYER_ATTACK1 )
self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
end
if ( (SinglePlayer() && SERVER) || CLIENT ) then
self.Weapon:SetNetworkedFloat( "LastShootTime", CurTime() )
end
end
function SWEP:SecondaryAttack()
end
TRANSITION_TIME = 6
if(CLIENT)then
function GotDruggedByAHippy()
if( LocalPlayer():GetNetworkedFloat("drugs_start") + TRANSITION_TIME > CurTime() ) then
local s = LocalPlayer():GetNetworkedFloat("drugs_start");
local e = s + TRANSITION_TIME;
local c = CurTime();
local pf = (c-s) / (e-s);
tab[ "$pp_colour_colour" ] = 1 + pf*3
tab[ "$pp_colour_brightness" ] = -pf*0.19
tab[ "$pp_colour_contrast" ] = 1 + pf*5.31
DrawBloom(0.65, (pf^2)*0.1, 9, 9, 4, 7.7,255,255,255)
DrawColorModify( tab )
elseif( LocalPlayer():GetNetworkedFloat("drugs_end") - TRANSITION_TIME < CurTime() )then
local e = LocalPlayer():GetNetworkedFloat("drugs_end");
local s = e - TRANSITION_TIME;
local c = CurTime();
local pf = 1 - (c-s) / (e-s);
tab[ "$pp_colour_colour" ] = 1 + pf*3
tab[ "$pp_colour_brightness" ] = -pf*0.19
tab[ "$pp_colour_contrast" ] = 1 + pf*5.31
DrawBloom(0.65, (pf^2)*0.1, 9, 9, 4, 7.7,255,255,255)
DrawColorModify( tab )
else
tab[ "$pp_colour_colour" ] = 1 + 3
tab[ "$pp_colour_brightness" ] = -0.19
tab[ "$pp_colour_contrast" ] = 1 + 5.31
DrawBloom(0.65, 0.1, 9, 9, 4, 7.7,255,255,255)
DrawColorModify( tab )
end
end
hook.Add("RenderScreenspaceEffects", "DruggedUpArentIDickHead", GotDruggedByAHippy)
end
[/lua]
Here you go freshly baked just for you :). [url]http://img.photobucket.com/albums/v665/mld82/FoodStuffs/IMG_1250.jpg[/url]
Btw it still wont work :'( when I try to use it, it says its a null entity. If I try to open script it it says
Couldn't include file '\terrortown\entities\weapons\weapon_ttt_drug\shared.lua' (File not found)
even though it is there. Why oh why :(
Any errors relating to the weapon when you first spawn?
No, not as far as I can see, I looked through them all and they were wire related.
[editline]11:10AM[/editline]
Btw could me using the tttbase be making any difference?
[QUOTE=sintwin;20871548]No, not as far as I can see, I looked through them all and they were wire related.
[editline]11:10AM[/editline]
Btw could me using the tttbase be making any difference?[/QUOTE]
I don't know, maybe.
Sorry, you need to Log In to post a reply to this thread.