/// <summary> /// Checks if the player or its faction has sufficient credits. /// </summary> /// <param name="playerId">The entityId of the player.</param> /// <param name="requiredCredits">The minimal required amount of credits on the balance.</param> /// <returns></returns> public static bool HasSufficientCredits(long playerId, long requiredCredits) { // Session should be active to continue. if (MySession.Static == null) { return(false); } // Get balance of player. long balance = GetPlayerBalance(playerId); if (balance >= requiredCredits) { return(true); } // Get balance of players faction (if any). var faction = FactionUtils.GetFactionOfPlayer(playerId); if (faction != null) { faction.TryGetBalanceInfo(out balance); } // Check faction balance. if (balance >= requiredCredits) { return(true); } // Insufficient balance. return(false); }
public static bool RemoveCredits(long playerId, long creditsToRemove) { // Session should be active to continue. if (MySession.Static == null) { return(false); } var player = PlayerUtils.GetPlayer(playerId); if (player == null) { return(false); } var balance = GetPlayerBalance(player); if (balance >= creditsToRemove) { player.RequestChangeBalance(-creditsToRemove); return(true); } var faction = FactionUtils.GetFactionOfPlayer(playerId); if (faction == null) { return(false); } // Try remove from faction if player has one. balance = GetFactionBalance(faction); if (balance >= creditsToRemove) { faction.RequestChangeBalance(-creditsToRemove); return(true); } return(false); }