1. This forum is obsolete and read-only. Feel free to contact us at support.keenswh.com

Possible to access player's current and max PCU usage?

Discussion in 'Modding API' started by comfyfutons, Mar 31, 2019.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. comfyfutons

    comfyfutons Trainee Engineer

    Messages:
    24
    The question from the title... I can't seem to find it anywhere in

    MyAPIGateway.Session.Player
    MyAPIGateway.Session.Player.Client
    MyAPIGateway.Session.Player.Character

    If it is not possible to access information about performance cost unit usage that's a real downer for my mod.

    any help is appreciated
    thanks
     
  2. Digi

    Digi Senior Engineer

    Messages:
    2,393
    I'm not seeing a way to access current PCU usage.

    Max you can calculate it like the game does it...
    Code:
    // Converted to modAPI from Sandbox.Game.World.MyBlockLimits.GetInitialPCU()
    public static int GetInitialPCU(long identityId = -1L)
    {
    	var settings = MyAPIGateway.Session.SessionSettings;
    
    	switch(settings.BlockLimitsEnabled)
    	{
    		case MyBlockLimitsEnabledEnum.NONE:
    			return 2147483647;
    
    		case MyBlockLimitsEnabledEnum.PER_FACTION:
    			if(settings.BlockLimitsEnabled == MyBlockLimitsEnabledEnum.PER_FACTION && identityId != -1L && MyAPIGateway.Session.Factions.TryGetPlayerFaction(identityId) == null)
    				return 0;
    
    			if(settings.MaxFactionsCount == 0)
    				return settings.TotalPCU;
    
    			return settings.TotalPCU / settings.MaxFactionsCount;
    
    		case MyBlockLimitsEnabledEnum.PER_PLAYER:
    			return settings.TotalPCU / (int)settings.MaxPlayers;
    	}
    
    	return settings.TotalPCU;
    }
    
    (wow, this forum converts 4 spaces into an 8-space tab for code tag... and quote tag removes all spaces :woot:)
     
Thread Status:
This last post in this thread was made more than 31 days old.