PDA

View Full Version : Tutorial for basic modding and code changing


ASk
06-02-2002, 04:50 AM
The mod referenced in this tutorial can be found at http://www.darklordofsith.net

file: g_weapon.c
Original, line 1674
//rww - We don't want rockets to be deflected, do we?
missile->clipmask = MASK_SHOT;// | CONTENTS_LIGHTSABER;
missile->splashDamage = ROCKET_SPLASH_DAMAGE;
missile->splashRadius = ROCKET_SPLASH_RADIUS;

// we don't want it to ever bounce
missile->bounceCount = 0;


changed to


//rww - We don't want rockets to be deflected, do we? Well, we do....25% chance :P
if(Q_irand(1, 4)==1) //defines 25% chance
{
missile->clipmask = MASK_SHOT | CONTENTS_LIGHTSABER;
}
else
{
missile->clipmask = MASK_SHOT;
}
missile->splashDamage = ROCKET_SPLASH_DAMAGE;
missile->splashRadius = ROCKET_SPLASH_RADIUS;

// we don't want it to ever bounce...yeah right :P
missile->s.eFlags |= EF_ROCKETBOUNCE; //custom flag for special processing of the bounces (speed down, etc)
missile->bounceCount=5; //bounce count


so here I added a random number, based on which the fired rocket gets the deflectable by saber property.
Also notice that i changed the bounce count

file: g_missile.c
original, line168 - end of if...else code
added

if (ent->s.eFlags & EF_ROCKETBOUNCE)
{
VectorScale( ent->s.pos.trDelta, 0.8, ent->s.pos.trDelta );
ent->damage *= 1.2; //up damage, etc
ent->speed /= 1.2;
ent->splashDamage *=1.05;

// check for stop
if ( trace->plane.normal[2] > 0.2 && VectorLength( ent->s.pos.trDelta ) < 40 )
{
G_SetOrigin( ent, trace->endpos );
return;
}
if (ent->bounceCount==0)
{
G_ExplodeMissile(ent); //explode at the end
return;
}
}


Well...usually the missile disappears...it will explode at the end of bounces

file: g_cmds.c
original, line 2726

else if (Q_stricmp(cmd, "thedestroyer") == 0 && CheatsOk( ent ) && ent && ent->client && ent->client->ps.saberHolstered && ent->client->ps.weapon == WP_SABER)
{
Cmd_ToggleSaber_f(ent);

if (!ent->client->ps.saberHolstered)
{
if (ent->client->ps.dualBlade)
{
ent->client->ps.dualBlade = qfalse;
//ent->client->ps.fd.saberAnimLevel = FORCE_LEVEL_1;
}
else
{
ent->client->ps.dualBlade = qtrue;

trap_SendServerCommand( -1, va("print \"%sTHE DESTROYER COMETH\n\"", S_COLOR_RED) );
G_ScreenShake(vec3_origin, NULL, 10.0f, 800, qtrue);
//ent->client->ps.fd.saberAnimLevel = FORCE_LEVEL_3;
}
}

edited:

else if (Q_stricmp(cmd, "thedestroyer") == 0 && ent && ent->client && ent->client->ps.saberHolstered && ent->client->ps.weapon == WP_SABER)
{
Cmd_ToggleSaber_f(ent);

if (!ent->client->ps.saberHolstered)
{
if (ent->client->ps.dualBlade)
{
ent->client->ps.dualBlade = qfalse;
//ent->client->ps.fd.saberAnimLevel = FORCE_LEVEL_1;
}
else
{
ent->client->ps.dualBlade = qtrue;

trap_SendServerCommand( -1, va("print \"%sTHE DESTROYER COMETH\n\"", S_COLOR_RED) );
G_ScreenShake(vec3_origin, NULL, 10.0f, 800, qtrue);
if(ent->health<3)
{
ent->health=ent->health;
}
else
{
ent->health=0.5*ent->health;
}
}

//ent->client->ps.fd.saberAnimLevel = FORCE_LEVEL_3;

}


if you can see, i added halving the health here and also a check whether the user have little health to not halve it (else you would die from the command)
file: bg_pmove.c
original:

float forceJumpHeight[NUM_FORCE_POWER_LEVELS] =
{
32,//normal jump (+stepheight+crouchdiff = 66)
96,//(+stepheight+crouchdiff = 130)
192,//(+stepheight+crouchdiff = 226)
384//(+stepheight+crouchdiff = 418)
};

float forceJumpStrength[NUM_FORCE_POWER_LEVELS] =
{
JUMP_VELOCITY,//normal jump
420,
590,
840
};


edited the values:

float forceJumpHeight[NUM_FORCE_POWER_LEVELS] =
{
69,//normal jump (+stepheight+crouchdiff = 66)
288,//(+stepheight+crouchdiff = 130)
576,//(+stepheight+crouchdiff = 226)
1152//(+stepheight+crouchdiff = 418)
};

float forceJumpStrength[NUM_FORCE_POWER_LEVELS] =
{
JUMP_VELOCITY,//normal jump
840,
1180,
1680
};

This effectively triples the jump height (note: in the recent version i lowered the values to 1.5 the original Strength and 2 the original Height

Now for the yummy code - how to make disruptor shooting through walls:

file: g_weapon.c
original, line 607:

if ( tr.surfaceFlags & SURF_NOIMPACT )
{
render_impact = qfalse;
}

edited:

if ( tr.entityNum >= ENTITYNUM_MAX_NORMAL ) {
if ( tr.surfaceFlags & SURF_NOIMPACT )
{
render_impact = qfalse;
break;
}

// otherwise continue tracing thru walls
VectorMA (tr.endpos,1,forward,start);

tent = G_TempEntity( tr.endpos, EV_DISRUPTOR_SNIPER_SHOT );
VectorCopy( muzzle, tent->s.origin2 );
tent->s.shouldtarget = fullCharge;
tent->s.eventParm = ent->s.number;
tent = G_TempEntity(tr.endpos, EV_MISSILE_MISS);
tent->s.eventParm = DirToByte(tr.plane.normal);
tent->s.eFlags |= EF_ALT_FIRING;

continue;
}

This code checks whether the entity the trace hit is solid ( tr.entityNum >= ENTITYNUM_MAX_NORMAL ), then checks if it's the skybox. Afterwards, if it's a wall, it renders the shot and the impact mark and goes out of the loop.
Notice the VectorMA (tr.endpos,1,forward,start);
code. This moves the vector of the trace one point forward, putting it behind the wall, so in the next trace it wont stumble again on this same wall :P


Hope this helped.
Post suggestions here or email them at ask@darklordofsith.net

Elijah
06-02-2002, 05:03 AM
*bows* now..... do we need C++?

Vesentac
06-02-2002, 05:05 AM
You forgot to explain what the line paragraph of code means, after all it is the "key" to the whole thing :p

sonictrio
08-09-2002, 03:44 PM
If you want my coding tutorial (only the slow rocket mod but you don't need C++, MSVC and I've added a new and extremely easy way to create PK3's!). E-mail me at rswann@eircom.net:fett: