Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #RequireContext CSmMode
- #Include "MathLib" as MathLib
- #Include "TextLib" as TextLib
- #Include "Libs/Nadeo/Mode.Script.txt" as Mode
- #Include "Libs/Nadeo/ShootMania/SM.Script.txt" as SM
- #Include "Libs/Nadeo/ShootMania/Score.Script.txt" as Score
- #Const CompatibleMapTypes "MeleeArena"
- #Const Version "2012-09-23"
- /* -------------------------------------- */
- // Settings
- /* -------------------------------------- */
- #Setting S_TimeLimit 600 as _("Time limit") ///< Time limit on a map
- #Setting S_PointLimit 25 as _("Point limit") ///< Point limit on a map
- #Const C_UITickInterval 200 ///< Time interval between UI update
- #Const RollCount 10
- /* -------------------------------------- */
- // Globales variables
- /* -------------------------------------- */
- declare Ident[] G_SpawnsList; ///< Id of all the BlockSpawns of the map
- declare Ident G_LatestSpawnId; ///< Id of the last BlockSpawn used
- /* -------------------------------------- */
- // Functions
- /* -------------------------------------- */
- /* -------------------------------------- */
- /// Fill the SpawnsList with all the BlockSpanws of the map
- Void FillSpawnsList() {
- foreach (BlockSpawn in BlockSpawns) { G_SpawnsList.add(BlockSpawn.Id); }
- }
- /* ------------------------------------- */
- /** Update the infos UI of a player
- *
- * @param _Player The player to update
- *
- * @return The ManiaLink string
- */
- Text UpdateLayerInfos(CSmPlayer _Player) {
- if (_Player.Score == Null) return "";
- return """
- <frame posn="150 -88">
- <label posn="0 1" halign="left" valign="bottom" text="/{{{ Scores.count }}}"/>
- <label posn="0 0" halign="right" valign="bottom" style="TextRaceChrono" text="{{{ Scores.keyof(_Player.Score) + 1 }}}"/>
- </frame>
- """;
- }
- Integer RealRandom (Integer Min, Integer Max)
- {
- declare Rand = MathLib::Rand(Min, Max);
- foreach(Player in Players)
- {
- Rand += MathLib::NearestInteger(Player.Position.X * Player.Position.Y * Player.Position.Z);
- }
- return Min + (Rand % (Max - Min + 1));
- }
- Void SetRoll(CSmPlayer _Player, Integer _Roll)
- {
- declare netwrite Text RollName for UIManager.GetUI(_Player);
- declare netwrite Text RollDesc for UIManager.GetUI(_Player);
- declare StealRatio for _Player = 0.;
- SetPlayerWeapon(_Player, CSmMode::EWeapon::Rocket, True);
- _Player.AmmoGain = 1.;
- _Player.ArmorMax = 200;
- _Player.Armor = 100;
- _Player.StaminaGain = 1.;
- _Player.StaminaMax = 1.;
- StealRatio = 0.;
- switch(_Roll)
- {
- case 1:{
- SetPlayerWeapon(_Player, CSmMode::EWeapon::Laser, False);
- _Player.AmmoGain = 2.;
- RollName = "$0f0Instagib";
- RollDesc = "One shot, one kill";
- break;}
- case 2:{
- SetPlayerWeapon(_Player, CSmMode::EWeapon::Nucleus, False);
- _Player.AmmoGain = 2.;
- RollName = "$ff0Nucleus Only";
- RollDesc = "Only Nucleus ^^";
- break;}
- case 3:{
- _Player.StaminaMax = 0.1;
- RollName = "$f00Low Stamina";
- RollDesc = "Can't run";
- break;}
- case 4:{
- _Player.ArmorMax = 500;
- _Player.Armor = 500;
- RollName = "$0f0Tank";
- RollDesc = "More armor";
- break;}
- case 5:{
- _Player.ArmorMax = 100;
- RollName = "$f00Glass Canon";
- RollDesc = "Less armor";
- break;}
- case 6:{
- _Player.ArmorGain = 50;
- RollName = "$0f0Regen";
- RollDesc = "You regenerate your health";
- break;}
- case 7:{
- _Player.AmmoGain = 5.;
- _Player.AmmoPower = 0.7;
- RollName = "$ff0Fast shooter";
- RollDesc = "Faster reloading, less damage";
- break;}
- case 8:{
- RollName = "$ff0Vanilla";
- RollDesc = "Nothing";
- break;}
- case 9:{
- StealRatio = 1.;
- RollName = "$0f0Vampire";
- RollDesc = "Steal armor from enemies";
- break;}
- case 10:{
- StealRatio = -1.;
- _Player.ArmorMax = 500;
- _Player.Armor = 500;
- RollName = "$f00Reflection";
- RollDesc = "You get the damage you do";
- break;}
- }
- }
- Void Roll(CSmPlayer _Player)
- {
- SetRoll(_Player, RealRandom(1, RollCount));
- }
- /* ------------------------------------- */
- /** Spawn a player
- *
- * @param _Player The player to spawn
- */
- Void SpawnPlayers(CSmPlayer _Player) {
- if (G_SpawnsList.count == 0) FillSpawnsList();
- declare SpawnId = NullId;
- while (True) {
- SpawnId = G_SpawnsList[MathLib::Rand(0, G_SpawnsList.count - 1)];
- if (SpawnId != G_LatestSpawnId) break;
- if (G_SpawnsList.count == 1) break;
- }
- Roll(_Player);
- SM::SpawnPlayer(_Player, 0, BlockSpawns[SpawnId]);
- G_LatestSpawnId = SpawnId;
- declare Tmp = G_SpawnsList.remove(SpawnId);
- }
- /* ------------------------------------- */
- /** Get the help manialink string.
- *
- * @return The manialink string
- */
- Text UpdateLayerSpawnScreen() {
- declare Text ML;
- declare RulesText = _("Free for all\n\n- Hit an opponent to score a point.\n- The player with the most points wins.");
- declare RulesTip = _("Press F1 to show rules");
- ML = """
- <script><!--
- main () {
- declare FrameRules <=> Page.GetFirstChild("FrameRules");
- declare FrameShow <=> Page.GetFirstChild("FrameShow");
- declare ShowRules = False;
- while(True) {
- if (ShowRules) {
- FrameRules.Show();
- FrameShow.Hide();
- } else {
- FrameRules.Hide();
- FrameShow.Show();
- }
- yield;
- // process events.
- foreach (Event in PendingEvents) {
- switch (Event.Type) {
- case CMlEvent::Type::MouseClick :
- {
- if (Event.ControlId == "FrameRules") ShowRules = !ShowRules;
- }
- case CMlEvent::Type::KeyPress:
- {
- if (Event.CharPressed == "2424832") ShowRules = !ShowRules; // F1
- }
- }
- }
- }
- }
- --></script>
- <frame posn="0 -70 0" id="FrameShow">
- <quad posn="0 0 10" sizen="140 20" halign="center" valign="center" style="Bgs1InRace" substyle="BgTitle3_5" />
- <label posn="0 0 11" scale="2" halign="center" valign="center" style="TextTitle3" text="{{{ RulesTip }}}" />
- </frame>
- <frame posn="0 50 1" id="FrameRules">
- <frame posn="0 0 5">
- <quad posn="0 0 10" sizen="120 20" halign="center" valign="center" style="Bgs1InRace" substyle="BgTitle3_5" />
- <label posn="0 0 11" scale="2" halign="center" valign="center" style="TextTitle3" text="$fffMelee" />
- </frame>
- <frame posn="0 -10 5">
- <quad posn="0 0 10" sizen="300 120" halign="center" bgcolor="222c" />
- <label posn="-145 -5 11" sizen="145 5" scale="2" autonewline="1" style="TextCardSmallScores2" text="{{{ RulesText }}}" />
- </frame>
- </frame>
- """;
- return ML;
- }
- /* ------------------------------------- */
- // Main
- /* ------------------------------------- */
- main() {
- UseClans = False;
- declare LayerSpawnScreen <=> UIManager.UILayerCreate();
- declare LayerScoresTable <=> UIManager.UILayerCreate();
- LayerSpawnScreen.Type = CUILayer::EUILayerType::ScreenIn3d;
- LayerScoresTable.Type = CUILayer::EUILayerType::ScoresTable;
- while (!ServerShutdownRequested) {
- /* ------------------------------------- */
- // Map/Round begin
- /* ------------------------------------- */
- Mode::LoadMap();
- G_SpawnsList.clear();
- G_LatestSpawnId = NullId;
- Score::MatchBegin();
- Score::RoundBegin();
- MatchEndRequested = False;
- UIManager.ResetAll();
- SM::SetupDefaultVisibility();
- LayerSpawnScreen.ManialinkPage = UpdateLayerSpawnScreen();
- UIManager.UIAll.UILayers.add(LayerSpawnScreen);
- LayerScoresTable.ManialinkPage = """
- <frame posn="0 -47">
- <quad posn="0 0 1" sizen="40 8" style="Bgs1InRace" halign="center" substyle="BgList"/>
- <label posn="0 -2 2" sizen="40 8" halign="center" text="{{{_("Point limit")}}}: {{{ S_PointLimit }}}" />
- </frame>
- """;
- UIManager.UIAll.UILayers.add(LayerScoresTable);
- UIManager.UIAll.UISequence = CUIConfig::EUISequence::Intro;
- UIManager.UIAll.BigMessageSound = CUIConfig::EUISound::StartRound;
- UIManager.UIAll.BigMessageSoundVariant = 0;
- UIManager.UIAll.BigMessage = _("New match");
- wait(UIManager.UIAll.UISequenceIsCompleted);
- UIManager.UIAll.BigMessage = "";
- UIManager.UIAll.UISequence = CUIConfig::EUISequence::Playing;
- declare LastUITick = 0;
- StartTime = Now;
- EndTime = StartTime + (S_TimeLimit * 1000);
- while (!MatchEndRequested && !ServerShutdownRequested) {
- /* ------------------------------------- */
- // Play loop
- /* ------------------------------------- */
- yield;
- foreach (Event, PendingEvents) {
- log(Event);
- if (Event.Type == CSmModeEvent::EType::OnArmorEmpty) {
- log(Event);
- if (Event.Shooter == Event.Victim || Event.Shooter == Null) {
- Score::RemovePoints(Event.Victim, 1);
- }
- PassOn(Event);
- } else if (Event.Type == CSmModeEvent::EType::OnHit) {
- if (Event.Shooter == Event.Victim) {
- Discard(Event);
- } else {
- declare Points = Event.Damage / 100;
- Score::AddPoints(Event.Shooter, Points);
- Event.ShooterPoints = Points;
- // Play sound and notice if someone is close to win
- if (Event.Shooter != Null && Event.Shooter.Score != Null) {
- declare Gap = S_PointLimit - Event.Shooter.Score.RoundPoints;
- if (Gap <= 3 && Gap > 0) {
- declare Variant = 3 - Gap;
- declare Msg = "";
- if (Gap > 1)
- Msg = TextLib::Compose(_("$<%1$> is %2 points from victory!"), Event.Shooter.Name, TextLib::ToText(Gap));
- else
- Msg = TextLib::Compose(_("$<%1$> is 1 point from victory!"), Event.Shooter.Name);
- UIManager.UIAll.SendNotice(
- Msg,
- CUIConfig::ENoticeLevel::PlayerInfo,
- Null, CUIConfig::EAvatarVariant::Default,
- CUIConfig::EUISound::TieBreakPoint, Variant
- );
- } else if (Gap <= 0) {
- UIManager.UIAll.SendNotice(
- TextLib::Compose(_("$<%1$> gets the final hit!"), Event.Shooter.Name),
- CUIConfig::ENoticeLevel::PlayerInfo,
- Null, CUIConfig::EAvatarVariant::Default,
- CUIConfig::EUISound::VictoryPoint, 0
- );
- }
- }
- PassOn(Event);
- }
- } else if (Event.Type == CSmModeEvent::EType::OnPlayerRequestRespawn) {
- Score::RemovePoints(Event.Player, 1);
- PassOn(Event);
- } else {
- PassOn(Event);
- }
- }
- foreach (Player in Players) {
- // Spawn
- if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned && !Player.RequestsSpectate) {
- SpawnPlayers(Player);
- }
- }
- /* -------------------------------------- */
- // Update UI
- if (LastUITick + C_UITickInterval < Now) {
- declare UsedLayers = Ident[];
- // Add layer and create it if necessary
- foreach (Player in Players) {
- declare UI <=> UIManager.GetUI(Player);
- if (UI == Null) continue;
- declare CUILayer LayerInfos;
- if (UI.UILayers.count != 1) {
- LayerInfos <=> UIManager.UILayerCreate();
- UI.UILayers.add(LayerInfos);
- } else {
- LayerInfos <=> UI.UILayers[0];
- }
- UsedLayers.add(LayerInfos.Id);
- LayerInfos.ManialinkPage = UpdateLayerInfos(Player);
- }
- // Remove layers
- declare LayersToRemove = Ident[];
- foreach (Layer in UIManager.UIAll.UILayers) { UsedLayers.add(Layer.Id); }
- foreach (Layer in UIManager.UILayers) {
- if (!UsedLayers.exists(Layer.Id)) {
- LayersToRemove.add(Layer.Id);
- }
- }
- foreach (LayerId in LayersToRemove) {
- UIManager.UILayerDestroy(UIManager.UILayers[LayerId]);
- }
- LastUITick = Now;
- }
- /* -------------------------------------- */
- // victory conditions
- declare IsMatchOver = False;
- if (Now > StartTime + (S_TimeLimit * 1000))
- IsMatchOver = True;
- foreach (Player in Players) {
- if (Player.Score != Null && Player.Score.RoundPoints >= S_PointLimit) IsMatchOver = True;
- }
- if (IsMatchOver) break;
- }
- /* ------------------------------------- */
- // Map/Round end
- /* ------------------------------------- */
- Score::RoundEnd();
- Score::MatchEnd(True);
- /* -------------------------------------- */
- // End match sequence
- declare CUser Winner <=> Null;
- declare MaxPoints = 0;
- foreach (Score in Scores) {
- if (Score.Points > MaxPoints) {
- MaxPoints = Score.Points;
- Winner <=> Score.User;
- } else if (Score.Points == MaxPoints) {
- Winner <=> Null;
- }
- }
- foreach (Player in Players) {
- if (Player.User != Winner) UnspawnPlayer(Player);
- }
- UIManager.UIAll.BigMessageSound = CUIConfig::EUISound::EndRound;
- UIManager.UIAll.BigMessageSoundVariant = 0;
- if (Winner != Null) {
- UIManager.UIAll.BigMessage = TextLib::Compose(_("$<%1$> wins the match!"), Winner.Name);
- } else {
- UIManager.UIAll.BigMessage = _("|Match|Draw");
- }
- sleep(2000);
- UIManager.UIAll.UISequence = CUIConfig::EUISequence::EndRound;
- UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::ForcedVisible;
- sleep(5000);
- UIManager.UIAll.UISequence = CUIConfig::EUISequence::Podium;
- wait(UIManager.UIAll.UISequenceIsCompleted);
- UIManager.UIAll.ScoreTableVisibility = CUIConfig::EVisibility::Normal;
- UIManager.UIAll.BigMessage = "";
- Mode::UnloadMap();
- }
- UIManager.UILayerDestroy(LayerSpawnScreen);
- UIManager.UILayerDestroy(LayerScoresTable);
- }
Advertisement
Add Comment
Please, Sign In to add comment