Hello everyone!
A little while ago I started working on a mod for frisbeesky... I am still not done with it though... having a hard time with getting weapons to work xD, but I digress. The main point of the mod was to incorporate better speedometers into the game. I have made them, and they work well so I thought I would post the code I have for them here so if others want to use them they can.
The code is a bit of a mess, but it serves it's purpose.
These functions will return the current velocity measured over the time speedRefreshTime.
Code
- xAxisSpeed() {
- return self GetVelocity()[0];
- }
- yAxisSpeed() {
- return self GetVelocity()[1];
- }
- zAxisSpeed() {
- return self GetVelocity()[2];
- }
- xyPlaneSpeed() {
- if(!isdefined(self.originT0) || !isdefined(self.speedRefreshTime)) return;
- vel = int(sqrt((self.origin[0] - self.originT0[0]) * (self.origin[0] - self.originT0[0])
- + (self.origin[1] - self.originT0[1]) * (self.origin[1] - self.originT0[1])) / self.speedRefreshTime);
- return vel; /*if(self.origin > self.originT0) return vel;
- else return -1 * vel;*/
- }
- xzPlaneSpeed() {
- if(!isdefined(self.originT0) || !isdefined(self.speedRefreshTime)) return;
- vel = int(sqrt((self.origin[0] - self.originT0[0]) * (self.origin[0] - self.originT0[0])
- + (self.origin[2] - self.originT0[2]) * (self.origin[2] - self.originT0[2])) / self.speedRefreshTime);
- return vel; /*if(self.origin > self.originT0) return vel;
- else return -1 * vel;*/
- }
- yzPlaneSpeed() {
- if(!isdefined(self.originT0) || !isdefined(self.speedRefreshTime)) return;
- vel = int(sqrt((self.origin[1] - self.originT0[1]) * (self.origin[1] - self.originT0[1])
- + (self.origin[2] - self.originT0[2]) * (self.origin[2] - self.originT0[2])) / self.speedRefreshTime);
- return vel; /*if(self.origin > self.originT0) return vel;
- else return -1 * vel;*/
- }
- xyzSpeed() {
- if(!isdefined(self.originT0) || !isdefined(self.speedRefreshTime)) return;
- vel = int(sqrt(sqrt(((self.origin[1] - self.originT0[1]) * (self.origin[1] - self.originT0[1]))
- + ((self.origin[2] - self.originT0[2]) * (self.origin[2] - self.originT0[2])))
- + ((self.origin[0] - self.originT0[0]) * (self.origin[0] - self.originT0[0]))) / self.speedRefreshTime);
- return vel; /*if(self.origin > self.originT0) return vel;
- else return -1 * vel;*/
- }
The following code is what drives the timing and what not
Code
- speedometersThink() {//Called From onPlayerSpawned
- self endon("disconnect");
- self endon("death");
- if(!isdefined(self.speedometers)) assertmsg("^3speedometers ^7Init ^1FAILED^7!!!");
- self.speedRefreshTime = 0.1;
- self.originT0 = self.origin;
- for(;;) {
- wait self.speedRefreshTime;
- for(i = 0; i < self.speedometers.size; i++) {//This updates the huds.. which will not be included because that code is very poorly optimized
- self.speedometers[i].hud SetValue(self [[self.speedometers[i].func]]());
- }
- self.originT0 = self.origin;
- }
- }
I hope this helps someone out, or at least is found somewhat interesting