Raised This Month: $12 Target: $400
 3% 

auto unstuck Optimize


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 05-05-2012 , 07:46   auto unstuck Optimize
Reply With Quote #1

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")
    }


Last edited by vamppa; 05-05-2012 at 07:48.
vamppa is offline
Apollyon
SourceMod Donor
Join Date: Dec 2007
Location: California
Old 05-05-2012 , 16:40   Re: auto unstuck Optimize
Reply With Quote #2

Here ya go. I've been using it this way on my servers.
Attached Files
File Type: sma Get Plugin or Get Source (player_unstuck.sma - 180 views - 3.1 KB)
__________________
Apollyon is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 05-06-2012 , 16:42   Re: auto unstuck Optimize
Reply With Quote #3

thanks a lot!
is anyone up to optimize it even further by replacing set_task with a get_gametime method ?
vamppa is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 05-07-2012 , 00:25   Re: auto unstuck Optimize
Reply With Quote #4

Quote:
Originally Posted by vamppa View Post
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.
Attached Files
File Type: sma Get Plugin or Get Source (stuck.sma - 747 views - 3.9 KB)
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019

Last edited by yokomo; 05-07-2012 at 13:55. Reason: Change some code
yokomo is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 05-07-2012 , 11:51   Re: auto unstuck Optimize
Reply With Quote #5

Quote:
Originally Posted by Apollyon View Post
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 View Post
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.
vamppa is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 05-07-2012 , 13:57   Re: auto unstuck Optimize
Reply With Quote #6

Quote:
Originally Posted by vamppa View Post
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.
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
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019
yokomo is offline
vamppa
Senior Member
Join Date: Apr 2010
Location: The Netherlands
Old 05-08-2012 , 09:48   Re: auto unstuck Optimize
Reply With Quote #7

redownloaded, recompiled
I get the same error, does running it on a LAN game have anything to do with it?
vamppa is offline
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
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 05-08-2012 , 10:56   Re: auto unstuck Optimize
Reply With Quote #9

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.
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019
yokomo is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 05-08-2012 , 12:11   Re: auto unstuck Optimize
Reply With Quote #10

@vamppa, it`s better to register the entity`s think rather then just the think forward.
SpeeDeeR is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:26.


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