TTT2
TTT2 copied to clipboard
EquipmentEditor: Set clip on buy
Added SWEP.SetClipOnBuy
and SWEP.ClipOnBuy
to set the weapon's clip on buy via the equipment editor. I did not want to just use the latter variable to set a clip on buy to all weapons as most "one time use weapons" instantly remove the weapon on use which makes this slider pointless. It is therefore something swep makers have to integrate into their weapon, which is pretty simple.
I also reordered some elements in the equipment menu because they were out of place. It now looks like this:
Im opposed to the networking part, can you quickly explain why that is necessary?
Im opposed to the networking part, can you quickly explain why that is necessary?
It is needed to update the clip variable on the client as well. This was the easiest solution I could find at least. As @ZenBre4ker said the saved keys are networked, but I have to set wep.Primary.ClipSize
to the value of wep.ClipOnBuy
if wep.SetClipOnBuy
is set to true. I could probably also achieve this with the already networked data and a hook/timer combo. But I did not investigate this. I'm also not at home for the coming two weeks. So if someone wants to look into it, please go ahead, I'm only available via text though
@saibotk Just to ping you as you did not answer to my comment
But why does the client need this? What happens if you dont do that?
Seems like something that gmod should/would handle.
But why does the client need this? What happens if you dont do that?
Seems like something that gmod should/would handle.
The Playerinfo HUD element is bugged and shows the wrong max clip size. GMod does not handle this, GMod sadly has no max clip. This is manually handled by TTT
Can this be solved via the weapon entity's network variables? Like we do with the sprint system? Seems like the more correct place for this instead of another side channel network update. If not im fine with this. Thanks for explaining!
Can this be solved via the weapon entity's network variables? Like we do with the sprint system? Seems like the more correct place for this instead of another side channel network update. If not im fine with this. Thanks for explaining!
Not sure, hm. It is not something that is updated on the fly though. Maybe I can use the synced data from @ZenBre4ker's settings stuff, but I did not investigate this and he did not yet answer
So, Im wondering why this is something TTT2 should implement? Isnt that a default setting when you get equipment, that it can have ammo directly?
Otherwise while cliponBuy is synchronized it is just a static setting. But generally you would only need to check it on the client on the receiving end and add that amount to your clip. Not really necessary to send it to the client additionally.
So, Im wondering why this is something TTT2 should implement? Isnt that a default setting when you get equipment, that it can have ammo directly?
Yes. But there are multiple weapons that want to have a configurable clip size. Using the .Primary.Clip
variable doesn't work because it is only updated on weapon initialization when the file is loaded (so only once per map change) and it would also break weapons that do not account for dynamic clip size.
I therefore added the ClipOnBuy
variable that is only used if the weapon creator enables it. It can be used so that the defi has a definable amount of uses without the hacking that is currently in place.
Not really necessary to send it to the client additionally.
As I said in a previous comment that does not work. If you do not set the MaxClip on the client manually, it ends up showing stuff like "4 / 1" (four out of one) left, which I consider a bug.
I'm not sure if I actually answered your question though as I already wrote the same in the description and the previous comments. So you might have to clarify your question a bit more
Edit: I think I got your second part. I'm not sure how to use it though. Is there a hook or a callback when the data arrived on the client? I don't want to poll it in a think hook for example
There should be something in the database you can hook to.
There should be something in the database you can hook to.
All I could find is this: https://github.com/TTT-2/TTT2/blob/master/lua/ttt2/libraries/database.lua#L291
But as far as I can see this is only called in the realm where it is stored (the server in this case) and it is also not called when the weapon is initialized and the value from the database is only read, not changed
Mhh, normally it should be synced. Same way we do it for "database"-element in the ui.
Mhh, normally it should be synced. Same way we do it for "database"-element in the ui.
I've never worked with your synced database stuff. So if you think there is a better solution to my custom syncing, I'd really appreciate pointers that show me what to do because I'm not that motivated to start working through all the database and syncing stuff you did, that was quite a lot. Thanks!
I Thought about this here, should work the same for your case: https://github.com/TTT-2/TTT2/blob/297be1b71501eef88f96b81602eb5d132785690b/lua/ttt2/libraries/items.lua#L87-L101
Thank you, I will check it out!
I simplified the syncing a lot by using the syncing that sven already implemented
Before merging I will probably rename the variable. I also have to test if the UI is working as intended, I think I forgot to set the MaxClip. But that is an easy fix.
Just so you are aware and don't merge it yet.
Tested and works. @ZenBre4ker feel free to merge once your comments are resolved.