View Single Post
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 05-08-2012 , 10:10   Re: auto unstuck Optimize
Reply With Quote #8

alright got it working now but it feels "log" slow, heavy gravity, like high CPU usage.
ive increased the delay from 0.5 to 0.7 and I have removed the "effects" from the plugin
new code
PHP Code:
#include <amxmodx>
#include <fakemeta>

new UnstuckClassname[] = "UnstuckEnt"

new MaxPlayers
new cvar[3]

new const 
Float:size[][3] =
{
    {
0.00.01.0}, {0.00.0, -1.0}, {0.01.00.0}, {0.0, -1.00.0}, {1.00.00.0}, {-1.00.00.0}, {-1.01.01.0}, {1.01.01.0}, {1.0, -1.01.0}, {1.01.0, -1.0}, {-1.0, -1.01.0}, {1.0, -1.0, -1.0}, {-1.01.0, -1.0}, {-1.0, -1.0, -1.0},
    {
0.00.02.0}, {0.00.0, -2.0}, {0.02.00.0}, {0.0, -2.00.0}, {2.00.00.0}, {-2.00.00.0}, {-2.02.02.0}, {2.02.02.0}, {2.0, -2.02.0}, {2.02.0, -2.0}, {-2.0, -2.02.0}, {2.0, -2.0, -2.0}, {-2.02.0, -2.0}, {-2.0, -2.0, -2.0},
    {
0.00.03.0}, {0.00.0, -3.0}, {0.03.00.0}, {0.0, -3.00.0}, {3.00.00.0}, {-3.00.00.0}, {-3.03.03.0}, {3.03.03.0}, {3.0, -3.03.0}, {3.03.0, -3.0}, {-3.0, -3.03.0}, {3.0, -3.0, -3.0}, {-3.03.0, -3.0}, {-3.0, -3.0, -3.0},
    {
0.00.04.0}, {0.00.0, -4.0}, {0.04.00.0}, {0.0, -4.00.0}, {4.00.00.0}, {-4.00.00.0}, {-4.04.04.0}, {4.04.04.0}, {4.0, -4.04.0}, {4.04.0, -4.0}, {-4.0, -4.04.0}, {4.0, -4.0, -4.0}, {-4.04.0, -4.0}, {-4.0, -4.0, -4.0},
    {
0.00.05.0}, {0.00.0, -5.0}, {0.05.00.0}, {0.0, -5.00.0}, {5.00.00.0}, {-5.00.00.0}, {-5.05.05.0}, {5.05.05.0}, {5.0, -5.05.0}, {5.05.0, -5.0}, {-5.0, -5.05.0}, {5.0, -5.0, -5.0}, {-5.05.0, -5.0}, {-5.0, -5.0, -5.0}
}

public 
plugin_init()
{
    
register_plugin("Automatic Unstuck","1.5p","NL)Ramon(NL"//Patched by wbyokomo
    
cvar[0] = register_cvar("amx_autounstuck","1")
    
cvar[2] = register_cvar("amx_autounstuckdelay","0.7"//set 0.5 or 1.0 is enough, so less native called.
    
MaxPlayers get_maxplayers()
    new 
ent engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
    
set_pev(ent,pev_classname,UnstuckClassname)
    
set_pev(ent,pev_nextthink,5.0)
    
    
register_forward(FM_Think,"ForwardThink")
}

public 
ForwardThink(ent)
{
    static 
Classname[33]
    
pev(ent,pev_classname,Classname,charsmax(Classname))
    
    if(!
equal(Classname,UnstuckClassname)) return FMRES_IGNORED;
    
    if(
get_pcvar_num(cvar[0])) checkstuck();
    
    
set_pev(ent,pev_nextthink,get_gametime()+get_pcvar_float(cvar[2]))
    
    return 
FMRES_IGNORED
}

checkstuck()
{
    new 
Float:origin[3], Float:mins[3], Float:vec[3], hulloplayer
    
for(player=1player<=MaxPlayersplayer++)
    {
        if(
is_user_alive(player))
        {
            
pev(playerpev_originorigin)
            
hull pev(playerpev_flags) & FL_DUCKING HULL_HEAD HULL_HUMAN
            
if(!is_hull_vacant(originhull,player) && !(pev(player,pev_solid) & SOLID_NOT))
            {
                
pev(playerpev_minsmins)
                
vec[2] = origin[2]
                for(
o=0sizeof size; ++o)
                {
                    
vec[0] = origin[0] - mins[0] * size[o][0]
                    
vec[1] = origin[1] - mins[1] * size[o][1]
                    
vec[2] = origin[2] - mins[2] * size[o][2]
                    if(
is_hull_vacant(vechull,player))
                    {
                        
engfunc(EngFunc_SetOriginplayervec)
                        
set_pev(player,pev_velocity,{0.0,0.0,0.0})
                        
sizeof size
                    
}
                }
            }
        }
    }
}

bool:is_hull_vacant(const Float:origin[3], hull,id)
{
    static 
tr
    engfunc
(EngFunc_TraceHulloriginorigin0hullidtr)
    if(!
get_tr2(trTR_StartSolid) || !get_tr2(trTR_AllSolid)) //get_tr2(tr, TR_InOpen))
        
return true
    
    
return false

I am begining to doubt now whether which method is more CPU/resource friendly, get_gametime method or set_task?
also as far as I know our game does not use !is_user_alive, we are never considered dead.
what would be best to replace that with? !is_user_connected?
if only we had something for recognizing when user is in spectate ">> http://forums.alliedmods.net/showthr...=184299&page=3 "

greetz and thanks for the help so far :_)

Last edited by vamppa; 05-08-2012 at 10:11.
vamppa is offline