Advertisement
Guest User

Untitled

a guest
Feb 24th, 2013
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.18 KB | None | 0 0
  1. /**
  2. * Mode Laser
  3. */
  4.  
  5. #Extends "Modes/ShootMania/ModeBase.Script.txt"
  6.  
  7. #Const CompatibleMapTypes "MeleeArena"
  8. #Const Version "2013-01-24"
  9.  
  10. #Include "MathLib" as MathLib
  11. #Include "TextLib" as TextLib
  12. #Include "Libs/Nadeo/Layers.Script.txt" as Layers
  13. #Include "Libs/Nadeo/Message.Script.txt" as Message
  14. #Include "Libs/Nadeo/Interface.Script.txt" as Interface
  15. #Include "Libs/Nadeo/ShootMania/SM.Script.txt" as SM
  16. #Include "Libs/Nadeo/ShootMania/Score.Script.txt" as Score
  17. #Include "Libs/Nadeo/ShootMania/SpawnScreen.Script.txt" as SpawnScreen
  18. #Include "Libs/Nadeo/ShootMania/ScoresTable.Script.txt" as ScoresTable
  19.  
  20. /* -------------------------------------- */
  21. // Settings
  22. /* -------------------------------------- */
  23. #Setting S_TimeLimit 600 as _("Time limit") ///< Time limit on a map
  24. #Setting S_PointLimit 70 as _("Points limit") ///< Points limit on a map
  25.  
  26. #Const C_NbBots 0 ///< Number of bots
  27.  
  28. /* -------------------------------------- */
  29. // Globales variables
  30. /* -------------------------------------- */
  31. declare Ident[] G_SpawnsList; ///< Id of all the BlockSpawns of the map
  32. declare Ident G_LatestSpawnId; ///< Id of the last BlockSpawn used
  33. declare Ident[Integer] G_PrevScoreId; ///< Save the id of the first three scores
  34.  
  35. /* -------------------------------------- */
  36. // Exstend
  37. /* -------------------------------------- */
  38.  
  39. /* -------------------------------------- */
  40. // Server start
  41. /* -------------------------------------- */
  42. ***StartServer***
  43. ***
  44. /* -------------------------------------- */
  45. // Set mode options
  46. UseClans = False;
  47. G_PrevScoreId = [1 => NullId, 2 => NullId, 3 => NullId];
  48.  
  49. /* -------------------------------------- */
  50. // Create the rules
  51. declare ModeName = "Melee";
  52. declare ModeRules = _("Free for all\n\n- Hit an opponent to score a point.\n- The player with the most points wins.");
  53. SpawnScreen::CreateRules(ModeName, ModeRules);
  54.  
  55. SpawnScreen::CreateScores();
  56. SpawnScreen::CreateMapInfo();
  57. Interface::CreateRank();
  58.  
  59. /* -------------------------------------- */
  60. // Create the scores table
  61. ScoresTable::Load();
  62. ScoresTable::SetColumnsWidth(2., 2., 3., 15., 2., 2., 0., 0., 0., 4., 5.);
  63. ScoresTable::SetTableFormat(2, 6);
  64. ScoresTable::Build();
  65.  
  66. /* -------------------------------------- */
  67. // Create the UI layers
  68. declare LayerAttached = False;
  69. declare LayerUpdated = False;
  70. declare LayerDestroyed = False;
  71. declare LayerMarkersId = Layers::Create("Markers");
  72. Layers::GetFromId(LayerMarkersId).Type = CUILayer::EUILayerType::Markers;
  73. LayerAttached = Layers::Attach("Markers", NullId);
  74. ***
  75.  
  76. /* -------------------------------------- */
  77. // Map start
  78. /* -------------------------------------- */
  79. ***StartMap***
  80. ***
  81. XmlRpc.SendCallback("beginMap","");
  82. SetNbFakePlayers(C_NbBots, 0);
  83. G_SpawnsList.clear();
  84. G_LatestSpawnId = NullId;
  85. Score::MatchBegin();
  86. Score::RoundBegin();
  87.  
  88. LayerUpdated = Layers::Update("Markers", "");
  89. SM::SetupDefaultVisibility();
  90.  
  91. // Init scores
  92. yield; ///< Allow the scores array to be sorted
  93. foreach (Score in Scores) {
  94. declare Integer LastPoint for Score;
  95. LastPoint = 0;
  96. }
  97. declare LeadId = NullId;
  98. if (Scores.existskey(0)) LeadId = Scores[0].User.Id;
  99. declare CurrentPointLimit = S_PointLimit;
  100.  
  101. /* -------------------------------------- */
  102. // New map message
  103. UIManager.UIAll.SendNotice(
  104. "",
  105. CUIConfig::ENoticeLevel::MatchInfo,
  106. Null, CUIConfig::EAvatarVariant::Default,
  107. CUIConfig::EUISound::StartRound, 0
  108. );
  109.  
  110. StartTime = Now;
  111. EndTime = StartTime + (S_TimeLimit * 1000);
  112. UIManager.UIAll.UISequence = CUIConfig::EUISequence::Playing;
  113. ***
  114.  
  115. ***OnNewPlayer***
  116. ***
  117. ScoresTable::SetFooterStats(Player, TextLib::Compose(_("Points limit: %1"), TextLib::ToText(S_PointLimit)));
  118. ***
  119.  
  120. ***OnNewSpectator***
  121. ***
  122. ScoresTable::SetFooterStats(Spectator, TextLib::Compose(_("Points limit: %1"), TextLib::ToText(S_PointLimit)));
  123. ***
  124.  
  125. /* -------------------------------------- */
  126. // Play loop
  127. /* -------------------------------------- */
  128. ***PlayLoop***
  129. ***
  130. foreach (Event, PendingEvents) {
  131. if (Event.Type == CSmModeEvent::EType::OnArmorEmpty) {
  132. if (Event.Shooter == Event.Victim || Event.Shooter == Null) {
  133. Score::RemovePoints(Event.Victim, 1);
  134. }
  135. XmlRpc.SendCallback("playerDeath", Event.Victim.Login);
  136. PassOn(Event);
  137. } else if (Event.Type == CSmModeEvent::EType::OnHit) {
  138. if (Event.Shooter == Event.Victim) {
  139. Discard(Event);
  140. } else {
  141. declare Points = Event.Damage / 100;
  142. // 1 bonus points for hitting the first player
  143. // if (Scores.existskey(0) && Scores[0].User.Id == Event.Victim.User.Id) Points += 1;
  144. Score::AddPoints(Event.Shooter, Points);
  145. Event.ShooterPoints = Points;
  146. XmlRpc.SendCallback("playerHit", "Victim:"^Event.Victim.Login^";Shooter:"^Event.Shooter.Login^";"^Points);
  147. if (Event.Shooter != Null && Event.Shooter.Score != Null) {
  148. // Play sound and notice if someone is close to win
  149. declare LastPoint for Event.Shooter.Score = 0;
  150. declare Gap = S_PointLimit - Event.Shooter.Score.RoundPoints;
  151. if (Gap <= 3 && Gap > 0) {
  152. declare Variant = 3 - Gap;
  153. declare Msg = "";
  154. if (Gap > 1)
  155. Msg = TextLib::Compose(_("$<%1$> is %2 points from victory!"), Event.Shooter.Name, TextLib::ToText(Gap));
  156. else
  157. Msg = TextLib::Compose(_("$<%1$> is 1 point from victory!"), Event.Shooter.Name);
  158.  
  159. Message::SendBigMessage(
  160. Msg,
  161. 3000,
  162. 2,
  163. CUIConfig::EUISound::TieBreakPoint,
  164. Variant
  165. );
  166. } else if (Gap <= 0) {
  167. Message::SendBigMessage(
  168. TextLib::Compose(_("$<%1$> gets the final hit!"), Event.Shooter.Name),
  169. 3000,
  170. 3,
  171. CUIConfig::EUISound::VictoryPoint,
  172. 0
  173. );
  174. } else {
  175. declare SoundGap = S_PointLimit / 5;
  176. if(SoundGap < 5) SoundGap = 5;
  177. if (Event.Shooter.Score.RoundPoints / SoundGap > LastPoint) {
  178. LastPoint = Event.Shooter.Score.RoundPoints / SoundGap;
  179. Message::SendBigMessage(
  180. Event.Shooter,
  181. TextLib::Compose(
  182. _("$666Score : $fff%1 / %2"),
  183. TextLib::ToText(Event.Shooter.Score.RoundPoints),
  184. TextLib::ToText(S_PointLimit)
  185. ),
  186. 3000,
  187. 0,
  188. CUIConfig::EUISound::ScoreProgress,
  189. ((Event.Shooter.Score.RoundPoints / SoundGap) - 1)
  190. );
  191. }
  192. }
  193. }
  194. PassOn(Event);
  195. }
  196. } else if (Event.Type == CSmModeEvent::EType::OnPlayerRequestRespawn) {
  197. XmlRpc.SendCallback("playerRespawn", Event.Player.Login);
  198. Score::RemovePoints(Event.Player, 1);
  199. PassOn(Event);
  200. } else {
  201. PassOn(Event);
  202. }
  203. }
  204.  
  205. /* -------------------------------------- */
  206. // Spawn players
  207. foreach (Player in Players) {
  208. if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned && !Player.RequestsSpectate) {
  209. MeleeSpawnPlayer(Player);
  210. SetPlayerWeapon(Player, CSmMode::EWeapon::Laser, False);
  211. Player.AmmoGain = 2.0;
  212. Player.ArmorMax = 100;
  213. }
  214. }
  215.  
  216. /* -------------------------------------- */
  217. // Play sound and notice if someone is taking the lead
  218. if (Scores.existskey(0) && Scores[0].User.Id != LeadId) {
  219. LeadId = Scores[0].User.Id;
  220. Message::SendBigMessage(
  221. TextLib::Compose(
  222. _("$<%1$> takes the lead!"),
  223. Scores[0].User.Name
  224. ), ///< Message
  225. 3000, ///< Duration
  226. 1, ///< Priority
  227. CUIConfig::EUISound::PhaseChange, ///< Sound
  228. 1 ///< Sound variant
  229. );
  230. }
  231.  
  232. /* -------------------------------------- */
  233. // Update UI points limit
  234. if (CurrentPointLimit != S_PointLimit) {
  235. CurrentPointLimit = S_PointLimit;
  236. foreach (Player in Players) ScoresTable::SetFooterStats(Player, TextLib::Compose(_("Points limit: %1"), TextLib::ToText(S_PointLimit)));
  237. foreach (Spectator in Spectators) ScoresTable::SetFooterStats(Spectator, TextLib::Compose(_("Points limit: %1"), TextLib::ToText(S_PointLimit)));
  238. }
  239.  
  240. Message::Loop();
  241. UpdateMarkers();
  242.  
  243. /* -------------------------------------- */
  244. // victory conditions
  245. declare IsMatchOver = False;
  246. if (Now > EndTime) IsMatchOver = True;
  247. foreach (Player in Players) {
  248. if (Player.Score != Null && Player.Score.RoundPoints >= S_PointLimit) IsMatchOver = True;
  249. }
  250.  
  251. if (IsMatchOver) MB_StopMap = True;
  252. ***
  253.  
  254. /* -------------------------------------- */
  255. // Map end
  256. /* -------------------------------------- */
  257. ***EndMap***
  258. ***
  259. XmlRpc.SendCallback("endMap",GetRankings());
  260. EndTime = -1;
  261. Score::RoundEnd();
  262. Score::MatchEnd(True);
  263. LayerUpdated = Layers::Update("Markers", "");
  264.  
  265. /* -------------------------------------- */
  266. // End match sequence
  267. declare CUser Winner <=> Null;
  268. declare MaxPoints = 0;
  269. foreach (Score in Scores) {
  270. if (Score.Points > MaxPoints) {
  271. MaxPoints = Score.Points;
  272. Winner <=> Score.User;
  273. } else if (Score.Points == MaxPoints) {
  274. Winner <=> Null;
  275. }
  276. }
  277. foreach (Player in Players) {
  278. if (Player.User != Winner) UnspawnPlayer(Player);
  279. Interface::UpdatePosition(Player);
  280. }
  281.  
  282. sleep(1000);
  283. Message::CleanBigMessages();
  284. UIManager.UIAll.BigMessageSound = CUIConfig::EUISound::EndRound;
  285. UIManager.UIAll.BigMessageSoundVariant = 0;
  286. if (Winner != Null) {
  287. UIManager.UIAll.BigMessage = TextLib::Compose(_("$<%1$> wins the match!"), Winner.Name);
  288. } else {
  289. UIManager.UIAll.BigMessage = _("|Match|Draw");
  290. }
  291. sleep(2000);
  292. UIManager.UIAll.UISequence = CUIConfig::EUISequence::EndRound;
  293. UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::ForcedVisible;
  294. sleep(5000);
  295.  
  296. UIManager.UIAll.UISequence = CUIConfig::EUISequence::Podium;
  297. wait(UIManager.UIAll.UISequenceIsCompleted);
  298.  
  299. UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::Normal;
  300. UIManager.UIAll.BigMessage = "";
  301. ***
  302.  
  303. /* -------------------------------------- */
  304. // Server end
  305. /* -------------------------------------- */
  306. ***EndServer***
  307. ***
  308. LayerDestroyed = Layers::Destroy("Info");
  309. ScoresTable::Unload();
  310. Interface::DestroyRank();
  311. SpawnScreen::DestroyRules();
  312. SpawnScreen::DestroyScores();
  313. SpawnScreen::DestroyMapInfo();
  314. ***
  315.  
  316. /* -------------------------------------- */
  317. // Functions
  318. /* -------------------------------------- */
  319.  
  320. /* ------------------------------------- */
  321. /** Spawn a player
  322. *
  323. * @param _Player The player to spawn
  324. */
  325. Void MeleeSpawnPlayer(CSmPlayer _Player) {
  326. if (G_SpawnsList.count == 0) {
  327. foreach (BlockSpawn in BlockSpawns) G_SpawnsList.add(BlockSpawn.Id);
  328. }
  329.  
  330. declare SpawnId = NullId;
  331. while (True) {
  332. SpawnId = G_SpawnsList[MathLib::Rand(0, G_SpawnsList.count - 1)];
  333. if (SpawnId != G_LatestSpawnId) break;
  334. if (G_SpawnsList.count == 1) break;
  335. }
  336. G_LatestSpawnId = SpawnId;
  337. SM::SpawnPlayer(_Player, 0, BlockSpawns[SpawnId]);
  338. declare Removed = G_SpawnsList.remove(SpawnId);
  339. }
  340.  
  341. /* ------------------------------------- */
  342. /** Update the markers above the players
  343. *
  344. * @return The markers manialink
  345. */
  346. Text UpdateLayerMarkers() {
  347. declare MarkersML = "";
  348.  
  349. /*if (Scores.count >= 1) MarkersML ^= """<frame id="Marker_First"><quad posn="0 0 3" sizen="10 10" halign="center" style="Icons64x64_1" substyle="First"/></frame>""";
  350. if (Scores.count >= 2) MarkersML ^= """<frame id="Marker_Second"><quad posn="0 0 2" sizen="10 10" halign="center" style="Icons64x64_1" substyle="Second"/></frame>""";
  351. if (Scores.count >= 3) MarkersML ^= """<frame id="Marker_Third"><quad posn="0 0 1" sizen="10 10" halign="center" style="Icons64x64_1" substyle="Third"/></frame>""";*/
  352.  
  353. return MarkersML;
  354. }
  355.  
  356. /* ------------------------------------- */
  357. /// Update the markers when necessary
  358. Void UpdateMarkers() {
  359. declare I = 0;
  360. declare ScoreUpdated = False;
  361.  
  362. foreach (Score in Scores) {
  363. I += 1;
  364. if (G_PrevScoreId[I] != Score.Id) {
  365. G_PrevScoreId[I] = Score.Id;
  366. ScoreUpdated = True;
  367. }
  368. if (I >= 3) break;
  369. }
  370.  
  371. if (ScoreUpdated) {
  372. declare LayerUpdated = Layers::Update("Markers", UpdateLayerMarkers());
  373. UIManager.UIAll.Hud3dMarkers = "";
  374. I = 0;
  375. foreach (Score in Scores) {
  376. I += 1;
  377. declare MarkerId = "First";
  378. if (I == 2) MarkerId = "Second";
  379. else if (I == 3) MarkerId = "Third";
  380. UIManager.UIAll.Hud3dMarkers ^= """<marker playerlogin="{{{Score.User.Login}}}" manialinkframeid="Marker_{{{MarkerId}}}" visibility="WhenInMiddleOfScreen" />""";
  381. if (I >= 3) break;
  382. }
  383. }
  384. }
  385.  
  386. // Get the current rankings for xmlrpc callbacks
  387. Text GetRankings() {
  388. declare PlayerList = "";
  389. foreach (Score in Scores) {
  390. PlayerList ^= Score.User.Login^":"^Score.Points^";";
  391. }
  392. return PlayerList;
  393. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement