[Cs:s] How to get buying weapon price

Please post any questions about developing your plugin here. Please use the search function before posting!
cssbestrpg
Senior Member
Posts: 309
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

[Cs:s] How to get buying weapon price

Postby cssbestrpg » Thu Jun 03, 2021 6:19 pm

Hi,
how i can get price of current weapon price, when player purchases a weapon?
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

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

Postby satoon101 » Thu Jun 03, 2021 8:44 pm

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.
Image
cssbestrpg
Senior Member
Posts: 309
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

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

Postby cssbestrpg » Fri Jun 04, 2021 4:55 am

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)
User avatar
satoon101
Project Leader
Posts: 2698
Joined: Sat Jul 07, 2012 1:59 am

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

Postby satoon101 » Fri Jun 04, 2021 12:00 pm

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.
Image
cssbestrpg
Senior Member
Posts: 309
Joined: Sun May 17, 2020 7:56 am
Location: Finland
Contact:

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

Postby cssbestrpg » Sat Jun 05, 2021 3:03 pm

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

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 14 guests