Raised This Month: $ Target: $400
 0% 

Moving entities


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
moosewanted
Member
Join Date: May 2009
Old 08-02-2009 , 04:54   Moving entities
Reply With Quote #1

Silly title to be honest, don't really know what to name this thread.

Anyway I stole all this code from blockmaker so that I could just have code that could move entities but when I try to run this ingame it doesn't work(nothing moves). I guess I missed something.

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

#define ENTMOVER_ADMIN_LEVEL ADMIN_USER

new playerViewModel[33][32];
new 
gGrabbed[33];

new 
Float:GrabLength[33];
new 
Float:GrabOffset[33][3];

public 
plugin_init()
{
    
register_clcmd("+entgrab""cmdGrab"ENTMOVER_ADMIN_LEVEL);
    
register_clcmd("-entgrab""cmdRelease"ENTMOVER_ADMIN_LEVEL);
}

public 
client_PreThink(id)
{
    
//make sure player is connected
    
if (is_user_connected(id))
    {
        if (
gGrabbed[id] > 0)
        {
            
//move the entity the player has grabbed
            
moveGrabbedEntity(id);
        }
    }
    return 
PLUGIN_CONTINUE;
}

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] * GrabLength[id] / fLength) + GrabOffset[id][0];
    
vMoveTo[1] = (fOrigin[1] + fDirection[1] * GrabLength[id] / fLength) + GrabOffset[id][1];
    
vMoveTo[2] = (fOrigin[2] + fDirection[2] * GrabLength[id] / fLength) + GrabOffset[id][2];
    
vMoveTo[2] = float(floatround(vMoveTo[2], floatround_floor));

    
//move the block and its sprite (if it has one)
    
moveEntity(idgGrabbed[id], vMoveTo);
}

moveEntity(identFloat:vMoveTo[3])
{
    
//set the position of the block
    
entity_set_origin(entvMoveTo);

    
//get the sprite that sits above the block (if any)
    
new sprite entity_get_int(entEV_INT_iuser3);

    
//if sprite entity is valid
    
if (sprite)
    {
        
//get size of block
        
new Float:vSizeMax[3];
        
entity_get_vector(entEV_VEC_maxsvSizeMax);

        
//move the sprite onto the top of the block
        
vMoveTo[2] += vSizeMax[2] + 0.15;
        
entity_set_origin(spritevMoveTo);
    }
}

public 
cmdGrab(id)
{
    
//make sure player has access to use this command
    
if (get_user_flags(id) & ENTMOVER_ADMIN_LEVEL)
    {
        
//get the entity the player is aiming at and the length
        
new entbody;
        
GrabLength[id] = get_user_aiming(identbody);

        
//get who is currently grabbing the entity (if anyone)
        
new grabber entity_get_int(entEV_INT_iuser2);

        
//if entity is not being grabbed by someone else
        
if (grabber == || grabber == id)
        {
            
//set the ent to 'being grabbed'
            
setGrabbed(ident);
        }
    }    
    return 
PLUGIN_HANDLED;
}

setGrabbed(ident)
{
    new 
Float:fpOrigin[3];
    new 
Float:fbOrigin[3];
    new 
Float:fAiming[3];
    new 
iAiming[3];
    new 
bOrigin[3];
    
    
//get players current view model then clear it
    
entity_get_string(idEV_SZ_viewmodelplayerViewModel[id], 32);
    
entity_set_string(idEV_SZ_viewmodel"");
    
    
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(entEV_VEC_originfbOrigin);    //get block position
    
IVecFVec(iAimingfAiming);
    
FVecIVec(fbOriginbOrigin);
    
    
//set gGrabbed
    
gGrabbed[id] = ent;
    
GrabOffset[id][0] = fbOrigin[0] - iAiming[0];
    
GrabOffset[id][1] = fbOrigin[1] - iAiming[1];
    
GrabOffset[id][2] = fbOrigin[2] - iAiming[2];
    
    
//indicate that entity is being grabbed
    
entity_set_int(entEV_INT_iuser2id);
}

public 
cmdRelease(id)
{
    
//make sure player has access to use this command
    
if (get_user_flags(id) & ENTMOVER_ADMIN_LEVEL)
    {
        
//if player is grabbing an entity
        
if (gGrabbed[id])
        {
            
//indicate that the block is no longer being grabbed
            
entity_set_int(gGrabbed[id], EV_INT_iuser20);

            
//set the players view model back to what it was
            
entity_set_string(idEV_SZ_viewmodelplayerViewModel[id]);

            
//indicate that player is not grabbing an object
            
gGrabbed[id] = 0;
        }
    }
    return 
PLUGIN_HANDLED;

moosewanted is offline
SnoW
Veteran Member
Join Date: Oct 2008
Location: Finland WisdomNuggets: 8
Old 08-02-2009 , 05:06   Re: Moving entities
Reply With Quote #2

The question is what you want. There already exists plugins that can "move entities", such as jedi grab. But do you want to do something else than use ready plugin?
SnoW is offline
Send a message via MSN to SnoW
moosewanted
Member
Join Date: May 2009
Old 08-02-2009 , 05:16   Re: Moving entities
Reply With Quote #3

I just wish to know what is wrong with the code to be honest. Parts of the code are useful for other plugins I have in mind but at the moment I just want to get this working.
moosewanted 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 18:20.


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