Mod InstantGib

You can talk about ManiaScript for ManiaPlanet here

Moderator: English Moderator

Triseaux
Posts: 155
Joined: 28 May 2012, 11:07

Re: Mod InstantGib

Post by Triseaux »

Yop0
Ok all i have been uploaded mi last InstanGib script her : http://www.maniapark.com/liste_gamemode.php?game=2

But If you download the script post her your name of server and manialink for adding to top of topics pleas.
group leader : "Beniii"
Deaod
Posts: 19
Joined: 17 Jun 2012, 12:09

Re: Mod InstantGib

Post by Deaod »

An in my opinion greatly improved version of the script by Triseaux.
Includes a new algorithm for randomizing spawns (and the option to turn it off, mostly). If turned off, it will always use the same order of spawns, and not shuffle them before each map starts.
Also includes a few more options you can adjust through the menu.

Code: Select all

#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-07-22"

/* -------------------------------------- */
// Settings
/* -------------------------------------- */
#Setting    TIME_LIMIT	    600 as _("Time limit (seconds)")	// Time limit on a map // in seconds
#Setting    POINT_LIMIT	    25	as _("Point limit")	// Point limit on a map
#Setting    KILL_REWARD     1 as _("Kill Reward") // players get awarded this many points when killing another player
#Setting    SUICIDE_PENALTY 0 as _("Suicide Penalty") // players get their score reduced by this amount when suiciding
#Setting    RELOAD_SPEED    1.7 as _("Reload Speed") // reload factor // default 1.7, minimum 0.0, maximum 10.0 // 2.0 means double reload speed
#Setting    MUTATE_SPAWNS   True as _("Randomize Spawns")

#Const  UI_TICK_INTERVAL	500	// Time interval between UI update // in milliseconds

/* -------------------------------------- */
// Globales variables
/* -------------------------------------- */
declare CSmBlockSpawn[]	BlockSpawnList;		// List of all the BlockSpawns of the map

declare CUILayer LayerSpawnScreen;
declare CUILayer LayerScoresTable;

/* -------------------------------------- */
// Functions
/* -------------------------------------- */

/** 
 * Fill BlockSpawnList with all the BlockSpanws of the map
 */
Void FillSpawnsList() {
	foreach (BlockSpawn in BlockSpawns) { BlockSpawnList.add(BlockSpawn); }
}

/**
 * Spawn a player
 *
 * @param	Player		The player to spawn
 */
Void SpawnPlayer(CSmPlayer Player) {
	SM::SpawnPlayer(Player, 0, BlockSpawnList[0]);
	SetPlayerWeapon(Player, CSmMode::EWeapon::Laser, False);
	Player.AmmoGain = RELOAD_SPEED;
	Player.ArmorMax = 100;
	
	// move spawn to the end of the list
	declare i=0;
	while (i < BlockSpawnList.count-1) { // assuming count of 10, loop 9 times.
	    declare tmp=BlockSpawnList[i+1].Id;
	    BlockSpawnList[i+1]=BlockSpawnList[i];
	    BlockSpawnList[i]=BlockSpawns[tmp];
		i=i+1;
	}
}

/** 
 * Mutate (ie. shuffle) the list of spawns
 */
Void MutateSpawnsList() {
    // TODO maybe mutate the list every once in a while
    declare i=0;
    while(i<BlockSpawnList.count) { // this should be enough, you can use arbitrary values, should the need arise
        // find a pair (a,b) of valid indices to swap
        declare a=MathLib::Rand(0, BlockSpawnList.count-1);
        declare b=MathLib::Rand(0, BlockSpawnList.count-1);
        
        // now swap them
        declare tmp=BlockSpawnList[b].Id;
        BlockSpawnList[b]=BlockSpawnList[a];
        BlockSpawnList[a]=BlockSpawns[tmp];
        
        i=i+1;
    }
}

/** 
 * Initialize all spawns on the map
 */
Void InitSpawns() {
    BlockSpawnList.clear();
    
	FillSpawnsList();
	
	if (MUTATE_SPAWNS) MutateSpawnsList();
}

/**
 * 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>
	""";
}

/** 
 * Get the help manialink string.
 *
 * @return		The manialink string
 */
Text UpdateLayerSpawnScreen() {
	declare Text ML;
	
	declare KillRewardText=TextLib::ToText(KILL_REWARD)^" ";
    if (KILL_REWARD==1) KillRewardText=KillRewardText^_("point");
    else KillRewardText=KillRewardText^_("points");
        
    declare SuicidePenaltyText=TextLib::ToText(SUICIDE_PENALTY)^" ";
    if (SUICIDE_PENALTY==1) SuicidePenaltyText=SuicidePenaltyText^_("point");
    else SuicidePenaltyText=SuicidePenaltyText^_("points");
	
	declare RulesText = TextLib::Compose(_("InstaGib DeathMatch\n\nFree-for-all where every hit kills the victim. Every kill gives you %1. Suicides reduce your score by %2.\nThe first player to reach %3 points wins.\n\n\nCredits: Triseaux (original script)"),  KillRewardText, SuicidePenaltyText, TextLib::ToText(POINT_LIMIT));
	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="$fffInstaGib DeathMatch" />
			</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;
}

/**
 * Play a short intro
 */
Void PlayIntro() {
    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 = "";
}

/**
 * Set up the Help screen
 */
Void AddSpawnScreen() {
    LayerSpawnScreen <=> UIManager.UILayerCreate();
    LayerSpawnScreen.Type = CUILayer::EUILayerType::ScreenIn3d;
    LayerSpawnScreen.ManialinkPage = UpdateLayerSpawnScreen();
	UIManager.UIAll.UILayers.add(LayerSpawnScreen);
}

/**
 * Set up the scoreboard
 */
Void AddScoresTable() {
    LayerScoresTable <=> UIManager.UILayerCreate();
	LayerScoresTable.Type = CUILayer::EUILayerType::ScoresTable;
    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")}}}: {{{ POINT_LIMIT }}}" />
		</frame>
	""";
	UIManager.UIAll.UILayers.add(LayerScoresTable);
}

/**
 * Set up the UI: help screen and scoreboard
 */
Void SetupUI() {
    UIManager.ResetAll();
	SM::SetupDefaultVisibility();
	
	AddSpawnScreen();
	AddScoresTable();
}

/**
 * Things to do before the map can start
 */
Void SetupMatch() {
    Mode::LoadMap();
    Score::MatchBegin();
	Score::RoundBegin();
    
	MatchEndRequested = False;
	
    InitSpawns();
	SetupUI();
	PlayIntro();
	
	StartTime = Now;
    EndTime = StartTime + (TIME_LIMIT * 1000);
	
	UIManager.UIAll.UISequence = CUIConfig::EUISequence::Playing;
}

/**
 * Player got killed by the environment
 */
Void OnArmorEmptyCallback(CSmModeEvent Event) {
    if (Event.Shooter == Event.Victim || Event.Shooter == Null) {
        Score::RemovePoints(Event.Victim, SUICIDE_PENALTY);
	}
	PassOn(Event);
}

/**
 * A player was killed.
 * If applicable display the remaining points for victory.
 */
Void OnHitCallback(CSmModeEvent Event) {
    if (Event.Shooter == Event.Victim) {
		Discard(Event);
	} else {
		Score::AddPoints(Event.Shooter, KILL_REWARD);
		Event.ShooterPoints = KILL_REWARD;
		// Play sound and notice if someone is close to win
		if (Event.Shooter != Null && Event.Shooter.Score != Null && POINT_LIMIT > 0) {
			declare Gap = POINT_LIMIT - 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);
	}
}

/**
 * Player wants to be set back to a spawn block
 */
Void OnPlayerRequestRespawnCallback(CSmModeEvent Event) {
    Score::RemovePoints(Event.Player, SUICIDE_PENALTY);
    PassOn(Event);
}

/**
 * Process all events triggered by the game
 */
Void ProcessEvents() {
    foreach (Event in PendingEvents) {
        switch(Event.Type) {
            case CSmModeEvent::EType::OnArmorEmpty: {
                OnArmorEmptyCallback(Event);
            }
            
            case CSmModeEvent::EType::OnHit:{
                OnHitCallback(Event);
            }
            
            case CSmModeEvent::EType::OnPlayerRequestRespawn: {
                OnPlayerRequestRespawnCallback(Event);
            }
            
            default: {
                PassOn(Event);
            }
        }
	}
}

/**
 * Respawn all players that want to play and are currently dead
 */
Void RespawnPlayers() {
    foreach (Player in Players) {
		if (Player.SpawnStatus == CSmPlayer::ESpawnStatus::NotSpawned && !Player.RequestsSpectate) {
			SpawnPlayer(Player);
		}
	}
}

/**
 * Updating the UI
 */
Void UpdateUI() {
    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]);
	}
}

/**
 * Actions to do after a map ended. Cleanup, declaring a winner if any
 */
Void EndMatch() {
    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 = "";
	
	UIManager.UILayerDestroy(LayerSpawnScreen);
	UIManager.UILayerDestroy(LayerScoresTable);
	
	Mode::UnloadMap();
}

/**
 * Main
 */
main() {
	UseClans = False;
	
	while (!ServerShutdownRequested) {
	    SetupMatch();
	    
		declare LastUITick = 0;
		while (!MatchEndRequested && !ServerShutdownRequested) {
			yield;
			
			ProcessEvents();
			
			RespawnPlayers();
			
			// only update the UI every once in a while
			if (LastUITick + UI_TICK_INTERVAL < Now) {
				UpdateUI();
				LastUITick = Now;
			}
			
			// victory conditions
			declare IsMatchOver = False;
			if (Now > StartTime + (TIME_LIMIT * 1000)) 
				IsMatchOver = True;
			foreach (Player in Players) {
				if (Player.Score != Null && POINT_LIMIT > 0 && Player.Score.RoundPoints >= POINT_LIMIT) IsMatchOver = True;
			}
			
			if (IsMatchOver) break;
		}
		
		EndMatch();
	}
}
Post Reply

Return to “ManiaScript”

Who is online

Users browsing this forum: No registered users and 1 guest