Skip to content

Commit

Permalink
Set the URL to request automatically
Browse files Browse the repository at this point in the history
I forgot i let the URL used by my Manialink in the script, it's now fixed and automatically set.
Also updated the README to help anyone understands what all of this does or doesn't.
  • Loading branch information
Harest committed Nov 16, 2019
1 parent 0dfffca commit 20e2823
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
41 changes: 26 additions & 15 deletions Main.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
// Manialink main script - Generate the ManiaLink Script for ManiaPlanet

// Include file to check client
require(__DIR__."/includes/functions.php");
require(__DIR__."/class/class.cacheManager.php");
$cacheManager = new cacheManager();
Expand All @@ -15,19 +13,30 @@
$SimpleBoard = boolval(filter_input(INPUT_GET, 'SimpleBoard')); // Used to display a board without start quest button (e.g. quest started elsewhere w/o the board)
$SimpleBoard = ($SimpleBoard == true) ? "True" : "False";
$ShootManiaCall = boolval(filter_input(INPUT_GET, 'SM')); // Used to know if it's a ShootMania call, else it's considered a TM² one
$RequiredContext = ($ShootManiaCall == true) ? "CSmMlScriptIngame" : "CTmMlScriptIngame";
$HideGui = strtolower(filter_input(INPUT_GET, 'HideGui'));
$HideGui = ($HideGui == 'yes') ? "yes" : "no";
$HideGuiGet = strtolower(filter_input(INPUT_GET, 'HideGui'));

$BgColor = "000B";
if($HideGui=="yes") {
// Set constants used in the script
$BgColor = "000B"; // Background color of the board window
$HideGui = "no";
if ($HideGuiGet == "yes") {
// Hide the background and some UI elements when you click on the "Start Quest" button of the board
// Useful if you don't want to display another window to the player when (s)he starts the quest
$HideGui = "yes";
$BgColor = "000F";
}

// Name of the RaceTime constant of GUIPlayer in TM²/SM used for a check
$startTimeVar = "RaceStartTime";
if ($ShootManiaCall == true) $startTimeVar = "StartTime";
// Name of the RequireContext condition for the script to run in-game
$RequiredContext = "CTmMlScriptIngame";
if ($ShootManiaCall == true) {
$startTimeVar = "StartTime";
$RequiredContext = "CSmMlScriptIngame";
}
// URL used in the few requests done in the script (to get the board, the tokens and register a completed quest)
$urlToRequest = ($_SERVER['SERVER_HTTPS'] == "on") ? "https://" : "http://";
$urlToRequest .= $_SERVER['HTTP_HOST'].str_replace("Main.php", "", $_SERVER['SCRIPT_NAME']);

// Get the quest title
// Get the quest info
$QuestInfo = array("title" => "", "map_uid" => "", "author_login" => "");
if ($State == "board" or $State == "start") {
// Quest info are cached for 1h
Expand Down Expand Up @@ -247,7 +256,7 @@
// Requesting quest info and players who completed it
if (DebugMode) log("Retrieving quest " ^ TextLib::ToText(G_QuestId) ^ " info...");
declare CHttpRequest request;
request = Http.CreateGet("https://www.i-volve.net/games/tm2ml/GetBoard.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&" ^ Now);
request = Http.CreateGet("'.$urlToRequest.'GetBoard.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&" ^ Now);
wait(request.IsCompleted);
// Assigning results
Expand Down Expand Up @@ -303,7 +312,7 @@
} else {
// MapUid matches, requesting quest tokens list
if (DebugMode) log("Retrieving quest " ^ TextLib::ToText(G_QuestId) ^ " tokens...");
request = Http.CreateGet("https://www.i-volve.net/games/tm2ml/GetTokens.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&" ^ Now);
request = Http.CreateGet("'.$urlToRequest.'GetTokens.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&" ^ Now);
wait(request.IsCompleted);
declare STokensJsonResponse Response;
Response.fromjson(request.Result);
Expand Down Expand Up @@ -399,7 +408,7 @@
// MapUid matches, requesting quest tokens list
if (DebugMode) log("Retrieving quest " ^ TextLib::ToText(G_QuestId) ^ " tokens...");
declare CHttpRequest request;
request = Http.CreateGet("https://www.i-volve.net/games/tm2ml/GetTokens.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&" ^ Now);
request = Http.CreateGet("'.$urlToRequest.'GetTokens.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&" ^ Now);
wait(request.IsCompleted);
declare STokensJsonResponse Response;
Response.fromjson(request.Result);
Expand Down Expand Up @@ -449,22 +458,24 @@
}
// If all the tokens are collected we submit the completion to the server for processing
if(TokensAreCollected())
if (TokensAreCollected())
{
// Get the player positions list at each token as csv
// Log all tokens for quest if debug activated
declare Text Pe_PlayerPosString = LogMissingTokens();
declare CHttpRequest request;
if (DebugMode) log("Quest " ^ TextLib::ToText(G_QuestId) ^ " completed. Processing...");
request = Http.CreateGet("https://www.i-volve.net/games/tm2ml/UpdateQuest.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&Login=" ^ LocalUser.Login ^ "&UserName=" ^ LocalUser.Name ^ "&Positions=" ^ TextLib::URLEncode(Pe_PlayerPosString) ^ "&MapUid=" ^ P_QuestMapUid[G_QuestId] ^ "&" ^ Now);
request = Http.CreateGet("'.$urlToRequest.'UpdateQuest.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&Login=" ^ LocalUser.Login ^ "&UserName=" ^ LocalUser.Name ^ "&Positions=" ^ TextLib::URLEncode(Pe_PlayerPosString) ^ "&MapUid=" ^ P_QuestMapUid[G_QuestId] ^ "&" ^ Now);
clearPersistentData();
wait(request.IsCompleted);
if (DebugMode) {
log("All tokens collected.");
}
// Only log visible to anyone that returns what happened, can be useful
log(request.Result);
} else if (DebugMode) {
LogMissingTokens();
}
}
}
Expand Down
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,30 @@
[Official forum link](https://forum.maniaplanet.com/viewtopic.php?f=266&t=46335)
## Introduction
This is a tool usable in Trackmania² and ShootMania which are both on ManiaPlanet. It allows you to add quests inside your maps.
It's made of ManiaScript alongside PHP/SQL to read/write data used in the quests. This ManiaScript is loaded in your maps from a Manialink call inside a MediaTracker clip.
It's made of ManiaScript alongside PHP/SQL to read/write data used in the quests. This ManiaScript is loaded in your maps from a Manialink call inside a MediaTracker clip.

## How it works
Each quest has a set of `tokens`. The tokens are conceptually the things the player needs to collect, while realistically it's your MediaTracker triggers, so it's where the player need to be at some point.
Currently, there's no display output by this script of the quest progression. Everything will have to be done with your MediaTracker.
This means you can currently do two things properly:

* Either the supposedly last token will always be the last token gathered by players in a specific place and you don't need to restrict the order with MediaTracker clips condition. You'll be able to set a MediaTracker trigger at that place to display something to the player for the quest completion.
* Either you can't be sure of the order in which tokens will be collected so you establish your own order (either by giving hints to the player or not). Here you'll restrict the order with MediaTracker clips condition as explained below.

So, if you followed, this currently exclude a case: handling a quest where tokens don't have any specific order and can be collected in a common place. While players will be able to complete it, the issue is that you'll not be able to know it and do something with that. The Manialink calls from the MediaTracker work in one-way. It'd require the script and not the MediaTracker to handle it which is not yet a possibility.

## How to install
Unless authorized to use the manialink MLSideQuests, you'll need to create one (thankfully the first is free) [over there](https://www.maniaplanet.com/account/manialinks).
It needs to point out to wherever you hosted the scripts, and on the Main.php script.
Yes, you need to host the scripts and create the database (see `_private` folder, file `tm2ml_sidequests.sql` for the tables). I'll let you find a web host yourself for that, there's a lot of free ones that should do the job fine.
The database connection info need to be set in `includes/dbConfig.php`.
Note: While Memcached is used to cache some data, mostly database query results, it'll still work fine without having Memcached installed. If you know how to edit the scripts, feel free to strip all the Memcached layer for your own Manialink.

Once it's done, you'll need to populate the database tables `quests` and `tokens`.
Quests table is kinda self-explanatory, the tokens are conceptually the things the player needs to collect, while realistically it's your MediaTracker triggers.
Quests table is kinda self-explanatory, what the tokens are is explained above.
Some values may stay `NULL`, it's as you want. Not everything is used as of yet, like the tokens names or the map MX id. They're there for an eventual improvement of all this with a web interface for instance to admin it.
To help you set the positions of the tokens (if you want to, positions are not needed if you don't care), you can find a MapEditor Plugin in `_private`: `CursorCoordsMod.Script.txt`. You need to place it in `Documents/ManiaPlanet/Scripts/EditorPlugins`. It's quite primitive but it mostly does the job.

## MediaTracker information and how to use
There's several things to know here:

Expand All @@ -24,11 +34,11 @@ There's several things to know here:
* There's two very useful conditions you'll want to use : `not yet triggered X`, `already triggered X`. You may have never understand what that X is. Well, it's the index of the MT clip. An index is the position of the clip in the list minus 1 because in programming languages most of the data structures start at 0. To help you a bit : there's 9 clips / page.
So, what you can do is for instance with a quest start in the clip index 5, specify that any token that doesn't have any order to be collected need a condition of `already triggered 5`.
What you can also do if there's a real tokens order is to set the first one at `already triggered index of quest start` and the others to `already triggered index of token-1`.


Now, here's the format of the Manialinks. You may want to replace MLSideQuests by the name of your own manialink.
Now, here's the format of the Manialinks. You want to replace `MLSideQuests` by the name of your own manialink.
You'll need to specify the QuestId value and the Token id value if needed depending on the State.
To use it in ShootMania you only need to add the parameter `SM=1` in each Manialink call (don't forget the & before).
To use it in ShootMania you only need to add the parameter `SM=1` in each Manialink call (don't forget the & before).

### Starting a quest
There's two ways for that:

Expand Down

0 comments on commit 20e2823

Please sign in to comment.