Adding Weapons (FA:S 2)

Need some help with gamemode related stuff?

Adding Weapons (FA:S 2)

Postby Andy » Sat Jun 07, 2014 7:46 pm

Hello there!

My name is Andy, and I've recently been 'hired' as coder for an up-rising community called Hazardous Gaming.
I really like the gamemode, and most of the coding is easy to understand, which makes me happy as a newbie.

My problem is:
I'm trying to add FA:S 2 to the gamemode, and to the shop menu, and it worked pretty well... with the Glock 20. I've tried with several other weapons (AK47,AK74,G3A3,SKS), and each of them has different problems. And yes, I have been google'ing for hours without results, since noone really dares to try and edit this awesome gamemode. Hope you can help me.
Here's a list:

AK47:
  • When bought, it's hovering above the ground, can't pick it up.
  • When in equipment menu, it shows up as "AK-Composite.

AK74
  • When bought, it's hovering above the ground, can't pick it up.
  • When in equipment menu, it shows up as "AK-Composite.

G3A3:
  • When bought, it's hovering above the ground, can't pick it up.
  • When in equipment menu, it shows up as "AK-Composite.

SKS:
  • Doesn't show up in the equipment-menu at all when pocketed.


Codes for the weapons:

AK47:
Code: Select all
local ITEM = {}
local WEAPON = {}


ITEM.ID = "fas2_ak47"

ITEM.Name = "AK-47"
ITEM.ClassSpawn = "Engineer"
ITEM.Scrap = 250
ITEM.Small_Parts = 280
ITEM.Chemicals = 170
ITEM.Chance = 100
ITEM.Info = "AK-47 the Father of all Russian Assault rifles. "
ITEM.Type = "weapon"
ITEM.Remove = true
ITEM.Energy = 1
ITEM.Ent = "fas2_ak47"
ITEM.Model = "models/weapons/w_rif_ak47.mdl"
ITEM.Script = ""
ITEM.Weight = 6
ITEM.ShopHide = true

WEAPON.ID = ITEM.ID
WEAPON.AmmoType = "fas2_ammo_762x39"

function ITEM.ToolCheck( p )
   return true
end

function ITEM.Use( ply )
   local WepName = "fas2_ak47"
   local gotWep = false
   for k, v in pairs(ply:GetWeapons()) do
      if v:GetClass() == WepName then gotWep = true end
   end
   if gotWep == false then
      ply:Give(WepName)
      ply:GetWeapon(WepName):SetClip1(0)
      return true
   else
      ply:ChatPrint("Weapon already equipped.")
      return false
   end
end

function ITEM.Create( ply, class, pos )
   local ent = ents.Create("ent_weapon")
   --ent:SetNetworkedInt("Ammo", self.Energy)
   ent:SetNWString("WepClass", ITEM.Ent)
   ent:SetModel(ITEM.Model)
   ent:SetAngles(Angle(0,0,0))
   ent:SetPos(pos)
   ent:Spawn()
   
   return ent
end

PNRP.AddItem(ITEM)
PNRP.AddWeapon(WEAPON)


AK74:
Code: Select all
local ITEM = {}
local WEAPON = {}


ITEM.ID = "fas2_ak74"

ITEM.Name = "AK-74"
ITEM.ClassSpawn = "Engineer"
ITEM.Scrap = 200
ITEM.Small_Parts = 280
ITEM.Chemicals = 250
ITEM.Chance = 100
ITEM.Info = "AK-74 Is chambered in 5.45x39 which was inspired by 5.62 NATO  "
ITEM.Type = "weapon"
ITEM.Remove = true
ITEM.Energy = 1
ITEM.Ent = "fas2_ak74"
ITEM.Model = "models/weapons/w_rif_ak47.mdl"
ITEM.Script = ""
ITEM.Weight = 4
ITEM.ShopHide = true

WEAPON.ID = ITEM.ID
WEAPON.AmmoType = "fas2_ammo_545x39"

function ITEM.ToolCheck( p )
   return true
end

function ITEM.Use( ply )
   local WepName = "fas2_ak74"
   local gotWep = false
   for k, v in pairs(ply:GetWeapons()) do
      if v:GetClass() == WepName then gotWep = true end
   end
   if gotWep == false then
      ply:Give(WepName)
      ply:GetWeapon(WepName):SetClip1(31)
      return true
   else
      ply:ChatPrint("Weapon already equipped.")
      return false
   end
end

function ITEM.Create( ply, class, pos )
   local ent = ents.Create("ent_weapon")
   --ent:SetNetworkedInt("Ammo", self.Energy)
   ent:SetNWString("WepClass", ITEM.Ent)
   ent:SetModel(ITEM.Model)
   ent:SetAngles(Angle(0,0,0))
   ent:SetPos(pos)
   ent:Spawn()
   
   return ent
end

PNRP.AddItem(ITEM)
PNRP.AddWeapon(WEAPON)


G3A3:
Code: Select all
local ITEM = {}
local WEAPON = {}


ITEM.ID = "fas2_g3"

ITEM.Name = "HK G3"
ITEM.ClassSpawn = "Engineer"
ITEM.Scrap = 300
ITEM.Small_Parts = 360
ITEM.Chemicals = 280
ITEM.Chance = 100
ITEM.Info = "HK G3 is Chambered In 5.56 NATO And was used in almost every Conflict since 1959.  "
ITEM.Type = "weapon"
ITEM.Remove = true
ITEM.Energy = 1
ITEM.Ent = "fas2_g3"
ITEM.Model = "models/weapons/w_rif_ak47.mdl"
ITEM.Script = ""
ITEM.Weight = 6
ITEM.ShopHide = true

WEAPON.ID = ITEM.ID
WEAPON.AmmoType = "fas2_ammo_556x45"

function ITEM.ToolCheck( p )
   return true
end

function ITEM.Use( ply )
   local WepName = "fas2_g3"
   local gotWep = false
   for k, v in pairs(ply:GetWeapons()) do
      if v:GetClass() == WepName then gotWep = true end
   end
   if gotWep == false then
      ply:Give(WepName)
      ply:GetWeapon(WepName):SetClip1(0)
      return true
   else
      ply:ChatPrint("Weapon already equipped.")
      return false
   end
end

function ITEM.Create( ply, class, pos )
   local ent = ents.Create("ent_weapon")
   --ent:SetNetworkedInt("Ammo", self.Energy)
   ent:SetNWString("WepClass", ITEM.Ent)
   ent:SetModel(ITEM.Model)
   ent:SetAngles(Angle(0,0,0))
   ent:SetPos(pos)
   ent:Spawn()
   
   return ent
end

PNRP.AddItem(ITEM)
PNRP.AddWeapon(WEAPON)


SKS:
Code: Select all
local ITEM = {}
local WEAPON = {}


ITEM.ID = "fas2_sks"

ITEM.Name = "SKS"
ITEM.ClassSpawn = "Engineer"
ITEM.Scrap = 200
ITEM.Small_Parts = 300
ITEM.Chemicals = 200
ITEM.Chance = 100
ITEM.Info = "SKS Was the first Soviet attempt at creating a service rifle after 1944. Chambered in 7.62X39 "
ITEM.Type = "weapon"
ITEM.Remove = true
ITEM.Energy = 1
ITEM.Ent = "fas2_sks"
ITEM.Model = "models/weapons/w_snip_awp.mdl"
ITEM.Script = ""
ITEM.Weight = 8
ITEM.ShopHide = true

WEAPON.ID = ITEM.ID
WEAPON.AmmoType = "fas2_ammo_762x39"

function ITEM.ToolCheck( p )
   return true
end

function ITEM.Use( ply )
   local WepName = "fas2_sks"
   local gotWep = false
   for k, v in pairs(ply:GetWeapons()) do
      if v:GetClass() == WepName then gotWep = true end
   end
   if gotWep == false then
      ply:Give(WepName)
      ply:GetWeapon(WepName):SetClip1(0)
      return true
   else
      ply:ChatPrint("Weapon already equipped.")
      return false
   end
end

function ITEM.Create( ply, class, pos )
   local ent = ents.Create("ent_weapon")
   --ent:SetNetworkedInt("Ammo", self.Energy)
   ent:SetNWString("WepClass", ITEM.Ent)
   ent:SetModel(ITEM.Model)
   ent:SetAngles(Angle(0,0,0))
   ent:SetPos(pos)
   ent:Spawn()
   
   return ent
end

PNRP.AddItem(ITEM)
PNRP.AddWeapon(WEAPON)


M24:
Code: Select all
local ITEM = {}
local WEAPON = {}


ITEM.ID = "fas2_m24"

ITEM.Name = "M24"
ITEM.ClassSpawn = "Engineer"
ITEM.Scrap = 200
ITEM.Small_Parts = 250
ITEM.Chemicals = 200
ITEM.Chance = 100
ITEM.Info = "The M24 is a 7.62X51 NATO Sniper rifle based on the Mauser Bolt action system."
ITEM.Type = "weapon"
ITEM.Remove = true
ITEM.Energy = 1
ITEM.Ent = "fas2_m24"
ITEM.Model = "models/weapons/w_snip_awp.mdl"
ITEM.Script = ""
ITEM.Weight = 8
ITEM.ShopHide = true

WEAPON.ID = ITEM.ID
WEAPON.AmmoType = "fas2_ammo_762x51"

function ITEM.ToolCheck( p )
   return true
end

function ITEM.Use( ply )
   local WepName = "fas2_m24"
   local gotWep = false
   for k, v in pairs(ply:GetWeapons()) do
      if v:GetClass() == WepName then gotWep = true end
   end
   if gotWep == false then
      ply:Give(WepName)
      ply:GetWeapon(WepName):SetClip1(0)
      return true
   else
      ply:ChatPrint("Weapon already equipped.")
      return false
   end
end

function ITEM.Create( ply, class, pos )
   local ent = ents.Create("ent_weapon")
   --ent:SetNetworkedInt("Ammo", self.Energy)
   ent:SetNWString("WepClass", ITEM.Ent)
   ent:SetModel(ITEM.Model)
   ent:SetAngles(Angle(0,0,0))
   ent:SetPos(pos)
   ent:Spawn()
   
   return ent
end

PNRP.AddItem(ITEM)
PNRP.AddWeapon(WEAPON)


And Glock 20 just to compare:
Code: Select all
local ITEM = {}
local WEAPON = {}


ITEM.ID = "fas2_glock20"

ITEM.Name = "Glock 20"
ITEM.ClassSpawn = "Engineer"
ITEM.Scrap = 90
ITEM.Small_Parts = 90
ITEM.Chemicals = 60
ITEM.Chance = 100
ITEM.Info = "Glock 20 secondary weapon favoured for its 10x25 Cartridge. This model looks like it's been made in the back of a shed."
ITEM.Type = "weapon"
ITEM.Remove = true
ITEM.Energy = 16
ITEM.Ent = "fas2_glock20"
ITEM.Model = "models/weapons/w_pist_glock18.mdl"
ITEM.Script = ""
ITEM.Weight = 4
ITEM.ShopHide = true

WEAPON.ID = ITEM.ID
WEAPON.AmmoType = "fas2_ammo_10x25"

function ITEM.ToolCheck( p )
   return true
end

function ITEM.Use( ply )
   local WepName = "fas2_glock20"
   local gotWep = false
   for k, v in pairs(ply:GetWeapons()) do
      if v:GetClass() == WepName then gotWep = true end
   end
   if gotWep == false then
      ply:Give(WepName)
      ply:GetWeapon(WepName):SetClip1(0)
      return true
   else
      ply:ChatPrint("Weapon already equipped.")
      return false
   end
end

function ITEM.Create( ply, class, pos )
   local ent = ents.Create("ent_weapon")
   --ent:SetNetworkedInt("Ammo", self.Energy)
   ent:SetNWString("WepClass", ITEM.Ent)
   ent:SetModel(ITEM.Model)
   ent:SetAngles(Angle(0,0,0))
   ent:SetPos(pos)
   ent:Spawn()
   
   return ent
end

PNRP.AddItem(ITEM)
PNRP.AddWeapon(WEAPON)
Last edited by Andy on Sun Jun 08, 2014 3:15 pm, edited 1 time in total.
Andy
 
Posts: 7
Joined: Sat Jun 07, 2014 5:07 pm

Re: Adding Weapons (FA:S 2)

Postby [TBU] CrazyKid » Sat Jun 07, 2014 9:27 pm

Welcome to the forums.

First of all, to address the floating untouchable entity concerns, if you are adding custom addon content into the gamemode, you will need to have the exact entity classname for every spawned item you intend on adding. You can discover this info by starting a game of PostNuke, spawning the weapon using the spawn menu, looking at it, and typing pnrp_getinfo into your clientside console window. That command will print a list of details about any item you use it on into text chat. It's fairly straightforward. Once you attain the entity classnames for each entity you plan on adding, that would be the entity you would want to base your entity off of. Item files are meant for the shop menu, while entity files are meant for each entity that is being dropped. So, use the exact entity classname of the spawned entity you are trying to add into the gamemode as the base for your entity file.

If the entity classname is the same as the ones you are already using, there's a chance that the addon didn't install correctly. Please let me know if spawning it normally works compared to spawning it through the shop menu.

As for the name issue in the equipment menu, unfortunately, due to a bug within our system, any items in the shop menu which use the same model path as one another will appear to be the original item in the equipment menu. You are able to work around this by changing the model file name, but that would require a separate download for every client connecting. So either you can change the model file name, or simply remove either weapon which is causing the conflict. We will add this to our bugs list and try to fix it by the next patch.

However, I did notice that in the G3A3 file's code that you provided, that the model path differs from the AK-74 and AK-47 model paths. Please confirm if this is showing up as an AK-Composite in the equipment menu.

As for the SKS not appearing in the menu whatsoever, that issue is unbeknownst to me. Please verify that the entity has a valid model icon within the spawn menu. You may also want to verify every model path / entity classname if you continue having problems.

If you need any further assistance don't hesitate to get in touch.

Sincerely,
CrazyKid
PNRP Lead Administrator
[TBU] CrazyKid
Developer
 
Posts: 455
Joined: Tue Apr 26, 2011 10:58 pm

Re: Adding Weapons (FA:S 2)

Postby Andy » Sun Jun 08, 2014 3:19 pm

Hey CrazyKid, thanks for the welcome and the quick response.

I did the pnrp_getinfo on the four weapons, and got the right models. I just fucked up that before. Thanks!
I entitynames were though the same as I've written in the files above, which is placed in PostNukeRP/Gamemode/items as you said.

Everything is working correctly when I spawn them, except for the equipment thingy. I'm sure it's installed correctly.

I don't understand your fix for the equipment menu though... Do you want me to change the model-name from, let's say, "models/weapons/w_ak47.mdl" to "models/weapons/w_ak47_1.mdl" or something? Or do you mean to "models/weapons/test/w_ak47.mdl"?

G3A3 thingy is fixed. Found out that it was all supposed to use the ak47 model listed above. I have edited the codes, and edited my original post.

So, I tried adding another weapon; M24. Turns out, that this causes the SKS to show up as M24 in the equipment menu. The good news is that the M24 is working great. Posted the code for that above too.


That is what I intended to send, but then I realised; I'm using the wrong fucking model for the SKS too. Both the guns are now named SKS.

Maybe I have to change
Code: Select all
ent:SetModel(ITEM.Model)

to
Code: Select all
ent:SetModel("models/weapons/testweapon.mdl")

to make the weapon spawn with its actual model, and then use the other model for ITEM.Model, since all the weapons except clock uses some different world models for icons as for world spawn. I'll test that.

Btw, I'm just writing these "notes" to help other people to fix their shit, if they get the same problem. You don't need to answer everything here right now :)


EDIT:
I forgot to say; none of the ammo I have added is appearing in the equipment menu either. I'm going to check to model names soon and report back
Andy
 
Posts: 7
Joined: Sat Jun 07, 2014 5:07 pm

Re: Adding Weapons (FA:S 2)

Postby Andy » Sun Jun 08, 2014 3:47 pm

Okay, I need to ask something here.
This might be a complete noob-question, but is "models/weapons/asdf.mdl" the same as "PostNukeRP/content/models/weapons/" or just "*123.123.123.123* port *66666*/models/weapons/" or does it get it automaticly from workshop downloads/addons folder?
Because the models I'm using isn't in any of the directories expect addons/workshop. Should I add them into the gamemode folder?
Andy
 
Posts: 7
Joined: Sat Jun 07, 2014 5:07 pm

Re: Adding Weapons (FA:S 2)

Postby [TBU] CrazyKid » Mon Jun 09, 2014 6:33 am

Hello again,

Firstly, to fix the equipment menu not showing the correct weapon you could try to change the model file name, for example, models/weapons/w_ak47.mdl to models/weapons/w_ak47_1.mdl as you replied.

Second, the weapon models from custom addon content are located within the garrysmod/garrysmod/addons/ directory, within the addon's folder itself. If you do not have access to that folder you will need to download a program to extract .gma files (garry's mod addon files). The program available is called gmadconv.exe and is located here: http://www.facepunch.com/showthread.php?t=1173875

You simply drag the addon's .gma file located within your garrysmod/garrysmod/addons directory to the executable and it will run, and extract the addon's files.

Thirdly, you do not need to move the weapon pack's content into the gamemode folder. It can be used as an addon just the same.

And lastly, I'm not sure if models actually matter in regard to ammo appearing in the equipment menu. I believe it's the type of ammo which could possibly break. Are you using a custom ammo type from the weapon pack addon?

Thanks,
CrazyKid
[TBU] CrazyKid
Developer
 
Posts: 455
Joined: Tue Apr 26, 2011 10:58 pm

Re: Adding Weapons (FA:S 2)

Postby Andy » Mon Jun 09, 2014 6:39 am

Alright, I better get to fucking work then...

About the ammo; yes, I am using custom ammo types from the weapon pack addon. Do I need to add them to a list somewhere in the equipment system?
Andy
 
Posts: 7
Joined: Sat Jun 07, 2014 5:07 pm

Re: Adding Weapons (FA:S 2)

Postby Andy » Mon Jun 09, 2014 4:37 pm

Okay, I got this figured out.
Thanks for everything CrazyKid :)

The problem is that FA:S 2 weapons use css models as a kind of base, and them put a non-physical 'coat' over that to make them look like another model.
The solution is to rewrite the FA:S 2 weapons inside lua/weapons/weapon_name/shared.lua and give it a new "base-model" to coat in there. It's called SWEP.WorldModel, and it's right below the confusing SWEP.wm.
This requires you to extract and afterwards delete the workshop-file, and then make a new folder inside addons for the extracted FA:S 2. In here you should do the step above.
Lastly, you'll just have to write the same model inside the .lua-file in the items folder.
Repeat this for EVERY weapon you add. And remember, only use one model for one weapon, or else you have to copy/paste and rename the model.

I will post later when I figure out a fix for ammo.
Andy
 
Posts: 7
Joined: Sat Jun 07, 2014 5:07 pm

Re: Adding Weapons (FA:S 2)

Postby [TBU] CrazyKid » Tue Jun 10, 2014 7:29 pm

I'm glad you've got it all sorted out. I was glad to help. Thanks for providing your fix information. If you have any other problems don't hesitate to let me know. Thanks again! :)
[TBU] CrazyKid
Developer
 
Posts: 455
Joined: Tue Apr 26, 2011 10:58 pm

Re: Adding Weapons (FA:S 2)

Postby Andy » Wed Jun 11, 2014 12:01 pm

I still can't figure out the ammo part.
I'm really lost.
Where can you edit the equipment menu?
Andy
 
Posts: 7
Joined: Sat Jun 07, 2014 5:07 pm

Re: Adding Weapons (FA:S 2)

Postby eldarstorm » Wed Jun 11, 2014 4:02 pm

The front end of the menu should be here
PostNukeRP/Gamemode/derma/equipment.lua
Image
User avatar
eldarstorm
Developer
 
Posts: 1172
Joined: Tue Nov 17, 2009 1:56 pm

Next

Return to PNRP Tech and Troubleshooting

Who is online

Users browsing this forum: No registered users and 1 guest

cron