|
from: http://planethalflife.com/fixxxer/hl_first.htm
So, you want to customise half-life to suit your own needs? Well, you can start by downloading the source code. Go to Wavelength and get it at once!
--------------------------------------------------------------------------------
NOTICE:All the tutorials found on this page are designed to be written and compiled using MS Visual C++ 5 or greater. The learning edition is available at around £40 for students and £70 otherwise. I would recommend you get hold of a copy if you want to edit half-life since Valve's project files were done using Visual C++.
--------------------------------------------------------------------------------
Your First MOD
Now that you've successfully learnt the C and C++ langauges it is now time to dive in and have a go at actually modifying something. You can start by downloading the Half-Life souce code from Wavelength. Done that? Good. Now, let's start by organising your directories:
Now open the project 'mp' in the 'dlls' directory using MS VC++.
Goto project settings and scroll across to the custom build tab.
Change the description to 'Copying to myfirstmoddlls'
Change the first build command to "copy $(TargetPath) C:halflifemyfirstmoddlls" and the first output file to "C:halflifemyfirstmoddlls$(TargetName)" where C:halflife is your Half-Life directory.
Now open the project 'cl_dll' in the 'cl_dll' directory using MS VC++.
Goto project settings and scroll across to the custom build tab.
Change the description to 'Copying to myfirstmodcl_dlls'
Change the first build command to "copy $(TargetPath) C:halflifemyfirstmodcl_dlls" and the first output file to "C:halflifemyfirstmodcl_dlls$(TargetName)" where C:halflife is your Half-Life directory.
Finally create the folders 'dlls' and 'cl_dlls' under your 'myfirstmod' directory.
So what good did all that do?
Well, I've set out your directory structure for you, If you would prefer a different structure then feel free to change it, but note that you need a directory under half-life which contains the dlls and cl_dlls directories and that MS VC++ needs to copy or create the dlls in these directories. Using my directory structure you can keep all of your source code in the 'MFM Sources' directory (you will probably need to keep source for each MOD you make in a different directory). We have also set-up a folder under half-life which will contain your final output files (the ones you distribute) called 'MyFirstMod' and changed the default compile commands so that they copy the DLLs to these directories once the build is complete.
But how does half-life know to use my mod?
It doesn't, thats the next thing we do.
Open up notepad and enter the following text
// My First Mod Game .dll Listing File
game "My First Mod" // Game title
url_info "www.contaminated.net" // information URL
url_dl "www.contaminated.net" // Download URL
version "0.01" // version of mod
size "1" // size of mod (in bytes)
svonly "0" // server side only mod? (1=yes 0=no)
cldll "1" // client side dll? (1=yes 0=no)
hlversion "1009" // version of halflife
type "multiplayer_only" // type of mod
nomodels "1" // game selects player model (1=yes 0=no)
mpentity "info_player_deathmatch" // name of multiplayer spawn entity
gamedll "dllsmp.dll" // file and location of dll
Save this as liblist.gam in your 'myfirstmod' directory
All this file does is provide half-life with some useful information on your game. It contains the title, URL's for information and downloading (so that when it's released on the internet people can decide if they want it), the version, the size of the download, if the MOD is server side (IE clients do not need to download any additional graphics or the client DLL), if the mod contains a client side DLL (our one will), the version of Half-Life required, the type of mod (multiplayer_only is a special value that disables the single player game code. You could have any string you want here), if the game should allow the player to choose their models and finally the location of the game dll relative to the directory liblist.gam is in.
NOTE: The following code illustrates the additional information used for Single Player Mods:
// The starting map for a single player game
startmap "c0a0"
// The starting map for the hazard course in single player
trainingmap "t0a0"
What do I do now?
First we check that it is working, open up the game dll source project (project 'mp' in the 'dlls' directory) and hit the build button. Now use explorer or something to check that mp.dll got copyed to the dlls directory under your halflife/myfirstmod/ directory. If it didn't check that your paths for the copy command are correct (project settings -> custom build tab ). Now open the client dll source project (project 'cl_dll' in the 'cl_dlls' directory) and hit the build button. Again, use explorer or something to check that client.dll got copyed to the halflife/myfirstmod/cl_dlls/ directory. Exit MS VC++ to ensure your settings are saved.
Start up Half-Life and click the 'Custom Game' button, click your MOD and then click the activate button (if 'My First Mod' does not appear on the list check your liblist.gam file). Now go to the main screen, verify that the Single player and hazard course buttons have been disabled, if not check that the DLL's compiled and your liblist.gam file is correct. Click 'multiplayer' then 'LAN game' (Note I don't know what happens if you don't have a LAN set-up, try an internet game!), 'Create Game', 'Okay' (NOTE that no maps are listed, I don't know why). This should bring up the console with an error message along the lines of 'Unknown not found'. Type "map stalkyard" at the console (no quotes) and hit enter. If the game appears to lock up as the console starts to scroll up then you will have to change your build settings for the client DLL as follows:
Open the client dll project, and go to 'project settings'
Now click the 'C/C++' tab and change the category to 'Optimizations'. Go to the 'Inline function expansion' list box and set it to 'Disabled *'
Click okay
Now goto the build menu and select 'rebuild all'
Attempt to start a LAN game again, it should work this time.
Now that you've managed to compile the source code and get it to start a multiplayer game without crashing, let's make a simple modification.
Because my imagination is strained at the moment we are going to change snarks so that they never explode. This means your gonna have to fight your way out like a real man (or woman)! In the source code snarks are often reffered to as squeaks because they, well, squeak.
Start by opening up squeakgrenade.cpp in the game dll project. and find the implementation of the HuntThink function - this does all the thinking for the Snark. At the moment it looks something like this
void CSqueakGrenade::HuntThink( void )
{
// Some stuff here!!!!!!
// explode when ready
if (gpGlobals->time >= m_flDie)
{
g_vecAttackDir = pev->velocity.Normalize( );
pev->health = -1;
Killed( pev, 0 );
return;
}
// more stuff here
// squeek if it's about time blow up
if ((m_flDie - gpGlobals->time <= 0.5) && (m_flDie - gpGlobals->time >= 0.3))
{
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_die1.wav", 1, ATTN_NORM, 0, 100 + RANDOM_LONG(0,0x3F));
CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 256, 0.25 );
}
// higher pitch as squeeker gets closer to detonation time
float flpitch = 155.0 - 60.0 * ((m_flDie - gpGlobals->time) / SQUEEK_DETONATE_DELAY);
if (flpitch < 80)
flpitch = 80;
// even more stuff here!
}
Looking at this code you will see that the if (gpGlobals->time >= m_flDie) section blows the squeak up and the rest handles noises. However, because squeaking is dependant on the snark dieing and we are going to make snarks immortal we need to change this code also. All you have to do is delete the red sections of code below:
void CSqueakGrenade::HuntThink( void )
{
// Some stuff here!!!!!!
// explode when ready
if (gpGlobals->time >= m_flDie)
{
g_vecAttackDir = pev->velocity.Normalize( );
pev->health = -1;
Killed( pev, 0 );
return;
}
// more stuff here
// squeek if it's about time blow up
if ((m_flDie - gpGlobals->time <= 0.5) && (m_flDie - gpGlobals->time >= 0.3))
{
EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, "squeek/sqk_die1.wav", 1, ATTN_NORM, 0, 100 + RANDOM_LONG(0,0x3F));
CSoundEnt::InsertSound ( bits_SOUND_COMBAT, pev->origin, 256, 0.25 );
}
// higher pitch as squeeker gets closer to detonation time
float flpitch = 155.0 - 60.0 * ((m_flDie - gpGlobals->time) / SQUEEK_DETONATE_DELAY);
if (flpitch < 80)
flpitch = 80;
// even more stuff here!
}
With these sections removed the snark timer is removed and they now only detonate when you kill them.
Compile the source code, enable your mod and load up crossfire ("map crossfire" when the error message appears). Pick up 15 snarks (don't throw any), a crossbow and at least 15 crossbow bolts. Go up onto the storage area opposite the bunker and throw some snarks towards the bunker. Now play target practice. If the snarks explode then somethings gone wrong - check that you've done everything correctly, that the MOD is enabled, you are in a multiplayer game (remember, our mod is multiplayer only!) and that the correct version of your DLLs is present in the correct directory under your "Half-Life/myfirstmod" folder. Notice that since we haven't changed anything in the client DLL, we don't have to resompile it!
Note If, when you make your own MOD, you don't need to modify the HUD then you don't need to compile and include the client DLL. |
|