Garry's Mod

Garry's Mod

Team Fortress 2
 This topic has been pinned, so it's probably important
Lead 30 Jun, 2016 @ 12:50am
HOWTO: CREATE A CUSTOM WEAPON! (or a pack)
Hello Friend! I heard your here because you wanted to create your very own weapon pack! Is that right? Well heres how to do it!

Things you will need...
   1. Knowledge on modifying an "items_game.txt" file.
   2. Models, Materials, and Sounds of the weapons you are going to add.
   3. Time.

And most important of all...
Knowledge of making a weapon in lua.
================================
STEP 1. Feel free to decompile the gamemode to grab the required files.
-----
I say this because, you need to know what to do to get it working right or what weapon to base yours on, look for these files in "/teamfortress/gamemode/items/"
-----

STEP 2. Edit as how you please.
-----
It shouldn't be too hard to understand the basic layout, especially if you already know how to edit a "items_game.txt",



Make a addon folder with this folder: gamemodes/teamfortress/entities/weapons/tf_weapon_YOURWEAPONNAMEHERE
so it shall not get picked up by sandbox. then in teamfortress folder make a gamemode folder (NOT GAMEMODES, GAMEMODE) and in there make a items folder. and IN THE ITEMS FOLDER make a workshop THEN IN WORKSHOP MAKE A items_YOURPACKTITLE.lua


edit the lua with notepad or wordpad or anything else (I suggest sublime text or notepad++!)


in the lua file, heres a example of a melee:

"items_game" { "qualities" { } "items" { "1018" { "name" "Hidden Big Axe" "item_class" "tf_weapon_sword" "craft_class" "weapon" "capabilities" { "nameable" "1" "can_modify_socket" "1" "can_gift_wrap" "1" } "show_in_armory" "1" "item_type_name" "#TF_Weapon_Axe" "item_name" "#TF_HalloweenBoss_Axe" "item_description" "#TF_HalloweenBoss_Axe_Desc" "item_slot" "melee" "item_quality" "rarity4" "item_logname" "headtaker" "item_iconname" "headtaker" "propername" "1" "min_ilevel" "5" "max_ilevel" "5" "image_inventory" "backpack/weapons/c_models/c_headtaker/c_headtaker" "image_inventory_size_w" "128" "image_inventory_size_h" "82" "model_player" "models/weapons/c_models/c_bigaxe/c_bigaxe.mdl" "attach_to_hands" "1" "used_by_classes" { } "visuals" { "sound_melee_miss" "Weapon_Sword.Swing" "sound_melee_hit" "Weapon_Sword.HitFlesh" "sound_melee_hit_world" "Weapon_Sword.HitWorld" "sound_melee_burst" "Weapon_Sword.SwingCrit" "sound_special1" "Sword.Hit" "sound_special2" "Sword.Idle" } "attributes" { "crit mod disabled" { "attribute_class" "mult_crit_chance" "value" "0" } "max health additive penalty" { "attribute_class" "add_maxhealth" "value" "-25" } } "allowed_attributes" { "all_items" "1" "dmg_reductions" "1" "player_health" "1" "attrib_healthregen" "1" "player_movement" "1" "attrib_dmgdone" "1" "attrib_critboosts" "1" "attrib_onhit_slow" "1" "attrib_vs_burning" "1" "attrib_firerate" "1" } "mouse_pressed_sound" "ui/item_knife_large_pickup.wav" "drop_sound" "ui/item_metal_weapon_drop.wav" } } "attributes" { } "item_sets" { } "attribute_controlled_attached_particles" { } }

follow that for a melee.

Lets go over that,
why 1018? because anything over 1017 is not taken by any item.
The name is obviously the name.
The craft class MUST be weapon
The item classes is the tf_weapon_YOURNAMEHERE folder you made.
Ect ect, just use your knowledge of lua here, its basic.

Ignore everything from capabilities to show_in_armory,
These parts, you will have to put in yourself.




It is suggested to do guns after melee.

After making this items_somethinghere.lua and putting that stuff, make a lua file called shared.lua inside the tf_weapon_NAMEHERE folder you made!

Follow this example here:

if SERVER then AddCSLuaFile( "shared.lua" ) end if CLIENT then SWEP.PrintName = "Wrench" SWEP.Slot = 2 SWEP.GlobalCustomHUD = {HudAccountPanel = true} end SWEP.Base = "tf_weapon_melee_base" SWEP.ViewModel = "models/weapons/v_models/v_wrench_engineer.mdl" SWEP.WorldModel = "models/weapons/w_models/w_wrench.mdl" SWEP.Crosshair = "tf_crosshair3" SWEP.Swing = Sound("Weapon_Wrench.Miss") SWEP.SwingCrit = Sound("Weapon_Wrench.MissCrit") SWEP.HitFlesh = Sound("Weapon_Wrench.HitFlesh") SWEP.HitWorld = Sound("Weapon_Wrench.HitWorld") SWEP.HitBuildingSuccess = Sound("Weapon_Wrench.HitBuilding_Success") SWEP.HitBuildingFailure = Sound("Weapon_Wrench.HitBuilding_Failure") SWEP.BaseDamage = 65 SWEP.DamageRandomize = 0.1 SWEP.MaxDamageRampUp = 0 SWEP.MaxDamageFalloff = 0 SWEP.Primary.Delay = 0.8 SWEP.HoldType = "MELEE" SWEP.NoHitSound = true SWEP.UpgradeSpeed = 25 function SWEP:Think() self:CallBaseFunction("Think") if SERVER and self.WeaponMode == 1 and (not self.NextHealthCheck or CurTime()>=self.NextHealthCheck) then if not self.InitialBaseDamage then self.InitialBaseDamage = self.BaseDamage end self.BaseDamage = self.InitialBaseDamage * Lerp((self.Owner:GetMaxHealth()-self.Owner:Health()) / self.Owner:GetMaxHealth(), self.MinDamage, self.MaxDamage) local sp for _,v in ipairs(SpeedTable) do if self.Owner:Health()<=v[1] then sp = v[2] break end end if sp~=self.LastSpeed then if sp then self.LocalSpeedBonus = sp else self.LocalSpeedBonus = nil end self.Owner:ResetClassSpeed() self.LastSpeed = sp end self.NextHealthCheck = CurTime() + 0.1 end end function SWEP:Deploy() if SERVER and self.WeaponMode == 1 then self.NameOverride = "pickaxe" end return self:CallBaseFunction("Deploy") end function SWEP:Holster() if SERVER and self.WeaponMode == 1 then self.LastSpeed = nil end return self:CallBaseFunction("Holster") end


Since you do have lua knowledge, you should be able to do this.





and thats a basic guide, please note this is not done.
Last edited by Lead; 30 Jun, 2016 @ 1:08am
< >
Showing 1-1 of 1 comments
Lead 21 Oct, 2016 @ 6:07pm 
"items_game" { "qualities" { } "items" { "1020" { "name" "STAFF" "item_class" "tf_weapon_merasmus_staff" "craft_class" "weapon" "capabilities" { "nameable" "1" "can_modify_socket" "1" "can_gift_wrap" "1" } "show_in_armory" "1" "item_type_name" "STAFF" "item_name" "STAFF" "item_description" "MORTALS MUST DIEEEE" "item_slot" "melee" "item_quality" "rarity4" "item_logname" "STAFF" "item_iconname" "STAFF" "propername" "1" "min_ilevel" "5" "max_ilevel" "5" "image_inventory" "" "image_inventory_size_w" "128" "image_inventory_size_h" "82" "model_player" "" "attach_to_hands" "1" "used_by_classes" { } "visuals" { "sound_melee_miss" "Weapon_Sword.Swing" "sound_melee_hit" "Weapon_Sword.HitFlesh" "sound_melee_hit_world" "Weapon_Sword.HitWorld" "sound_melee_burst" "Weapon_Sword.SwingCrit" "sound_special1" "Sword.Hit" "sound_special2" "Sword.Idle" } "attributes" { "crit mod disabled" { "attribute_class" "mult_crit_chance" "value" "0" } } "allowed_attributes" { "all_items" "1" "dmg_reductions" "1" "player_health" "1" "attrib_healthregen" "1" "player_movement" "1" "attrib_dmgdone" "1" "attrib_critboosts" "1" "attrib_onhit_slow" "1" "attrib_vs_burning" "1" "attrib_firerate" "1" } "mouse_pressed_sound" "ui/item_knife_large_pickup.wav" "drop_sound" "ui/item_metal_weapon_drop.wav" } } "attributes" { } "item_sets" { } "attribute_controlled_attached_particles" { } }
Is one example.
< >
Showing 1-1 of 1 comments
Per page: 1530 50