Raised This Month: $12 Target: $400
 3% 

CS_OnBuyAttempt


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 02-13-2016 , 10:21   CS_OnBuyAttempt
Reply With Quote #1

Hi i am again here

A player have reported to me that function is broken:

PHP Code:
public CS_OnBuyAttempt(id,iItem)
{
    if((
iItem == CSI_DEFUSER) && !cs_get_user_defuse(id))
    {
        new 
iMoney cs_get_user_money(id);
        
        if(
iMoney >= 200)
        {
            
cs_set_user_money(id,iMoney 200);
        }
    }

This is a small fix to discount money if player will buy a defuse, but the problem is for Team TR side.
The money will be deduced if TR not have defuse, and i know that i can add a team check to fix that.

But the real problem is that player have defuser command in autobuy.txt, and CS is trying to buy a defuse even if he is TR.

Ps. It is possible to add a team in function header, soo i not need to retreive cs_get_user_team?

Thanks for read, and sorry if is not a valid issue here.

__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
xPaw
Retired AMX Mod X Moderator
Join Date: Jul 2008
Old 02-13-2016 , 12:49   Re: CS_OnBuyAttempt
Reply With Quote #2

Have you tried using CS_OnBuy instead?
__________________
xPaw is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-13-2016 , 12:56   Re: CS_OnBuyAttempt
Reply With Quote #3

Can you try to rephraze your issue? I really don't get.

Remember this:

- CS_OnBuyAttempt: called when player issue a command (basically that would be the same as using ClientCommand). So, it's called before anything else, before any game checks to see if you can actually buy the item and such.

- CS_OnBuy: called when player is about to get the item. Game checks are done, and you can sure to receive what you bought. Money is not yet taken.


So, what are you trying to do, what is the actual issue with those two forwards?
__________________
Arkshine is offline
Cryptix
New Member
Join Date: Dec 2006
Old 02-13-2016 , 14:25   Re: CS_OnBuyAttempt
Reply With Quote #4

He's trying to reduce $200 for those who purchase defuse-kit (CTs Only). As he states, for some reason T-Side can simulate a defuse-kit purchase through "autobuy". So it would just keep reducing $200 each time a T-side player autobuys.
Cryptix is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-13-2016 , 15:05   Re: CS_OnBuyAttempt
Reply With Quote #5

I don't see how it can happen. Server-side, there is a team check, whatever you're using old-menu with or alias "defuser".

I've tried myself, putting autobuy.txt in my Steam\steamapps\common\Half-Life\czero ; then typing "autobuy" in the console, result: I can buy it when I'm CT, I can't when I'm T (and money is not taken)

Did I miss something?
__________________

Last edited by Arkshine; 02-13-2016 at 15:06.
Arkshine is offline
Netsys
Senior Member
Join Date: Feb 2010
Old 02-13-2016 , 18:06   Re: CS_OnBuyAttempt
Reply With Quote #6

Smiley you must use CS_OnBuy instead of CS_OnBuyAttempt
Netsys is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 02-13-2016 , 19:56   Re: CS_OnBuyAttempt
Reply With Quote #7

Quote:
Originally Posted by Netsys View Post
Smiley you must use CS_OnBuy instead of CS_OnBuyAttempt
Same result bro, the problem is try to buy a item that can used only by CT team like defuser.
I am simple checking if user has defuse or not, but if he is tr i need to add a check to team until here ok.

But in CstrikeHacks.cpp

Code:
if (HasInternalCommandForward && *UseBotArgs && MF_ExecuteForward(ForwardInternalCommand, client, *BotArgs) > 0)
  {
    return;
  }

  if (HasOnBuyAttemptForward && CurrentItemId && MF_ExecuteForward(ForwardOnBuyAttempt, client, CurrentItemId) > 0)
  {
    return;
  }
Someone can try to pass TeamId to forward? that will be welcome in this cases not?
@Arkshine the real problem is case if you will deduce money from player, or cs_get_user_defuse function need to always return FALSE in case of teamTR player.

Sorry again if i cannot explain better.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 02-13-2016 at 19:57.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 02-14-2016 , 04:25   Re: CS_OnBuyAttempt
Reply With Quote #8

Quote:
Originally Posted by Arkshine View Post
I've tried myself, putting autobuy.txt in my Steam\steamapps\common\Half-Life\czero ; then typing "autobuy" in the console, result: I can buy it when I'm CT, I can't when I'm T (and money is not taken)
Could you tell me how to reproduce the issue? because I can't.

Or are you trying to give free defuser or something? if so, then use CS_OnBuy, forward will not be called if you are T and you try to buy defuser.
__________________

Last edited by Arkshine; 02-14-2016 at 04:32.
Arkshine is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 02-14-2016 , 06:20   Re: CS_OnBuyAttempt
Reply With Quote #9

I will test it again, but basically is using autobuy.txt
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 02-18-2016 , 13:33   Re: CS_OnBuyAttempt
Reply With Quote #10

here is a fix for my problem, a guy that tested this have not used lest amxx dev versions.

https://github.com/alliedmodders/amx...c81c2b658d7905

Ps. Thanks for help
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:22.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode