I want to learn how to code a half-life mod

New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
If you are serious about this, first learn how to code in C++, before even downloading the halflife sdk. Get a book about C++. Online tutorials are usually from a doubtfull quality. Your local library should have something usefull. I don't have any English book suggestions. Leen Ammeraal wrote a great C++ book in Dutch. If your book has assignments, make the assignments. If not, try to make a simple C++ program every chapter, testing your skills.

To compile and build your code you will need a compiler. There are some great free compilers for dos/windows:
www.mingw.org (commandline)
www.borland.com (commandline or free "turbo C++" DOS compilers with UI in the museum)
http://www.delorie.com/djgpp/ (dos command line compiler)
You might want to check out one of those first to see if coding is your thing. Borland Turbo C++ is a great compiler to get started in. To code a half-life mod, Microsoft Visual C++ is the most convienent.

If you worked through your book, you're ready to do some modding. You can get the halflife sdk from fileplanet. Make sure you have version 2.3. If you have a decent connection, i'd get the full version, with all tools and some documentation. Otherwise, get the sourcecode only version. There are some great tutorials about half-life modding at
www.thewavelength.net
Try to make some small changes, and create your own mini-mod. If you feel confident with the sdk code, try to find a team that needs a coder (that shouldn't be too hard), to get some experience working in a team. Don't try to start your own mod without any previous experience. Leading a team and keeping people motivated is a harder job than you'd think.

Please only append to this thread if you have something usefull to tell to new coders (like book-suggestions, half-life modding links). Don't tell me how much great/sucky this sticky is, or how you created your l33t mod in which the shotgun shoots 4 bullets instead of 2 without ever touching a book. You can do that in other threads if you have to.
 

jc

New Member
Joined
Sep 22, 2002
Messages
12
Best answers
0
i would suggest a visit to www.cplusplus.com. That is the reference I used most often when I came unstuck.

two very simple things:

making sure you dont get = and == wrong
================================
The most important thing to remember is the = and == operators. They are not the same and you compiler wont always bork if you get it wrong. A tip i picked up to avoid this is to organise your statements differently *gives example*

Code:
if (somevar=1) { printf("somebody smells\n"); }
that line is wrong and your compiler wouldnt tell you (because testing an assignment like this is legal)... by switching the statement round tho:

Code:
if (1=somevar) { printf("somebody smells\n"); }
when your compiler sees this it should (if its not retarded) spank you for trying to assing a value to a constant. so now when u do one of these typos your compiler will let you know and you want be left banging your head against the wall wondering why nothing is working.

remember your logical operators
========================
i used to always get my AND's and OR's confused. DONT. && is and and || is or.

if (esf==good && ghp==good) { printf("two good mods!!\n"); }
 
Fumoffu!
Retired Forum Staff
💻 Oldtimer
Joined
Nov 21, 2002
Messages
2,888
Best answers
0
/me starts a small rant on some general coding pointers >=o

Like HarSens pointed out, I'd say that thewavelength is the best site you could ask for, if you need tutorials and forum help. For tutorials and articles, also affilliated with thewavelength - check out HLCI and HLPP.

As far as the compiler is concerned, I would personally recommend that you start with something like "Turbo C++", and get a good grip with general C++ coding. Check out the help libraries and start to mess around with example codes to see how they run. You should soon be able to start writing your own code - next, you should look into some text on Object Oriented Programming (OOP). OOPS is a big part of Half-Life coding, and unless you know about how to use classes and objects, and multiple functions. Another important aspect of OOP that you must have good knowledge on, before you can start to code for a mod, is inheritence.

After you've learnt how to code the OOP way, you should move to a better compiler like MS Visual C++ (I would personally recomment MS Visual Studio .net). The importance of using such a compiler is that you can manage all your source and header files through projects, something that is missing in DOS compilers like TCPP. If you start to understand how HL code basically works, I would say 'Welcome to the world of OOD (Object Oriented Design)'. :)

As far as errors are concerned - syntax and normal visible errors are the easiest to fix, and if you get a lot of errors on your first compile, don't loose your head - it's not that hard. What you have to really look out for are logical errors, where your syntax is all correct, but something goes wrong because of a misplaced line or two. To be able to fix logical errors, you really have to know your own code - to be able to go through it and pinpoint the error. You will probably get used to finding errors and become faster with practice - programming in ANY high level language is all about practicing and learning through mistakes. No one can become a so-called 'l33t coder' just by reading books or tutorials.

Going a bit into the code...

Like JC pointed out in his post above, = != == ...

= <-- used for passing static or equational values to the lvalue variable on the left.
Example:
Code:
int a = 10;
== <-- used for CHECKING in conditional literals, example: if/for/while/switch/etc.
Exampe:
Code:
if (a == 10) { cout << "Yes"; }
If you by-chance put if ( a = 10 ), instead of CHECKING if a is equal to 10 - the compiler will PASS the numerical value '10' to a. Hence no matter what a was before, the outcome will be that a will be changed to 10.

Another thing to be vary of is function overloading and recursion... I doubt you'll get to use recursion much in basic HL modding, but if you create some complex functions where you want to achieve an efficient method of repetition, recursion would be your best option. I would recommend that you read some text on this before trying to implement this.

And before you do start coding, it would be useful if you get a basic grasp on boolean logic and algebra - [ link ]. Furthermore, when using multiple operators in one statement, you can often stumble upon an output that you weren't expecting - because you don't know about the priority of C++ operators. When you have a basic statement like this:
Code:
x -= 10 + 8 % 2;
.. you might not get what you are looking for either because you didn't use paranthesis () or because you don't know about the operator's priorities that the compiler understands.

Courtesy of cplusplus.com said:
1 :: scope Left
2 () [ ] -> . sizeof Left
3 ++ -- increment/decrement Right
~ Complement to one (bitwise)
! unary NOT
& * Reference and Dereference (pointers)
(type) Type casting
+ - Unary less sign
4 * / % arithmetical operations Left
5 + - arithmetical operations Left
6 << >> bit shifting (bitwise) Left
7 < <= > >= Relational operators Left
8 == != Relational operators Left
9 & ^ | Bitwise operators Left
10 && || Logic operators Left
11 ?: Conditional Right
12 = += -= *= /= %=
>>= <<= &= ^= |= Assignation Right
13 , Comma, Separator Left
I am not going to comment on pointers because I personally hate using them, since I think using pointers is an insecure way of passing data. That's the only thing I like about Java as opposed to C++ --> No pointers! >_< Although it is important for you to get an idea about accessing memory addresses and using dynamic memory. Using pointers actually makes your code more efficient and can avoid excessive cluttering up of code. And another thing: you should get accustomed to defining your own data types (typedef) - as I believe this comes in very handy when making a certain type of gameplay or working on a project that involves using many similar datatypes. Using these also helps organize your own code by knowing which variables are being used where. Learn about #define as well..

On a concluding note, ALWAYS use comments with your code. Comments only take up space in your source file and are not used when compiling. It is humanly not possible to manage 1000+ functions in half-life modding just by remembering what does what... I'm sure you would be able to make out the purpose of a function or statement by looking at the code around it, but why not just use comments to help yourself become more efficient with code? There are basically two types of comments:
Code:
// get material type
step = PM_MapTextureTypeStepType( pmove->chtexturetype );
// is a one-line commenting method, your compiler will ignore everything after // while compiling until it finds a newline.
Next:
Code:
/*
============
PM_FlyMove

The basic solid body movement clip that slides along multiple planes
============
*/
int PM_FlyMove (void)
{
//blah blah...
}
Here, the compiler will ignore everything BETWEEN /* and */, this is useful for multi-line commenting or in-source documentation.

Another very important thing about code is that you must ALWAYS keep your code CLEAN and ORGANIZED. Note the difference between A and B:

A:
PHP:
for(int a=0;a<10;a++){cout<<"Element [<<a+1<<"] is "<<x[a];cout<<endl;y[ a ]=x[ y ];}
B:
PHP:
for ( int a = 0; a < 10; a++ )
   { // Displaying the 10 values inside array 'x',
     //  and copying values to array 'y'.
       cout << "Element [" << a+1 << "] is " << x[a] << "\n";
       y[ a ] = x[ a ];
   }
( Don't mind the php colors, that's the only way I could wrap the syntax on these forums... )

Now imagine that you were going through your own code... would you even WANT to look at A? No matter how good a coder you become, you must always keep your code organized. :smile:

Guess that's about it for now, I'll edit this post if something else comes to mind - /me hopes this post has been useful for people starting with C++ ...
 
New Member
Joined
Nov 28, 2002
Messages
59
Best answers
0
Dont forget about VERC, Another place to find the HL_SDK 2.3, and help with modding. I believe this is where the modding began.
VERC Collective
 
New Member
Joined
Nov 27, 2002
Messages
13
Best answers
0
I'm surprised you mentioned MinGW but not Dev-C++. Dev-C++ is a graphical IDE (Integrated Development Environment) and uses the MinGW ported tools and compiler. A good IDE can really help out, as most command line compilers require you to fiddle around with makefiles and the like, and are very unfriendly to newbies or anyone who doesn't want to code for a non-windows box.

I'd mention cplusplus.com but someone else has, excellent resource, especially the library refference section. One other word on compilers, while all the compilers listed are free, they will not compare to the purchased compilers, specifically Microsoft's latest Visual Studio .NET. Which will cost money, however, you get a friendlier IDE and a much much better compiler.
 
New Member
Joined
Nov 28, 2002
Messages
59
Best answers
0
I agree, if your new to coding, the command line compilers are very hard to come to terms with, while MSVS.NET is a click click ordeal. It tells you what script file has an error click on the error and it jumps to the script and line the error is on (or starts at)
As well you can find more info about MSVS.NET such as tutorials on how to set up a custom build and shortcuts on how to do certain parts of code, that using notepad (or other editor) dont have.
It'll always be overwhelming at first, but once your mind gets a grip on whats going on, things will flow, just keep trying until you get it to work for you.
The definition of insaniity is trying the same thing over and over, expecting different results
So try other methods too if you cant get something to work.
 

jc

New Member
Joined
Sep 22, 2002
Messages
12
Best answers
0
microsofts latest compiler is available for free but without the ide. details of this and how to use it can be found on thewavelength.net

free ide's other the DevShed are out there. one is:

http://www.objectcentral.com/vide.htm

there is another which is very similar to vis c++ which i did like very much but at this moment its name escapes me.
 
New Member
Joined
Nov 27, 2002
Messages
13
Best answers
0
jc said:
microsofts latest compiler is available for free but without the ide. details of this and how to use it can be found on thewavelength.net

free ide's other the DevShed are out there. one is:

http://www.objectcentral.com/vide.htm

there is another which is very similar to vis c++ which i did like very much but at this moment its name escapes me.
Are you sure it's the full compiler? If I remember right they have two different versions, a lesser one that goes with the 100$ Visual C++ .NET software, and another much faster and much better compiler for producing optimized code that goes into their thousand plus dollar Visual Studio .NET. I could be wrong but that's the impression I got.
 
New Member
Joined
Mar 29, 2004
Messages
26
Best answers
0
Say if i added code into a file using notepad then compiled it would it work or do i need ms visual 5, I have 4.0 but i get this error all the time:

Microsoft eMbedded Visual c++ has discovered no CE platform SDK on your dektop.
 
New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
If you have coding questions, please ask them in a different thread... And it might be good to actually read the posts in this thread first :|
 
Member
✔️ HL Verified
🚂 Steam Linked
Discord Member
Joined
Nov 23, 2003
Messages
134
Best answers
0
Well, i used C++ for dummies to get started =p and it has worked quiet well, also there is C++ Programming for the absolute beginer, which also has taught me quiet a bit...until i forgot =x
 
New Member
Joined
Mar 31, 2004
Messages
10
Best answers
0
well i tried some other programs before i tried C++
I really havent coded in C++ but you should at least know the basics that there are

Varibles
Functions
Arrays

I hope this helps you (it might be helpful for someone to post a list of functions
 
New Member
Joined
Apr 27, 2004
Messages
10
Best answers
0
If you want a better understanding of what variables are, i'll go ahead and tell you here... since i have yet to see a C++ tutorial or book explain it in much detail.

The first time i picked up C++, i blindly accepted that the 'int' keyword would let me make an integer and that a 'float' or 'double' would let me make a floating point variable but i was completely oblivious to how they worked or anything else. As you come into contact with corporate level code such as game engines or code written for distribution, you will notice they dont use simple things like:

int a = 1;
for( ; a<100; ++a )
cout << "HELLO #" << a;

but instead more or less something that may look like:

BYTE dwVal = 1;
for( ; dwVal < (BYTE)100; ++dwVal ) //typecase BYTE to prevent signed/unsigned mismatch
cout << "HELLO #" << (DWORD)dwVal; //typecase DWORD to prevent output of character value of BYTE

As an inexperienced coder you may see that as foreign code and not understand it but hopefully the comments will help explain the reason for using the typecasts. If you aren't sure why i typcasted those values, if you're using MSVC, remove the typcasts and see what happens. Neither will generate an error. The first line produces no unwanted results, instead it will give you a signed/unsigned mismatch ( i'll explain this later ). The cout... line, when the typecast is removed, will produce no warning or error but something far worse, a run-time glitch. It will display "HELLO #A" when the value of dwVal is 65. One obvious giveaway if you understand how ascii values work, is that the value 65 is 'A' in ascii.

Now onto teaching you variables (Assuming you have used them before =\).

First, the integer, which most likely was the very first variable you used in programming. The integer, depending on the compiler, is generally a 4byte peice of memory. A byte is simply the smallest peice of memory accessable without using boolean algebra or binary mathematics. It consists of 8 bits and when unsigned has range from 0-255, and when signed has range from -128-127. Now i'll go ahead and give you a few common variables with condensed information.

int a = 0; //integer, signed ( holds negative or positive value ), 4bytes
unsigned int a = 0; //integer, unsigned, 4bytes
char a = 'b'; //character, signed, 1byte
unsigned char a = 'c'; //character, unsigned, 1byte
float a = 2.1f; //float, signed, 4bytes
unsigned float a = 5.1f; //float, unsigned, 4bytes
double a = 3.184014; //double, signed, 8bytes
unsigned double a = 30.10831; //double, unsigned, 8bytes

Now you might be thinking "Ok, i get all of this but what's this signed and unsigned?"

A signed variable basically means it has a sign.. it can be a '+' or a '-' positive or negative.

Alright, now what's up with their size in memory?

Basically in memory everything is composed of bits, or tiny binary digits commonly known as binary switches, that can hold one of two values, 1 or 0: they can be on or off. Now say you have 2 bits instead of just 1, the posibilities of values would be:
00 - 01 - 10 - 11 or four posibilities. Now for 3:
000 - 001 - 010 - 011 - 100 - 101 - 110 - 111 or eight posibilities. Now for 4:
0000 - 0001 - 0010 - 0011 - 0100 - 0101 - 0110 - 0111 - 1000 - 1001 - 1010 - 1011 - 1100 - 1101 - 1110 - 1111 or sixteen posibilities.

If you notice the pattern, it increases by multiples of two for each bit you add. This is because this is in binary format. Binary meaning 2 this has a base of 2 whereas our standard decimal system has a base of 10. This is the same principal as you learned in kindergarten:

one hundreds places, tens places, ones places..... etc

Each digit you add multiplies the maximum value represented by that number of digits by 10. For binary it is 2. With that said, the maximum value for any UNSIGNED NON IEEE VARIABLE ( IEEE means floating point ) is 2^(x number of bytes). Basically the more bytes, the more values it can represent.

For extended learning if you wanted to know, the reason mainly that integers are 4bytes generally is because of the way that the ia-32 processor architecture manages machine code, or it's closest relative asm.
In asm you have some general purpose registers, 4 of which follow the same pattern, EAX, EBX, ECX, EDX.

EAX is 32bits ( extended ax ). Its lower WORD or lower 2 bytes is known as AX ( accumulator ). AX's HIGHER byte is known as AH and it's LOWER byte is known as AL. Therefore to make it easier on the processor to process values in c++ the standard 32bit, 16bit, and 8bit values are used in integral values.

Ok i get it now, so what was this DWORD and BYTE stuff?

In the ms winuser.h ( i believe ) file they are 'typedef'ed or defined as a type. The syntax of typedef is as follows:
typedef <type> <operator name>

typedef unsigned long DWORD;
typedef unsigned char BYTE;

etc etc.

Well if you guys want to know more just ask :). If you have any questions feel free to email me at [email protected] or come on the ESF's irc channel i should be in there.
 
New Member
Joined
Nov 24, 2001
Messages
692
Best answers
0
Nice tutorial, just a few comments:

just2n said:
int a = 1;
for( ; a<100; ++a )
cout << "HELLO #" << a;
Interesting way to make for loops. Why not place the "int a=1" inside the loop?

Each digit you add multiplies the maximum value represented by that number of digits by 10. For binary it is 2. With that said, the maximum value for any UNSIGNED NON IEEE VARIABLE ( IEEE means floating point ) is 2^(x number of bytes). Basically the more bytes, the more values it can represent.
Actually it's 2^(number of bits)-1. You forgot the 0 :p
And the IEEE meaning floating point is bull**** (www.ieee.org). Just say unsigned decimal value or something.



As for a completely different thing, I just got the eclipse development enviroment www.eclipse.org. It's an awesome environment for Java, almost on par with Visual Studio .Net. It is also supposed to be usable for C/C++.
 
New Member
Joined
Sep 22, 2004
Messages
185
Best answers
0
Instead of just jumping into coding a HL MOD after learning some C++/C programming, I would suggest the (attempted) coding of a MUD. MUDs are great for newbie coders, for obvious reasons...
-No graphics yet. Allows you to worry about less variables at first.
-No bounding boxes, etc. MUDs are simplistic, because they're text.
-A lot more support. You can find more help for coding a MUD, then for coding a MOD, because, a lot of people like to start with MUDs.
-It's better to learn how to program, using ANSI standards, and learning other standards afterwards.

Using C (typically), to learn to program MUDs gives you, not only the knowledge you need, but the scope. By reading through clear, concisely commented algorythms, you learn the use of libraries created by others. And because it's all text, it's a lot easier to learn (and yes, it's also easier to go from text-only to 3d-enabled graphics later, then to start with 3d-enabled graphics).

And what do you need to program a MUD? you'll need either a Unix/Linux server available (which can cost money), or you can program using the tool I use: CYGWIN.

http://www.cygwin.com/

Cygwin is a Linux emulator, that will compile your Unix-based MUD code... Assuming you use Unix-based code... I'd reccomend it. Then, you'll need a codebase... Lo and behold...

http://www.mudmagic.com/

Now you have your codebase to modify (yes, a MOD of a text game, not a game from scratch -- that's too complicated if you're indeed a newbie). I would suggest downloading the code for either Godwars, Smaug, or ROM. My own personal favorite is SWR, though.

So let's say, you download Cygwin, and then you download a MUD, and it gives you an error when you try to make, saying "Unable to find source file dir.h", this is fixed, go through each of the *.c files, and either comment out #include <sys \dir.h="">sys\dir.h, or delete #include <sys \dir.h="">sys\dir.h. I would suggest unzipping with WinRAR, so all the directories stay intact. After that, I'm sure you can figure things out. (By the way, edit the source files with notepad, notepad2, or editpad, depending on if you have one of the second two.)

So, you don't know how to access things? Try:

cd c:

That will put you in the HDD, now, let's assume, you unzipped to C: \MUD, to get there, you would type:

cd c:
cd MUD


Not sure where to go from there? Use the DIR command. Look for the directories... For SWR, to get to the source files, you would type in from the beginning of the BASH:

cd c:
cd swr
cd dist
cd src

To compile the code, you would type MAKE. If you want (you should) to learn the Linux commands, to assist you, http://www.ss64.com/bash/ will help.

This sounds complicated, though, it is NOT after you figure things out. Now, if you try to say copy the code and it tells you the "mount device is busy," then you'll want to type in PS, and look for the number next to the location of your executable, and from there, you type kill (number of instance).

If you're familiar with DOS, it will be very easy for you to figure things out. Getting around the system using Cygwin is complicated at first, but, if you can figure things out, and you get around to writing code into the game then good for you. Don't forget to make backups of the game source code, otherwise, you could end up having to start all over from scratch, when you edit a few hundred lines, and can't figure out WHICH line(s) are causing what problems.

Now, if you don't have the patience to figure out how to code a MUD, then, perhaps you shouldn't be thinking about coding an HL MOD. Why? Because they both use the same language-basis, and they're both time consuming. Rome wasn't built in a day, and your skills at programming won't be either. However, there's a lot more comments in MUD code to show you what the code is doing...

Think whatever you want of this post, ignore it, but, it's a good way to start out in the world of game development... And the more games you have on your resume (assuming you're going to be a gamedev), the better your resume looks... Especially if you can give them a CD copy of your source code from an old game(s) you learned program to develop with.

-------------------------------------------------------------Addition
It totally slipped my mind, but, if you *DO* get it to compile, and it compiles to the full, and you manage to copy the executable to the area directory, then to run it you would type:

if godwars/merc
./merc.exe &

if smaug
./smaug.exe &

if swreality
./swreality.exe &

I dunno about ROM... I don't like ROM anyway.

To connect to the NOW RUNNING executable MUD, you would go to:

Start -> Run -> Type in "telnet localhost 4000"
</sys></sys>-------------------------------------------------------------End

-------------------------------------------------------------Addition

I thought about it some more, and if you'd like to get into OOP (Object-Oriented Programming), and you'd like to do so with a less complicated language, there is a language that is SOMETHING like VB or C++, called "Dream Maker" or DM for short.

http://www.byond.com/ -- Byond comes with a client and a creation utility, so you can browse other BYOND games, and you can also make BYOND games. BYOND is 2d SNES style, and it's rather easy to develop even with graphics, because the interface is Drag & Drop, instead of you having to write graphics code.



You could also look in Java or PHP/CGI, but, I don't know too much about those...
-------------------------------------------------------------End

Take note, these are *ALL* just suggestions to help you grasp concepts of programming. If you feel you're ready and up to the challenge, go for the Half-Life MOD, and modify the heck out of the code... But while you're at it... Try to MOD something that isn't being modded by 10 other MODs...
 
New Member
Joined
Jul 4, 2004
Messages
35
Best answers
0
help me plz

ok i want to learn about c++ i havent done anything with programming before and wondered if someone could give me a link to microsoft visual c++ because i cant find where to download it
 
Lost in space
Banned
Joined
Oct 21, 2003
Messages
814
Best answers
0
krobelus said:
ok i want to learn about c++ i havent done anything with programming before and wondered if someone could give me a link to microsoft visual c++ because i cant find where to download it
You can't legally download it, and you should have made a new topic to ask instead of replying to this thread.

Search google.com for free C++ compilers if you're REALLY interested though.
 

Users who are viewing this thread

Top Bottom