Solution to saving edited weapon values?

Hi there, I’ve run into an issue I don’t know where to continue from. I’m currently attempting to edit weapon values (weapons from a workshop addon - the weapons are not my own creation) for a gamemode I’m creating. The gamemode provides weapon information when a weapon is equipped (via weapons.Get), but so far, editing the weapon (via weapons.GetStored - not weapons.Get ), only seems to result in changing the values within the current server environment. This does not affect the values returned by weapons.Get and I need them to.

From here, I see I have 2 options available:

  • Instead of editing the weapon via inside the gamemode and using weapons.GetStored, I can just edit the weapon file itself
    OR
  • Figure out a way to overwrite the weapon’s code so that the values I assign in the gamemode are saved into the weapon’s file permanently

I would like to avoid option 1 at all costs, as going through some 40 weapons (+ more in the future if I decide more) takes a whooooole lot of time and makes updating the weapon pack (which updates quite often) a huge pain in the ass. But with that being said, I have no clue how to go about option 2, or if it’s even possible to in the first place.

Any help would be appreciated.

Ctrl+S is usually the save hotkey in text programs

Why would you not want to do it in the gamemode? That is the proper way. After the weapons are all loaded, you just override whatever values you need to using weapons.GetStored. Every time your gamemode loads, your script will be ran and the values will be set.

I say and I qoute:
“so far, editing the weapon (via weapons.GetStored - not weapons.Get ), only seems to result in changing the values within the current server environment. This does not affect the values returned by weapons.Get and I need them to.

I don’t understand.

If I put that first line in a gamemode, then every time the gamemode is loaded, the value would be set. weapons.Get works just fine.

It isn’t doing that for me. Re-read what I wrote in the initial post carefully.

If that isn’t working for you, then you’re doing something wrong. Instead of telling me to read your post again, perhaps you can elaborate further.

The code that changes the value:



if weapons.Get( "cw_kk_ins2_m40a1" ) then
    local wep = weapons.GetStored( "cw_kk_ins2_m40a1" )
    wep.Damage = 100
    insertmorewep.here
end


How the values are printed, inside a vgui DPanel paint function:



local wep = weapons.Get( selectedprimary )
draw.SimpleText( "Damage: " .. math.Round( wep.Damage, 3 ), "fontgoeshere", xoffset, yoffset, color )


The default value is 63, and it only ever shows 63.

[editline]1st November 2016[/editline]

Pics or it didn’t happen:

The code that edits the weapon value

The code that draws the weapon text

The order in which the files are loaded (the menu one being first)

Yup that’s was what i exactly did with MRP and worked to fix some missing sounds and tweat damage

What?

[lua]
if weapons.Get( “cw_kk_ins2_m40a1” ) then
local wep = weapons.GetStored( “cw_kk_ins2_m40a1” )
wep.Damage = 100
insertmorewep.here
end
[/lua]

I was confirming that i did your same thing to deal with this problem
Although you can delay the include a bit so it gets called just after weapons loads, or in InitPostEntity hook

Well that’s the thing, the weapon’s damage DOES get changed to 100. The weapon still FUNCTIONS as if it had 100 damage, but using weapons.Get doesn’t show that, it just shows it’s initial value.

This is where I am stuck…

Because you are changing the value SERVERSIDE ONLY, you need to change it clientside too so client will know it.

Yup, just run the code that modifies the weapon in a shared file

Oh that would be it, how did I not think of doing that… Shit I’m stupid. Thanks for helping!

It’s a rookie mistake, very common when starting out. It can take quite a while until you fully understand how states work and interact with each other, just don’t let it stop you :slight_smile:

I remember that I had trouble with similar things too, when I started out.

It’s my first major project, yea it’s been a huge learning experience.