AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [CS:GO] Setting money ( the only way possible ) (https://forums.alliedmods.net/showthread.php?t=315139)

eyal282 03-24-2019 10:20

[CS:GO] Setting money ( the only way possible )
 
If you're about to hit me with: "SetEntProp(client, Prop_Send, "m_iAccount", money);", I'll hit you with this video, proving it will never work unless you rek a nob, or grab a hostage, forcing your money to update.

https://youtu.be/VRGWWNEcmgo

Additional Info:

The plugin used to give 3000$ on VIP evacuation replicates it completely. You cannot do anything similar to that without Sourcemod.

Using this snippet in CS:S uses the regular method to set money, except the stock will always return false in CS:S

Useful Commands will soon have this snippet ( !money is from Useful Commands ) but right now and during testing it didn't.

The snippet is used to properly set cash, basically giving the player 0 money and forcing it to update. Set the cash in the traditional way and use RefreshMoney to force it to refresh. Please note that using any refresh function more than once in a single function / frame can be dangerous and fail the refresh.

Code:



/**
 * Gives a client a weapon and ammo for that weapon.
 *
 * @param client                Client Index.
 * @param money                        Amount of money to give to the Client.
 
 * @noreturn.
 */
stock bool SetClientMoney(int client, int money)
{
        SetEntProp(client, Prop_Send, "m_iAccount", money);
}

/**
 * Forces a money refresh on a certain number of clients. Please limit to once per function / frame / 0.1 seconds or whatever.
 *
 * @param clients                Array holding the client indexes.
 * @param numClients        Number of clients inside the array
 
 * @return                                true if money was successfully refreshed, false if failed to refresh. If this is used in CS:S or any other game, will always return false.
 
 */
stock bool RefreshMoney(int clients[], int numClients)
{       
        int moneyEntity = CreateEntityByName("game_money");
       
        if(moneyEntity == -1)
                return false;

        DispatchKeyValue(moneyEntity, "Award Text", "");
       
        DispatchSpawn(moneyEntity);
       
        AcceptEntityInput(moneyEntity, "SetMoneyAmount 0");

       
        for(inti=0;i < numClients;i++)
                AcceptEntityInput(moneyEntity, "AddMoneyPlayer", clients[i]);
               
               
        AcceptEntityInput(moneyEntity, "Kill");
       
        return true;
}

/**
 * Forces a money refresh on a certain number on a client. Never use this twice or more in a row, instead go to the function RefreshMoney to refresh as many players as you like at once.
 *
 * @param client                Client index to refresh money.
 
 * @return                                true if money was successfully refreshed, false if failed to refresh. If this is used in CS:S or any other game, will always return false.
 
 */
stock bool RefreshClientMoney(int client)
{       
        int clients[1];
        clients[0] = client;
       
        return RefreshMoney(client, 1);
}

/**
 * Forces a money refresh on all clients.
 
 * @return                                true if money was successfully refreshed, false if failed to refresh. If this is used in CS:S or any other game, will always return false.
 
 */
 
stock bool RefreshAllClientsMoney()
{       
        int clients[MAXPLAYERS+1], num;
       
        for(int i=1;i <= MaxClients;i++)
        {
                if(!IsClientInGame(i))
                        continue;
                       
                clients[num] = i;
                num++
        }
       
        return RefreshMoney(clients, num);
}

stock int GetClientMoney(client)
{
        return GetEntProp(client, Prop_Send, "m_iAccount");
}


Ilusion9 03-24-2019 16:46

Re: [CS:GO] Setting money ( the only way possible )
 
PHP Code:

mp_backup_round_auto 0 

Try with this cvar on 0.

eyal282 03-25-2019 11:31

Re: [CS:GO] Setting money ( the only way possible )
 
Quote:

Originally Posted by Ilusion9 (Post 2644795)
PHP Code:

mp_backup_round_auto 0 

Try with this cvar on 0.

"mp_backup_round_auto" = "1" game - If enabled will keep in-memory backups to handle reconnecting players even if th

Not a chance this way is better, it stops the players from having their money saved when disconnecting.

TheDS1337 03-26-2019 11:25

Re: [CS:GO] Setting money ( the only way possible )
 
Spawning the entity without checking if it's created is a bad idea... why didn't you check if moneyEntity actually points to an entity?

eyal282 03-26-2019 17:24

Re: [CS:GO] Setting money ( the only way possible )
 
Quote:

Originally Posted by TheDS1337 (Post 2644991)
Spawning the entity without checking if it's created is a bad idea... why didn't you check if moneyEntity actually points to an entity?

Why would creating the entity even fail?

TheDS1337 03-26-2019 20:57

Re: [CS:GO] Setting money ( the only way possible )
 
Quote:

Originally Posted by eyal282 (Post 2645028)
Why would creating the entity even fail?

Very unlikely, but also a good habit :)

eyal282 04-03-2019 09:05

Re: [CS:GO] Setting money ( the only way possible )
 
Stock is now better.

gubka 04-03-2019 09:17

Re: [CS:GO] Setting money ( the only way possible )
 
Quote:

Originally Posted by eyal282 (Post 2646107)
Stock is now better.

That should be faster, because why use checking the FindEntityByClassname when it faster to create new and delete it
PHP Code:

stock SetClientMoney(clientmoney)
{
    
SetEntProp(clientProp_Send"m_iAccount"money);

    
int entity CreateEntityByName("game_money");
    if(
entity != INVALID_ENT_REFERENCE)
    {
        
DispatchKeyValue(entity"AwardText""");
    
        
DispatchSpawn(entity);

        
SetVariantInt(0);
        
AcceptEntityInput(entity"SetMoneyAmount");
        
        
SetVariantInt(client);
        
AcceptEntityInput(entity"AddMoneyPlayer");
        
        
AcceptEntityInput(entity"Kill");
        
        return 
true;
    }

    return 
false;


and i never had issue with giving money by the
Quote:

/**
* @brief Sets the money on a client.
*
* @param clientIndex The client index.
* @param iMoney The money amount.
**/
void AccountSetMoney(int clientIndex, int iMoney)
{
SetEntData(clientIndex, g_iOffset_PlayerAccount, iMoney, _, true);
}

eyal282 04-04-2019 07:29

Re: [CS:GO] Setting money ( the only way possible )
 
Quote:

Originally Posted by gubka (Post 2646109)
That should be faster, because why use checking the FindEntityByClassname when it faster to create new and delete it
PHP Code:

stock SetClientMoney(clientmoney)
{
    
SetEntProp(clientProp_Send"m_iAccount"money);

    
int entity CreateEntityByName("game_money");
    if(
entity != INVALID_ENT_REFERENCE)
    {
        
DispatchKeyValue(entity"AwardText""");
    
        
DispatchSpawn(entity);

        
SetVariantInt(0);
        
AcceptEntityInput(entity"SetMoneyAmount");
        
        
SetVariantInt(client);
        
AcceptEntityInput(entity"AddMoneyPlayer");
        
        
AcceptEntityInput(entity"Kill");
        
        return 
true;
    }

    return 
false;


and i never had issue with giving money by the

Argue with everything I said in the video. If you can do what it claims you can't sure whatever.

Forgot to say, you can also find the game data for the task. I don't know anything about gamedatas and I know they occasionally require updates and this isn't L4D2, every two weeks there's an update.

Ilusion9 04-04-2019 08:13

Re: [CS:GO] Setting money ( the only way possible )
 
PHP Code:


        SetVariantInt
(0);
        
AcceptEntityInput(entity"SetMoneyAmount");
        
        
SetVariantInt(client);
        
AcceptEntityInput(entity"AddMoneyPlayer"

So, these "SetVariantInt"s works for you?


All times are GMT -4. The time now is 08:53.

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