I've been working on adding sprinting to my Quake mod for over the course of about a week. (Meaning that I've been working on it off and on, or whenever I stumble back over the code)
It hasn't gone quite how I've planned, but it's going as good as expected I guess.. I added sprinting and it worked, yay. But then I wanted something more so I decided to add a "cool down" kind of thing for the sprinting. (You can only sprint for 4 seconds) it seems like it all should work, but it just doesn't. I've combed through the code for about an hour (which is a long time since there isn't much) and added things, changed things, shorted the function... a lot...
Anyways, I've been avoiding asking for help on here because I want to actually learn something, and you wouldn't believe how much more I've learned on my own then when I was asking everyone else for help, but, I've given in for now. I really need to finish this before this Friday (I have a deadline to meet) and I have some more things that I need to implement/fix as well.. but enough rambling, here's what I have.
Code: Select all
/*
=================
Sprinting
=================
*/
if (self.speed)
{
sprint_time = sprint_time + 1;
cvar_set ("cl_forwardspeed", "95");
if(sprint_time == 4) //four seconds
{
sound (other, CHAN_VOICE, "AMB/breath.wav", 1, ATTN_STATIC);
self.speed = !self.speed;
}
}
else
{
cvar_set ("cl_forwardspeed", "50");
if(sprint_time <= 4 && sprint_time >= 1)
{
sprint_time = sprint_time - 1;
}
if (sprint_time <= -1)
{
sprint_time = 0;
}
if(sprint_time >=5)
{
sprint_time = 4;
}
}
I've done a minor debugging process for it and the problem is that sprint_time is always 0. Yes, zero, No matter what.
PS. I'm pretty sure a switch, case, break thing might work better, but I haven't grasped how to do that yet so yeah, multiple "if" functions for now
PSS. speed (aka, self.speed) is a button. (I have it assigned to left trigger) so when the player holds down the trigger the player sprints, and when he/she lets go, they walk