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

[TF2] How to change a Player's Score, without using CalcPlayerScore?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Steveh
Member
Join Date: Oct 2010
Old 05-21-2011 , 10:56   [TF2] How to change a Player's Score, without using CalcPlayerScore?
Reply With Quote #1

Hello,

I have looked into this, and unfortunately can't find a solution. I have tried changing m_iFrags, but that only changes your Kills in TF2, not your actual Score.

Any ideas?

Steveh
Steveh is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 05-22-2011 , 03:09   Re: [TF2] How to change a Player's Score, without using CalcPlayerScore?
Reply With Quote #2

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <tf2_stocks>
#include <sdkhooks>

public Plugin:myinfo = {
    
name "SetScore",
    
author "bl4nk",
    
description "Set a player's score to whatever you want",
    
version "1.0.0",
    
url "http://forums.alliedmods.net/"
};

new 
g_iSetScore[MAXPLAYERS+1] = { -1, ... };

public 
OnPluginStart() {
    
RegAdminCmd("sm_setscore"Command_SetScoreADMFLAG_ROOT"sm_setscore <#userid|name> <score> - Set a player's score  (-1 to disable)");
}

public 
OnMapStart() {
    new 
iIndex FindEntityByClassname(MaxClients+1"tf_player_manager");
    if (
iIndex == -1) {
        
SetFailState("Unable to find tf_player_manager entity");
    }
    
    
SDKHook(iIndexSDKHook_ThinkPostHook_OnThinkPost);
}

public 
OnClientPutInServer(iClient) {
    
g_iSetScore[iClient] = -1;
}

public 
Action:Command_SetScore(iClientiArgCount) {
    if (
iArgCount 2) {
        
ReplyToCommand(iClient"[SM] Usage: sm_setscore <#userid|name> <score>");
        return 
Plugin_Handled;
    }
    
    
decl String:szTarget[65];
    
GetCmdArg(1szTargetsizeof(szTarget));

    
decl String:szTargetName[MAX_TARGET_LENGTH+1];
    
decl iTargetList[MAXPLAYERS+1], iTargetCountbool:bTnIsMl;

    if ((
iTargetCount ProcessTargetString(
            
szTarget,
            
iClient,
            
iTargetList,
            
MAXPLAYERS,
            
COMMAND_FILTER_CONNECTED,
            
szTargetName,
            
sizeof(szTargetName),
            
bTnIsMl)) <= 0)
    {
        
ReplyToTargetError(iClientiTargetCount);
        return 
Plugin_Handled;
    }
    
    
decl String:szScore[6];
    
GetCmdArg(2szScoresizeof(szScore));

    new 
iScore StringToInt(szScore);
    
ClampInt(iScore, -14095);
    
    for (new 
0iTargetCounti++)
    {
        
g_iSetScore[iTargetList[i]] = iScore;
    }
    
    return 
Plugin_Handled;
}

public 
Hook_OnThinkPost(iEnt) {
    static 
iTotalScoreOffset = -1;
    if (
iTotalScoreOffset == -1) {
        
iTotalScoreOffset FindSendPropInfo("CTFPlayerResource""m_iTotalScore");
    }
    
    new 
iTotalScore[MAXPLAYERS+1];
    
GetEntDataArray(iEntiTotalScoreOffsetiTotalScoreMaxClients+1);
    
    for (new 
1<= MaxClientsi++) {
        if (
IsClientInGame(i) && g_iSetScore[i] > -1) {
            
iTotalScore[i] = g_iSetScore[i];
        }
    }
    
    
SetEntDataArray(iEntiTotalScoreOffsetiTotalScoreMaxClients+1);
}

stock ClampInt(&iValueiMiniMax) {
    if (
iValue iMin) {
        
iValue iMin;
    } else if (
iValue iMax) {
        
iValue iMax;
    }

Requires SDKHooks.

sm_setscore <#userid|name> <score> - Set a player's score (-1 to disable)

Last edited by bl4nk; 07-01-2011 at 17:57. Reason: forgot & on ClampInt
bl4nk is offline
Steveh
Member
Join Date: Oct 2010
Old 05-23-2011 , 02:30   Re: [TF2] How to change a Player's Score, without using CalcPlayerScore?
Reply With Quote #3

Thanks, I will try this later today.

Steveh
Steveh is offline
Steveh
Member
Join Date: Oct 2010
Old 05-24-2011 , 02:36   Re: [TF2] How to change a Player's Score, without using CalcPlayerScore?
Reply With Quote #4

Thanks! It works perfectly! You can lock this topic if you want now.

Steveh
Steveh is offline
El Diablo War3Evo
Veteran Member
Join Date: Jun 2013
Old 11-29-2016 , 16:31   Re: [TF2] How to change a Player's Score, without using CalcPlayerScore?
Reply With Quote #5

There is a strange side effect to this...

Keeping players score at 0 .. forcing it, seems to have people whom join my server "auto level" their cosmetics just by killing at least 1 person and sitting around while it spams levels on their cosmetics.
__________________
El Diablo War3Evo is offline
Benoist3012
Veteran Member
Join Date: Mar 2014
Location: CWave::ForceFinish()
Old 11-30-2016 , 07:57   Re: [TF2] How to change a Player's Score, without using CalcPlayerScore?
Reply With Quote #6

Sounds like points are stored somewhere else, and the server still tries to reupdate m_iTotalScore, and the items server probably catch the value at CTFPlayerResource::m_iTotalScore , store it somewhere on its end, like in OldKnownValue variable

And probably does int iPoints = NewValue-OldKnownValue;
if (iPoints > 0) AddPointsOnPlayerCosmetics(iPoints);

And since the value is always reset back to 0 it probably has OldKnowValue on 0 for that player, and NewValue on 1.

That's only an assumption maybe it's an other thing. But you should try to look if points aren't stored somewhere else.
__________________

Last edited by Benoist3012; 11-30-2016 at 07:58.
Benoist3012 is offline
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 12:28.


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