What to do with Multiple Lua Files in a Weapon SWEP
0 replies, posted
I recently found a SWEP for a grappling hook written for TTT and decided to add it to my server. Because this is the first kind of non-weapon that I have wanted to add, I was surprised to find that both the weapon and its' rope entity have three different lua files. They both have a init.lua, cl_init.lau, and the usual shared.lua. I have no idea what to do with these other two files. If I simply add the whole thing to my server, it says that the grappling hook is unknown. If anyone could provide some information on how to deal with these other two files, I would be very appreciative. I'll provide the code if it helps.
weapon_ttt_grapplehook:
init.lau:
[CODE]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
CreateConVar("rope_distance", 2000, false)[/CODE]
cl_init.lua:
[CODE]include('shared.lua')
function SWEP:CustomAmmoDisplay()
self.AmmoDisplay = self.AmmoDisplay or {}
self.AmmoDisplay.Draw = false
self.AmmoDisplay.PrimaryClip = 1
self.AmmoDisplay.PrimaryAmmo = -1
self.AmmoDisplay.SecondaryAmmo = -1
return self.AmmoDisplay
end
function SWEP:SetWeaponHoldType( t )
end[/CODE]
shared.lau:
[CODE]if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "pistol"
if CLIENT then
SWEP.PrintName = "Spiderman's Gun"
SWEP.Slot = 6
SWEP.Icon = "EDIT ME" //Edit the image to anything you wish.
end
SWEP.CanBuy = { ROLE_DETECTIVE }
SWEP.LimitedStock = true
SWEP.AllowDrop = true
SWEP.AutoSpawnable = false
SWEP.EquipMenuData = {
type = "Spidermans Gun",
desc = "Zip through the skys as Spiderman would!"
};
SWEP.AmmoEnt = "item_ammo_pistol_ttt"
SWEP.Kind = WEAPON_EQUIP1
SWEP.Base = "weapon_tttbase"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
local sndPowerUp = Sound("rope_hit.wav")
local sndPowerDown = Sound ("shoot_rope.wav")
local sndTooFar = Sound ("to_far.wav")
SWEP.IronSightsPos = Vector( 6.05, -5, 2.4 )
SWEP.IronSightsAng = Vector( 2.2, -0.1, 0 )
function SWEP:Initialize()
nextshottime = CurTime()
end
function SWEP:Think()
if (!self.Owner || self.Owner == NULL) then return end
if ( self.Owner:KeyPressed( IN_ATTACK ) ) then
self:StartAttack()
elseif ( self.Owner:KeyDown( IN_ATTACK ) && inRange ) then
self:UpdateAttack()
elseif ( self.Owner:KeyReleased( IN_ATTACK ) && inRange ) then
self:EndAttack( true )
end
if ( self.Owner:KeyPressed( IN_ATTACK2 ) ) then
self:Attack2()
end
end
function SWEP:DoTrace( endpos )
local trace = {}
trace.start = self.Owner:GetShootPos()
trace.endpos = trace.start + (self.Owner:GetAimVector() * 14096)
if(endpos) then trace.endpos = (endpos - self.Tr.HitNormal * 7) end
trace.filter = { self.Owner, self.Weapon }
self.Tr = nil
self.Tr = util.TraceLine( trace )
end
function SWEP:StartAttack()
local gunPos = self.Owner:GetShootPos()
local disTrace = self.Owner:GetEyeTrace()
local hitPos = disTrace.HitPos
local x = (gunPos.x - hitPos.x)^2;
local y = (gunPos.y - hitPos.y)^2;
local z = (gunPos.z - hitPos.z)^2;
local distance = math.sqrt(x + y + z);
local distanceCvar = GetConVarNumber("rope_distance")
inRange = false
if distance <= distanceCvar then
inRange = true //100
end
if inRange then
if (SERVER) then
if (!self.Beam) then
self.Beam = ents.Create( "rope" )
self.Beam:SetPos( self.Owner:GetShootPos() )
self.Beam:Spawn()
end
self.Beam:SetParent( self.Owner )
self.Beam:SetOwner( self.Owner )
end
self:DoTrace()
self.speed = 10000
self.startTime = CurTime() - self.speed
self.endTime = CurTime() + self.speed
local self.dt = -1
if (SERVER && self.Beam) then
self.Beam:GetTable():SetEndPos( self.Tr.HitPos )
end
self:UpdateAttack()
self.Weapon:EmitSound( sndPowerDown )
else
self.Weapon:EmitSound( sndTooFar )
end
end
function SWEP:UpdateAttack()
self.Owner:LagCompensation( true )
if (!endpos) then endpos = self.Tr.HitPos end
if (SERVER && self.Beam) then
self.Beam:GetTable():SetEndPos( endpos )
end
lastpos = endpos
if ( self.Tr.Entity:IsValid() ) then
endpos = self.Tr.Entity:GetPos()
if ( SERVER ) then
self.Beam:GetTable():SetEndPos( endpos )
end
end
local vVel = (endpos - self.Owner:GetPos())
local Distance = endpos:Distance(self.Owner:GetPos())
local et = (self.startTime + (Distance/self.speed))
if(self.dt != 0) then
self.dt = (et - CurTime()) / (et - self.startTime)
end
if(self.dt < 0) then
self.Weapon:EmitSound( sndPowerUp )
self.dt = 0
end
if(self.dt == 0) then
zVel = self.Owner:GetVelocity().z
vVel = vVel:GetNormalized()*(math.Clamp(Distance,0,7))
end
if( SERVER ) then
local gravity = GetConVarNumber("sv_Gravity")
vVel:Add(Vector(0,0,(gravity/100)*1.3))
if(zVel < 0) then
vVel:Sub(Vector(0,0,zVel/100))
end //prob
self.Owner:SetVelocity(vVel)
end
endpos = nil
self.Owner:LagCompensation( false )
end
function SWEP:EndAttack( shutdownsound )
if ( shutdownsound ) then
self.Weapon:EmitSound( sndPowerDown )
end
if ( CLIENT ) then return end
if ( !self.Beam ) then return end
self.Beam:Remove()
self.Beam = nil
end
function SWEP:Attack2()
if (CLIENT) then return end
local CF = self.Owner:GetFOV()
if CF == 90 then
self.Owner:SetFOV(30,.3)
elseif CF == 30 then
self.Owner:SetFOV(90,.3)
end
end
function SWEP:Holster()
self:EndAttack( false )
return true
end
function SWEP:OnRemove()
self:EndAttack( false )
return true
end
function SWEP:PrimaryAttack()
end
function SWEP:SecondaryAttack()
end[/CODE]
rope:
init.lau:
[CODE]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
local sndOnline = Sound( "hl1/fvox/activated.wav" )
/*---------------------------------------------------------
Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()
self.Entity:DrawShadow( false )
self.Entity:SetSolid( SOLID_NONE )
end
function ENT:Think()
end
[/CODE]
cl_init.lua:
[CODE]include('shared.lua')
local matBeam = Material( "cable/blue_elec" )
/*---------------------------------------------------------
Name: Initialize
---------------------------------------------------------*/
function ENT:Initialize()
self.Size = 0
self.MainStart = self.Entity:GetPos()
self.MainEnd = self:GetEndPos()
self.dAng = (self.MainEnd - self.MainStart):Angle()
self.speed = 10000
self.startTime = CurTime()
self.endTime = CurTime() + self.speed
self.dt = -1
end
function ENT:Think()
self.Entity:SetRenderBoundsWS( self:GetEndPos(), self.Entity:GetPos(), Vector()*8 )
self.Size = math.Approach( self.Size, 1, 10*FrameTime() )
end
function ENT:DrawMainBeam( StartPos, EndPos, dt, dist )
local TexOffset = 0
local ca = Color(255,255,255,255)
EndPos = StartPos + (self.dAng * ((1 - dt)*dist))
-- Beam effect
render.SetMaterial( matBeam )
render.DrawBeam( EndPos, StartPos,
2,
TexOffset*-0.4, TexOffset*-0.4 + StartPos:Distance(EndPos) / 256,
ca )
end
function ENT:Draw()
local Owner = self.Entity:GetOwner()
if (!Owner || Owner == NULL) then return end
local StartPos = self.Entity:GetPos()
local EndPos = self:GetEndPos()
local ViewModel = Owner == LocalPlayer()
if (EndPos == Vector(0,0,0)) then return end
if ( ViewModel ) then
local vm = Owner:GetViewModel()
if (!vm || vm == NULL) then return end
local attachment = vm:GetAttachment( 1 )
StartPos = attachment.Pos
else
local vm = Owner:GetActiveWeapon()
if (!vm || vm == NULL) then return end
local attachment = vm:
Sorry, you need to Log In to post a reply to this thread.