So I’ve been working on lag compensation for like the last 5 days.
Since it’s an interesting subject that I know has to be tackled outside of graal too, I’ve put in more of my might.
I want to show my code because damn I’ve spent five days on it, rewriting it like 4 times. (and nobody will see it otherwise).
This is the weapon (the part ran individually by each player):
// NPC made by 2ndwolf
if (playerenters) {
toweapons Dummy Thing;
// this.loop = 10;
timeout = .05;
}
//this is the showani weapon
if ( timeout && isweapon ) {
if(npcs[testnpc(1,1)].save[9] == 0){ //is travelling
this.loop++;
this.waittime++;
if(this.bigsiteration != npcs[testnpc(1,1)].save[4]){
this.waittime = 0;
// this.newloop = this.loop;
// this.lags[this.lagindex%5] = this.newloop - this.oldloop;
this.letlag = 10; //this shouldn't be hardcoded but oh well
// if(this.lagindex<5) this.letlag = 10;
// else this.letlag = (this.lags[0]+this.lags[1]+this.lags[2]+this.lags[3]+this.lags[4])/5;
//this.lagindex++;
this.difference = {(npcs[testnpc(1,1)].save[2]-npcs[testnpc(1,1)].save[0])/this.letlag,(npcs[testnpc(1,1)].save[3]-npcs[testnpc(1,1)].save[1])/this.letlag};
this.bigsiteration = npcs[testnpc(1,1)].save[4];
// this.oldloop = this.newloop;
}
this.dx = npcs[testnpc(1,1)].save[2]-npcs[testnpc(1,1)].save[0]+this.difference[0]*this.waittime;
this.dy = npcs[testnpc(1,1)].save[3]-npcs[testnpc(1,1)].save[1]+this.difference[1]*this.waittime;
this.dist = (this.dx^2 + this.dy^2)^0.5;
this.dir = getdir(this.dx,this.dy);
if(this.dist < 1){
callnpc testnpc(1,1),whatnext,;
this.waittime = 0;
}
else {
this.showanicoords = {npcs[testnpc(1,1)].save[0]+this.difference[0]*this.waittime,npcs[testnpc(1,1)].save[1]+this.difference[1]*this.waittime};
showani 387,this.showanicoords[0],this.showanicoords[1],this.dir,bartender#v(npcs[testnpc(1,1)].save[5])#v(npcs[testnpc(1,1)].save[6]),;//0,;
this.textwidth = textwidth(1,arial,,#s(bartender.words));
showtext 388,this.showanicoords[0]-(this.textwidth/16)/2+1.5,this.showanicoords[1]-1.5,arial,,#s(bartender.words);
showtext 389,this.showanicoords[0]-(this.textwidth/16)/2+1.5+3/16,this.showanicoords[1]+1.5+3/16,arial,bold,#s(bartender.words);
changeimgvis 387,1;
changeimgvis 388,2;
changeimgvis 389,1;
changeimgcolors 389,0,0,0,1;
}
} else { //is idle and waiting
this.showanicoords = { npcs[testnpc(1,1)].save[0] , npcs[testnpc(1,1)].save[1] };
showani 387,this.showanicoords[0],this.showanicoords[1],this.dir,bartender#v(npcs[testnpc(1,1)].save[5])#v(npcs[testnpc(1,1)].save[6]),;
this.textwidth = textwidth(1,arial,,#s(bartender.words));
showtext 388,this.showanicoords[0]-(this.textwidth/16)/2+1.5,this.showanicoords[1]-1.5,arial,,#s(bartender.words);
showtext 389,this.showanicoords[0]-(this.textwidth/16)/2+1.5+3/16,this.showanicoords[1]+1.5+3/16,arial,bold,#s(bartender.words);
changeimgvis 387,1;
changeimgvis 388,2;
changeimgvis 389,1;
changeimgcolors 389,0,0,0,1;
}
timeout = .05;
}
It can also wait and speak! (Haven’t tested the part where he waits, but since he starts by waiting and has no problem, I assume it works (I know I shouldn’t).