Page 1 of 1

[Cs:s] How to get buying weapon price

Posted: Thu Jun 03, 2021 6:19 pm
by cssbestrpg
Hi,
how i can get price of current weapon price, when player purchases a weapon?

Re: [Cs:s] How to get buying weapon price

Posted: Thu Jun 03, 2021 8:44 pm
by satoon101
If you don't have weapon customizations that would affect it, you can always use something like (iirc):

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.

Re: [Cs:s] How to get buying weapon price

Posted: Fri Jun 04, 2021 4:55 am
by cssbestrpg
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

Posted: Fri Jun 04, 2021 12:00 pm
by satoon101
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:

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.

Re: [Cs:s] How to get buying weapon price

Posted: Sat Jun 05, 2021 3:03 pm
by cssbestrpg
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