Mutator script that plays sounds via mutate command - SOLVED

Discussions about Coding and Scripting
Post Reply
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Mutator script that plays sounds via mutate command - SOLVED

Post by Aldebaran »

I am studying hole day now to get my little mutator script working...
Compiling has no errors. But when testing in UT99 the "mutate PlaySounds list" command and the "mutate PlaySounds sound1" command not work.
It seems that the function Mutate is not called.
Shouldn't I use the classname after the mutate command in the console?
Or isn't it right that the function Mutate starts automatically when the class is called via console command?

Code: Select all

class PlaySounds extends Mutator;

    #exec AUDIO IMPORT FILE="Sounds\sound1.wav" NAME="sound1" GROUP="CustSounds"
    #exec AUDIO IMPORT FILE="Sounds\sound2.wav" NAME="sound2" GROUP="CustSounds"

    var string SndStr;
    var PlayerPawn SenderPawn;

    function Mutate(string MutateString, PlayerPawn Sender)
    {
       SndStr = caps(MutateString);
       SenderPawn = Sender;

       if(Left(SndStr, 15) ~= "PLAYSOUNDS LIST")
       {
          SenderPawn.ClientMessage("Available Sounds:");   
          SenderPawn.ClientMessage("sound1,sound2");
       }
       
       PlaySnd();

       if(NextMutator != none)
       {
          NextMutator.Mutate(MutateString, Sender);
       }
    }

    function PlaySnd()
    {
          local PlayerPawn PP;

          switch SndStr
          {
             case "PLAYSOUNDS SOUND1":
             	foreach AllActors( class 'PlayerPawn', PP )
                {
             	   PP.ClientPlaySound(Sound'sound1', False);
                }
                break;
             case "PLAYSOUNDS SOUND2":
             	foreach AllActors( class 'PlayerPawn', PP )
                {
             	   PP.ClientPlaySound(Sound'sound2', False);
                }
             	break;                     
         }

    }
EDIT: Changed listed code after discussion here to the working one. Old code deleted.
Last edited by Aldebaran on Wed Jul 27, 2016 1:01 pm, edited 4 times in total.
User avatar
Barbie
Godlike
Posts: 2792
Joined: Fri Sep 25, 2015 9:01 pm
Location: moved without proper hashing

Re: Mutator that plays sounds via console mutate command

Post by Barbie »

Apart from the problem itself: If I am not sure if something is called or not or I want to know the value of parameters and variables, I use the "log" function:

Code: Select all

function Mutate(string MutateString, PlayerPawn Sender) {
	log(self $ ".Mutate called with MutateString=" $ MutateString $ ", Sender=" $ Sender);
	...
You will find the log message in the log files.

Also the function BroadCastMessage() can be used for displaying debugging infos or even combine both:

Code: Select all

function DebugLog(coerce string Caller, string msg) {
	msg = "DebugLog for" @ Caller $ ":" @ msg;
	log(msg);
	BroadCastMessage(msg);
}

function Mutate(string MutateString, PlayerPawn Sender) {
	DebugLog("Mutate", "MutateString=" $ MutateString $ ", Sender=" $ Sender);
	...
"Multiple exclamation marks," he went on, shaking his head, "are a sure sign of a diseased mind." --Terry Pratchett
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Mutator that plays sounds via console mutate command

Post by Aldebaran »

Barbie wrote:You will find the log message in the log files.
Wait... I am analyzing right now :)
Last edited by Aldebaran on Mon Jul 25, 2016 8:28 pm, edited 1 time in total.
Chris
Experienced
Posts: 134
Joined: Mon Nov 24, 2014 9:27 am

Re: Mutator that plays sounds via console mutate command

Post by Chris »

You're trying to call a sound for client from a server executed function... Why don't you just use an Exec modified function?
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Mutator that plays sounds via console mutate command

Post by Aldebaran »

It was a stupid beginner's mistake... I have forgotten to delete my old .u file before recompiling.
Now it works like a charm after some corrections :rock:
Chris wrote:Why don't you just use an Exec modified function?
I don't know the difference for now, sorry. But my version seems to work fine.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Mutator that plays sounds via console mutate command

Post by sektor2111 »

I don't understand at all your PostBeginPlay. It does nothing, it calls Nothing from Super.Class and it does a return like a bad copy of a mutator. People used return in case of a bad instance... It's your problem after all, I won't write such things. ELSE I've already described results of abusing "return;" in a chain of mutators - it might stop working and/or even blocking other chained mutators. Good luck, some day you'll figure this. I did the same crap in some MHBotyMan which I removed later (in V4).
Aldebaran wrote: function PlaySnd()
{
local Pawn P;
local PlayerPawn PP;

P = Pawn(Owner);
I'm interested what you have in console related to these "Owner" and "P" things, at first look they seems None like...
Last edited by sektor2111 on Mon Jul 25, 2016 11:20 pm, edited 1 time in total.
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Mutator that plays sounds via console mutate command

Post by Aldebaran »

sektor2111 wrote:I don't understand at all your PostBeginPlay.
I have assigned some values to some variables there. When I do it in the defaultproperties section I get some warnings while compilation.
But I deleted them in this posted code...
sektor2111 wrote:People used return in case of a bad instance...
I did not knew if I can omit the return lines. So when it makes no great difference you are right.
sektor2111 wrote:I'm interested what you have in console related to these "Owner" and "P" things, at first look they seems None like...
The code I posted was not correct, I changed some code also these lines were deleted then...
Last edited by Aldebaran on Mon Jul 25, 2016 11:25 pm, edited 1 time in total.
User avatar
sektor2111
Godlike
Posts: 6403
Joined: Sun May 09, 2010 6:15 pm
Location: On the roof.

Re: Mutator that plays sounds via console mutate command

Post by sektor2111 »

So you get Mutate working then, that's good.
Aldebaran
Masterful
Posts: 672
Joined: Thu Jan 28, 2016 7:30 pm

Re: Mutator that plays sounds via console mutate command- SO

Post by Aldebaran »

I have changed the code in first post to a working one.
Post Reply