Scripting: Add text to HUD/Screen



> >

Created 1 year ago

Scripting: Add text to HUD/Screen

Learn how to add text to the top left corner of your server
alien_1471270929.jpg

Introduction:


In this tutorial you will learn how to add your own custom text to the top left corner of your gameserver.

You will need to have a Call of Duty 1 server with CoDaM installed.

Don't have CoDaM installed?


If you don't have a cod1 server or codam, please refer to one of the following tutorials:

How to install CoDaM
How to create a Call of Duty Server on Linux
How to create a Call of Duty server with CoDaM on Windows


Step 1 - Let's get started:


  1. Open your CoDaM.pk3 file with an archiving tool like 7-Zip, WinRAR or WinZIP.
  2. You will see two folders, codam and maps , open the codam folder
  3. Locate the utils.gsc file and open it with a text editor, preferably Notepad++

Step 2:


Somewhere around line 133, you should see a function called __showCredit():
__showCredit()
{
	ver = newHudElem();
	ver.x = 1;
	ver.y = 474;
	ver.alignX = "left";
	ver.alignY = "middle";
	ver.sort = 99999;
	ver.fontScale = 0.6;
	ver.archived = true;
	ver.label = level.codam_credit;
	ver setValue( level.codam_version );

	return;
}

Step 3:


We will now paste the following code inside that function, right at the bottom before the return;
mycustomtext = newHudElem();
mycustomtext.archived = true;
mycustomtext.x = 15;
mycustomtext.y = 15;
mycustomtext.alignX = "left";
mycustomtext.alignY = "top";
mycustomtext.alpha = 1;
mycustomtext.fontscale = 1;
mycustomtext settext(&"^3THIS IS MY CUSTOM TEXT");
Feel free to change the text to your own liking.

The finished code should look like this:

__showCredit()
{
	ver = newHudElem();
	ver.x = 1;
	ver.y = 474;
	ver.alignX = "left";
	ver.alignY = "middle";
	ver.sort = 99999;
	ver.fontScale = 0.6;
	ver.archived = true;
	ver.label = level.codam_credit;
	ver setValue( level.codam_version );
		 
	mycustomtext = newHudElem();
	mycustomtext.archived = true;
	mycustomtext.x = 15;
	mycustomtext.y = 15;
	mycustomtext.alignX = "left";
	mycustomtext.alignY = "top";
	mycustomtext.alpha = 1;
	mycustomtext.fontscale = 1;
	mycustomtext settext(&"^3THIS IS MY CUSTOM TEXT");

	return;
}

Step 4 - You're done!


Close the file and save it, you will eventually have to confirm a dialog box to update the archive.

You can now restart the server and the text should appear.


Good to know: You can also draw rectangles and colorize them:


An example code would look like this:
rectangle = newHudElem();
rectangle.x = 0;
rectangle.y = 0;
rectangle.alignX = "left";      
rectangle.alignY = "top";
rectangle.alpha = 0.7;
rectangle setshader("black", 640, 20);
As you can see, in this case we have used the rectangle setshader method. The 640,420 defines the width and height of the rectangle.


General Information:

  • You can use color tags like ^1 ^2 in text
  • You can position the text using rectangle.x (horizontally / 0-640) and rectangle.y (vertically / 0-480)
  • You can set opacity with rectangle.alpha, 0.5 would be 50% opacity and 1 would be no opacity
  • You can also animate the text, but this will be covered in a different tutorial or added later.


Tutorial Details

Created: 1 year ago by alien

Views: 2013 Views

Keywords: Custom text, hud text, rectangles, scripting,

Share this Knowledge with your friends!

Direct Link:

1 Comments

(y)
Commented by The Monst3r VolT  (Aug 15th, 2016 04:47 PM)

Please sign in or create an account to post a comment.