This shows you the differences between two versions of the page.
|
pjv:laboratoare:2025:a04 [2025/11/26 13:02] alexandru.gradinaru |
pjv:laboratoare:2025:a04 [2025/11/26 17:53] (current) andrei.lapusteanu Fixed cloudscript incorrect code |
||
|---|---|---|---|
| Line 28: | Line 28: | ||
| * Sistem de Level up | * Sistem de Level up | ||
| * se activeaza dupa ce ai acumulat suficient XP | * se activeaza dupa ce ai acumulat suficient XP | ||
| - | * dupa acumulare de suficient XP dureaza (de ex 30s) - dupa care se trimite un email de notificare {{ :pjv:laboratoare:2025:whatsapp_image_2025-11-26_at_12.33.01.jpeg?700 |}} | + | * dupa acumulare de suficient XP dureaza (de ex 1 min) - dupa care se trimite un email de notificare {{ :pjv:laboratoare:2025:whatsapp_image_2025-11-26_at_12.33.01.jpeg?700 |}} |
| * dupa levelup, la o noua lansare a jocului, se va lansa o alta scena cu nivel de dificultate ridicat (informatia este citita din Title Data) | * dupa levelup, la o noua lansare a jocului, se va lansa o alta scena cu nivel de dificultate ridicat (informatia este citita din Title Data) | ||
| Line 189: | Line 189: | ||
| <code javascript> | <code javascript> | ||
| - | handlers.IncrementCounter = function(args, context) { | + | handlers.incrementCounter = function(args, context) { |
| var res = server.GetUserReadOnlyData({ | var res = server.GetUserReadOnlyData({ | ||
| PlayFabId: currentPlayerId, | PlayFabId: currentPlayerId, | ||
| Keys: ["Counter"] | Keys: ["Counter"] | ||
| }); | }); | ||
| - | | + | |
| var count = 0; | var count = 0; | ||
| if (res.Data["Counter"] !== undefined) { | if (res.Data["Counter"] !== undefined) { | ||
| Line 200: | Line 200: | ||
| } | } | ||
| count++; | count++; | ||
| - | | + | |
| server.UpdateUserReadOnlyData({ | server.UpdateUserReadOnlyData({ | ||
| PlayFabId: currentPlayerId, | PlayFabId: currentPlayerId, | ||
| Data: { "Counter": count } | Data: { "Counter": count } | ||
| }); | }); | ||
| - | | + | |
| return count; | return count; | ||
| }; | }; | ||
| Line 213: | Line 213: | ||
| <code csharp> | <code csharp> | ||
| - | void CallCloudScript() | + | private void CallCloudScript() |
| { | { | ||
| - | PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest | + | var request = new ExecuteCloudScriptRequest |
| { | { | ||
| - | FunctionName = "IncrementCounter" | + | FunctionName = "incrementCounter", |
| + | GeneratePlayStreamEvent = true | ||
| + | }; | ||
| + | PlayFabClientAPI.ExecuteCloudScript(request, | ||
| + | result => | ||
| + | { | ||
| + | var counterValue = Convert.ToInt32(result.FunctionResult); | ||
| + | Debug.Log($"Returned counter value: {counterValue}"); | ||
| }, | }, | ||
| - | result => Debug.Log($"Counter: {result.FunctionResult}"), | + | error => |
| - | error => Debug.LogError(error.GenerateErrorReport()) | + | { |
| - | ); | + | Debug.LogError($"Cloud Script error: {error.GenerateErrorReport()}"); |
| + | }); | ||
| } | } | ||
| </code> | </code> | ||
| Line 292: | Line 300: | ||
| === Procesul General === | === Procesul General === | ||
| - | 1. **Configurare serviciu email** - Cont gratuit pe [[https://resend.com|Resend]], obțineți API key | + | - **Configurare serviciu email** - Cont gratuit pe [[https://resend.com|Resend]], obțineți API key |
| - | 2. **CloudScript face HTTP request** - Adaptăm exemplul existent ''makeHTTPRequest'' din codul deja existent in CloudScript | + | - **CloudScript face HTTP request** - Adaptăm exemplul existent ''makeHTTPRequest'' din codul deja existent in CloudScript |
| - | 3. **Scheduled Task verifică periodic** - Rulează la 10-15 min, verifică playeri cu training completat | + | - **Scheduled Task verifică periodic** - Rulează la 10-15 min, verifică playeri cu training complet |
| === Implementare CloudScript === | === Implementare CloudScript === | ||
| Line 331: | Line 339: | ||
| <note> | <note> | ||
| - | Pentru testare rapidă, API extern (Resend) este mai simplu. Pentru producție, folosiți Add-on SMTP oficial. | + | Pentru testare rapidă, API extern (Resend) este mai simplu. Pentru producție, folosiți Add-on-ul SMTP din PlayFab. |
| </note> | </note> | ||
| Line 338: | Line 346: | ||
| </note> | </note> | ||
| - | ===== Resurse ===== | + | **Resurse:** |
| * [[https://resend.com/docs|Resend API]] | * [[https://resend.com/docs|Resend API]] | ||
| * [[https://learn.microsoft.com/en-us/gaming/playfab/features/engagement/emails/quickstart|PlayFab SMTP Setup]] | * [[https://learn.microsoft.com/en-us/gaming/playfab/features/engagement/emails/quickstart|PlayFab SMTP Setup]] | ||