I would also like to know this.
This is my failed attempt, everything that happens when you aim at
a entity and press '+ent_grab' it only comes up the message, nothing more.
I would be very pleased if someone would create/edit a script so it works with entity. I haven't spent so much time tried fixing this though.
And yes I'm aware of the 'resetHud' event, so don't mention anything about it.
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#define MIN_DIST 70.0
#define THROW_POWER 1500
#define MAX_PLAYERS 32
#define MAX_LENGTH 32
new grab[MAX_PLAYERS + 1];
new Float:grabdistance[MAX_PLAYERS + 1];
new bool:grabsearch[MAX_PLAYERS + 1];
public plugin_init()
{
register_plugin("Entity Grab", "1.0", "[A]tomen");
register_clcmd("+grab_ent", "ent_grab_on", ADMIN_KICK);
register_clcmd("-grab_ent", "ent_grab_off", ADMIN_KICK);
register_event("DeathMsg", "deathmsg", "a");
register_event("ResetHUD", "resethud", "be");
}
public ent_grab_on(id, level, cid)
{
if(!cmd_access(id, level, cid, 1))
return 1;
grabsearch[id] = true;
return 1;
}
public ent_grab_off(id, level, cid)
{
if(!cmd_access(id, level, cid, 1))
return 1;
grabsearch[id] = false;
grab[id] = false;
return 1;
}
public grab_ent(id, ent)
{
grab[id] = ent;
grabsearch[id] = false;
static Float:origin[2][3];
pev(id, pev_origin, origin[0]);
pev(ent, pev_origin, origin[1]);
grabdistance[id] = get_distance_f(origin[0], origin[1]);
client_print(id, print_chat, "[AMXX] You grabbed a func_breakable");
}
public is_ent_grabbed(ent)
{
for(new i; i <= MAX_PLAYERS; i++)
{
if(grab[i] == ent)
return (i+1);
}
return -1;
}
public client_PreThink(id)
{
new buttons = pev(id, pev_button);
if(grabsearch[id])
{
new aimid, aimbody;
if(get_user_aiming(id, aimid, aimbody) && aimid)
{
static classname[MAX_LENGTH + 1];
pev(aimid, pev_classname, classname, MAX_LENGTH);
if(equal(classname, "func_breakable"))
{
if(is_ent_grabbed(aimid) == -1)
grab_ent(id, aimid);
else
{
client_print(id, print_chat, "[AMXX] The Entity is already Grabbed")
grabsearch[id] = false;
}
}
}
}
if(grab[id])
{
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(id, ilook, 3);
IVecFVec(ilook, look);
pev(grab[id], pev_origin, grabbedorigin);
pev(id, pev_origin, origin[0]);
pev(grab[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(look, origin[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(grab[id], pev_velocity, velocity);
if(buttons & IN_ATTACK)
{
set_pev(id, pev_button, buttons & ~IN_ATTACK);
grabdistance[id] += 7;
}
else if(buttons & IN_ATTACK2)
{
set_pev(id, pev_button, buttons & ~IN_ATTACK2);
grabdistance[id] -= 7;
if(grabdistance[id] < MIN_DIST)
grabdistance[id] = MIN_DIST;
}
else if(buttons & IN_JUMP)
{
set_pev(id, pev_button, buttons & ~IN_JUMP);
velocity_by_aim(id, THROW_POWER, velocity);
set_pev(grab[id], pev_velocity, velocity);
grab[id] = 0;
}
}
if(is_ent_grabbed(id) != -1)
set_pev(id, pev_button, buttons & ~IN_MOVELEFT & ~IN_MOVERIGHT & ~IN_FORWARD & ~IN_BACK & ~IN_JUMP);
}
public deathmsg()
{
new attacker = read_data(1);
grab[attacker] = false;
grabsearch[attacker] = false;
}
public resethud(id)
{
grab[id] = false;
grabsearch[id] = false;
}
public client_disconnect(id)
{
grabsearch[id] = false;
grab[id] = false;
}
public client_putinserver(id)
{
grabsearch[id] = false;
grab[id] = false;
}
Here's one of my older attempts:
http://forums.alliedmods.net/showthread.php?t=71893
NOTE: My script isn't supposed to teleport the entity by origin, if you meant that.
__________________