ADS and how to use currencies

General development topics: using various Unity tools, publishing games, etc.
Forum rules
Please be aware, that we're not providing official support via forum — it's entirely community-driven; see the support page for more information.
Post Reply
ShimaHyou
Posts: 4
Joined: Tue Aug 25, 2020 3:51 am

ADS and how to use currencies

Post by ShimaHyou »

Hello :D ,
So I have 2 currencies "tickets" to read chapters and "diamonds" to select premium choices and I have an ADS script, so I want to trigger the ADS and subtract one ticket at the start of each naninovel script.
And know how to add premium choices with diamonds currencies?

I get this answer on unity store:

"For premium choices you can make use of a custom choice handler; see the guide for more info: https://naninovel.com/guide/choices.htm ... e-handlers Alternatively, you can use conditional script execution (https://naninovel.com/guide/naninovel-s ... execution) to show the premium choices only in case they're available. To check the availability of choices, a custom script expression function (https://naninovel.com/guide/script-expr ... -functions) can be used. There are multiple ways to show an ad at the end of a script; the easiest would probably be via a custom command: https://naninovel.com/guide/custom-commands or with @showUI built-in command and a custom UI (https://naninovel.com/guide/user-interf ... tomization)."

I tried but I can't seem to understand how to use UI custom or custom choice :? , English is not my language so trying to understand the doc it's not easy.

User avatar
Elringus
Admin
Posts: 162
Joined: Mon May 11, 2020 6:03 pm

Re: ADS and how to use currencies

Post by Elringus »

Hey, Please clarify what exactly you have issues with by describing what you're doing step by step, what you expect to happen and what is actually happening.

ShimaHyou
Posts: 4
Joined: Tue Aug 25, 2020 3:51 am

Re: ADS and how to use currencies

Post by ShimaHyou »

hello, so for what I already do I seriously don't remember, so for premium choices https://ibb.co/HVPt78S, yesterday I test something new which work, even though I'm sure they're a more easy solution do to this, I create a "choice handler" with this method

Code: Select all

public void Pegi18Choice()
    {
        if (playFabManager.Player_Rubis >= 64)
        {
            playFabManager.Player_Rubis -= 64;
            txtRubis.text = playFabManager.Player_Rubis.ToString();
        }
        else
        {
            playFabManager.LoadingMessage("not enough diamonds");
            playFabManager.LoadingHide();
        }
    }

in inspector button "on click" https://ibb.co/0qKyMVy so I will have to create a "choice handler" per choice, but now I need to add a condition, if player click on the premium choice and don't have enough diamonds make the player impossible to continue until he has enough diamonds to select premium choice or choose the free choice.

as for the tickets and ADS, one ticket it's to read one chapter(NaniNovel Script) so when you get to 0 ticket I need to make it impossible to start the next chapter, but I don't know how to run these scripts at the start of each NaniNovel script:

ADS Script:

Code: Select all

public class ADS : MonoBehaviour
{
    string gameId = "000000";
    //bool testMode = true;

void Start()
{
    // Initialize the Ads service:
    Advertisement.Initialize(gameId);
    ShowInterstitialAd();
}

public void ShowInterstitialAd()
{
    // Check if UnityAds ready before calling Show method:
    if (Advertisement.IsReady())
    {
        Advertisement.Show();
    }
    else
    {
        Debug.Log("Interstitial ad not ready at the moment! Please try again later!");
    }
}
}

Tickets Script:

Code: Select all

public void DownTickets()
    {
         tickets -= 1;
         Debug.Log(tickets);
    }
User avatar
Elringus
Admin
Posts: 162
Joined: Mon May 11, 2020 6:03 pm

Re: ADS and how to use currencies

Post by Elringus »

Just use a custom command to run a C# script at any point inside a naninovel script: https://naninovel.com/guide/custom-commands

It's also possible to subscribe for OnPlay event of IScriptPlayer engine service.

ShimaHyou
Posts: 4
Joined: Tue Aug 25, 2020 3:51 am

Re: ADS and how to use currencies

Post by ShimaHyou »

Hello and thank you, I finally understand how to use custom command.
Do you know what I need to use to prevent the player to go to the next NaniNovel script if he has zero ticket?

Code: Select all

public class TicketStory : Command
{
    PlayFabManager playFabManager;
    
int ticketAmmount; public override UniTask ExecuteAsync(CancellationToken cancellationToken = default) { playFabManager = GameObject.Find("PlayFabManager").GetComponent<PlayFabManager>(); DownTicket(); return UniTask.CompletedTask; } public void DownTicket() { if (playFabManager.Player_Tickets >= 1) { playFabManager.Player_Tickets -= 1; ticketAmmount = 1; SubstractTK(ticketAmmount); } else { playFabManager.LoadingMessage("not enough ticket"); playFabManager.LoadingHide(); } } void SubstractTK(int ammount) { var request = new SubtractUserVirtualCurrencyRequest() { VirtualCurrency = "TK", Amount = ammount }; PlayFabClientAPI.SubtractUserVirtualCurrency(request, SubSuccess, SubFailed); } private void SubFailed(PlayFabError err) { // } private void SubSuccess(ModifyUserVirtualCurrencyResult result) { // } }

and how to force the game to stay on the choices until the player have enough diamonds to choose a premium choice or the free choice? I have a normal script:

Code: Select all

public class PegiChoices : MonoBehaviour
{
    [SerializeField] Text txtRubis;
    
PlayFabManager playFabManager; private int pegiChoiceAmmount; private void Awake() { playFabManager = GameObject.Find("PlayFabManager").GetComponent<PlayFabManager>(); txtRubis.text = playFabManager.Player_Rubis.ToString(); } public void Choice1() { if (playFabManager.Player_Rubis >= 30) { playFabManager.Player_Rubis -= 30; //PlayFab Sync Data pegiChoiceAmmount = 30; SubstractRB(pegiChoiceAmmount); } else { playFabManager.LoadingMessage("not enough rubis"); playFabManager.LoadingHide(); } } }
User avatar
Elringus
Admin
Posts: 162
Joined: Mon May 11, 2020 6:03 pm

Re: ADS and how to use currencies

Post by Elringus »

You can add custom expression functions and use them in the "if" statements of scenario scripts: https://naninovel.com/guide/script-expr ... -functions

ShimaHyou
Posts: 4
Joined: Tue Aug 25, 2020 3:51 am

Re: ADS and how to use currencies

Post by ShimaHyou »

Hello,

I take a look but I don't understand how to use it for my case, I'm going to see if someone on discord can explain.

thank you for the direction :D.

Post Reply