AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved] Moving func_wall (https://forums.alliedmods.net/showthread.php?t=126915)

grimvh2 05-15-2010 06:23

[Solved] Moving func_wall
 
Hi again,

M having trouble with moving func_wall's, heres my current code :

PHP Code:

public DoGrab(id)
{
    if(!
UserGrabbing[id])
    {
        new 
EntEntBody
        get_user_aiming
(idEntEntBody)
    
        if(
Ent)
        {
            new 
szClassname[32]
            
pev(Entpev_classnameszClassname31)
    
            if(
equal(szClassname"func_wall"))
            {
                if(!
IsGrabbed[Ent])
                {
                    
IsGrabbed[Ent]++
                    
UserGrabbing[id] = Ent
                    set_rendering
(EntkRenderFxNone25500kRenderTransColor80)
                
                    static 
Float:origin[2][3];
                
                    
pev(idpev_originorigin[0]);
                    
pev(Entpev_originorigin[1]);

                    
GrabDistance[id] = get_distance_f(origin[0], origin[1]);
                }
            }
        }
    }
}

public 
client_PreThink(id)
{
    if(!
is_user_alive(id)) return PLUGIN_CONTINUE;
    
    if(!
UserGrabbing[id]) return PLUGIN_CONTINUE;
    
    new 
buttons pev(idpev_button);
    
    static 
Float:origin[2][3], ilook[3], Float:look[3];
    static 
Float:direction[3], Float:moveto[3], Float:grabbedorigin[3];

    static 
Float:velocity[3], Float:length;

    
get_user_origin(idilook3);
    
IVecFVec(ilooklook);

    
pev(UserGrabbing[id], pev_origingrabbedorigin);

    
pev(idpev_originorigin[0]);
    
pev(UserGrabbing[id], pev_origin,origin[1]);

    
direction[0] = look[0] - origin[0][0];
    
direction[1] = look[1] - origin[0][1];
    
direction[2] = look[2] - origin[0][2];

    
length get_distance_f(lookorigin[0]);

    if(!
length)
        
length 1.0;

    
moveto[0] = origin[0][0] + direction[0] * GrabDistance[id];
    
moveto[1] = origin[0][1] + direction[1] * GrabDistance[id];
    
moveto[2] = origin[0][2] + direction[2] * GrabDistance[id];

    
velocity[0] = (moveto[0] - origin[1][0]) * 8;
    
velocity[1] = (moveto[1] - origin[1][1]) * 8;
    
velocity[2] = (moveto[2] - origin[1][2]) * 8;

    
set_pev(UserGrabbing[id], pev_velocityvelocity);

    if(
buttons IN_ATTACK)
    {
        
set_pev(idpev_buttonbuttons & ~IN_ATTACK);
        
GrabDistance[id] += 7;
    }

    else if(
buttons IN_ATTACK2)
    {
        
set_pev(idpev_buttonbuttons & ~IN_ATTACK2);
        
GrabDistance[id] -= 7;

        if(
GrabDistance[id] < MIN_DIST)
            
GrabDistance[id] = MIN_DIST;
    }
    
    return 
PLUGIN_CONTINUE


The entity gets a color, but doesn't move at all. ( no error logs )
I have tried many ways and looked at many plugins like : entmover, jedi grab, grab plugins but nothing seems to work.

Greetings Grim.

joropito 05-15-2010 09:40

Re: Moving func_wall
 
Are the func_wall brush entities or created by the plugin?

You should use entity_set_origin instead of just modify pev_*

Also it's recommended to just set the entity as "used" at clcmd and then at client_PreThink do the job. That will result in a smooth movement.

I'm smelling bb here?

grimvh2 05-15-2010 09:58

Re: Moving func_wall
 
Quote:

Originally Posted by joropito (Post 1180820)
Are the func_wall brush entities or created by the plugin?

You should use entity_set_origin instead of just modify pev_*

Also it's recommended to just set the entity as "used" at clcmd and then at client_PreThink do the job. That will result in a smooth movement.

I'm smelling bb here?

You smell good. Imma try that.

Edit: Can't seem to get it moving :s

joropito 05-15-2010 10:03

Re: Moving func_wall
 
Quote:

Originally Posted by grimvh2 (Post 1180836)
You smell good. Imma try that.

If they're brush entities, I have the code donde. Just ask me.

EXteRmiNaToR 05-15-2010 11:14

Re: Moving func_wall
 
Quote:

Originally Posted by joropito (Post 1180838)
If they're brush entities, I have the code donde. Just ask me.

Post the code if you can,please.I need this for something i want to do.

joropito 05-15-2010 11:35

Re: Moving func_wall
 
PHP Code:

#include <amxmisc>
#include <engine>

#define PLUGIN_NAME     "JoRoGrab"
#define PLUGIN_AUTHOR   "JoRoPiTo"
#define PLUGIN_VERSION  "0.1"
#define PLUGIN_CVAR     "jorograb"

#define MAX_PLAYERS     32

new g_PlayerGrab[MAX_PLAYERS+1]
new 
Float:g_PlayerGrabLen[MAX_PLAYERS+1]
new 
Float:g_PlayerGrabLook[MAX_PLAYERS+1][3]
new 
Float:g_PlayerGrabMins[MAX_PLAYERS+1][3]
new 
Float:g_PlayerGrabMaxs[MAX_PLAYERS+1][3]
new 
g_MaxClients

public plugin_init()
{
        
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_AUTHOR)
        
register_cvar(PLUGIN_CVARPLUGIN_VERSIONFCVAR_SERVER|FCVAR_SPONLY)

        
register_clcmd("+grab""grab_hold")
        
register_clcmd("-grab""grab_release")

        
g_MaxClients get_global_int(GL_maxClients)
}

public 
client_putinserver(id)
{
        
g_PlayerGrab[id] = 0

}

////////////////////////////////////////////////////////////////////

public grab_release(idlevelcid)
{
        if(!
cmd_access(idlevelcid1))
                return 
PLUGIN_HANDLED

        g_PlayerGrab
[id] = 0
        
return PLUGIN_HANDLED
}

public 
grab_hold(idlevelcid)
{
        if(!
cmd_access(idlevelcid1))
                return 
PLUGIN_HANDLED

        
static entbody
        
static Float:vorigin[3], Float:end[3], Float:mins[3]
        
get_user_aiming(identbody)
        if(
_is_block(ent) && !_is_grabbed(ent))
        {
                
entity_get_vector(idEV_VEC_originvorigin)
                
entity_get_vector(entEV_VEC_absminmins)
                
entity_get_vector(entEV_VEC_absmaxend)
                
vector_sum(endmins)
                
vector_mul(end0.5)
                
entity_get_vector(entEV_VEC_sizeg_PlayerGrabMins[id])
                
entity_get_vector(entEV_VEC_sizeg_PlayerGrabMaxs[id])
                
vector_mul(g_PlayerGrabMins[id], -0.5)
                
vector_mul(g_PlayerGrabMaxs[id], 0.5)

                new 
Float:len get_distance_f(voriginend)
                
g_PlayerGrab[id] = ent
                g_PlayerGrabLen
[id] = len
        
}
        return 
PLUGIN_HANDLED
}

stock _is_grabbed(ent)
{
        for(new 
1<= g_MaxClientsi++)
        {
                if(
g_PlayerGrab[i] == ent)
                        return 
true
        
}
        return 
false
}

stock _is_block(ent)
{
        if(
is_valid_ent(ent) && (ent >= MAX_PLAYERS))
                return 
true

        
return false
}

public 
client_PreThink(id)
{
        if(
g_PlayerGrab[id])
        {
                new 
iorigin[3], ilook[3]
                new 
Float:vdest[3], Float:vorigin[3], Float:vlook[3], Float:vdir[3], Float:vlen
                
new buttons
                get_user_origin
(idiorigin1)
                
get_user_origin(idilook3)
                
buttons entity_get_int(idEV_INT_button)
                
IVecFVec(ioriginvorigin)
                
IVecFVec(ilookvlook)
                if(!
vector_compare(vlookg_PlayerGrabLook[id]) || (buttons & (IN_ATTACK|IN_ATTACK2)))
                {
                        
g_PlayerGrabLook[id] = vlook
                        vdir 
vlook
                        vector_substract
(vdirvorigin)
                        
vlen get_distance_f(vlookvorigin)

                        if(
vlen == 0.0vlen 1.0

                        
if(buttons IN_ATTACK)
                                
g_PlayerGrabLen[id] -= 0.5
                        
else if(buttons IN_ATTACK2)
                                
g_PlayerGrabLen[id] += 0.5

                        vdest
[0] = (vorigin[0] + vdir[0] * g_PlayerGrabLen[id] / vlen)
                        
vdest[1] = (vorigin[1] + vdir[1] * g_PlayerGrabLen[id] / vlen)
                        
vdest[2] = (vorigin[2] + vdir[2] * g_PlayerGrabLen[id] / vlen)
                        
vdest[2] = float(floatround(vdest[2], floatround_floor))

                        
set_brush_origin(g_PlayerGrab[id], vdest)
                }
        }
}

stock vector_substract(Float:vecDst[], const Float:vecSrc[])
{
        
vecDst[0] -= vecSrc[0]
        
vecDst[1] -= vecSrc[1]
        
vecDst[2] -= vecSrc[2]
}

stock vector_compare(const Float:vecA[], const Float:vecB[])
{
        if((
vecA[0] == vecB[0]) && (vecA[1] == vecB[1]) && (vecA[2] == vecB[2]))
                return 
true

        
return false
}

stock vector_mul(Float:vec[], const Float:ammount)
{
        
vec[0] *= ammount
        vec
[1] *= ammount
        vec
[2] *= ammount
}

stock vector_sum(Float:vecDst[], const Float:vecSrc[])
{
        
vecDst[0] += vecSrc[0]
        
vecDst[1] += vecSrc[1]
        
vecDst[2] += vecSrc[2]
}

stock vector_copy(Float:vecDst[], const Float:vecSrc[])
{
        
vecDst[0] = vecSrc[0]
        
vecDst[1] = vecSrc[1]
        
vecDst[2] = vecSrc[2]
}

stock set_brush_origin(entFloat:origin[3])
{
        static 
Float:size[3], Float:mins[3], Float:absmin[3], Float:absmax[3]

        
entity_get_vector(entEV_VEC_minsmins)
        
entity_get_vector(entEV_VEC_maxssize)
        
vector_substract(sizemins)
        
absmin[0] = origin[0] - (size[0]/2.0)
        
absmin[1] = origin[1] - (size[1]/2.0)
        
absmin[2] = origin[2]
        
absmax[0] = origin[0] + (size[0]/2.0)
        
absmax[1] = origin[1] + (size[1]/2.0)
        
absmax[2] = origin[2] + size[2]
        
entity_set_vector(entEV_VEC_absminabsmin)
        
entity_set_vector(entEV_VEC_absmaxabsmax)
        
origin[0] = absmin[0] - mins[0]
        
origin[1] = absmin[1] - mins[1]
        
origin[2] = absmin[2] - mins[2]
        
entity_set_origin(entorigin)



EXteRmiNaToR 05-15-2010 11:41

Re: Moving func_wall
 
Thanks!:)

grimvh2 05-15-2010 18:40

Re: Moving func_wall
 
Tested, 1 minor thing : it grabs at bottem of the entity ( not such big deal ).

But it seems like it doesnt grab big blocks :s

edit : and some other blooks to. No error logs.
Edit2 : fixed, that some blocks didnt got grabbed.

{PHILMAGROIN} 05-16-2010 04:18

Re: Moving func_wall
 
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);



grimvh2 05-16-2010 08:43

Re: Moving func_wall
 
Fixed it myself ( Used my brainzzz :p )
Solved


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

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