skadistats / clarity-examples

Example code for clarity
BSD 3-Clause "New" or "Revised" License
113 stars 37 forks source link

How to get current gold of each player at each tick? #36

Closed harshawasthi90 closed 1 year ago

harshawasthi90 commented 6 years ago

Hi,

I would like to get current gold help by each player at each tick. How can I get that?

The approach that I thought of is to listen for DOTA_COMBATLOG_GOLD event on onCombatLogEntry. Then always update the player gold (i.e. if its negative he lost gold, if its positive he gained). But this doesn't account for the 1 gold a player receives per second.

Is there a better way to do this? Because I couldn't find any entity that exposes the current gold of hero per tick.

Thanks. Harsh.

spheenik commented 6 years ago

You gotta use entities to do this. There's two entities CDOTA_DataRadiant and CDOTA_DataDire. Each of them has an array with data per player, with these properties:

m_iTotalEarnedGold           
m_iReliableGold              
m_iUnreliableGold            
m_hItems                     
m_iParity                    
m_hInventoryParent           
m_bStashEnabled              
m_hTransientCastItem         
m_iStartingPosition          
m_iTotalEarnedXP             
m_iSharedGold                
m_iHeroKillGold              
m_iCreepKillGold             
m_iIncomeGold                
m_iNetWorth                  
m_iDenyCount                 
m_iLastHitCount              
m_iLastHitStreak             
m_iLastHitMultikill          
m_iNearbyCreepDeathCount     
m_iClaimedDenyCount          
m_iClaimedMissCount          
m_iMissCount                 
m_nPossibleHeroSelection     
m_iMetaLevel                 
m_iMetaExperience            
m_iMetaExperienceAwarded     
m_flBuybackCooldownTime      
m_flBuybackGoldLimitTime     
m_flBuybackCostTime          
m_flCustomBuybackCooldown    
m_fStuns                     
m_fHealing                   
m_iTowerKills                
m_iRoshanKills               
m_hCameraTarget              
m_hOverrideSelectionEntity   
m_iObserverWardsPlaced       
m_iSentryWardsPlaced         
m_iCreepsStacked             
m_iCampsStacked              
m_iRunePickups               
m_iGoldSpentOnSupport        
m_iHeroDamage                
m_iWardsPurchased            
m_iWardsDestroyed            
m_nKillsPerOpposingTeamMember

the prefix for this is m_vecDataTeam.XXXX, so to get reliable gold for the second player, you do m_vecDataTeam.0001.m_iReliableGold.

A general example of handling entities is here.

Notice @UsesEntities, and the getEntity()-function.

Good luck!

harshawasthi90 commented 6 years ago

Thanks a lot... It was really helpful... :)

armand-hoxha25 commented 4 years ago

Hello, Thanks for the above reply, it is VERY helpful to understand how to obtain gold. I have a question on the tick rate. I rewrote the dumpmana example, to obtain the m_iTotalGoldEarned, and in the end I obtained an output of 9479 rows (for only 1 player), but the game was about 53 minutes long (3180 seconds). I have read other issues on the clarity package, so I understand that dota has a 30fps tickrate. Am I missing something or does the parser out the status of total gold earned every 0.3 seconds of game time?

Thanks a lot for the work you put into this tool, really appreciate it!

spheenik commented 4 years ago

Well, it's correct that the tickrate in dota replays is always 30ticks/second. How many times the variable is updated is not fixed though - might change when valve change how it works. It's also possible that it is not updated while the game is paused (ticks continue even if the game is paused). So it's better to not assume any update rate on m_iTotalGoldEarned.

armand-hoxha25 commented 4 years ago

Thanks for the reply. Yea I figured that the number of entries probably had to do simply with the entity being updated. So right now, I essentially put the m_iTotalGoldEarned to be pulled in the combat log, as I needed a way to put a time stamp on when it was changed. Would you know a better way to about this?

spheenik commented 4 years ago

Regarding time: https://github.com/skadistats/clarity/issues/106