AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   auto unstuck Optimize (https://forums.alliedmods.net/showthread.php?t=184425)

vamppa 05-05-2012 07:46

auto unstuck Optimize
 
could someone make this plugin work without the fun module? (only <amxmodx> <amxmisc><fakemeta> )
the "effects" this plugin uses can be removed.
PHP Code:

#include <amxmodx>
#include <fun>
#include <fakemeta>

new stuck[33]

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.8.1.3746","AMXX Dev Team")
    
cvar[0] = register_cvar("amx_autounstuck","1")
    
cvar[1] = register_cvar("amx_autounstuckeffects","0")
    
cvar[2] = register_cvar("amx_autounstuckwait","7")
    
set_task(0.1,"checkstuck",0,"",0,"b")
}

public 
checkstuck() {
    if(
get_pcvar_num(cvar[0]) >= 1) {
        static 
players[32], pnumplayer
        get_players
(playerspnum)
        static 
Float:origin[3]
        static 
Float:mins[3], hull
        
static Float:vec[3]
        static 
o,i
        
for(i=0i<pnumi++){
            
player players[i]
            if (
is_user_connected(player) && is_user_alive(player)) {
                
pev(playerpev_originorigin)
                
hull pev(playerpev_flags) & FL_DUCKING HULL_HEAD HULL_HUMAN
                
if (!is_hull_vacant(originhull,player) && !get_user_noclip(player) && !(pev(player,pev_solid) & SOLID_NOT)) {
                    ++
stuck[player]
                    if(
stuck[player] >= get_pcvar_num(cvar[2])) {
                        
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)
                                
effects(player)
                                
set_pev(player,pev_velocity,{0.0,0.0,0.0})
                                
sizeof size
                            
}
                        }
                    }
                }
                else
                {
                    
stuck[player] = 0
                
}
            }
        }
    }
}

stock 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
}

public 
effects(id) {
    if(
get_pcvar_num(cvar[1])) {
        
set_hudmessage(255,150,50, -1.00.6506.01.5,0.1,0.7// HUDMESSAGE
        
show_hudmessage(id,"You should be unstucked now!"// HUDMESSAGE
        
message_begin(MSG_ONE_UNRELIABLE,105,{0,0,0},id )      
        
write_short(1<<10)   // fade lasts this long duration
        
write_short(1<<10)   // fade lasts this long hold time
        
write_short(1<<1)   // fade type (in / out)
        
write_byte(20)            // fade red
        
write_byte(255)    // fade green
        
write_byte(255)        // fade blue
        
write_byte(255)    // fade alpha
        
message_end()
        
client_cmd(id,"spk fvox/blip.wav")
    }



Apollyon 05-05-2012 16:40

Re: auto unstuck Optimize
 
1 Attachment(s)
Here ya go. I've been using it this way on my servers.

vamppa 05-06-2012 16:42

Re: auto unstuck Optimize
 
thanks a lot!
is anyone up to optimize it even further by replacing set_task with a get_gametime method ?

yokomo 05-07-2012 00:25

Re: auto unstuck Optimize
 
1 Attachment(s)
Quote:

Originally Posted by vamppa (Post 1703738)
thanks a lot!
is anyone up to optimize it even further by replacing set_task with a get_gametime method ?

Here a patched version of Original Unstuck by Romono and using pev_nextthink method based on Hawk522 tutorial.

vamppa 05-07-2012 11:51

Re: auto unstuck Optimize
 
Quote:

Originally Posted by Apollyon (Post 1702830)
Here ya go. I've been using it this way on my servers.

Error on compiling "undefined symbol get_user_noclip"
think it is a fun module function, ive removed it.
anything else that im overlooking?


Quote:

Originally Posted by yokomo (Post 1703956)
Here a patched version of Original Unstuck by Romono and using pev_nextthink method based on Hawk522 tutorial.

awesome.
compiles fine till LAN game start up. (I use LAN for testing since recently)
I get this error.
http://i46.tinypic.com/2hmkem8.jpg

yokomo 05-07-2012 13:57

Re: auto unstuck Optimize
 
Quote:

Originally Posted by vamppa (Post 1704260)
Error on compiling "undefined symbol get_user_noclip"
think it is a fun module function, ive removed it.
anything else that im overlooking?



awesome.
compiles fine till LAN game start up. (I use LAN for testing since recently)
I get this error.
http://i46.tinypic.com/2hmkem8.jpg

This problem happen when messsage are sending too fast, please increase delay time. I use 0.5 with no problem. Also please redownload the new code, i've change a bit. http://forums.alliedmods.net/showpos...56&postcount=4

vamppa 05-08-2012 09:48

Re: auto unstuck Optimize
 
redownloaded, recompiled
I get the same error, does running it on a LAN game have anything to do with it?

vamppa 05-08-2012 10:10

Re: auto unstuck Optimize
 
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 :_)

yokomo 05-08-2012 10:56

Re: auto unstuck Optimize
 
PHP Code:

if(is_user_alive(player)) 

that's mean it only work for alive player. "is_user_alive" already check "is_user_connected".
Then i don't know what the problem cause your server lag.

SpeeDeeR 05-08-2012 12:11

Re: auto unstuck Optimize
 
@vamppa, it`s better to register the entity`s think rather then just the think forward.


All times are GMT -4. The time now is 07:20.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.