1. Post #1
    crysismaster's Avatar
    December 2008
    85 Posts
    Hey guys im sorta new here as you can see but im also an amateur LUA coder.
    Im trying to program a model (HK416) i found on Garry's Mod which can be found here http://www.garrysmod.org/downloads/?a=view&id=18418 anyways i added all the code and i realized it didn't have a view model. Well i just copied the model files and renamed it to v_416_m416.mdl which in its case the world model would be w_416_m416.mdl so i did that and with all the code in place i launched gmod but when i equipped the weapon it was really high in the air but viewable and shot and their was also no sound and it shot like a shotgun.

    Here is the code ----->


    if ( CLIENT ) then
    SWEP.Category = "RED WEAPONS"
    SWEP.Author = "dnatoxic"
    SWEP.Contact = "No contacts"
    SWEP.Purpose = "Shoot! SHOOOT!"
    SWEP.Instructions = " ."
    SWEP.PrintName = "Jitte"
    SWEP.Instructions = ""
    SWEP.Slot = 2
    SWEP.SlotPos = 0
    SWEP.IconLetter = "r"

    killicon.AddFont("cse_awp","CSKillIcons",SWEP.Icon Letter,Color(255,80,0,255))
    end

    if ( SERVER ) then
    AddCSLuaFile( "shared.lua" )
    end


    SWEP.Base = "g36_base1"

    SWEP.Spawnable = true
    SWEP.AdminSpawnable = true

    SWEP.ViewModel = "models/weapons/NT/v__416_m416.mdl"
    SWEP.WorldModel = "models/weapons/NT/w_416_m416.mdl"
    SWEP.HoldType = "ar2"

    SWEP.Weight = 6.8
    SWEP.AutoSwitchTo = false
    SWEP.AutoSwitchFrom = false

    SWEP.Primary.Sound = Sound("weapons/sound/mx_fire_2")
    SWEP.Primary.Recoil = 5
    SWEP.Primary.Unrecoil = 3.5
    SWEP.Primary.Damage = 9950
    SWEP.Primary.NumShots = 4
    SWEP.Primary.Cone = 0
    SWEP.Primary.ClipSize = 21
    SWEP.Primary.Delay = 0.06 //Don't use this, use the tables below!
    SWEP.Primary.DefaultClip = 81 //Always set this 1 higher than what you want.
    SWEP.Primary.Automatic = true //Don't use this, use the tables below!
    SWEP.Primary.Ammo = "smg1"

    SWEP.Secondary.ClipSize = -1
    SWEP.Secondary.DefaultClip = -1
    SWEP.Secondary.Automatic = false
    SWEP.Secondary.Ammo = "none"

    //Firemode configuration

    SWEP.data = {}
    SWEP.mode = "semi" //The starting firemode
    SWEP.data.newclip = false //Do not change this

    SWEP.data.zoomfov = 45
    SWEP.data.snipefov = 15
    SWEP.data.scope = true

    SWEP.data.semi = {}
    SWEP.data.semi.Delay = 1.2
    SWEP.data.semi.Cone = 0.07
    SWEP.data.semi.ConeZoom = 0.001

    //End of configuration

    function SWEP:Think()
    if SinglePlayer() then self.data.singleplayer(self) end
    if self.data.init then
    self.Weapon:SetClip1( self.Weapon:Clip1() - 1 )
    self.data.init = nil
    end
    if self.data.newclip then
    if self.data.newclip == 0 then
    self.data.newclip = false

    if self:Ammo1() > self.Primary.ClipSize - 1 then
    if self.data.oldclip == 0 then
    self.Weapon:SetClip1( self.Weapon:Clip1() - 1 )
    if SERVER then
    self.Owner:GiveAmmo(1,self.Primary.Ammo,true)
    end
    end
    end
    else
    self.data.newclip = self.data.newclip - 1
    end
    end
    if self.rezoom then
    if self.rezoom <= CurTime() then
    self.Owner:SetFOV(self.zoomto,.3)
    self.rezoom = nil
    self.zoomto = nil
    end
    end
    end

    function SWEP:PrimaryAttack()
    if ( !self:CanPrimaryAttack() ) or self.data.newclip or self.data.init then return end

    if CLIENT then
    self.xhair.loss = self.xhair.loss + self.Primary.Recoil
    end

    --self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
    self.Weapon:SetNextPrimaryFire( CurTime() + self.data[self.mode].Delay )

    self.Weapon:EmitSound(self.Primary.Sound)
    self:TakePrimaryAmmo( 1 )

    self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )

    if self.Owner:GetFOV() == 90 then
    self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.data[self.mode].Cone )
    else
    self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.data[self.mode].ConeZoom )
    if SERVER then
    self.zoomto = self.Owner:GetFOV()
    self.Owner:SetFOV(90,.3)
    self.rezoom = CurTime() + self.data[self.mode].Delay
    end
    end
    end

    function SWEP:Deploy()
    if SERVER then
    self.zoomto = nil
    self.rezoom = nil
    end
    return true
    end


    function SWEP:SecondaryAttack()
    if ( !self:CanPrimaryAttack() ) or self.data.newclip or self.data.init or self.rezoom then return end
    if self.Owner:KeyDown(IN_USE) then
    self.data[self.mode].Init(self)
    elseif SERVER then
    if self.Owner:GetFOV() == 90 then
    self.Owner:SetFOV(self.data.zoomfov,.3)
    elseif self.Owner:GetFOV() == self.data.zoomfov and self.data.snipefov > 0 then
    self.Owner:SetFOV(self.data.snipefov,.3)
    else
    self.Owner:SetFOV(90,.3)
    end
    end
    end

    function SWEP:Reload()
    if SERVER and self.Owner:GetFOV() ~= 90 then
    self.Owner:SetFOV(90,.3)
    end

    self.data.oldclip = self.Weapon:Clip1()

    self.Weapon:DefaultReload(ACT_VM_RELOAD)
    self.data.newclip = 1

    if SERVER then
    self.zoomto = nil
    self.rezoom = nil
    end
    end

    Edited:

    Some one please help!

  2. Post #2
    kevkev's Avatar
    April 2007
    1,093 Posts
    Jesus crist people, please use the [lua] tags.

  3. Post #3
    Unrealomega's Avatar
    January 2009
    262 Posts
    I think the recent requests for help have been unanswered because of the lack of [lua] tags. It makes the reading twice as hard to read.

    Also, I'm unsure if it's just because you copy-pasted into a post, but you really need to indent. It makes reading this mess hard.

    if ( CLIENT ) then
    	SWEP.Category = "RED WEAPONS"
    	SWEP.Author = "dnatoxic"
    	SWEP.Contact = "No contacts"
    	SWEP.Purpose = "Shoot! SHOOOT!"
    	SWEP.Instructions = " ."
    	SWEP.PrintName = "Jitte"
    	SWEP.Instructions = ""
    	SWEP.Slot = 2
    	SWEP.SlotPos = 0
    	SWEP.IconLetter = "r"
    
    	killicon.AddFont("cse_awp","CSKillIcons",SWEP.Icon Letter,Color(255,80,0,255))
    end
    
    if ( SERVER ) then
    	AddCSLuaFile( "shared.lua" )
    end
    
    
    SWEP.Base = "g36_base1"
    
    SWEP.Spawnable = true
    SWEP.AdminSpawnable = true
    
    SWEP.ViewModel = "models/weapons/NT/v__416_m416.mdl"
    SWEP.WorldModel = "models/weapons/NT/w_416_m416.mdl"
    SWEP.HoldType = "ar2"
    
    SWEP.Weight = 6.8
    SWEP.AutoSwitchTo = false
    SWEP.AutoSwitchFrom = false
    
    SWEP.Primary.Sound = Sound("weapons/sound/mx_fire_2")
    SWEP.Primary.Recoil = 5
    SWEP.Primary.Unrecoil = 3.5
    SWEP.Primary.Damage = 9950
    SWEP.Primary.NumShots = 4
    SWEP.Primary.Cone = 0
    SWEP.Primary.ClipSize = 21
    SWEP.Primary.Delay = 0.06 //Don't use this, use the tables below!
    SWEP.Primary.DefaultClip = 81 //Always set this 1 higher than what you want.
    SWEP.Primary.Automatic = true //Don't use this, use the tables below!
    SWEP.Primary.Ammo = "smg1"
    
    SWEP.Secondary.ClipSize = -1
    SWEP.Secondary.DefaultClip = -1
    SWEP.Secondary.Automatic = false
    SWEP.Secondary.Ammo = "none"
    
    //Firemode configuration
    
    SWEP.data = {}
    SWEP.mode = "semi" //The starting firemode
    SWEP.data.newclip = false //Do not change this
    
    SWEP.data.zoomfov = 45
    SWEP.data.snipefov = 15
    SWEP.data.scope = true
    
    SWEP.data.semi = {}
    SWEP.data.semi.Delay = 1.2
    SWEP.data.semi.Cone = 0.07
    SWEP.data.semi.ConeZoom = 0.001
    
    //End of configuration
    
    function SWEP:Think()
    	if SinglePlayer() then self.data.singleplayer(self) end
    	if self.data.init then
    		self.Weapon:SetClip1( self.Weapon:Clip1() - 1 )
    		self.data.init = nil
    	end
    	if self.data.newclip and self.data.newclip == 0 then
    		self.data.newclip = false
    		if self:Ammo1() > self.Primary.ClipSize - 1 and self.data.oldclip == 0 then
    			self.Weapon:SetClip1( self.Weapon:Clip1() - 1 )
    			if SERVER then
    				self.Owner:GiveAmmo(1,self.Primary.Ammo,true)
    			end
    		end
    	else
    		self.data.newclip = self.data.newclip - 1
    	end
    	if self.rezoom and self.rezoom <= CurTime() then
    		self.Owner:SetFOV(self.zoomto,.3)
    		self.rezoom = nil
    		self.zoomto = nil
    	end
    end
    
    function SWEP:PrimaryAttack()
    	if ( !self:CanPrimaryAttack() ) or self.data.newclip or self.data.init then return end
    
    	if CLIENT then
    		self.xhair.loss = self.xhair.loss + self.Primary.Recoil
    	end
    
    	--self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
    	self.Weapon:SetNextPrimaryFire( CurTime() + self.data[self.mode].Delay )
    
    	self.Weapon:EmitSound(self.Primary.Sound)
    	self:TakePrimaryAmmo( 1 )
    
    	self.Owner:ViewPunch( Angle( math.Rand(-0.2,-0.1) * self.Primary.Recoil, math.Rand(-0.1,0.1) *self.Primary.Recoil, 0 ) )
    
    	if self.Owner:GetFOV() == 90 then
    		self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.data[self.mode].Cone )
    	else
    		self:CSShootBullet( self.Primary.Damage, self.Primary.Recoil, self.Primary.NumShots, self.data[self.mode].ConeZoom )
    		if SERVER then
    			self.zoomto = self.Owner:GetFOV()
    			self.Owner:SetFOV(90,.3)
    			self.rezoom = CurTime() + self.data[self.mode].Delay
    		end
    	end
    end
    
    function SWEP:Deploy()
    	if CLIENT then return end
    	self.zoomto = nil
    	self.rezoom = nil
    	return true
    end
    
    
    function SWEP:SecondaryAttack()
    	if ( !self:CanPrimaryAttack() ) or self.data.newclip or self.data.init or self.rezoom then return end
    	if self.Owner:KeyDown(IN_USE) then
    		self.data[self.mode].Init(self)
    	elseif SERVER then
    		if self.Owner:GetFOV() == 90 then
    			self.Owner:SetFOV(self.data.zoomfov,.3)
    		elseif self.Owner:GetFOV() == self.data.zoomfov and self.data.snipefov > 0 then
    			self.Owner:SetFOV(self.data.snipefov,.3)
    		else
    			self.Owner:SetFOV(90,.3)
    		end
    	end
    end
    
    function SWEP:Reload()
    	if SERVER and self.Owner:GetFOV() ~= 90 then self.Owner:SetFOV(90, .3) end
    
    	self.data.oldclip = self.Weapon:Clip1()
    
    	self.Weapon:DefaultReload(ACT_VM_RELOAD)
    	self.data.newclip = 1
    
    	if SERVER then
    		self.zoomto = nil
    		self.rezoom = nil
    	end
    end

    Just cleaned it up for other's who want to help can read it. :P

  4. Post #4
    Waffler's Avatar
    May 2005
    311 Posts
    You can't just rename the model files to make it work, and I don't know if line 34 is a shotgun sound or not( but by reading the file name, I'm sure its a shotgun sound )

  5. Post #5
    ¦FlapJack¦'s Avatar
    August 2008
    226 Posts
    Jesus crist people, please use the [lua] tags.
    Code tags are actually better. People on IE can actually see them, and they don't break the page boundrys.

  6. Post #6
    TheGreatVax's Avatar
    March 2008
    137 Posts
    It's self explaining that you can't just get a viewmodel by renaming a w_ to a v_, right?
    It is not?
    It is not possible to do that, viewmodels need a seperate model.
    You can't just choose path/sound, instead path/sound.wav or whatever filetype it is

    /dumbrating

  7. Post #7
    emperus's Avatar
    March 2009
    348 Posts
    Wow this inspired me, maybe I'd make a SWEP creator :)

  8. Post #8

    January 2008
    85 Posts
    In my option
    You did v__ (double _)
    but it should be only one _
    Example
    Yours_
    v__
    Real
    v_

    Edited:

    Haha i'm confusing, i know. I have talent in that.
    Just in example you did "Double" underlines instead of one underline.
    Reply With Quote Edit / Delete Reply Estonia Show Events Dumb Dumb x 1 (list)