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

Wallhang / Wallclimb


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 10-10-2012 , 23:08   Wallhang / Wallclimb
Reply With Quote #1

This code allows a player to climb/crawl through walls. Also when the player stop while climbing, he will be stuck to the wall and will not fall.

PHP Code:
//Two global variables. First tells us if the player is above ground and stuck to the wall.
//Second finds the origin of the player when he is near a wall.

new g_bfStuckToWall;
new 
Float:g_flWallOrigin[33];

#define stickPlayer(%1)            g_bfStuckToWall |= (1 << (%1 & 31))
#define unstickPlayer(%1)        g_bfStuckToWall &= ~(1 << (%1 & 31))
#define isStuck(%1)                g_bfStuckToWall & (1 << (%1 & 31)) 
PHP Code:
//Register touch to find if player is touching a wall.
//Register prethink to create wallclimb when conditions are proper.

register_touch("worldspawn","player","Touch_Climb");
register_touch("func_brush","player","Touch_Climb");
register_touch("func_breakable","player","Touch_Climb");
register_forward(FM_PlayerPreThink"Forward_PlayerPreThink"0); 
PHP Code:
public Touch_Climb(Ent,id)
{
    
//If player is touching a wall then we find it's origin

    
pev(id,pev_origin,g_flWallOrigin[id]);
        
    return 
PLUGIN_HANDLED;

PHP Code:
public Forward_PlayerPreThink(id)
{
    
//If player is dead then ignore.
    
    
if(!is_user_alive(id))
        return;
        
    static 
iButton[33], iCrawlSpeed;
    
    
//Get button that player is using as well as the speed he is supposed to move on the wall.
    //I left iCrawlSpeed as a get_pcvar_num so you can register a cvar for that.
    
    
iButton[id] = get_user_button(id);
    
iCrawlSpeed get_pcvar_num(YOU_CVAR);

    if(
iButton[id] & IN_USE)
    {
        
//Here we have three matrices holding the origin of the player, previous origin and velocity.
        
        
static Float:fOrigin[33][3];
        static 
Float:fOriginOld[33][3];
        static 
Float:fVelocity[33][3];
        
        
//Get user origin.
        
        
pev(id,pev_origin,fOrigin[id]);
        
        
//If he is far from the wall then return.
        
        
if(get_distance_f(fOrigin[id],g_flWallOrigin[id]) > 10.0)
            return;
        
        
//If holding iButton and moving forward
        
        
if(iButton[id] & IN_FORWARD)
        {
            
//Check if player is stuck to wall.
            
switch(isStuck(id)){
                
                
//If not them make him move.
                
case 0:{
                    
velocity_by_aim(id,iCrawlSpeed,fVelocity[id]);
                    
set_pev(id,pev_velocity,fVelocity[id]);
                }
                
                
//If yes then unstuck him.
                
default:{
                    
unstickPlayer(id);
                }
            }
        }
        
        
//If holding iButton and moving back
        
        
else if(iButton[id] & IN_BACK)
        {
            switch(
isStuck(id)){
                case 
0:{
                    
velocity_by_aim(id,-iCrawlSpeed,fVelocity[id]);
                    
set_pev(id,pev_velocity,fVelocity[id]);
                }
                            
                default:{
                    
unstickPlayer(id);
                }
            }
        }
        
        else if(
iButton[id])
        {
            
//If Player is holding iButton but not moving, then g_bStuckToWall = true
            //and previous origin will now always be equal to current.
            
            
switch(isStuck(id)){
                case 
0:{
                    
fOriginOld[id] = fOrigin[id];
                    
stickPlayer(id);
                }
            }
            
            
//Set his velocity to zero.
            
velocity_by_aim(id,0,fVelocity[id]);
            
set_pev(id,pev_velocity,fVelocity[id]);
            
            
//if the diference between previous and current origins are small, then set
            //set player's new origin as previous
            
            
if(get_distance_f(fOrigin[id],fOriginOld[id]) <= 10){
                
set_pev(id,pev_origin,fOriginOld[id]);
            }
        }
    }


Last edited by vitorrossi; 11-12-2012 at 14:53.
vitorrossi is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-10-2012 , 23:17   Re: Wallhang / Wallclimb
Reply With Quote #2

What is this? Are you having issues? Does this code work? Why did you post it here?
__________________
fysiks is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 10-11-2012 , 00:17   Re: Wallhang / Wallclimb
Reply With Quote #3

Yeah it works, I struggled with it and finally got it to work, so I thought I'd share!

Last edited by vitorrossi; 10-11-2012 at 00:17.
vitorrossi is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 10-11-2012 , 00:57   Re: Wallhang / Wallclimb
Reply With Quote #4

Quote:
Originally Posted by fysiks View Post
What is this? Why did you post it here?
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 10-11-2012 , 01:15   Re: Wallhang / Wallclimb
Reply With Quote #5

Definition under the Code Snippets/Tutorials Forum:

Quote:
Post tutorials/snippets/includes/stocks of code here that you find useful
If it doesn't belong here just delete it

Last edited by vitorrossi; 10-11-2012 at 01:50.
vitorrossi is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 10-11-2012 , 01:20   Re: Wallhang / Wallclimb
Reply With Quote #6

Normally, when people post stuff here, they post an explanation and/or a tutorial. You just post a snippet with zero details.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
micapat
Veteran Member
Join Date: Feb 2010
Location: Nyuu, nyuu (France).
Old 10-11-2012 , 01:44   Re: Wallhang / Wallclimb
Reply With Quote #7

"For some reason if you make these as "new" and also not an array, the player starts falling".

LOL.

Furthermore register_touch would be better.
__________________
micapat is offline
vitorrossi
Senior Member
Join Date: Apr 2012
Location: NY, USA
Old 10-11-2012 , 01:53   Re: Wallhang / Wallclimb
Reply With Quote #8

Quote:
Originally Posted by micapat View Post
"For some reason if you make these as "new" and also not an array, the player starts falling".

LOL.
Yeah I'm new lol so somethings are still a mistery to me. Anyway, I will upload a better explanation

Edit: I added some explanation to my steps. If this still doesn't belong here then sorry I posted. Was just trying to share things I've learned

Last edited by vitorrossi; 10-11-2012 at 02:09.
vitorrossi is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 10-11-2012 , 03:08   Re: Wallhang / Wallclimb
Reply With Quote #9

I meant an explanation about what the snippet as a whole does and/or tries to accomplish
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 10-11-2012 , 09:29   Re: Wallhang / Wallclimb
Reply With Quote #10

I'd also suggest using a bitsum instead of a bool array.
As such....
Code:
new bool:g_bStuckToWall[33];

PHP Code:
new g_bStuckToWall;
#define stickPlayer(%1)    g_bStuckToWall |= (1 << (%1 & 31));
#define unstickPlayer(%1)    g_bStuckToWall &= ~(1 << (%1 & 31));
#define isStuck(%1)        g_bStuckToWall & (1 << (%1 & 31)); 
This will be much faster and more efficient. As well as at the end of the round (to unstick people) you can simply g_bStuckToWall = 0 rather than looping through the array and setting all to false.

If you'd like more information about bitsums read THIS tutorial by Bugsy.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Reply



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 21:00.


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