Page 1 of 1

solo scripts

Posted: 16 May 2013, 12:44
by xbx
I was trying "invasion" title pack the other day and noticed that we didn't get actual medals.

so you should know you can do something like this in the solo script to give medals:

Code: Select all

{
	declare metadata Integer ObjectiveAuthor 	for Map;
	declare metadata Integer ObjectiveGold 	for Map;
	declare metadata Integer ObjectiveSilver 	for Map;
	declare metadata Integer ObjectiveBronze 	for Map;
	declare metadata Integer RaceCheckpoints 	for Map;

	if (_Time <= ObjectiveAuthor)
		Solo_SetNewRecord(_Score, ::EMedal::Author);
	else if (_Time <= ObjectiveGold)
		Solo_SetNewRecord(_Score, ::EMedal::Gold);
	else if (_Time <= ObjectiveSilver)
		Solo_SetNewRecord(_Score, ::EMedal::Silver);
	else if (_Time <= ObjectiveBronze)
		Solo_SetNewRecord(_Score, ::EMedal::Bronze);
	else 
		Solo_SetNewRecord(_Score, ::EMedal::Finished);
}


You can also do this in the maptype script, that will run the mode when clicking on the green flag, to help testing:

Code: Select all

.....
if(Event.Type == CPluginEvent::Type::StartValidation) {
	StartTestMapWithMode("mymode.Script.txt");
	wait(!IsSwitchedToPlayground);
}
....

Re: solo scripts

Posted: 16 May 2013, 12:53
by steeffeen
also good to know for solo scripts brought over from a multiplayer game mode:
remove the code for ladder matches like

Code: Select all

Ladder_OpenMatch_Request();
as your solo script won't work otherwise

Re: solo scripts

Posted: 16 May 2013, 12:57
by faserg1
Will be in next update function that change map to next in solo?

Re: solo scripts

Posted: 19 Aug 2013, 11:36
by xbx
It already works in trackmania, but is broken in shootmania.
It'll be fixed in the next update.

here is a sample test script I've been using:

Code: Select all

#RequireContext CSmMode

#Const	CompatibleMapTypes	"MeleeArena"
#Const Version 			  "2013-08-13"

#Include "TextLib" as TextLib
#Include "Libs/Nadeo/Mode.Script.txt"

// === Main ===
main() 
{
	UIManager.ResetAll();
	
	declare LayerMapList = UIManager.UILayerCreate();
	UIManager.UIAll.UILayers.add(LayerMapList);

	declare CurUpdateNum  = 0;
	
	while( !ServerShutdownRequested ) {
		LoadMap();

		// intro & setup
		UIManager.UIAll.UISequence = CUIConfig::EUISequence::Intro;
		wait(UIManager.UIAll.UISequenceIsCompleted);


		// ask the user for the next map.
		CurUpdateNum += 1;
		LayerMapList.ManialinkPage = """
<frame>
<quad sizen="160 100" halign="center" valign="center" style="Bgs1InRace"  substyle="BgWindow3"/>
<label posn="-75 45 1" scale="1" halign="left" valign="center" text="Now playing: {{{Map.MapInfo.Name}}}" />
<label posn="-75 32 1" scale="2" halign="left" valign="center" text="Choose next map:" />
		""";
		declare MapIndex = 0;
		foreach (Map in MapList) {
			declare PostFix = "";
			if (MapIndex == NextMapIndex) 
				PostFix = "$z <--- next";
			LayerMapList.ManialinkPage ^= """
<label posn="-75 {{{25-5*MapIndex}}} 1" scale="1" halign="left" valign="center" text="{{{Map.Name^PostFix}}}" id="map_{{{MapIndex}}}" scriptevents="1" />
			""";
			MapIndex += 1;
		}
		LayerMapList.ManialinkPage ^= """
</frame>
<script><!--

#Include "TextLib" as TextLib

main() {
	declare netwrite SelectedMapIndex for UI = -1;
	declare netwrite UpdateNum for UI = 0;
	SelectedMapIndex = -1;
	UpdateNum = {{{CurUpdateNum}}};
	
	while (True) {
		yield;
		foreach (Event in PendingEvents) {
			if (Event.Type == CMlEvent::Type::MouseClick) {
				declare Parts = TextLib::Split("_", Event.ControlId);
				if (Parts.count == 2 && Parts[0] =="map") {
					SelectedMapIndex = TextLib::ToInteger(Parts[1]);
				}
			}
		}
	}
}

--></script>""";
	
		Synchro_DoBarrier();
		
		// wait for the clic in the list...
		declare LocalPlayerUI <=> UIManager.GetUI(Players[0]);
		declare netread UpdateNum for LocalPlayerUI = 0 ;
		declare netread SelectedMapIndex for LocalPlayerUI = -1;
		wait(UpdateNum == CurUpdateNum && SelectedMapIndex != -1); 
		
		log("nextmap .  UpdateNum=" ^ UpdateNum ^ "/" ^ CurUpdateNum ^ ", SelectedMapIndex=" ^ SelectedMapIndex);

		NextMapIndex = SelectedMapIndex;		// it's a good idea to set this as early as possible (in network games), 
												// as it allows the game to pre-download the maps & stuff on the clients.
		
	
		UIManager.UIAll.UISequence = CUIConfig::EUISequence::None;
		UnloadMap();
	}
	
	UIManager.UILayerDestroy(LayerMapList);
}