Raised This Month: $ Target: $400
 0% 

[Solved] Moving func_wall


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
{PHILMAGROIN}
Senior Member
Join Date: Aug 2007
Location: In the middle of the des
Old 05-16-2010 , 04:18   Re: Moving func_wall
Reply With Quote #9

here is what i just recently put together. I basically used all of necro's Blockmaker "Grab" code and made it how i wanted it.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>

#define PLUGIN "Grab"
#define VERSION "1.0"
#define AUTHOR "{PHILMAGROIN}"

new Float:gfGrabOffset[33][3];
new 
Float:gfGrablength[33];
new 
gGrabbed[33];
new 
iEntity;


public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
register_clcmd("+moveaim""cmdGrab"ADMIN_ADMIN"bind a key to +moveaim");
    
register_clcmd("-moveaim""cmdRelease"ADMIN_ADMIN);
}

public 
client_PreThink(id)
{
    
//if player has grabbed an entity
    
if (gGrabbed[id] > 0)
    {
        new 
Float:vMoveTo[3];
        
        
//get players
        
new buttons get_user_button(id);
        new 
oldbuttons get_user_oldbutton(id);
        
        
//if player has grabbed an entity
        
if (gGrabbed[id] > 0)
        {
            
//check for a single press on the following buttons
            
if (buttons IN_JUMP && !(oldbuttons IN_JUMP)) cmdJump(id);
            if (
buttons IN_DUCK && !(oldbuttons IN_DUCK)) cmdDuck(id);
        
            
//move the block the player has grabbed and get the move vector
            
moveGrabbedEntity(idvMoveTo);
        }
    }
}

public 
EntityModel(const szClassName[ ])
{
    
iEntity find_ent_by_class(iEntityszClassName)
}

public 
cmdJump(id)
{
    
//if the object the player is grabbing isn't too close
    
if (gfGrablength[id] > 72.0)
    {
        
//move the object closer
        
gfGrablength[id] -= 16.0;
    }
}

public 
cmdDuck(id)
{
    
//move the object further away
    
gfGrablength[id] += 16.0;
}

public 
cmdGrab(id)
{
    
//get the entity the player is aiming at and the length
    
new body;
    
    
gfGrablength[id] = get_user_aiming(idiEntitybody);
    
    
//check valid entity
    
if (!is_valid_ent(iEntity))
        return 
PLUGIN_HANDLED;
    
    
//get who is currently grabbing the entity (if anyone)
    
new grabber entity_get_int(iEntityEV_INT_iuser2);
    
    
//if entity is not being grabbed by someone else
    
if (grabber == || grabber == id)
    {
        
setGrabbed(id)
    }
    return 
PLUGIN_HANDLED;
}  

public 
setGrabbed(id)
{
    new 
Float:fpOrigin[3];
    new 
Float:fbOrigin[3];
    new 
Float:fAiming[3];
    new 
iAiming[3];
    new 
bOrigin[3];
    
    
get_user_origin(idbOrigin1);            //position from eyes (weapon aiming)
    
get_user_origin(idiAiming3);            //end position from eyes (hit point for weapon)
    
entity_get_vector(idEV_VEC_originfpOrigin);        //get player position
    
entity_get_vector(iEntityEV_VEC_originfbOrigin);    //get block position
    
IVecFVec(iAimingfAiming);
    
FVecIVec(fbOriginbOrigin);
    
    
//set gGrabbed
    
gGrabbed[id] = iEntity;
    
gfGrabOffset[id][0] = fbOrigin[0] - iAiming[0];
    
gfGrabOffset[id][1] = fbOrigin[1] - iAiming[1];
    
gfGrabOffset[id][2] = fbOrigin[2] - iAiming[2];
    
    
//indicate that entity is being grabbed
    
entity_set_int(iEntityEV_INT_iuser2id);
    
set_rendering(iEntitykRenderFxNone00190kRenderTransColor80
}

public 
cmdRelease(id)
{
    
//if player is grabbing an entity
    
if (gGrabbed[id])
    
    
//indicate that entity is no longer being grabbed
    
entity_set_int(iEntityEV_INT_iuser20);
    
set_rendering(iEntitykRenderFxNone000kRenderNormal0
    
    
//indicate that player is not grabbing an object
    
gGrabbed[id] = 0;
    
    return 
PLUGIN_HANDLED;
}

moveGrabbedEntity(idFloat:vMoveTo[3] = {0.00.00.0})
{
    new 
iOrigin[3], iLook[3];
    new 
Float:fOrigin[3], Float:fLook[3], Float:fDirection[3], Float:fLength;
    
    
get_user_origin(idiOrigin1);        //Position from eyes (weapon aiming)
    
get_user_origin(idiLook3);            //End position from eyes (hit point for weapon)
    
IVecFVec(iOriginfOrigin);
    
IVecFVec(iLookfLook);
    
    
fDirection[0] = fLook[0] - fOrigin[0];
    
fDirection[1] = fLook[1] - fOrigin[1];
    
fDirection[2] = fLook[2] - fOrigin[2];
    
fLength get_distance_f(fLookfOrigin);
    
    if (
fLength == 0.0fLength 1.0;        //avoid division by 0
    
    //calculate the position to move the block
    
vMoveTo[0] = (fOrigin[0] + fDirection[0] * gfGrablength[id] / fLength) + gfGrabOffset[id][0];
    
vMoveTo[1] = (fOrigin[1] + fDirection[1] * gfGrablength[id] / fLength) + gfGrabOffset[id][1];
    
vMoveTo[2] = (fOrigin[2] + fDirection[2] * gfGrablength[id] / fLength) + gfGrabOffset[id][2];
    
vMoveTo[2] = float(floatround(vMoveTo[2], floatround_floor));
    
    
//move the block 
    
entity_set_origin(iEntityvMoveTo);

__________________
[B]
{PHILMAGROIN} is offline
 



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 03:35.


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