AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Entity Grabbing plugin (https://forums.alliedmods.net/showthread.php?t=126512)

{PHILMAGROIN} 05-10-2010 06:51

Entity Grabbing plugin
 
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);



Exolent[jNr] 05-10-2010 17:58

Re: Entity Grabbing plugin
 
PHP Code:

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;


:arrow:
PHP Code:

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);
    
    
//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)
        
client_print(idprint_chat"test")
    }
    return 
PLUGIN_HANDLED;


Also, none of that code is mine lol.

{PHILMAGROIN} 05-10-2010 21:44

Re: Entity Grabbing plugin
 
Quote:

Originally Posted by Exolent[jNr] (Post 1176789)
PHP Code:

code 

Also, none of that code is mine lol.

haha oops. ya it was late last night (or this morning) and i was using some of your code but then deleted it.


Edit: thanks by the way!


All times are GMT -4. The time now is 03:55.

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