Invisible SWEP

Like the title says, it’s just not on the screen, and I’m wondering if anyone can point me in the right direction here. The SWEP shows up in the spawn menu and actually functions – sounds work, scope zooms in, I can switch between firing modes, fires fine, etc. (so at least I did the lua scripting correctly, thanks go out to Garry and Teta_Bonita for that) – but I can’t actually see it for some reason.

Bit of backstory, I’d found a custom weapon model for Counter-Strike: Condition Zero and thought I’d like to porting it over for my own use Garry’s Mod. Some of you may have seen the request thread. For the sake of it I figured I’d try and learn how to port it myself. Everything seemed to be okay. Step by step, I did the following:

  • Extracted the files from the Goldsrc .mdl files
  • Converted the .bmp textures to .vtf and created .vmt files for them using VTFEdit
  • Made the minor adjustment to the .qc file (changing $cdtexture to $cdmaterials)
  • Compiled with Studiomdl and got the new .mdl files and the other files
  • After I finished porting, or at least believed I had, I put it together as an addon with the lua file.

Thus I got my invisible working weapon. :stuck_out_tongue: So I’m wondering if someone can pick out what went wrong or at least may have gone wrong here. (Assuming it was in here and not in the porting process but being so new to this I can’t be sure.) I’ll provide the lua script and file structure below.

Saved as “Shared.lua”


//-- 'Realistic' Gun base: example SWEP
//-- By Teta_Bonita

if SERVER then

	AddCSLuaFile("shared.lua")
	SWEP.HoldType = "ar2"
	
end

if CLIENT then

	SWEP.DrawAmmo			= true
	SWEP.DrawCrosshair		= true
	SWEP.ViewModelFOV		= 76
	SWEP.ViewModelFlip		= true
	SWEP.CSMuzzleFlashes	= true
		
	SWEP.Slot				= 3
	SWEP.SlotPos			= 1
	SWEP.IconLetter			= "h"
	SWEP.DrawWeaponInfoBox  = true
	
	killicon.AddFont("weapon_rg_example", "CSKillIcons", SWEP.IconLetter, Color(255, 220, 0, 255))
	
end

SWEP.Base			= "rg_base"
SWEP.Category                   = "My Custom SWEPs"

//------------
//-- Info --
//------------
SWEP.PrintName		= "HK417"	
SWEP.Author			= "Myself :P"
SWEP.Purpose		= "For ze shoosting"
SWEP.Instructions	= "Hold your use key and press secondary fire to change fire modes."


//-------------
//-- Misc. --
//-------------
SWEP.Spawnable			= true
SWEP.AdminSpawnable		= true
SWEP.Weight				= 5
SWEP.AutoSwitchTo		= false
SWEP.AutoSwitchFrom		= false


//----------------------
//-- Primary Fire --
//----------------------
SWEP.Primary.Sound			= Sound("weapons/hk417/psg-1.wav")
SWEP.Primary.Damage			= 60 //-- This determines both the damage dealt and force applied by the bullet.
SWEP.Primary.NumShots		= 1
SWEP.Primary.ClipSize		= 20
SWEP.Primary.DefaultClip	= 80
SWEP.Primary.Ammo			= "smg1"
SWEP.MuzzleVelocity			= 820 //-- How fast the bullet travels in meters per second. For reference, an AK47 shoots at about 750, an M4 shoots at about 900, and a Luger 9mm shoots at about 350 (source: Wikipedia)
SWEP.FiresUnderwater 		= false


//-------------------------
//-- Secondary Fire --
//-------------------------
//-- Secondary Fire is used to switch ironsights and firemodes
SWEP.Secondary.ClipSize		= -1 //-- best left at -1
SWEP.Secondary.DefaultClip	= 1 //-- set to -1 if you don't use secondary ammo
SWEP.Secondary.Ammo			= "none" //-- Leave this if you want your SWEP to have grenades, otherwise set to "none" if you don't use secondary ammo.


//---------------------------------------
//-- Recoil, Spread, and Spray --
//---------------------------------------
SWEP.RecoverTime 	= 0.8 //-- Time in seconds it takes the player to re-steady his aim after firing.

//-- The following variables control the overall accuracy of the gun and typically increase with each shot
//-- Recoil: how much the gun kicks back the player's view.
SWEP.MinRecoil		= 0.15
SWEP.MaxRecoil		= 0.5
SWEP.DeltaRecoil	= 0.15 //-- The recoil to add each shot.  Same deal for spread and spray.

//-- Spread: the width of the gun's firing cone.  More spread means less accuracy.
SWEP.MinSpread		= 0.002
SWEP.MaxSpread		= 0.05
SWEP.DeltaSpread	= 0.005

//-- Spray: the gun's tendancy to point in random directions.  More spray means less control.
SWEP.MinSpray		= 0
SWEP.MaxSpray		= 1.4
SWEP.DeltaSpray		= 0.16


//---------------------------
//-- Ironsight/Scope --
//---------------------------
//-- IronSightsPos and IronSightsAng are model specific paramaters that tell the game where to move the weapon viewmodel in ironsight mode.

SWEP.IronSightsPos = Vector (2.4825, -2.0456, 1.1849)
SWEP.IronSightsAng = Vector (0, 0, 0)
SWEP.IronSightZoom			= 1.3 //-- How much the player's FOV should zoom in ironsight mode. 
SWEP.UseScope				= true //-- Use a scope instead of iron sights.
SWEP.ScopeScale 			= 0.4 //-- The scale of the scope's reticle in relation to the player's screen size.
SWEP.ScopeZooms				= {2,6,12} //-- The possible magnification levels of the weapon's scope.   If the scope is already activated, secondary fire will cycle through each zoom level in the table.
SWEP.DrawParabolicSights	= false //-- Set to true to draw a cool parabolic sight (helps with aiming over long distances)

-------------------------
-- Effects/Visual --
-------------------------
SWEP.ViewModel				= "models/weapons/v_hk417.mdl"
SWEP.WorldModel				= "models/weapons/w_hk417.mdl"

SWEP.MuzzleEffect			= "rg_muzzle_rifle" //-- This is an extra muzzleflash effect
//-- Available muzzle effects: rg_muzzle_grenade, rg_muzzle_highcal, rg_muzzle_hmg, rg_muzzle_pistol, rg_muzzle_rifle, rg_muzzle_silenced, none

SWEP.ShellEffect			= "rg_shelleject_rifle" //-- This is a shell ejection effect
//-- Available shell eject effects: rg_shelleject, rg_shelleject_rifle, rg_shelleject_shotgun, none

SWEP.MuzzleAttachment		= "1" //-- Should be "1" for CSS models or "muzzle" for hl2 models
SWEP.ShellEjectAttachment	= "2" //-- Should be "2" for CSS models or "1" for hl2 models


//-------------------
//-- Modifiers --
//-------------------
//-- Modifiers scale the gun's recoil, spread, and spray based on the player's stance
SWEP.CrouchModifier		= 0.7 -- Applies if player is crouching.
SWEP.IronSightModifier 	= 0.7 -- Applies if player is in iron sight mode.
SWEP.RunModifier 		= 1.4 -- Applies if player is moving.
SWEP.JumpModifier 		= 1.6 -- Applies if player is in the air (jumping)

//-- Note: the jumping and crouching modifiers cannot be applied simultaneously

//--------------------
//-- Fire Modes --
//--------------------
//-- You can choose from a list of firemodes, or add your own! \0/
SWEP.AvailableFireModes		= {"Semi","Burst","Auto"} -- What firemodes shall we use?
//-- "Auto", "Burst", "Semi", and "Grenade" are firemodes that are available by default.

-- RPM is the rounds per minute the gun can fire for each mode (if applicable)
SWEP.AutoRPM				= 500
SWEP.SemiRPM				= 300
SWEP.BurstRPM				= 500 //-- Burst RPM affects the space between the shots during the burst.  The space between bursts is determined by SemiRPM.
SWEP.DrawFireModes			= true //-- Set to true to allow drawing of a visual indicator for the current firemode.

end

File Structure

[Root Directory]/addons/HK417
info.txt
+lua
|-+effects
__|-(Just contains the premade scripts for the realistic guns effects)
|-+weapons
__|-+hk417
____|-shared.lua
+materials
|-+models
__|-+weapons
____|-+v_models
______|-(All the view model VTFs and VMTs)
____|-+w_models
______|-(All the world model VTFs and VMTs)
+models
|-+weapons
__|-(MDL and other files created by Sourcemdl after compiling)
+sound
|-(Self-explanatory, and like I said the sounds work fine)

Altough you have all the files that you need, sometimes v models/w models have a kind of encryption, so you can’t use them, toher then where they’re supposed to be used. Sorry you put all the work in, although i may be wrong, i’m no expert.

No they don’t.

Have you tried checking if the models actually work? Go into single player and search for your model in the model browse area and spawn it. If it shows up the model should be fine. Now I’m not great with weapons but what you have looks ok with the model part and all. But first see if the model is actually working by spawning it in singleplayer sandbox. If it is working then you can add me on steam if you want and I can help you fix the script.

Also use lua tags, some way as code but with lua.

Wait, isn’t Teta’s base broken now due to the update? Anyway, the model problem is due usually to a badly compiled model. Either that or you’re writing it wrong, I’ll look at it. Yeah, I say don’t use custom models unless you know that they work, instead try v_rif_ak47 and w_rif_ak47, those actually work and if you have some custom models that replace them, they look damn nice :D.

Okay, it is bad model I guess. I went and checked under the model browser as suggested and sure enough they were invisible under there as well. I may try and pass the model through XSI and see if I can make it work that way. In any case I suppose that means the LUA script itself is fine and this becomes a modeling question, so an admin may want to move this thread over there or just close it.