AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Wallhang/walljump (https://forums.alliedmods.net/showthread.php?t=210868)

bloody806 03-15-2013 14:40

Wallhang/walljump
 
I did it this way from tut.. and show error Please Help me.

Error: Array sizes do not match, or destination array is too small on line 71

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "xxx"

new crawlspeed;


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

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
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);  
    
}

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

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(crawlspeed);

    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//<----HERE IS ERROR
            
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]);
            }
        }
    }



YamiKaitou 03-15-2013 14:45

Re: Wallhang/walljump
 
PHP Code:

/* Gets distance between two origins (float). */
native Float:get_distance_f(const Float:Origin1[3], const Float:Origin2[3]); 

You are using get_distance_f incorrectly, look at the header above again

XAT 03-15-2013 15:46

Re: Wallhang/walljump
 
PHP Code:

new Float:g_flWallOrigin[33]; 

->

PHP Code:

new Float:g_flWallOrigin[33][3]; 


bloody806 03-15-2013 18:24

Re: Wallhang/walljump
 
Thank you.

ConnorMcLeod 03-16-2013 04:08

Re: Wallhang/walljump
 
I can't understand why you use switch statements with only 1 or 2 cases, just use <if>, and <if> <else> (not <else if> because your value is only 0 or 1).

Also, you may have better results using PostThink rather than PreThink.


All times are GMT -4. The time now is 21:39.

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