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

Changing Players Score in TF2


Post New Thread Reply   
 
Thread Tools Display Modes
Staats
Junior Member
Join Date: Jul 2008
Old 07-05-2008 , 03:57   Re: Changing Players Score in TF2
Reply With Quote #11

Alright, I'm trying to get the player's score using the above method, but for reasons I don't understand, the score is always 0. I've tried placing the ScoreEntity and ScoreOffset bits in a round restart hook (on plugin load gives me the error describe above), but this does not seem to help.

Final note: I have been testing on a local server. I connect and quickly cap a point or steal a flag (to get points) and then attempt to read my score on the local server. Seems like a reasonable way to test, but maybe not?

Code:
public Action:DumpInfo(client, args)
{
    new ScoreEntity = FindEntityByClassname(-1, "tf_player_manager");
    new ScoreOffset = FindSendPropInfo("CTFPlayerResource", "m_iScore");
    
    new maxclients = GetMaxClients();
    for(new i=1; i <= maxclients; i++)
    {
        if(IsClientInGame(i)) {
            new clientTeam = GetClientTeam(i);
            new Float:connectTime = max(GetGameTime(), GetClientTime(i));
            new score = GetEntData(ScoreEntity, ScoreOffset + (i * 4));
            
            new Float:ratio; 
            if (score > 1) {
                ratio = FloatDiv(float(score), connectTime);
            } 
            else {
                ratio = 0.0;
            }

            PrintToServer("Team: %d ",  clientTeam);
            PrintToServer("Score: %d ", score);
            PrintToServer("Time: %f ", connectTime);
            PrintToServer("Ratio: %f ", ratio);
        }
    }
    
    return Plugin_Handled;
}
Staats is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-05-2008 , 11:19   Re: Changing Players Score in TF2
Reply With Quote #12

Try using:
PHP Code:
new score TF2_GetPlayerResourceData(iTFResource_Score); 
bl4nk is offline
Staats
Junior Member
Join Date: Jul 2008
Old 07-05-2008 , 11:40   Re: Changing Players Score in TF2
Reply With Quote #13

That doesn't work, but this did:

Code:
TF2_GetPlayerResourceData(i, TFResource_TotalScore);
Looking at the source, it appears TF2_GetPlayerResourceData is a more generic version of the code posted. I didn't realize the API reference could be out of date - good to know all those functions in /include are available!
Staats is offline
msleeper
Veteran Member
Join Date: May 2008
Location: Atlanta, Jawjuh
Old 07-18-2008 , 21:40   Re: Changing Players Score in TF2
Reply With Quote #14

Quote:
Originally Posted by msleeper View Post
Hate to bump an old thread, but I have a semi-related question. Are there any special hoops I need to jump through to get the "Team Score" to update in TF2? I used this very basic code to incriment the Red team's score by one, but it does not always seem to update the scoreboard:

Code:
 
new Score = GetTeamScore(2);
PrintToChatAll("[HUNTED] Assassin's Score: %i", Score);
 
Score += 1;
SetTeamScore(2, Score);
 
Score = GetTeamScore(2);
PrintToChatAll("[HUNTED] Assassin's New Score: %i", Score);
While the Chat text does indeed get incrimented, the score on the scoreboard does not go up consistantly. It does increase but I'm not sure exactly what causes it yet - I think it may increase when the team naturally gains a point through capping a point or what have you, but other times it seems to go up without any real reason.

Thanks for any help!
Bump for possible help, still having this issue.
__________________
msleeper is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 07-21-2008 , 05:34   Re: Changing Players Score in TF2
Reply With Quote #15

Quote:
Originally Posted by msleeper View Post
Bump for possible help, still having this issue.
It seems SetTeamScore() doesn't mark the offset as changed.
  1. File a bug report
  2. Until it is fixed, you can do it yourself. You just have to find the right entity with the team index of the team you have changed the score of.
Code:
CTeam: 
 Sub-Class Table (1 Deep): DT_Team
-Member: m_iTeamNum (offset 952) (type integer) (bits 5)
-Member: m_iScore (offset 940) (type integer) (bits 32)
-Member: m_szTeamname (offset 908) (type string) (bits 0)
-Member: player_array_element (offset 0) (type integer) (bits 10)
-Member: "player_array" (offset 0) (type array) (bits 0)
Then use ChangeEdictState() on the offset, to mark it as changed and it will be sent to the clients immidiately.
berni is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-21-2008 , 12:57   Re: Changing Players Score in TF2
Reply With Quote #16

m_iScore is set every game frame by the mod, so it can't be changed like it can in other mods.
bl4nk is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 07-21-2008 , 14:49   Re: Changing Players Score in TF2
Reply With Quote #17

Well like msleeper was explaining it, it doesn't seem to get updated every frame. And in hl2dm I did it the way I described above
berni is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 07-21-2008 , 15:00   Re: Changing Players Score in TF2
Reply With Quote #18

I've been working with Nephyrin and pRED on an extension to change player's score. Trust me, it gets updated every frame.
bl4nk is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 07-21-2008 , 15:05   Re: Changing Players Score in TF2
Reply With Quote #19

I do believe you, but I was just drawing conclusions based on msleepers post
berni is offline
msleeper
Veteran Member
Join Date: May 2008
Location: Atlanta, Jawjuh
Old 07-21-2008 , 16:15   Re: Changing Players Score in TF2
Reply With Quote #20

Quote:
Originally Posted by berni View Post
It seems SetTeamScore() doesn't mark the offset as changed.
  1. File a bug report
  2. Until it is fixed, you can do it yourself. You just have to find the right entity with the team index of the team you have changed the score of.
Then use ChangeEdictState() on the offset, to mark it as changed and it will be sent to the clients immidiately.
Thank you very much for this, I will try this out as soon as I can.

Quote:
Originally Posted by bl4nk View Post
I've been working with Nephyrin and pRED on an extension to change player's score. Trust me, it gets updated every frame.
I have run into a similar problem that I haven't had a chance to fully explore or post about relating to changing the player and not the team's score, but what you said made it seem to be futile. Is this the case or do I need to do something similar to what berni posted about the Team score?
__________________
msleeper 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 00:02.


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