• I'm a lua fuckwit and I don't know anything on how to add something.
    11 replies, posted
I got hold of the laserdance gun's script. I'm trying to change it's viewmodel to a custom SMG. Last time I did this on a swep, everything works fine. This time around, not so much. [lua] AddCSLuaFile( "shared.lua" ) SWEP.Author = "" SWEP.Contact = "" SWEP.Purpose = "" SWEP.Instructions = "" if ( CLIENT ) then SWEP.PrintName = "Laser Weapon" // 'Nice' Weapon name (Shown on HUD) SWEP.Slot = 0 // Slot in the weapon selection menu SWEP.SlotPos = 10 // Position in the slot SWEP.DrawAmmo = false // Should draw the default HL2 ammo counter SWEP.DrawCrosshair = true // Should draw the default crosshair SWEP.DrawWeaponInfoBox = false // Should draw the weapon info box SWEP.BounceWeaponIcon = false // Should the weapon icon bounce? SWEP.SwayScale = 1.0 // The scale of the viewmodel sway SWEP.BobScale = 1.0 // The scale of the viewmodel bob SWEP.WepSelectIcon = surface.GetTextureID( "weapons/swep" ) SWEP.VElements = { ["some_unique_name3"] = { type = "Model", model = "models/props_combine/combine_barricade_short02a.mdl", bone = "ValveBiped.base", pos = Vector(1.582, -2.652, -4.481), angle = Angle(-128.663, 13.112, 95.181), size = Vector(0.035, 0.065, 0.021), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name4"] = { type = "Model", model = "models/props_lab/reciever01b.mdl", bone = "ValveBiped.base", pos = Vector(0.001, -0.431, -4.932), angle = Angle(0, 1.743, 87.53), size = Vector(0.157, 0.153, 0.144), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name"] = { type = "Model", model = "models/props_borealis/door_wheel001a.mdl", bone = "ValveBiped.base", pos = Vector(1.297, -1.514, -1.882), angle = Angle(0, 94.694, 0), size = Vector(0.097, 0.097, 0.097), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name1"] = { type = "Model", model = "models/props_c17/FurnitureFireplace001a.mdl", bone = "ValveBiped.base", pos = Vector(0.469, 0, 0), angle = Angle(-0.281, 97.831, -0.631), size = Vector(0.1, 0.1, 0.1), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name2"] = { type = "Model", model = "models/props_c17/oildrum001.mdl", bone = "ValveBiped.base", pos = Vector(0.774, -0.137, -0.551), angle = Angle(7.262, 0.544, 0), size = Vector(0.074, 0.086, 0.162), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""} } end SWEP.ViewModelFOV = 62 SWEP.ViewModelFlip = false SWEP.ViewModel = "models/weapons/v_smg1.mdl" SWEP.WorldModel = "models/weapons/w_357.mdl" SWEP.Author = "Garry Newman" SWEP.Contact = "Don't" SWEP.Purpose = "Kill stuff" SWEP.Instructions = "Click" SWEP.Spawnable = false SWEP.AdminSpawnable = true SWEP.Primary.ClipSize = -1 // Size of a clip SWEP.Primary.DefaultClip = -1 // Default number of bullets in a clip SWEP.Primary.Automatic = false // Automatic/Semi Auto SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = 8 // Size of a clip SWEP.Secondary.DefaultClip = 32 // Default number of bullets in a clip SWEP.Secondary.Automatic = true // Automatic/Semi Auto SWEP.Secondary.Ammo = "none" /*--------------------------------------------------------- Name: Swep:Initialize( ) Desc: Swep has been pulled out ---------------------------------------------------------*/ function Swep:Initialize() self.SWEP:CreateViewModels() end end /*--------------------------------------------------------- Name: SWEP:PrimaryAttack( ) Desc: +attack1 has been pressed ---------------------------------------------------------*/ function SWEP:PrimaryAttack() // Play shoot sound self.Weapon:EmitSound("Weapon_AR2.Single") self:ShootBullet( 50, 1, 0.0 ) // Punch the player's view self.Owner:ViewPunch( Angle( -10, 0, 0 ) ) self:SetNextPrimaryFire( CurTime() + 0.6 ) if ( SERVER ) then // Make the player fly backwards.. self.Owner:SetGroundEntity( NULL ) self.Owner:SetVelocity( self.Owner:GetVelocity() * -1 + self.Owner:GetAimVector() * -1000 ) end end /*--------------------------------------------------------- Name: SWEP:SecondaryAttack( ) Desc: +attack2 has been pressed ---------------------------------------------------------*/ function SWEP:SecondaryAttack() // Todo.. increase health.. self:SetNextSecondaryFire( CurTime() + 0.1 ) end /*--------------------------------------------------------- Name: SWEP:ShootBullet( ) Desc: A convenience function to shoot bullets ---------------------------------------------------------*/ function SWEP:ShootEffects() self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) // View model animation self.Owner:MuzzleFlash() // Crappy muzzle light self.Owner:SetAnimation( PLAYER_ATTACK1 ) // 3rd Person Animation end /*--------------------------------------------------------- Name: SWEP:ShootBullet( ) Desc: A convenience function to shoot bullets ---------------------------------------------------------*/ function SWEP:ShootBullet( damage, num_bullets, aimcone ) local bullet = {} bullet.Num = num_bullets bullet.Src = self.Owner:GetShootPos() // Source bullet.Dir = self.Owner:GetAimVector() // Dir of bullet bullet.Spread = Vector( aimcone, aimcone, 0 ) // Aim Cone bullet.Tracer = 1 // Show a tracer on every x bullets bullet.Force = 10000 // Amount of force to give to phys objects bullet.Damage = damage bullet.AmmoType = "Pistol" bullet.HullSize = 2 bullet.TracerName = "LaserTracer" self.Owner:FireBullets( bullet ) self:ShootEffects() end --Comment. function SWEP:ViewModelDrawn() local vm = self.Owner:GetViewModel() if (!ValidEntity(vm)) then return end if (!self.VElements) then return end for k, v in pairs( self.VElements ) do local model = v.modelEnt local sprite = v.spriteMaterial if (v.type == "Model" and ValidEntity(model)) then local m = vm:GetBoneMatrix(vm:LookupBone(v.bone)) local pos, ang = m:GetTranslation(), m:GetAngle() if (self.ViewModelFlip) then ang.r = -ang.r // Fixes mirrored models end model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z ) ang:RotateAroundAxis(ang:Up(), v.angle.y) ang:RotateAroundAxis(ang:Right(), v.angle.p) ang:RotateAroundAxis(ang:Forward(), v.angle.r) model:SetAngles(ang) model:SetModelScale(v.size) if (v.material == "") then model:SetMaterial("") elseif (model:GetMaterial() != v.material) then model:SetMaterial( v.material ) end if (v.surpresslightning) then render.SuppressEngineLighting(true) end render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255) render.SetBlend(v.color.a/255) model:DrawModel() render.SetBlend(1) render.SetColorModulation(1, 1, 1) if (v.surpresslightning) then render.SuppressEngineLighting(false) end elseif (v.type == "Sprite" and sprite) then local m = vm:GetBoneMatrix(vm:LookupBone(v.bone)) local pos, ang = m:GetTranslation(), m:GetAngle() if (self.ViewModelFlip) then ang.r = -ang.r // Fixes mirrored models end local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z render.SetMaterial(sprite) render.DrawSprite(drawpos, v.size.x, v.size.y, v.color) end end end function SWEP:CreateViewModels() for k, v in pairs( self.VElements ) do if (v.type == "Model" and v.model and (!ValidEntity(v.modelEnt) or v.createdModel != v.mode
ugh.. sorry for being off topic but why the fuck are the ends pink? OT: did you use the right directory?
I used [php] tags for the syntax highlighter (for the line numbers) Right directory? Don't follow you. Also, two ends in the init function hurr. Got rid of one of the ends, now I get "[addons\laserdancegun\lua\weapons\weapon_laserdance\shared.lua:256] 'end' expected (to close 'function' at line 211) near '<eof>'" which I can probably fix by commenting between the two functions (draw and create models)
You should probably learn what needs an end. [lua] function Swep:Initialize() self.SWEP:CreateViewModels() end end[/lua] That second end is throwing things off. There's nothing in that function that needs an end, other than the function itself. [lua]if ( CLIENT ) then SWEP.PrintName = "Laser Weapon" // 'Nice' Weapon name (Shown on HUD) SWEP.Slot = 0 // Slot in the weapon selection menu SWEP.SlotPos = 10 // Position in the slot SWEP.DrawAmmo = false // Should draw the default HL2 ammo counter SWEP.DrawCrosshair = true // Should draw the default crosshair SWEP.DrawWeaponInfoBox = false // Should draw the weapon info box SWEP.BounceWeaponIcon = false // Should the weapon icon bounce? SWEP.SwayScale = 1.0 // The scale of the viewmodel sway SWEP.BobScale = 1.0 // The scale of the viewmodel bob SWEP.WepSelectIcon = surface.GetTextureID( "weapons/swep" ) SWEP.VElements = { ["some_unique_name3"] = { type = "Model", model = "models/props_combine/combine_barricade_short02a.mdl", bone = "ValveBiped.base", pos = Vector(1.582, -2.652, -4.481), angle = Angle(-128.663, 13.112, 95.181), size = Vector(0.035, 0.065, 0.021), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name4"] = { type = "Model", model = "models/props_lab/reciever01b.mdl", bone = "ValveBiped.base", pos = Vector(0.001, -0.431, -4.932), angle = Angle(0, 1.743, 87.53), size = Vector(0.157, 0.153, 0.144), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name"] = { type = "Model", model = "models/props_borealis/door_wheel001a.mdl", bone = "ValveBiped.base", pos = Vector(1.297, -1.514, -1.882), angle = Angle(0, 94.694, 0), size = Vector(0.097, 0.097, 0.097), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name1"] = { type = "Model", model = "models/props_c17/FurnitureFireplace001a.mdl", bone = "ValveBiped.base", pos = Vector(0.469, 0, 0), angle = Angle(-0.281, 97.831, -0.631), size = Vector(0.1, 0.1, 0.1), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name2"] = { type = "Model", model = "models/props_c17/oildrum001.mdl", bone = "ValveBiped.base", pos = Vector(0.774, -0.137, -0.551), angle = Angle(7.262, 0.544, 0), size = Vector(0.074, 0.086, 0.162), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""} } end[/lua] Should probably be spaced this way (Though it seems to have the correct number of ends), just so it's more readable.
[QUOTE=Lord Ned;26419338]You should probably learn what needs an end. [lua] function Swep:Initialize() self.SWEP:CreateViewModels() end end[/lua] That second end is throwing things off. There's nothing in that function that needs an end, other than the function itself. [lua]if ( CLIENT ) then SWEP.PrintName = "Laser Weapon" // 'Nice' Weapon name (Shown on HUD) SWEP.Slot = 0 // Slot in the weapon selection menu SWEP.SlotPos = 10 // Position in the slot SWEP.DrawAmmo = false // Should draw the default HL2 ammo counter SWEP.DrawCrosshair = true // Should draw the default crosshair SWEP.DrawWeaponInfoBox = false // Should draw the weapon info box SWEP.BounceWeaponIcon = false // Should the weapon icon bounce? SWEP.SwayScale = 1.0 // The scale of the viewmodel sway SWEP.BobScale = 1.0 // The scale of the viewmodel bob SWEP.WepSelectIcon = surface.GetTextureID( "weapons/swep" ) SWEP.VElements = { ["some_unique_name3"] = { type = "Model", model = "models/props_combine/combine_barricade_short02a.mdl", bone = "ValveBiped.base", pos = Vector(1.582, -2.652, -4.481), angle = Angle(-128.663, 13.112, 95.181), size = Vector(0.035, 0.065, 0.021), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name4"] = { type = "Model", model = "models/props_lab/reciever01b.mdl", bone = "ValveBiped.base", pos = Vector(0.001, -0.431, -4.932), angle = Angle(0, 1.743, 87.53), size = Vector(0.157, 0.153, 0.144), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name"] = { type = "Model", model = "models/props_borealis/door_wheel001a.mdl", bone = "ValveBiped.base", pos = Vector(1.297, -1.514, -1.882), angle = Angle(0, 94.694, 0), size = Vector(0.097, 0.097, 0.097), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name1"] = { type = "Model", model = "models/props_c17/FurnitureFireplace001a.mdl", bone = "ValveBiped.base", pos = Vector(0.469, 0, 0), angle = Angle(-0.281, 97.831, -0.631), size = Vector(0.1, 0.1, 0.1), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name2"] = { type = "Model", model = "models/props_c17/oildrum001.mdl", bone = "ValveBiped.base", pos = Vector(0.774, -0.137, -0.551), angle = Angle(7.262, 0.544, 0), size = Vector(0.074, 0.086, 0.162), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""} } end[/lua] Should probably be spaced this way (Though it seems to have the correct number of ends), just so it's more readable.[/QUOTE] Yeah, I saw that double end earlier and fixed it
[QUOTE=Saza;26418367]I used [php] tags for the syntax highlighter (for the line numbers) Right directory? Don't follow you. Also, two ends in the init function hurr. Got rid of one of the ends, now I get "[addons\laserdancegun\lua\weapons\weapon_laserdance\shared.lua:256] 'end' expected (to close 'function' at line 211) near '<eof>'" which I can probably fix by commenting between the two functions (draw and create models)[/QUOTE] ah, k. thought it was changed in the [lua] highlighter. are there any more problems?
function Swep:Initialize() self.SWEP:CreateViewModels() end end remove an end.
Remove an end on line 66 and change self.SWEP to just self
[QUOTE=Saza;26420496]Yeah, I saw that double end earlier and fixed it[/QUOTE]
Okay. I got it to spawn finally. Though I get an error. The error is: [addons\laserdancegun\lua\weapons\weapon_laserdance\shared.lua:215] attempt to index local 'self' (a nil value) Giving Saza a weapon_laserdance [addons\laserdancegun\lua\weapons\weapon_laserdance\shared.lua:215] attempt to index local 'self' (a nil value) Current script reads: [lua] AddCSLuaFile( "shared.lua" ) SWEP.Author = "" SWEP.Contact = "" SWEP.Purpose = "" SWEP.Instructions = "" if ( CLIENT ) then SWEP.PrintName = "Laser Weapon" // 'Nice' Weapon name (Shown on HUD) SWEP.Slot = 0 // Slot in the weapon selection menu SWEP.SlotPos = 10 // Position in the slot SWEP.DrawAmmo = false // Should draw the default HL2 ammo counter SWEP.DrawCrosshair = true // Should draw the default crosshair SWEP.DrawWeaponInfoBox = false // Should draw the weapon info box SWEP.BounceWeaponIcon = false // Should the weapon icon bounce? SWEP.SwayScale = 1.0 // The scale of the viewmodel sway SWEP.BobScale = 1.0 // The scale of the viewmodel bob SWEP.WepSelectIcon = surface.GetTextureID( "weapons/swep" ) SWEP.VElements = { ["some_unique_name3"] = { type = "Model", model = "models/props_combine/combine_barricade_short02a.mdl", bone = "ValveBiped.base", pos = Vector(1.582, -2.652, -4.481), angle = Angle(-128.663, 13.112, 95.181), size = Vector(0.035, 0.065, 0.021), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name4"] = { type = "Model", model = "models/props_lab/reciever01b.mdl", bone = "ValveBiped.base", pos = Vector(0.001, -0.431, -4.932), angle = Angle(0, 1.743, 87.53), size = Vector(0.157, 0.153, 0.144), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name"] = { type = "Model", model = "models/props_borealis/door_wheel001a.mdl", bone = "ValveBiped.base", pos = Vector(1.297, -1.514, -1.882), angle = Angle(0, 94.694, 0), size = Vector(0.097, 0.097, 0.097), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name1"] = { type = "Model", model = "models/props_c17/FurnitureFireplace001a.mdl", bone = "ValveBiped.base", pos = Vector(0.469, 0, 0), angle = Angle(-0.281, 97.831, -0.631), size = Vector(0.1, 0.1, 0.1), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""}, ["some_unique_name2"] = { type = "Model", model = "models/props_c17/oildrum001.mdl", bone = "ValveBiped.base", pos = Vector(0.774, -0.137, -0.551), angle = Angle(7.262, 0.544, 0), size = Vector(0.074, 0.086, 0.162), color = Color(255, 255, 255, 255), surpresslightning = false, material = ""} } end SWEP.ViewModelFOV = 62 SWEP.ViewModelFlip = false SWEP.ViewModel = "models/weapons/v_smg1.mdl" SWEP.WorldModel = "models/weapons/w_357.mdl" SWEP.Author = "Garry Newman" SWEP.Contact = "Don't" SWEP.Purpose = "Kill stuff" SWEP.Instructions = "Click" SWEP.Spawnable = false SWEP.AdminSpawnable = true SWEP.Primary.ClipSize = -1 // Size of a clip SWEP.Primary.DefaultClip = -1 // Default number of bullets in a clip SWEP.Primary.Automatic = false // Automatic/Semi Auto SWEP.Primary.Ammo = "none" SWEP.Secondary.ClipSize = 8 // Size of a clip SWEP.Secondary.DefaultClip = 32 // Default number of bullets in a clip SWEP.Secondary.Automatic = true // Automatic/Semi Auto SWEP.Secondary.Ammo = "none" /*--------------------------------------------------------- Name: Swep:Initialize( ) Desc: Swep has been pulled out ---------------------------------------------------------*/ function SWEP:Initialize() self.CreateViewModels() end /*--------------------------------------------------------- Name: SWEP:PrimaryAttack( ) Desc: +attack1 has been pressed ---------------------------------------------------------*/ function SWEP:PrimaryAttack() // Play shoot sound self.Weapon:EmitSound("Weapon_AR2.Single") self:ShootBullet( 50, 1, 0.0 ) // Punch the player's view self.Owner:ViewPunch( Angle( -10, 0, 0 ) ) self:SetNextPrimaryFire( CurTime() + 0.6 ) if ( SERVER ) then // Make the player fly backwards.. self.Owner:SetGroundEntity( NULL ) self.Owner:SetVelocity( self.Owner:GetVelocity() * -1 + self.Owner:GetAimVector() * -1000 ) end end /*--------------------------------------------------------- Name: SWEP:SecondaryAttack( ) Desc: +attack2 has been pressed ---------------------------------------------------------*/ function SWEP:SecondaryAttack() // Todo.. increase health.. self:SetNextSecondaryFire( CurTime() + 0.1 ) end /*--------------------------------------------------------- Name: SWEP:ShootBullet( ) Desc: A convenience function to shoot bullets ---------------------------------------------------------*/ function SWEP:ShootEffects() self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) // View model animation self.Owner:MuzzleFlash() // Crappy muzzle light self.Owner:SetAnimation( PLAYER_ATTACK1 ) // 3rd Person Animation end /*--------------------------------------------------------- Name: SWEP:ShootBullet( ) Desc: A convenience function to shoot bullets ---------------------------------------------------------*/ function SWEP:ShootBullet( damage, num_bullets, aimcone ) local bullet = {} bullet.Num = num_bullets bullet.Src = self.Owner:GetShootPos() // Source bullet.Dir = self.Owner:GetAimVector() // Dir of bullet bullet.Spread = Vector( aimcone, aimcone, 0 ) // Aim Cone bullet.Tracer = 1 // Show a tracer on every x bullets bullet.Force = 10000 // Amount of force to give to phys objects bullet.Damage = damage bullet.AmmoType = "Pistol" bullet.HullSize = 2 bullet.TracerName = "LaserTracer" self.Owner:FireBullets( bullet ) self:ShootEffects() end --Custom models function SWEP:ViewModelDrawn() local vm = self.Owner:GetViewModel() if (!ValidEntity(vm)) then return end if (!self.VElements) then return end for k, v in pairs( self.VElements ) do local model = v.modelEnt local sprite = v.spriteMaterial if (v.type == "Model" and ValidEntity(model)) then local m = vm:GetBoneMatrix(vm:LookupBone(v.bone)) local pos, ang = m:GetTranslation(), m:GetAngle() if (self.ViewModelFlip) then ang.r = -ang.r // Fixes mirrored models end model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z ) ang:RotateAroundAxis(ang:Up(), v.angle.y) ang:RotateAroundAxis(ang:Right(), v.angle.p) ang:RotateAroundAxis(ang:Forward(), v.angle.r) model:SetAngles(ang) model:SetModelScale(v.size) if (v.material == "") then model:SetMaterial("") elseif (model:GetMaterial() != v.material) then model:SetMaterial( v.material ) end if (v.surpresslightning) then render.SuppressEngineLighting(true) end render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255) render.SetBlend(v.color.a/255) model:DrawModel() render.SetBlend(1) render.SetColorModulation(1, 1, 1) if (v.surpresslightning) then render.SuppressEngineLighting(false) end elseif (v.type == "Sprite" and sprite) then local m = vm:GetBoneMatrix(vm:LookupBone(v.bone)) local pos, ang = m:GetTranslation(), m:GetAngle() if (self.ViewModelFlip) then ang.r = -ang.r // Fixes mirrored models end local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z render.SetMaterial(sprite) render.DrawSprite(drawpos, v.size.x, v.size.y, v.color) end end end --comment functi
Make self.CreateViewModels() self:CreateViewModels() The error is bitching about a table, which i think is created by that function (I dont know how the SCK works) and you might not be calling it correctly
I'll ask the maker [editline]1st December 2010[/editline] but for now I gotta go sleep :v:
Sorry, you need to Log In to post a reply to this thread.