The Effigy monster talks into the console, this tutorial will show you how that was accomplished.
For this we will need to use the special Timer() function that can be set to call it self every x amount of time. And we need to set up some global variables for the speech and time. Declare the following variables first and put them in the defaultproperties.
var array<string> MonsterSpeech; var float TalkTime; defaultproperties { TalkTime=10.0 MonsterSpeech(0)="I'm going to get you!" MonsterSpeech(1)="Why are you hiding from me" MonsterSpeech(2)="Fear me!" }
TalkTime will control how often our timer is called. A fairly high setting should be good so the monsters don’t spam the chat. MonsterSpeech is the list of things that our monster can say. This list can be as long as you want. Next we need to start the timer in a function that is called early in the monsters life. PostBeginPlay is good for this. We also need to up the timer.
function PostBeginPlay() { Super.PostBeginPlay(); Level.Game.Broadcast(self, "Magdalena: HI!"); SetTimer(TalkTime, true); } function Timer() { local int i; i = Rand(MonsterSpeech.Length + 4); if (i < MonsterSpeech.Length) { Level.Game.Broadcast(self, "Magdalena: " $ MonsterSpeech[i]); } }
I was using my MagdalenaMonster for this so I put in her name. Replace where ever it says “Magdalena” with the name of your monster. In PostBeginPlay the timer is set using SetTimer(TalkTime, true); This means the Timer() will be called every TalkTime (10 seconds in our defaultproperties) and it is set to True, which means it will repeat. PostBeginPlay is a very important function for monsters and we must make sure the PostBeginPlay is called in the parent class also and not just overwritten in ours. To do this we use the special Super command. This tells it to call this functon in the parent class also. So don’t forget to include the line Super.PostBeginPlay(); in the function. In the Timer() function we can see that a random number is chosen using the Rand() function. The random number that can be returned has a chance of being longer than our list of things to say. This means that everytime the Timer() is called it has a chance to do nothing. This is good as it will make our monsters speech less predictable. Then using the Level.Game.Broadcast() function we tell out monster to talk and use the randomly chosen message.
Thats it! You might want to make things configurable such as the TalkTime, Speech and whether or not to turn on the speech feature in the first place.
TIP – The Broadcast function can be useful in debugging as it can display things to the screen in game rather than to the log file like Log(). both of these can be used to “log” almost anything you want! For example: Level.Game.Broadcast(self, Name @ Health); will log the monsters name followed by its health.
Recent Comments