I messed a long time with sprinting for my mod using the stuffcommands for the speed like that, but since darkplaces has a new physics QC file you can optionally activate, you can manage this alot easier in some ways.....so thats what I am doing now, but I was ' moderately' successful trying it with the stuff commands llike that. There is a tut here for footsteps sounds that I used as the main foundation, after all, it all ought to synchronize with the sounds in the end.
So in the playerpostthink() I had:
stuffspeed ();
playerfootstep ();
Code: Select all
void () stuffspeed =
{
if (((self.watertype == CONTENT_WATER) || (self.watertype == CONTENT_SLIME)))
{
if ((self.velocity != puff_org))
{
if (((self.waterlevel > FIND_NEAREST) && !(self.items & IT_SUIT)))
{
stuffcmd (self, "-speed\n");
}
else
{
if (((self.waterlevel == FIND_NEAREST) && !(self.items & IT_SUIT)))
{
stuffcmd (self, "cl_forwardspeed 175\n");
stuffcmd (self, "cl_backspeed 175\n");
stuffcmd (self, "cl_sidespeed 150\n");
self.walkvalue = CONTENT_EMPTY;
}
else
{
if ((self.items & IT_SUIT))
{
stuffcmd (self, "cl_forwardspeed 295\n");
stuffcmd (self, "cl_backspeed 295\n");
stuffcmd (self, "cl_sidespeed 270\n");
self.runvalue = CONTENT_EMPTY;
}
}
}
}
}
if (((self.runvalue == CONTENT_EMPTY) || (self.walkvalue == CONTENT_EMPTY)))
{
if (((!self.waterlevel && checkbottom (self)) && (self.velocity != puff_org)))
{
stuffcmd (self, "cl_forwardspeed 200\n");
stuffcmd (self, "cl_backspeed 200\n");
stuffcmd (self, "cl_sidespeed 175\n");
}
}
};
void () playerfootstep =
{
local float amp;
local float s;
if ((self.deadflag || (self.classname != "player")))
{
return;
}
if (!(self.flags & FL_ONGROUND))
{
return;
}
if (((time < self.nextfootstep) || (time < self.attack_finished)))
{
return;
}
if (((!self.waterlevel && checkbottom (self)) && (self.velocity != puff_org)))
{
if ((vlen (self.velocity) < 300))
{
amp = CAM_IDLE;
self.nextfootstep = (time + 0.3);
if (((self.runtime > self.sprint_finished) && (self.walktime == CONTENT_EMPTY)))
{
self.sprint_finished = ((time + (self.runtime - self.sprint_finished)) - FIND_NEAREST);
if (((self.runtime - self.sprint_finished) >= fAutoBotNextThink))
{
self.sprint_finished = fAutoBotNextThink;
stuffcmd (self, "bind shift \"+speed\"\n");
}
}
self.walkvalue = vlen (self.velocity);
if (((vlen (self.velocity) < MSG_UPDATENAME) && (self.velocity != puff_org)))
{
if ((vlen (self.velocity) < CAM_FOLLOW))
{
self.nextfootstep = (time + 0.6);
}
else
{
self.nextfootstep = (time + (vlen (self.velocity) / 9.5));
}
s = CONTENT_EMPTY;
}
}
if ((vlen (self.velocity) > 300))
{
amp = DO_ADD;
if (((self.runvalue == action) && (self.walktime != CONTENT_EMPTY)))
{
self.sprint_finished = (time + fAutoBotNextThink);
self.runtime = (self.sprint_finished + fAutoBotNextThink);
}
self.nextfootstep = (time + 0.15);
self.runvalue = vlen (self.velocity);
updatebreath ();
}
if ((s != CONTENT_EMPTY))
{
s = (random () * DO_ADD);
if ((s < FIND_NEAREST))
{
sound (self, CHAN_BODY, "boot1.wav", LMQUOTA_ARMOR, amp);
}
else
{
if ((s < FIND_FURTHEST))
{
sound (self, CHAN_DEV, "boot2.wav", LMQUOTA_ARMOR, amp);
}
else
{
if ((s < CAM_IDLE))
{
sound (self, CHAN_DEV, "boot3.wav", LMQUOTA_ARMOR, amp);
}
else
{
sound (self, CHAN_DEV, "boot4.wav", LMQUOTA_ARMOR, amp);
}
}
}
}
else
{
sound (self, CHAN_AUTO, "slip.wav", LMQUOTA_ARMOR, amp);
}
}
else
{
if (((!self.waterlevel && checkbottom (self)) && (self.velocity == puff_org)))
{
if ((self.runvalue || self.walkvalue))
{
sound (self, CHAN_AUTO, "breath2f.wav", FIND_NEAREST, ATTN_IDLE);
}
self.walkvalue = action;
self.runvalue = action;
}
}
};
Things like making sure the player is on ground, in or out of water and I decided to give him some extra speed if he has the biosuit and in water, but that got trickier. There was other code that defined the .sprint_time but that was where the problem lied, as I was going to make that change depending on the type of character shosen and if he or she had a rune for example. vlen (self.velocity) is your most key float here
in that its a direct measurement you can look at and see those cl_speed values in realtime.