Hi,
how i can get price of current weapon price, when player purchases a weapon?
[Cs:s] How to get buying weapon price
-
- Senior Member
- Posts: 309
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
Re: [Cs:s] How to get buying weapon price
If you don't have weapon customizations that would affect it, you can always use something like (iirc):
*Edit: also, if you hook buy_internal, it might include the amount they paid, but I can't remember.
Syntax: Select all
from weapons.manager import weapon_manager
weapon = 'ak47'
print(weapon_manager['ak47'].cost)
*Edit: also, if you hook buy_internal, it might include the amount they paid, but I can't remember.
-
- Senior Member
- Posts: 309
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
Re: [Cs:s] How to get buying weapon price
Thanks i got it work with this code:
Syntax: Select all
@EntityPreHook(EntityCondition.is_player, 'buy_internal')
def pre_buy(args):
weapon = 'weapon_'+args[1]
price = (weapon_manager[weapon].cost)
Re: [Cs:s] How to get buying weapon price
A couple things to note on that. First, the parentheses around the value in price are unnecessary. Also, weapon_manager will automatically add the 'weapon_' prefix, so no need to do that yourself. Lastly, and most importantly, there are items you can buy that are not weapons and will cause that to error. You might rather use something like:
One more thing to consider is that you are using a pre-hook. So, it is possible there is another hook that stops the purchasing of the weapon (like the SP weapon restriction package). In that case, you're getting the cost of a weapon that the player does not actually end up buying.
Syntax: Select all
@EntityPreHook(EntityCondition.is_player, 'buy_internal')
def pre_buy(stack_data):
try:
price = weapon_manager[stack_data[1]].cost
except KeyError:
return
One more thing to consider is that you are using a pre-hook. So, it is possible there is another hook that stops the purchasing of the weapon (like the SP weapon restriction package). In that case, you're getting the cost of a weapon that the player does not actually end up buying.
-
- Senior Member
- Posts: 309
- Joined: Sun May 17, 2020 7:56 am
- Location: Finland
- Contact:
Re: [Cs:s] How to get buying weapon price
I think the pre-hook for weapon purchasing price should work fine for my use.
Its going to be used my zombie riot plugin(In coming update i haven't release). It doesn't have any hooks that stops the purchasing of the weapon.
Thanks for your help
Its going to be used my zombie riot plugin(In coming update i haven't release). It doesn't have any hooks that stops the purchasing of the weapon.
Thanks for your help
Return to “Plugin Development Support”
Who is online
Users browsing this forum: No registered users and 5 guests