Creating message mutator

Lessons and tutorials about mods and maps
Post Reply
piazon79
Novice
Posts: 3
Joined: Fri Apr 05, 2019 6:31 pm

Creating message mutator

Post by piazon79 »

Hello,

I am trying to create a simple mutator that takes a wav file and plays the sound byte when a user types a certain word in the chat. For example when a player types "hello" in chat it plays a sound byte.

I'm importing my wav file like this:
#exec AUDIO IMPORT FILE="Sounds\hi_0.wav" NAME="hi_0" GROUP="Taunts"

But i can't figure out how to actually get it to play when the user types "hi" or "hello". I'm new to unreal script and I have searched all over the internet for assistance but nothing that I can find that relates to this. I know this is possible, I have the MOZMessages mutator but I'm trying to create my own sounds.

Any help is greatly appreciated. Thanks so much!
JackGriffin
Godlike
Posts: 3774
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Creating message mutator

Post by JackGriffin »

Post over at House of Fool's forum: https://hofgamingclan.com/forums/
The head guy there is a voice pack fanatic and they use 'zounds' type sound mods on their servers. I wouldn't be surprised if they weren't written by him.
So long, and thanks for all the fish
User avatar
PrinceOfFunky
Godlike
Posts: 1200
Joined: Mon Aug 31, 2015 10:31 pm

Re: Creating message mutator

Post by PrinceOfFunky »

piazon79 wrote:Hello,

I am trying to create a simple mutator that takes a wav file and plays the sound byte when a user types a certain word in the chat. For example when a player types "hello" in chat it plays a sound byte.

I'm importing my wav file like this:
#exec AUDIO IMPORT FILE="Sounds\hi_0.wav" NAME="hi_0" GROUP="Taunts"

But i can't figure out how to actually get it to play when the user types "hi" or "hello". I'm new to unreal script and I have searched all over the internet for assistance but nothing that I can find that relates to this. I know this is possible, I have the MOZMessages mutator but I'm trying to create my own sounds.

Any help is greatly appreciated. Thanks so much!
You just have to create a mutator class that listens to messages by registering it as a MessageMutator, GameInfo.uc contains this function "RegisterMessageMutator(Mutator M)", call it from the mutator in PostBeginPlay() using "self" as parameter. Then, everytime a player chats, one or more of these callbacks will be called: "MutatorTeamMessage(...)"/"MutatorBroadcastMessage(...)"/"MutatorBroadcastLocalizedMessage(...)", which are functions in Mutator.uc that you just need to redefine (also remember to add super.NameOfTheFunction(...).
Since you have the hi_0 file, do a check on the string and if the string contains "hello" (you can check it by using InStr) use a "for" on Level.PawnList, check if the pawn is a PlayerPawn and then play the sound as playerPawn.ClientPlaySound(...) (which is a function in PlayerPawn.uc).
Maybe there's a way to broadcast a sound but I'm not sure how.
"Your stuff is known to be buggy and unfinished/not properly tested"
piazon79
Novice
Posts: 3
Joined: Fri Apr 05, 2019 6:31 pm

Re: Creating message mutator

Post by piazon79 »

Thanks for the suggestions! I'll give this a try, may take me a while to figure it out since im newer to unreal script but i really appreciate the help!
User avatar
PrinceOfFunky
Godlike
Posts: 1200
Joined: Mon Aug 31, 2015 10:31 pm

Re: Creating message mutator

Post by PrinceOfFunky »

piazon79 wrote:Thanks for the suggestions! I'll give this a try, may take me a while to figure it out since im newer to unreal script but i really appreciate the help!
Something like this:

Code: Select all

class CustomMutator extends Mutator;

event PostBeginPlay() {
	Level.Game.RegisterMessageMutator(self);
}

function bool MutatorBroadcastMessage(Actor Sender, Pawn Receiver, out coerce string Msg, optional bool bBeep, out optional name Type) {
	//Should check if (Sender.isA('PlayerPawn')) ?
	if (inStr(Msg, "hello") != -1) {
		for (pawn = level.pawnList; (pawn != None) && (pawn.isA('PlayerPawn')); pawn = pawn.nextPawn) {
			pawn.ClientPlaySound(SOUND_GOES_HERE);
		}
	}
}
I actually don't remember if a sound must be used like textures do (Texture'Package.Group.Name') or in a different way.
"Your stuff is known to be buggy and unfinished/not properly tested"
User avatar
Barbie
Godlike
Posts: 2784
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Creating message mutator

Post by Barbie »

PrinceOfFunky wrote:

Code: Select all

for (pawn = level.pawnList; (pawn != None) && (pawn.isA('PlayerPawn')); pawn = pawn.nextPawn) {
	pawn.ClientPlaySound(SOUND_GOES_HERE);
	}
Because second argument of the for-loop is the loop condition and not every pawn in level.pawnList is a PlayerPawn, that loop will not iterate over all items in the list necessarily.

Better use something like this:

Code: Select all

for (pawn = level.pawnList; pawn != None; pawn = pawn.nextPawn)
	if (PlayerPawn(pawn) != None)
		PlayerPawn(pawn).ClientPlaySound(SOUND_GOES_HERE);
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
piazon79
Novice
Posts: 3
Joined: Fri Apr 05, 2019 6:31 pm

Re: Creating message mutator

Post by piazon79 »

Awesome! I'll try this out. Questions though, where does it check for what the playing is typing in order to play the sound? Like typing "hello" in chat will play that sound?
User avatar
Barbie
Godlike
Posts: 2784
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Creating message mutator

Post by Barbie »

piazon79 wrote:where does it check for what the playing is typing in order to play the sound?

Code: Select all

if (inStr(Msg, "hello") != -1)
piazon79 wrote:Like typing "hello" in chat will play that sound?
Close - typing it is not enough, the player has to send the text (press Enter) also. Also notice that "inStr" compares case sensitive .
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
User avatar
PrinceOfFunky
Godlike
Posts: 1200
Joined: Mon Aug 31, 2015 10:31 pm

Re: Creating message mutator

Post by PrinceOfFunky »

Barbie wrote:
PrinceOfFunky wrote:

Code: Select all

for (pawn = level.pawnList; (pawn != None) && (pawn.isA('PlayerPawn')); pawn = pawn.nextPawn) {
	pawn.ClientPlaySound(SOUND_GOES_HERE);
	}
Because second argument of the for-loop is the loop condition and not every pawn in level.pawnList is a PlayerPawn, that loop will not iterate over all items in the list necessarily.

Better use something like this:

Code: Select all

for (pawn = level.pawnList; pawn != None; pawn = pawn.nextPawn)
	if (PlayerPawn(pawn) != None)
		PlayerPawn(pawn).ClientPlaySound(SOUND_GOES_HERE);
You're right, it's been a long time that I don't code in unrealscript anymore :what: .
"Your stuff is known to be buggy and unfinished/not properly tested"
Post Reply