Creating message mutator

Lessons and tutorials about mods and maps

Creating message mutator

Postby piazon79 » Fri Apr 05, 2019 7:10 pm

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!
piazon79
Novice
 
Posts: 3
Joined: Fri Apr 05, 2019 6:31 pm

Re: Creating message mutator

Postby JackGriffin » Sat Apr 06, 2019 5:21 am

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
JackGriffin
Godlike
 
Posts: 3766
Joined: Fri Jan 14, 2011 1:53 pm
Personal rank: -Retired-

Re: Creating message mutator

Postby PrinceOfFunky » Sat Apr 06, 2019 2:05 pm

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.
Image
User avatar
PrinceOfFunky
Godlike
 
Posts: 1040
Joined: Mon Aug 31, 2015 10:31 pm

Re: Creating message mutator

Postby piazon79 » Sat Apr 06, 2019 3:35 pm

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!
piazon79
Novice
 
Posts: 3
Joined: Fri Apr 05, 2019 6:31 pm

Re: Creating message mutator

Postby PrinceOfFunky » Sat Apr 06, 2019 4:31 pm

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.
Image
User avatar
PrinceOfFunky
Godlike
 
Posts: 1040
Joined: Mon Aug 31, 2015 10:31 pm

Re: Creating message mutator

Postby Barbie » Sat Apr 06, 2019 9:16 pm

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
User avatar
Barbie
Godlike
 
Posts: 1687
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Creating message mutator

Postby piazon79 » Sat Apr 06, 2019 9:41 pm

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?
piazon79
Novice
 
Posts: 3
Joined: Fri Apr 05, 2019 6:31 pm

Re: Creating message mutator

Postby Barbie » Sat Apr 06, 2019 11:42 pm

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
Barbie
Godlike
 
Posts: 1687
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Creating message mutator

Postby PrinceOfFunky » Sun Apr 07, 2019 12:22 am

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: .
Image
User avatar
PrinceOfFunky
Godlike
 
Posts: 1040
Joined: Mon Aug 31, 2015 10:31 pm


Return to Development School

Who is online

Users browsing this forum: No registered users and 1 guest