Gah - a solution with more questions. – EntropicLqd

Legacy:Dezro/99 Bottles

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

Sing 99 Bottles of Beer[edit]

And this is the last place I'm putting this thing. I swear.

Inspired by

// 99 Bottles of Beer, in UnrealScript. Sings to every player
// simultaneously. Written for UT2003, but would work on other Unreal
// Engine games with little to no modification.
// Probably works on a network. I haven't checked.
// Written by "Dezro" Dave Smith:
class MutBottlesBeer extends Mutator;
var int StartingBottles;
var int CurrentBottle;
var int SongLine;
var bool Begun;
var bool StopSong;
function ModifyPlayer(Pawn Other)
	if (!Begun)
		CurrentBottle = StartingBottles;
		SetTimer(1.5, true);
		Begun = true;
function Timer()
	local Controller C;
	local bool PassAround;
	if (StopSong)
		SetTimer(0.001, false);
	for (C = Level.ControllerList; C != None; C = C.NextController)
		Switch (SongLine)
		Case 0:
			if (CurrentBottle == 1)
				C.Pawn.ClientMessage("One bottle of beer on the wall,");
				C.Pawn.ClientMessage(CurrentBottle $ " bottles of beer on the wall,");
		Case 1:
			if (CurrentBottle == 1)
				C.Pawn.ClientMessage("One bottle of beer.");
				C.Pawn.ClientMessage(CurrentBottle $ " bottles of beer.");
		Case 2:
			if (CurrentBottle == 1)
				C.Pawn.ClientMessage("Take it down, pass it around,");
				C.Pawn.ClientMessage("Take one down, pass it around,");
			PassAround = true;
			if (CurrentBottle == 1)
				C.Pawn.ClientMessage("One bottle of beer on the wall.");
			else if (CurrentBottle < 1)
				C.Pawn.ClientMessage("No more bottles of beer on the wall!");
				StopSong = true;
				C.Pawn.ClientMessage(CurrentBottle $ " bottles of beer on the wall.");
	if (PassAround)
		PassAround = false;
	if (SongLine > 3)
		SongLine = 0;
defaultproperties {
	FriendlyName="99 Bottles"
	Description="Sings to you during the battle."
	StartingBottles = 99


Wormbo: Nice. Actually you could optimize and localize it with LocalMessages, since the song also exists in other languages. :)

Tarquin: Submit it to ! Can you have arrays of strings? Might be neater than using the "switch" statement.

Dezro: I've already submitted it. I didn't use LocalMessages, since I wanted to keep it down to one file. I didn't use string arrays, because I didn't think of it. I should have... I could have added some customization if I went that route, too, which would make up for the lack of localization a bit. Ah, well.

Ike Bart: I tried to compile it in UnrealEd 2 and I got an error on line 29. It said: Error in MutBottlesBeer, Line 29: Unrecognized type 'Controller.' Since I'm an absolute newbie at Unreal script for Unreal Tournament, I'd like to know what to do to make it compatible with Unreal Tournament.

Dezro: That's the "little modification" I was talking about. UT1 doesn't use the pawn/controller setup, so you'd have to change some things. Make the following changes to the code:

Wherever you find this Replace it with this
local Controller C; local Pawn P;
for (C = Level.ControllerList; C != None; C = C.NextController) for (P = Level.PawnList; P != None; P = P.NextPawn)
C.Pawn.ClientMessage P.ClientMessage

Ike Bart: After making those changes, I get an error message at line 84. It said: Error in MutBottlesBeer, Line 84: Unexpected 'defaultproperties'

Dezro: That's a different problem. You're not supposed to use UnrealEd when coding. If you stll want to, remove the "var int StartingBottles;" line, replace every other instance of "StartingBottles" with 99, and delete the "defaultproperties" block. It'll compile after that, probably.

Ike Bart: Thanks for the suggestion, Dezro. I got UnrealEd to compile the script after following your suggestions. Now I have to test it out in Unreal Tournament. I hope I made the .ini file for it correctly.

Ike Bart: I tested it out in Unreal Tournament and it works. It took around nine minutes to finish off all 99 bottles of beer.