So I was trying to fix the rest of the errors present on an updated Master Sword SWEP, and I also got in contact with the (fixed Sword) creator for permission to work on this. I got every technical errors gotten rid of, but adding a SetWeaponHoldType seems to do absolutely nothing to the SWEP. Right now, the player looks like they're holding the weapon like a pistol, meaning there's no swing animation to indicate that the player is attacking.
Here's the code!
[CODE]if (SERVER) then
AddCSLuaFile("shared.lua")
AddCSLuaFile("cl_init.lua")
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
end
if (CLIENT) then
SWEP.PrintName = "Master Sword"
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = false
SWEP.CSMuzzleFlashes = false
end
SWEP.Author = "jA_cOp, spin attack mods by SpazeGlitch"
SWEP.Contact = ""
SWEP.Purpose = "Slaughter your enemies, Link-style."
SWEP.Instructions = "Primary Fire: Regular Attack\nSecondary Fire: Jump Attack\nReload: Spin Attack\nUse+Secondary Fire: Switch Spin Attacks"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.WorldModel = "models/weapons/v_masters.mdl"
SWEP.ViewModel = "models/weapons/v_masters.mdl"
util.PrecacheModel(SWEP.ViewModel)
util.PrecacheModel(SWEP.WorldModel)
SWEP.SetWeaponHoldType = "melee2"
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.ReloadRate = 1
SWEP.JumpRefire = false
SWEP.OldSpin = 0
/*---------------------------------------------------------
Initialize
---------------------------------------------------------*/
function SWEP:Initialize()
end
/*---------------------------------------------------------
Reload (Spin attack)
---------------------------------------------------------*/
SWEP.Spinning = 0
function SWEP:Reload()
if self.ReloadRate == 0 then return end
if SERVER then self.Owner:EmitSound(Sound("Zsword/oot-AdultLink_SwordSpin"..tostring(math.random(1,2))..".wav")) end
if self.OldSpin == 1 then
self.ReloadRate = 0
timer.Simple(1, function() self.Weapon:ReloadReset() end)
timer.Simple(4, function() self.Weapon:ReloadReset2() end)
self.Spinning = 1
if SERVER then
self.Owner:GodEnable()
self.EffectTable = {}
for i = 1,20 do
local firetrail = ents.Create("env_smoketrail")
table.insert(self.EffectTable,firetrail)
end
for _,ent in pairs(self.EffectTable) do
ent:SetPos(self.Owner:GetPos() + Vector(math.random(0,150),math.random(0,150),35))
ent:SetParent(self.Owner)
ent:SetKeyValue("spawnrate","500")
ent:SetKeyValue("lifetime","0.7")
ent:SetKeyValue("startcolor","255 130 0")
ent:SetKeyValue("endcolor","220 100 0")
ent:SetKeyValue("emittime","2")
ent:SetKeyValue("startsize","20")
ent:SetKeyValue("endsize","1")
ent:SetKeyValue("spawnradius","10")
ent:Spawn()
end
end
end
if self.OldSpin == 0 then
self.ReloadRate = 0
timer.Simple(0.5, function() self.Weapon:ReloadReset() end)
timer.Simple(3.5, function() self.Weapon:ReloadReset2() end)
self.Spinning = 1
if SERVER then
self.Owner:GodEnable()
self.EffectTable = {}
for i = 1,20 do
local firetrail = ents.Create("env_fire")
firetrail:SetPos(self.Owner:GetPos() + Vector(math.sin(self.Owner:GetAimVector():Angle().y+18*i)*100,math.cos(self.Owner:GetAimVector():Angle().y+18*i)*100,0))
firetrail:SetKeyValue("health","0.5")
firetrail:SetKeyValue("firesize","100")
firetrail:SetKeyValue("firetype","plasma")
firetrail:SetKeyValue("damagescale","0")
firetrail:SetKeyValue("spawnflags","10")
table.insert(self.EffectTable,firetrail)
end
for _,ent in pairs(self.EffectTable) do
ent:Fire("StartFire")
ent:Spawn()
end
end
end
end
function SWEP:ReloadReset()
self.Spinning = 0
if SERVER then
self.Owner:GodDisable()
for _,ent in pairs(self.EffectTable) do
ent:Remove()
end
end
end
function SWEP:ReloadReset2()
self.ReloadRate = 1
end
/*---------------------------------------------------------
Think (Jump attack stuff)
---------------------------------------------------------*/
function SWEP:JumpReset()
end
function SWEP:Think()
//Jump think
if self.InAirDmg == 1 then
local trace = {}
trace.start = self.Owner:GetPos()
trace.endpos = self.Owner:GetPos() + (self.Owner:GetUp() * -10)
trace.filter = self.Owner
local tr2 = util.TraceLine(trace)
self.Owner:SetHealth(self.PrevHP)
if tr2.Hit then
self.InAirDmg = 0
self.JumpRefire = false
self.Weapon:SetNextSecondaryFire(CurTime() + 0.8)
self.Weapon:SetNextPrimaryFire(CurTime() + 0.3)
if SERVER then self.Owner:EmitSound(Sound("player/pl_pain5.wav")) end
else
local ang = self.Owner:GetAimVector()
local spos = self.Owner:GetShootPos()
local trace = {}
trace.start = spos
trace.endpos = spos + (ang * 150)
trace.filter = self.Owner
local tr = util.TraceLine(trace)
if tr.HitNonWorld and self.JumpRefire == true then
self.JumpRefire = false
local bullet = {}
bullet.Num=5
bullet.Src = self.Owner:GetShootPos()
bullet.Dir= self.Owner:GetAimVector()
bullet.Spread = Vector(0.1,0.1,0.1)
bullet.Tracer = 0
bullet.Force = 500
bullet.Damage = 200
self.Owner:FireBullets(bullet)
self.Weapon:SendWeaponAnim(ACT_VM_HITCENTER)
timer.Simple(0.5,self.JumpReset,self)
if SERVER then self.Owner:EmitSound(Sound("npc/vort/claw_swing"..tostring(math.random(1,2))..".wav")) end
if SERVER then self.Owner:EmitSound(Sound("Zsword/oot-AdultLink_SwordSpin"..tostring(math.random(1,2))..".wav")) end
end
end
end
//Spinning think
if self.Spinning == 1 then
if self.OldSpin == 0 then
self.Owner:SetEyeAngles(Angle(0,self.Owner:EyeAngles().y + 11,0))
util.BlastDamage(self.Weapon, self.Owner, self.Owner:GetPos(), 200, 10)
end
if self.OldSpin == 1 then
self.Owner:SetEyeAngles(Angle(0,self.Owner:EyeAngles().y + 20,0))
util.BlastDamage(self.Weapon, self.Owner, self.Owner:GetPos(), 200, 5)
end
end
//end (DO NOT UNCOMMENT THIS END!! IT BORKS THE FILE!!)
/*---------------------------------------------------------
The gay ray! (shooting sword :ninja: ) (THIS IS PART OF THE SWEP:THINK!!)
---------------------------------------------------------*/
if SERVER then
self.plasmatablePreCheck = ents.FindByClass("env_citadel_energy_core")
self.plasmatable = {}
for _,core in pairs(self.plasmatablePreCheck) do
if core:GetKeyValues()["globalname"] == self.Owner:Name().."rifleshot" then
table.insert(self.plasmatable,core)
end
end
if self.plasmatable != nil then
for _,plasmashot in pairs(self.plasmatable) do
local trace = {}
trace.start = plasmashot:GetPos()
trace.
Try using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/SetHoldType]Weapon:SetHoldType[/url] instead
[QUOTE=Nick78111;51969266]Try using [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Weapon/SetHoldType]Weapon:SetHoldType[/url] instead[/QUOTE]
Would it look like this?
[CODE]function Weapon:SetHoldType("melee2")
self:SetHoldType (self.HoldType)
end[/CODE]
Or do I put it in SWEP Initialize?
[QUOTE=NarayanK;51969322]Would it look like this?
[CODE]function Weapon:SetHoldType("melee2")
self:SetHoldType (self.HoldType)
end[/CODE]
Or do I put it in SWEP Initialize?[/QUOTE]
This is not how Lua works. Functions for an Entity are initialized as such:
[code]
function ENT/SWEP/EFFECT:FunctionName( argument1, argument2, argument3 )
--Content
end
[/code]
Beyond that, however, this is the wrong approach. SWEP:SetWeaponHoldType must be preserved as it is called internally by SWEP:SetHoldType. Instead, wherever you're calling SetWeaponHoldType, call SetHoldType so it's automatically networked.
Edit:
On further inspection, you're overriding the SetWeaponHoldType function with a string. I'm surprised that didn't cause Lua errors-- instead, you should just be calling the SetHoldType with an argument in the Initialize function. You should really do more research on how Lua works, or programming in general.
tl;dr
Call self:SetHoldType( self.HoldType ) in your SWEP:Initialize function, set SWEP.HoldType somewhere in the outer scope.
[QUOTE=TFA;51969591]This is not how Lua works. Functions for an Entity are initialized as such:
[code]
function ENT/SWEP/EFFECT:FunctionName( argument1, argument2, argument3 )
--Content
end
[/code]
Beyond that, however, this is the wrong approach. SWEP:SetWeaponHoldType must be preserved as it is called internally by SWEP:SetHoldType. Instead, wherever you're calling SetWeaponHoldType, call SetHoldType so it's automatically networked.
Edit:
On further inspection, you're overriding the SetWeaponHoldType function with a string. I'm surprised that didn't cause Lua errors-- instead, you should just be calling the SetHoldType with an argument in the Initialize function. You should really do more research on how Lua works, or programming in general.
tl;dr
Call self:SetHoldType( self.HoldType ) in your SWEP:Initialize function, set SWEP.HoldType somewhere in the outer scope.[/QUOTE]
I found out the problem!
I actually did the thing in your tl;dr as one of the very first modifications I made to the HoldType before I started experimenting, but I listed SWEP.HoldType as SWEP.SetHoldType in the outer scope instead. Thanks!
[IMG]https://i.imgur.com/D5yk5cM.png[/IMG]
The weapon still doesn't swing, though, so now I have to find out what's causing that.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetAnimation]Entity:SetAnimation[/url]
Used with PLAYER_ATTACK1 for attack animations
[QUOTE=TFA;51970181][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/SetAnimation]Entity:SetAnimation[/url]
Used with PLAYER_ATTACK1 for attack animations[/QUOTE]
Thanks! It works now.
Sorry, you need to Log In to post a reply to this thread.