I'm trying to solve a well known bug, when surfing with high fps sometimes you get stuck, I wrote a plugin that kind of moves you back a frame everytime you get stuck, it worked well on singleplayer server, but on a dedicated server it lagged a lot, so I though that maybe the plugin was not efficent enough so I tried to write a module, but I ran into the same problem:
video ( first half of the video is without the module and the rest with).
This is the module code :
PHP Code:
vec3_t lastVel[33];
vec3_t lastOrg[33];
bool is_vector_zero(struct vec3_t v){
return v[0] == 0.0 && v[1] == 0.0;
}
bool IsUserSurfing(struct playermove_s* pMove){
if (!pMove->deadflag)
{
if (pMove->onground)
{
vec3_t end;
pmtrace_t trace;
for (int i = 0; i < 3; i++)
{
float flScale = pMove->frametime * pMove->velocity[i];
end[i] = pMove->origin[i] + flScale;
}
trace = pMove->PM_PlayerTrace(pMove->origin, end, PM_NORMAL, -1);
vec3_t plane = trace.plane.normal;
if (plane[2] != 0.0 && plane[2] != 1.0) {
return 1;
}
}
}
return 0;
}
void PM_Move(struct playermove_s *pMove, qboolean server) {
if (IsUserSurfing(pMove)) {
int player = pMove->player_index;
vec3_t vel = pMove->velocity;
vec3_t org = pMove->origin;
if (!is_vector_zero(pMove->velocity)) {
lastVel[player] = vel;
lastOrg[player] = org;
}
else if (!is_vector_zero(lastVel[player])) {
pMove->velocity = lastVel[player];
lastOrg[player][2] += 0.1;
pMove->origin = lastOrg[player];
}
}
}
I hooked PM_Move and checked when the player gets stuck while surfing and setted his previous velocity and moved him 0.1 units upwards to unstuck him.
As I said it worked very well on a singleplayer server but when used on a dedicated one it lagged, like everytime you got stucked you will notice, it drags you forward, I think that maybe the player's ping may be causing this.
I was wondering if I can modify directly the movement code, like *supercede* the original code with mine?
I'm kind of new to writing modules, started 2-3 days ago to learn.
Is the movement code for players running on client side, is it something that I can do to modify it more efficiently?
Or correct it in some way, like in PM_Move_Post?