• Please make sure you are familiar with the forum rules. You can find them here: https://forums.tripwireinteractive.com/index.php?threads/forum-rules.2334636/

Code Mut: Crazy Hats! (I NEED HELP)

Hey guys!

Firstly, let me introduce the project I've been working on for about a day or so. Crazy Hats! Basically, what this mutator does is allow the player to select one of several wacky, ridiculous hats to wear and frag zombies in. It's just a small thing that adds immense fun and hilarity (as well as uniquity) to the standard gameplay.

I'm basically working off of the SantaHats mutator from UT2004 (which was ported over to KF in SinngerG's Roll The Dice mutator). What I did was simply begin churning out 3D models of silly hats, and then I modified the mutator code to support the new additions.

Basically, I have an "if" statement running, where if(Hat == 1){ and then it attaches Hat #1. I've implemented three hats this way, using "else if" statements and such, and they are all driven by the int "Hat". For the time being, I've simply forced the value of "Hat" through the source code to test all the different hats out...

However, an important aspect of the code is not working for me at all, and that is the ability to manipulate a variable (client side) that sets which hat is available (by allowing a user to input a value for "Hat"). I have no idea how to go about doing this, because I don't know what class to extend in order to have this work.

What I'm basically thinking of is a console-based option, where the user opens their console, and types something like:

SetHat 1

And they are given the particular hat.

From what I gather, this is handled as an "exec function" but after multiple attempts to get this function to work properly, I've failed...

Can anyone help me understand how to go about this particular problem? Even better, would someone be willing to assist me with the programming side of this? All I need is a basic framework that I can add new hats to...

Here's some screens of my progress:

Santa Hat (this was the default, not something I made)
SantaHatTest.jpg


Stovepipe Hat
TopHatTest.jpg


Sombrero
SombreroTest.jpg


I'm making a bunch of other hats, such as:
- Baseball Cap
- Pope Hat
- Giant 'Fro
- Bunny Ears
- Cat Ears
- Devil Horns
- Halo
- Robot Antenna

And even more! I'm also up for suggestions, however, none of this matters unless I can resolve this code/someone helps me script.

Thanks in advance for any help! :D

EDIT: Also, I'm hoping that this has whitelist potential, mainly because it's not affecting anything truly critical to the gameplay, it's simply a visual tweak. If a dev can verify this for me, that'd be phenomenal and I'll happily continue working on this!

DOUBLE EDIT: I've also been looking at the Roll The Dice mutator's structure, in how it pulls information from the Chat Window in order to function (i.e. you say "!rtd" and the mutator activates). I'm considering going down this route in order to solve my dilemma... Some verification/experience doing this from other programmers would be much appreciated.
 
Last edited:
Thanks for the vote of confidence! :)

Here's some of the models I've completed (as well as the santa hat, which is not mine). I'm keeping them as low-poly as possible, so graphics don't get out of hand and file-sizes remain at a minimum.

hats.jpg


You haven't fragged zeds until you've fragged them with Bunny Ears.

More to come... Still trying to figure out this code, and I'm desperate for any kind of assistance. :p

EDIT: Gag-Arrow. Thanks for the suggestion Brit!

gagarrow.jpg


Scripting efforts are not going well at all...
 
Last edited:
Upvote 0
Okay, I've tried and tried, and now I'm ready to accept everyone laughing at me for incompetence.

Can someone please explain why my exec function is not working AT ALL in-game? I have literally seeded this function under EVERY class that was suggested on BeyondUnreal's wiki...

Included in the code is a generic sample of the attempt I've made to get this to work.

Code:
class ConsoleTest extends Console;

exec function SwapHats()
{
     Log("Success!");
}
Each time I try to get this code to function, I'm met with "Unrecognized Command" in the console, and absolutely nothing printing to the log.

Why I'm doing this?

I feel it would be more professional, and provide ease-of-access to the user, to be able to organize my data so that it is capable of being tweaked via console commands. Upon searching for console commands in UT2004, BeyondUnreal's wiki referenced me to the Exec Function which, according to them:

they provide a way to define new console commands in UnrealScript code.
The following is specified as well:

Exec functions can be declared anywhere, but they only actually work in the following objects:
(Note: this is only for UT2003/4, not UT or Unreal 1)

  • the Console interaction
  • the GameInfo actor (keep in mind that the GameInfo only exists on the server, though)
  • the local player's HUD actor
  • the local player's CheatManager (only offline)
  • the local player's AdminManager (an AdminBase subclass, only when logged in as admin and only available on the serverside)
  • the local PlayerController
  • the local player's PlayerInput
  • the local player's Pawn
  • that Pawn's selected Weapon and SelectedItem (Inventory)
  • in UT2004 also any local Interaction
You can not declare a working exec function in a mutator.
Note the last line of that snippet. However, they fail to specify if this definition applies strictly to defining an 'exec function' as a subclass of "Mutator" -

i.e: 'class MyMutator extends Mutator' and then I call the 'exec function' in that class

Or whether I can define an 'exec function' in a separate subclass, such as in "Console", and then reference variables from that command -

i.e: 'class MyConsoleCommand extends Console' and then I call the 'exec function' in that class. Then, the result of calling that 'exec function' manipulates data in my "Mutator" class.

Can anyone please shed some light on this for me? It's painful when I'm being informed of a specific thing, and yet every attempt yields zero results. :(

Also, if nobody can help me understand this here, can you please reference me somewhere that can assist me more thoroughly? Even if it's to another tutorial, I'd appreciate anything at this point...

EDIT: I also forgot to mention that I've made this same call as a separate file, having nothing to do with a mutator extension, simply an extension of the listed classes that allow 'exec functions'. What the heck am I missing here?

EDIT 2: After struggling all night with this, I stumbled upon this... While it's referring to UT3, I'm not surprised if the same holds true for UT2k4, that 'exec functions' are impossible and useless short of creating a full-blown mod. Apparently I'm to use the 'mutate' function in its stead, but this seems rather silly to me as a Mutator should honestly be capable of receiving console based input, at least via interaction... The necessity to include 'mutate' before each variable call makes the whole thing feel kinda cheap to say the least.

The struggle continues.

EDIT 3: Mutate works... Huzzah. While this is a huge step forward in me being able to get this thing working, it's also an enlightening aspect that makes me realize UScript is binding and seemingly disorganized due to it's requirements of code placement. I'll get used to it in time.

EDIT 4: Mutator now passes variables successfully between server and client. I'm going to bed before my now-liquified brain slides out of my nose and on to my keyboard.
 
Last edited:
Upvote 0
And yeah, UScript is like really disorganized C++/Java without an actual editor for it (Outside of UDK/Unrealed) which is fairly surprising for as long as it's existed

Truth.

I've had some experience with C++ (creating a text-based Battleship game with mild AI, etc.) and unfortunately it primed me for something a little more linear than what UScript actually is. Whereas C++ organizes all functions within a single location, UScript has managed to completely obfuscate the entire process by localizing variables and function calls within multiple classes. Half the battle is creating the code, while the other half is knowing where the heck to put it.

Frustrating as heck, but when you get it right you feel like a champion. :p

ALSO: I'd like to physically harm whoever decided on these naming conventions -

Code:
Role == ROLE_Authority;
Role != ROLE_Authority;

I understand they have become simply "client()" and "server()" in UT3, which saves everyone the pain of calling unnecessary "if" statements just to determine whether the function is client- or server-sided. [/rant]
 
Last edited:
Upvote 0
Ahahaha, yes, some of it just doesnt make any sense at all, especially when it comes to starting from scratch or even adding things to existing code, with no actual "True" Uscript-only editor, most would-be modders are put off

Hopefully you get this worked out, i may be of assistance once i figure out how to properly synch multiple different varaibles between everyone if someone per-say, doesnt have the mutator (KF should download mutators when players join a server, they're only like 1-10kb usually)
 
Upvote 0
Hey, thanks for the support everyone. Truth be told, I can't give a precise completion date because I'm working on this during my (extremely limited) spare-time...

I have managed to get the mutator working well, however, everything occurs strictly server-side, and nothing gets passed to the client. Furthermore, I have yet to find out how to allow clients to specify DIFFERING hats, as right now the command manipulates a single, global variable.

I'm working as hard as I possibly can on this, but the going is slow. :rolleyes:
 
Upvote 0