AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Money Spent (https://forums.alliedmods.net/showthread.php?t=293435)

EFFx 01-31-2017 20:01

Money Spent
 
Dudes, I'm trying to pick the money spent from a player.
Thats the code:

PHP Code:

new MoneySpent[33]

public 
plugin_init()
{
    
register_message(get_user_msgid("Money"), "Message_Money")
}
public 
Message_Money(iMsgIdiMsgDestid)
{
    new 
iMsgArgInt get_msg_arg_int(1)
    new 
PlayerMoneySpent = (DefaultMoneyStart iMsgArgInt)
    
    
MoneySpent[id] = PlayerMoneySpent
    
    
new userName[32]
    
get_user_name(iduserName31)
    
console_print(0,"Player Spenting: %s, Money Spent: %d",userNamePlayerMoneySpent)


But it returns the money adding up the equipment you own, not the money spent at the beginning of the round.

Output in the first round:

Code:

Player spenting: EFFx, Money spent: 7975 ( AWP+FULL AMMO, DEAGLE+FULL AMMO, VESTHELM AND ALL GRENADES
But when the round ends and start again, appear 7675 in the console, because I threw a HE Grenade. And if I don't threw any grenade and buy an AK in the round, it shows 14075.

What I want know is any other method to return the money spent at the beginning of the round.


And ahh, i'm reseting it with Ham_Spawn and it doesn't fix the issue.

EFFx 01-31-2017 21:44

Re: Money Spent
 
Done -

PHP Code:

#include <amxmodx>
#include <cl_buy>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "author"

enum WeaponsSettings
{
    
WeaponIndex,
    
WeaponPrice
}
new const 
WeaponsIndex[][WeaponsSettings] =
{
    {
1600},
    {
22200},
    {
3275},
    {
4300},
    {
53000},
    {
60},
    {
71400},
    {
83500},
    {
9300},
    {
10800},
    {
11750},
    {
121700},
    {
134200},
    {
142000},
    {
152250},
    {
16500},
    {
17400},
    {
184750},
    {
191500},
    {
205750},
    {
211700},
    {
223100},
    {
231250},
    {
24500},
    {
25200},
    {
26650},
    {
273500},
    {
282500},
    {
290},
    {
302350},
    {
31650},
    {
321000}
}

new 
MoneySpent[33]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_logevent("Round_Start",2"1=Round_Start")
}

public 
Round_Start()
{
    for(new 
1;get_maxplayers();i++)
        
MoneySpent[i] = 0
}
public 
client_buy(idiItem)
{
    if(
isUnavaliableItem(iItem))
    {
        
console_print(id"%d"iItem)
        
        if(!
user_has_weapon(idiItem))
        {
            
MoneySpent[id] += WeaponsIndex[iItem 1][WeaponPrice]
        }
        
console_print(id,"Money Spent: %d"MoneySpent[id])
    }
}
isUnavaliableItem(const iItem)
{
    return (
iItem 32) ? false true



yas17sin 01-31-2017 22:11

Re: Money Spent
 
i didn't understand the propose of this plugin you made. :/

EFFx 01-31-2017 22:19

Re: Money Spent
 
Show how much money a player has spent.

Bugsy 01-31-2017 22:41

Re: Money Spent
 
There is no weapon index 2 and you can accomplish this using a single dimension array by putting in a placeholder. This makes the weapon index the index of the weapon price.
PHP Code:

new const WeaponsIndex[][WeaponsSettings] =
{
    {
1600},
    {
22200},
    {
3275},
    {
4300},
    {
53000},
    {
60},
    {
71400},
    {
83500},
    {
9300},
    {
10800},
    {
11750},
    {
121700}
}

//to

new const WeaponPrices[] =
{
    
0,
    
600,
    
0,
    
275,
    
300,
    
3000,
    
0,
    
1400,
    
3500,
    
300,
    
800,
    
750,
    
1700



EFFx 02-01-2017 00:00

Re: Money Spent
 
Should be like this:

PHP Code:

new const WeaponsPrices[] =
{
    
0,
    
600,
    
275,
    
300,
    
3000,
    
0,
    
1400,
    
3500,
    
300,
    
800,
    
750,
    
1700,
    
4200,
    
2000,
    
2250,
    
500,
    
400,
    
4750,
    
1500,
    
5750,
    
1700,
    
3100,
    
1250,
    
500,
    
20,
    
650,
    
3500,
    
2500,
    
0,
    
2350,
    
650,
    
1000


And

PHP Code:

MoneySpent[id] += WeaponsIndex[iItem 1


Bugsy 02-01-2017 05:54

Re: Money Spent
 
No, you should not do '-1'. What I gave you will directly take the CSW_ weapon index.

Example using P228, weapon index 1, which is $600.

With what I told you:
PHP Code:

new const WeaponPrices[] =
{
    
0,
    
600,  <- Array index 1 Access with WeaponPricesCSW_P228 

What you claim (which is wrong):
PHP Code:

new const WeaponPrices[] =
{
    
0,     <- Array index 0 Access with WeaponPricesCSW_P228 ]
    
600

What I gave you is the purpose of padding the array with a 0 in slot 0 so you do not need to use '-1' every time you want the price. Your statement would be valid with an array not padded with 0 in index 0:
PHP Code:

new const WeaponsPrices[] =
{
    
600,  <- Array index 0 Access with WeaponPricesCSW_P228 ]
    
275


EFFx 02-01-2017 15:41

Re: Money Spent
 
Yea, its showing a debug with index out of bounds. It works only with -1.

Bugsy 02-01-2017 16:49

Re: Money Spent
 
I'm assuming you're using the full sized array and not just the sample I posted.

If you are, which weapon throws that error?

EFFx 02-01-2017 16:54

Re: Money Spent
 
I was picking all the weapons's price, not only until the ump45.
Vesthelm 1 and 2. All others weapon's index more than the ump45.


All times are GMT -4. The time now is 20:41.

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