• Attempting to retrieve weapon values from HL2 weapons
    13 replies, posted
I'm trying to retrieve the weapon values from the HL2 weapons, such as weapon damage, magazine capacity, printname, world model, and etc. This is being done dynamically by my custom menu panels for displaying weapon information. In this instance, the weapon is the AR2 (with classname "weapon_ar2") function WeaponOptionPanel:SetWeapon( newWeaponClass, weaponCost, weaponType, specialName, specialModel ) self.class = newWeaponClass self.cost = weaponCost local wep = weapons.GetStored( self.class ) self.name = specialName or wep.PrintName self.model = specialModel or wep.WorldModel self.tablekey = weaponType self.ammo = wep.Ammo --[[self.damage = wep.Damage self.recoil = wep.Recoil self.rof = wep.FireDelay self.magazine = wep.ClipSize]] self.ammowang = vgui.Create( "AmmoWang", self ) self.ammowang:SetDecimals( 0 ) self.ammowang:SetAmmo( self.ammo, GAMEMODE.AmmoTable[ self.ammo ][ LocalPlayer():Team() ] ) self.ammowang:SetSize( 10, 5 ) self.ammowang:SetPos( self:GetWide() - self.ammowang:GetWide() - 4, self:GetTall() / 2 - ( self.ammowang:GetTall() / 2 ) ) end It's erroring out on line 6 of this, the "self.name = specialName or wep.PrintName" line, with a nil value error. weapons.GetStored is obviously getting a valid string (which I've checked - IS weapon_ar2) so it's not erroring, but wep remains nil. So how am I supposed to retrieve weapon info for the HL2 weapons? I know the right classnames, I know the proper function. What am I missing?
weapons.GetStored only works on scripted weapons. I'm not sure of a way to programmatically get the values you want.
That's very frustrating. Does anyone know any of the values for the HL2 weapons? Because I can't find any files for them in all the gmod files I've scoured. Only reason I know the classname is from sandbox.
I'm not sure the exact values but I do know you can get them via GM/EntityFireBullets Print the bullet table for each weapon and use those!
But that's no way to dynamically retrieve weapon information for a menu, I'd have to manually paste all of the necessary information into my gamemode. That's not something I want to do for a menu for all of my guns. There's has to be SOME file or function somewhere I can use.
Original weapon files.
Thanks for the link. I've browsed through them and am slowly realizing I may not be able to dynamically retrieve HL2's weapon information, since this appears written in C++ (or C?). I'm going to continue looking. If anyone has any links to old threads about people discussing this, or someone's made their own spreadsheets gathering the weapon information on their own, I'd be grateful for links to anything. This helps, but it doesn't answer my original question.
I believe there are some ConVar's to set the HL2 weapons damage etc, but for other things like ammo capacity, reload times etc, you will need to hard-code a preset table for the HL2 weapons. Since it's only 9 or so weapons, it does not take that much time.
There is a list of convars that control weapon behaviors. try sk_plr_dmg_**** https://developer.valvesoftware.com/wiki/List_of_HL2_Cvars Although the convar which controls crowbar and stunstick can not be found in the GMOD.
So if I want to dynamically retrieve weapon information, and HL2 weapons will be included in that, I'll have to make a specific exception for the HL2 weapons and supplant weapon.Get with my own table. However, I still need to find all the values. Some will be easy but others not so much So doing a search for "ar2," I ran into several Cvars that exist, as was said, but don't really help me. "sk_npc_dmg_ar2  : 3  : , "sv", "rep"  : Damage dealt by the AR2 when fired by a player.** I'm pretty sure the ar2 does significantly more than 3 damage in Garry's Mod. sk_plr_dmg_ar2  : 8  : , "sv", "rep"  : Damage dealt to the player by the AR2.** This is closer to a value I could use but it's still not the correct value for me to show sk_max_ar2  : 60  : , "sv", "rep"  : Maximum amount of extra ammo that a player can hold for The AR2.** Max ammo capacity doesn't do much for me here. So I'm still looking. Unless I should give up trying to find any hard values and check for exact model, damage, and etc in-game in Garry's Mod. Running console commands or something.
You are better off defining a table with the data for the HL2 weapons as there is no way (that I know of) to access their values other than to hardcode them.
Damn. Would you happen to know where I can find the values to hardcode? Besides running checks on the weapons when I spawn them in sandbox or something. Like, some file in the gmod directory?
You would need to do it manually, check them in sandbox. They are coded in C++, compiled in the game code, no Lua files.
Appreciate the help.
Sorry, you need to Log In to post a reply to this thread.