I need to check if player stuck after use 10s NoClip mode and was looking for answer at question: how to check it? I found code of RTD, but in source was checked by run timer,force move and compare last with current origin...too complicated for me.
So started to seach other way and I think found it.
When player can`t move, stuck by other entity his flTimeStepSound go to 0. We have to little delay check function to give time for engine. There is one more situation, which flTimeStepSound is 0 - falling down, so we should check Z axis of velocity too.
Tested with silent footsteps too.
Fakemeta Way
Code:
#include <amxmodx>
#include <fakemeta>
#define PLUGIN "NoClip"
#define VERSION "1.0"
#define AUTHOR "R3X"
#define TASK_NOCLIP 14000
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("+noclip","cmdStartNoClip");
register_clcmd("-noclip","cmdStopNoClip");
}
public cmdStartNoClip(id){
if(is_user_alive(id)){
set_pev(id, pev_movetype, MOVETYPE_NOCLIP);
new tid=id+TASK_NOCLIP;
if(task_exists(tid))
remove_task(tid);
}
return PLUGIN_HANDLED;
}
public cmdStopNoClip(id){
set_pev(id, pev_movetype, MOVETYPE_WALK);
new tid=id+TASK_NOCLIP;
set_task(1.0, "taskStuck",tid);
return PLUGIN_HANDLED;
}
public taskStuck(id){
id -= TASK_NOCLIP;
static velocity[3];
pev(id, pev_velocity, velocity);
if(pev(id, pev_flTimeStepSound) == 0 && velocity[2]==0.0){
new szName[32];
get_user_name(id, szName, 31);
client_print(0, print_chat, "%s stuck, so will die :(", szName);
user_kill(id);
}
}
Engine Way
Code:
#include <amxmodx>
#include <engine>
#define PLUGIN "NoClip"
#define VERSION "1.0"
#define AUTHOR "R3X"
#define TASK_NOCLIP 14000
public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("+noclip","cmdStartNoClip");
register_clcmd("-noclip","cmdStopNoClip");
}
public cmdStartNoClip(id){
if(is_user_alive(id)){
entity_set_int(id, EV_INT_movetype, MOVETYPE_NOCLIP);
new tid=id+TASK_NOCLIP;
if(task_exists(tid))
remove_task(tid);
}
return PLUGIN_HANDLED;
}
public cmdStopNoClip(id){
entity_set_int(id, EV_INT_movetype, MOVETYPE_WALK);
new tid=id+TASK_NOCLIP;
set_task(1.0, "taskStuck",tid);
return PLUGIN_HANDLED;
}
public taskStuck(id){
id -= TASK_NOCLIP;
static velocity[3];
entity_get_vector(id, EV_VEC_velocity, velocity);
if(entity_get_int(id, EV_INT_flTimeStepSound) == 0 && velocity[2]==0.0){
new szName[32];
get_user_name(id, szName, 31);
client_print(0, print_chat, "%s stuck, so will die :(", szName);
user_kill(id);
}
}