Celebrating 12 years of Quake!
Adding QuakeWorld VWEPS
Tutorial by XavioR

9/02/08: Added some changes/fixes to the tutorial thanks to Tonik. All new changes are colored in red.

Adding VWEPS to your quakeworld mod is a fairly simple process, and in this tutorial I'll explain the basics. First, you should know that vweps are only visible to clients which support it. These clients include newer versions of ZQuake, Fuhquake XE .34, EZQuake 1.9+, etc. Players connecting on older/non-supporting clients will just see the standard player model in your mod. Also important to note is that only certain servers support VWEPS. Once you have both a server and a client that support the VWEPS extension, you also need to edit your qwprogs.dat to control them. In short: you need both a server and a client that support the vwep extension, and the qwprogs to set them in-game. This tutorial will explain how to implement VWEPS into your qwprogs; adding the VWEP extension to your client and/or server is not covered in the scope of this page.

If you just want to get to the qwprogs code, skip to step 3

1) So lets start. Find a server that supports VWEPs:
MVDSV .28: http://qw-dev.net/projects/list_files/mvdsv
MVDSV XE (.27): http://avirox.amnesiagames.com/Releases/Server/MVDSV%20XE/mvdsv_xe.exe
ZQuake server: http://zquake.frag.ru/eng/download/
There may be other servers supporting this feature as well.

2) Next, choose a client supporting the VWEP extension.
FuhQuake XE .34+: http://avirox.amnesiagames.com/Releases/Client/
EZQuake 1.9+: http://ezquake.sourceforge.net/download/
ZQuake (client): http://zquake.frag.ru/eng/download/
As above, there may be other clients supporting VWEPs that I have not listed here.

3) And now, for the Crème de la Crème: qwprogs implementation

The first file we're going to work with is defs.qc. We need to add the extension that precache's the model files. At the bottom of defs.qc, add the following lines:

#define VWEPS
#ifdef VWEPS
float(string model) precache_vwep_model = #532;
.float vw_index;
#endif


Okay, we've got the extension defined. The precache_vwep_model() function does pretty much what it says, but you have to keep tabs on the index #s that will be assigned to models (I will explain this further down). Now open up World.qc and go to the worldspawn() function. At the top of the function, add the following code:

#ifdef VWEPS
local float vw_available;
#endif

Now all the way at the bottom of worldspawn():

#ifdef VWEPS
vw_available = checkextension("ZQ_VWEP");

if (vw_available) {
// precache our vwep models
precache_vwep_model ("progs/vwplayer.mdl"); // vwep-enabled player model to use
precache_vwep_model ( "progs/w_axe.mdl"); // index #1
precache_vwep_model ( "progs/w_shot.mdl"); // index #2
precache_vwep_model ( "progs/w_shot2.mdl"); // #3
precache_vwep_model ( "progs/w_nail.mdl");
precache_vwep_model ( "progs/w_nail2.mdl");
precache_vwep_model ( "progs/w_rock.mdl");
precache_vwep_model ( "progs/w_rock2.mdl");
precache_vwep_model ( "progs/w_light.mdl"); // #8
precache_vwep_model ( "-"); // #9
}
#endif

This precache's the standard set of Quake weapons. The first thing that must always be precache'd is the VWEPs player model, "progs/vwplayer.mdl", which is given a vwep model index of 0. Every sequential model you precache afterwards is assigned the next number as an index. For example, in this case: w_axe.mdl is index #1, w_nail.mdl is index #4. We will make use out of these numbers in our next section of code.
These weapon models can be downloaded here or in Trickle's VWEP booth.

Everything is now precache'd and indexed to use in your mod. What needs to be done now is to tell the server what vwep, if any, should be set for the player. Each player entity has a .vw_index variable which is sent to the server and then to the clients. The value of the player's .vw_index corresponds to the index # of the precache'd model above. If the player's .vw_index is 3 (with the above order), other players will see that player holding the Super Shotgun. When .vw_index is set to 0, it shows players holding the standard quake weapon instead of a vwep. It should also be noted that if the .vw_index property is set to an index between 1 and 32 that doesn't exist, the standard weapon will also be drawn (using 0 is suggested for this, however). Note that the 9th precache'd vwep with the name "-" with the index value of 9 - when .vw_index is set to this value, the player will be rendered without any weapon (used for death anims)

Open up weapons.qc and scroll down to the W_SetCurrentAmmo function. Right above it, add the following new function:

#ifdef VWEPS
void () VWEPS_SetModel =
{
local float vw_model;

if (self.weaponmodel == "progs/v_axe.mdl")
vw_model = 1;
else
vw_model = 0; // we suppose that there is no vwep..

if (self.invisible_time != 0) { // don't draw VWEPs when player is invisible
self.vw_index = 0;
return;
}

if (self.weaponmodel == "progs/v_shot.mdl")
vw_model = 2;
else if (self.weaponmodel == "progs/v_shot2.mdl")
vw_model = 3;
else if (self.weaponmodel == "progs/v_nail.mdl")
vw_model = 4;
else if (self.weaponmodel == "progs/v_nail2.mdl")
vw_model = 5;
else if (self.weaponmodel == "progs/v_rock.mdl")
vw_model = 6;
else if (self.weaponmodel == "progs/v_rock2.mdl")
vw_model = 7;
else if (self.weaponmodel == "progs/v_light.mdl")
vw_model = 8;

self.vw_index = vw_model;
};
#endif

This is the function that will handle what vwep the player is holding.

Add this code as the last line of W_SetCurrentAmmo:

#ifdef VWEPS
VWEPS_SetModel ();
#endif


Now a rudimentary form of vweps should be working ingame. You can compile your mod and check 'em out if you like, but we have to polish things up a bit before we're done.

We don't want VWEPs appearing when a player is invisible. Open client.qc and go to the CheckPowerups() function. Find the line "self.modelindex = modelindex_eyes;" and add this after it:

#ifdef VWEPS
VWEPS_SetModel ();
#endif


Finally, we need to make sure that the VWEPs disappear when the player is dead. In client.qc, head over to PlayerPostThink and paste the following code in the start of the function:

#ifdef VWEPS
if (self.health <= 0)
self.vw_index = 0;
#endif


And we're done! Now players should see all the original Quake weapons on each other, and they shouldn't be visible when someone is invisible. You can play around with this and really do some interesting things, like adding more weapons and tweaking death sequences (ala MegaTF Coop's vweps). Later perhaps I'll hock up a small advanced VWEP code tutorial, but till then this will get your mod covering the basics. Have fun! =)