Raised This Month: $ Target: $400
 0% 

Entity Grabbing plugin


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
{PHILMAGROIN}
Senior Member
Join Date: Aug 2007
Location: In the middle of the des
Old 05-10-2010 , 06:51   Entity Grabbing plugin
Reply With Quote #1

I have been grabbing code from blockmaker and
a code snippet from Exo and I put it together and
got it to compile with no warnings or errors but it doesn't work.
any help is appreciated.

PHP Code:
/* Plugin generated by AMXX-Studio */

#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 = -1;
const 
TASK_GRAB 1000;

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];
        
        
//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 
cmdGrab(id)
{
    
//get the entity the player is aiming at and the length
    
new body;
    new 
Float:vGrabbedOrigin[3];
    new 
Float:vOrigin[3];
    new 
Float:vOffset[3];
    
    
gfGrablength[id] = get_user_aiming(idiEntitybody);
    
    
//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)
    {
        
//get origin of the block
        
entity_get_vector(iEntityEV_VEC_originvGrabbedOrigin);
        
        
//calculate offset from grabbed block
        
vOffset[0] = vGrabbedOrigin[0] - vOrigin[0];
        
vOffset[1] = vGrabbedOrigin[1] - vOrigin[1];
        
vOffset[2] = vGrabbedOrigin[2] - vOrigin[2];
        
        
//indicate that entity is being grabbed
        
entity_set_int(iEntityEV_INT_iuser2id);
        
client_print(idprint_chat"test")
    }
    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);
}

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);
    
    
//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:56.


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