Raised This Month: $32 Target: $400
 8% 

Solved Can't seem to understand CS_OnBuyCommand


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
andrept4
Senior Member
Join Date: Dec 2012
Location: Portugal
Old 06-20-2019 , 19:08   Can't seem to understand CS_OnBuyCommand
Reply With Quote #1

So, I'm trying to write a plugin that makes users with a certain flag have a "discount" when buying kevlar.
The problem is that only users with that flag can buy kevlar and kevlar+helmet, others can't. And nobody can buy any other weapon!
Here's the code:

Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>

ConVar cvar_bonusmoney = null;

int smbonusmoney = 0;

public Plugin myinfo = {
	name = "Privilegios Sponsor",
	author = "Gela | 1511",
	description = "Plugin feito pelo Gela para a PUNT.PT",
	version = "1.0",
	url = "punt.pt"
}

public void OnPluginStart() {
	cvar_bonusmoney = CreateConVar("sm_privilegiossponsor_bonus", "150", "Dinheiro que diminui o preco colete/colete+capacete", ADMFLAG_CONVARS);
	AutoExecConfig(true, "PrivilegiosSponsor", "sourcemod");

	smbonusmoney = GetConVarInt(cvar_bonusmoney);
}

public Action CS_OnBuyCommand(int client, const char[] weapon) {
	if(CheckCommandAccess(client, "sponsorprivilege", ADMFLAG_CUSTOM1)) {
		int money = GetEntProp(client, Prop_Send, "m_iAccount");
		if(StrEqual(weapon, "assaultsuit")) //check if player is buying kevlar or kevlar+helmet
		{
			if(GetEntProp(client, Prop_Data, "m_ArmorValue") != 100) {
				int smbonusmoneyy = 1000 - smbonusmoney;
				int moneyreceived = money - smbonusmoneyy;
				SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
				SetEntProp(client, Prop_Send, "m_ArmorValue", 100);
				SetEntProp(client, Prop_Data, "m_bHasHelmet", 1);
			} else {
				if(money >= 350) {
					int moneyreceived = money - 0;
					SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
					SetEntProp(client, Prop_Data, "m_bHasHelmet", 1)
				}
			}
		} 
		else if(StrEqual(weapon, "kevlar")) 
		{
			int smbonusmoneyy = 650 - smbonusmoney;
			int moneyreceived = money - smbonusmoneyy;
			SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
			SetEntProp(client, Prop_Data, "m_ArmorValue", 100);
			
		}
	}
	return Plugin_Handled;
}
__________________

Last edited by andrept4; 06-24-2019 at 06:23. Reason: forgot to tell the problem
andrept4 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 06-20-2019 , 20:49   Re: Can't seem to understand CS_OnBuyCommand
Reply With Quote #2

Quote:
Originally Posted by andrept4 View Post
So, I'm trying to write a plugin that makes users with a certain flag have a "discount" when buying kevlar.
The problem is that only users with that flag can buy kevlar and kevlar+helmet, others can't. And nobody can buy any other weapon!
Here's the code:

Code:
#include <sourcemod>
#include <cstrike>
#include <sdktools>

ConVar cvar_bonusmoney = null;

int smbonusmoney = 0;

public Plugin myinfo = {
	name = "Privilegios Sponsor",
	author = "Gela | 1511",
	description = "Plugin feito pelo Gela para a PUNT.PT",
	version = "1.0",
	url = "punt.pt"
}

public void OnPluginStart() {
	cvar_bonusmoney = CreateConVar("sm_privilegiossponsor_bonus", "150", "Dinheiro que diminui o preco colete/colete+capacete", ADMFLAG_CONVARS);
	AutoExecConfig(true, "PrivilegiosSponsor", "sourcemod");

	smbonusmoney = GetConVarInt(cvar_bonusmoney);
}

public Action CS_OnBuyCommand(int client, const char[] weapon) {
	if(CheckCommandAccess(client, "sponsorprivilege", ADMFLAG_CUSTOM1)) {
		int money = GetEntProp(client, Prop_Send, "m_iAccount");
		if(StrEqual(weapon, "assaultsuit")) //check if player is buying kevlar or kevlar+helmet
		{
			if(GetEntProp(client, Prop_Data, "m_ArmorValue") != 100) {
				int smbonusmoneyy = 1000 - smbonusmoney;
				int moneyreceived = money - smbonusmoneyy;
				SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
				SetEntProp(client, Prop_Send, "m_ArmorValue", 100);
				SetEntProp(client, Prop_Data, "m_bHasHelmet", 1);
			} else {
				if(money >= 350) {
					int moneyreceived = money - 0;
					SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
					SetEntProp(client, Prop_Data, "m_bHasHelmet", 1)
				}
			}
		} 
		else if(StrEqual(weapon, "kevlar")) 
		{
			int smbonusmoneyy = 650 - smbonusmoney;
			int moneyreceived = money - smbonusmoneyy;
			SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
			SetEntProp(client, Prop_Data, "m_ArmorValue", 100);
			
		}
	}
	return Plugin_Handled;
}
https://sm.alliedmods.net/new-api/cs...S_OnBuyCommand

so you should return Plugin_Handled ONLY if player tries to buy kevlar/helmet
and Plugin_Continue otherwise
__________________
8guawong is offline
andrept4
Senior Member
Join Date: Dec 2012
Location: Portugal
Old 06-21-2019 , 06:24   Re: Can't seem to understand CS_OnBuyCommand
Reply With Quote #3

Quote:
Originally Posted by 8guawong View Post
https://sm.alliedmods.net/new-api/cs...S_OnBuyCommand

so you should return Plugin_Handled ONLY if player tries to buy kevlar/helmet
and Plugin_Continue otherwise
So like this? :
Code:
 
public Action CS_OnBuyCommand(int client, const char[] weapon) {
	if(CheckCommandAccess(client, "sponsorprivilege", ADMFLAG_CUSTOM1)) {
		int money = GetEntProp(client, Prop_Send, "m_iAccount");
		if(StrEqual(weapon, "assaultsuit")) //check if player is buying kevlar or kevlar+helmet
		{
			if(GetEntProp(client, Prop_Data, "m_ArmorValue") != 100) {
				int smbonusmoneyy = 1000 - smbonusmoney;
				int moneyreceived = money - smbonusmoneyy;
				SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
				SetEntProp(client, Prop_Send, "m_ArmorValue", 100);
				SetEntProp(client, Prop_Data, "m_bHasHelmet", 1);
				return Plugin_Handled;
			}
		} 
		else if(StrEqual(weapon, "kevlar")) 
		{
			int smbonusmoneyy = 650 - smbonusmoney;
			int moneyreceived = money - smbonusmoneyy;
			SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
			SetEntProp(client, Prop_Data, "m_ArmorValue", 100);
			return Plugin_Handled;
		}
		return Plugin_Continue;
	}
	return Plugin_Continue;
}
__________________
andrept4 is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 06-21-2019 , 07:02   Re: Can't seem to understand CS_OnBuyCommand
Reply With Quote #4

Quote:
Originally Posted by andrept4 View Post
So like this? :
Code:
 
public Action CS_OnBuyCommand(int client, const char[] weapon) {
	if(CheckCommandAccess(client, "sponsorprivilege", ADMFLAG_CUSTOM1)) {
		int money = GetEntProp(client, Prop_Send, "m_iAccount");
		if(StrEqual(weapon, "assaultsuit")) //check if player is buying kevlar or kevlar+helmet
		{
			if(GetEntProp(client, Prop_Data, "m_ArmorValue") != 100) {
				int smbonusmoneyy = 1000 - smbonusmoney;
				int moneyreceived = money - smbonusmoneyy;
				SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
				SetEntProp(client, Prop_Send, "m_ArmorValue", 100);
				SetEntProp(client, Prop_Data, "m_bHasHelmet", 1);
				return Plugin_Handled;
			}
		} 
		else if(StrEqual(weapon, "kevlar")) 
		{
			int smbonusmoneyy = 650 - smbonusmoney;
			int moneyreceived = money - smbonusmoneyy;
			SetEntProp(client, Prop_Send, "m_iAccount", moneyreceived);
			SetEntProp(client, Prop_Data, "m_ArmorValue", 100);
			return Plugin_Handled;
		}
		return Plugin_Continue;
	}
	return Plugin_Continue;
}
yes try it
__________________
8guawong is offline
farawayf
Senior Member
Join Date: Jan 2019
Old 06-21-2019 , 07:32   Re: Can't seem to understand CS_OnBuyCommand
Reply With Quote #5

afaik the function will be done even if the player does not have that much money

PHP Code:

public Action CS_OnBuyCommand(int client, const char[] weapon) {
    if(
CheckCommandAccess(client"sponsorprivilege"ADMFLAG_CUSTOM1)) {
        
int money GetEntProp(clientProp_Send"m_iAccount");
        if(
StrEqual(weapon"assaultsuit")) {
            if(
money >= 1000) {
                if(
GetEntProp(clientProp_Data"m_ArmorValue") != 100) {
                    
int smbonusmoneyy 1000 smbonusmoney;
                    
int moneyreceived money smbonusmoneyy;
                    
SetEntProp(clientProp_Send"m_iAccount"moneyreceived);
                    
SetEntProp(clientProp_Send"m_ArmorValue"100);
                    
SetEntProp(clientProp_Data"m_bHasHelmet"1);
                }    
            }
        }    
        if(
StrEqual(weapon"kevlar")) {
            if(
money >= 650) {
                
int smbonusmoneyy 650 smbonusmoney;
                
int moneyreceived money smbonusmoneyy;
                
SetEntProp(clientProp_Send"m_iAccount"moneyreceived);
                
SetEntProp(clientProp_Data"m_ArmorValue"100);
            }    
        }
    }    
    return 
Plugin_Continue;


Last edited by farawayf; 06-21-2019 at 07:34.
farawayf is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 06-22-2019 , 06:05   Re: Can't seem to understand CS_OnBuyCommand
Reply With Quote #6

https://sm.alliedmods.net/new-api/cs...GetWeaponPrice
__________________
Ilusion9 is offline
Reply



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 03:11.


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