Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ammo constants for max clip ammo and max backpack ammo #544

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

OciXCrom
Copy link
Contributor

@OciXCrom OciXCrom commented Sep 2, 2018

To prevent using magic numbers. Most usual case is giving a weapon to a player:

give_item(id, "weapon_ak47")
cs_set_user_bpammo(id, CSW_AK47, 30)

The number 30 here should have a constant, as well as all others. I know there's cs_get_weapon_info, but there's no need to use a function here.

@OciXCrom
Copy link
Contributor Author

OciXCrom commented Sep 2, 2018

Aaaand the old commits popped up again. If someone knows how to fix that, let me know, if not, so be it.

@rsKliPPy
Copy link
Contributor

rsKliPPy commented Sep 3, 2018

The function is there exactly because you shouldn't hardcode that stuff, this is just going backwards.

@wopox1337
Copy link
Contributor

Why not give names to enums? This enums can declare array sizes

@OciXCrom
Copy link
Contributor Author

OciXCrom commented Sep 3, 2018

@rsKliPPy In order to use that function, the value of it will needs to be cached in a variable in order for it to be optimized.

static const some_ammo = cs_get_weapon_info(CSW_AK47, CS_WEAPONINFO_GUN_CLIP_SIZE)
give_item(id, "weapon_ak47")
cs_set_user_bpammo(id, CSW_AK47, some_ammo)

Imagine what you have to do when you have multiple weapons - it's very inconvenient. These values never change by default so it's better to have them as constants.

You can get the weapon cost with the same function, but we still have price constants in the file.

@wopox1337 It will give a tag mismatch when used in one of the existing functions, e.g. cs_set_user_bpammo.

@rsKliPPy
Copy link
Contributor

rsKliPPy commented Sep 3, 2018

You won't be setting ammo every frame, chill.

@ClaudiuHKS
Copy link
Contributor

Since there is a cstrike_const.inc file, I'd agree implementing these constants.

@OciXCrom
Copy link
Contributor Author

OciXCrom commented Sep 3, 2018

@rsKliPPy I'm aware of that, but I'm also aware that plugin approvers will say to precache the value for maximum optimization and "good practice".

@HamletEagle
Copy link
Contributor

I don't think you have to cache the result. Using the native directly also accounts for plugins altering WeaponInfoStruct on the fly to change bpammo/price/etc(not very likely to happen, but still).

@Arkshine
Copy link
Member

Arkshine commented Sep 3, 2018

^ That's mainly the reason.

That's said, having constants to get the original and default value could make sense but doesn't seem really useful at first glance.

@WPMGPRoSToTeMa
Copy link
Contributor

@wopox1337

This enums can declare array sizes

What do you mean?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants