PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#define KZ_LEVEL ADMIN_KICK // Adminlevel
#define MIN_DIST 70.0
#define THROW_POWER 1500
new grab[32]
new Float:grabdistance[32]
new bool:grabsearch[32]
new MaxPlayers;
public plugin_init() {
register_plugin("ProKreedzGrab","1.0","p4ddY")
register_clcmd("+grab","grab_on",KZ_LEVEL)
register_clcmd("-grab","grab_off",KZ_LEVEL)
register_event("DeathMsg","deathmsg","a")
register_event("ResetHUD","resethud","be")
MaxPlayers = get_maxplayers();
}
// =================================================================================================
public grab_on(id,level,cid) {
if(!cmd_access(id,level,cid,1))
return PLUGIN_HANDLED
grabsearch[id-1] = true
return PLUGIN_HANDLED
}
public grab_off(id,level,cid) {
if(!cmd_access(id,level,cid,1))
return PLUGIN_HANDLED
grabsearch[id-1] = false
grab[id-1] = 0
return PLUGIN_HANDLED
}
// =================================================================================================
public grab_player(id,target) {
grab[id-1] = target
grabsearch[id-1] = false
new Float:origin1[3], Float:origin2[3]
entity_get_vector(id,EV_VEC_origin,origin1)
entity_get_vector(target,EV_VEC_origin,origin2)
grabdistance[id-1] = get_distance_f(origin1,origin2)
new name[32]
get_user_name(target,name,31)
client_print(id,print_chat,"[Grab] %s",name)
if(callfunc_begin("detect_cheat","prokreedz.amxx") == 1) {
callfunc_push_int(target)
callfunc_push_str("Grab")
callfunc_end()
}
}
// =================================================================================================
public is_user_grabbed(id) {
for(new i=0;i<32;i++) {
if(grab[i] == id)
return (i+1)
}
return -1
}
// =================================================================================================
public client_PreThink(id) {
new buttons = entity_get_int(id,EV_INT_button)
if(grabsearch[id-1] == true) {
new aimid, aimbody
if(get_user_aiming(id,aimid,aimbody) != 0.0 && aimid != 0) {
new targetclass[16]
entity_get_string(aimid,EV_SZ_classname,targetclass,16)
if(equal(targetclass,"player")) {
if(is_user_grabbed(aimid) == -1)
grab_player(id,aimid)
else {
client_print(id,print_chat,"[Grab] Ii deja grabat")
grabsearch[id-1] = false
}
}
}
}
if(grab[id-1] > 0) { // Took this from JediGrap by KCE
new Float:origin1[3], Float:origin2[3], ilook[3], Float:look[3], Float:direction[3], Float:moveto[3], Float:grabbedorigin[3], Float:velocity[3], Float:length
get_user_origin(id,ilook,3)
IVecFVec(ilook,look)
entity_get_vector(grab[id-1],EV_VEC_origin,grabbedorigin)
entity_get_vector(id,EV_VEC_origin,origin1)
entity_get_vector(grab[id-1],EV_VEC_origin,origin2)
direction[0] = look[0] - origin1[0]
direction[1] = look[1] - origin1[1]
direction[2] = look[2] - origin1[2]
length = get_distance_f(look,origin1)
if(!length)
length = 1.0 // avoid division by 0
moveto[0] = origin1[0] + direction[0] * grabdistance[id-1] / length
moveto[1] = origin1[1] + direction[1] * grabdistance[id-1] / length
moveto[2] = origin1[2] + direction[2] * grabdistance[id-1] / length
velocity[0] = (moveto[0] - origin2[0]) * 8
velocity[1] = (moveto[1] - origin2[1]) * 8
velocity[2] = (moveto[2] - origin2[2]) * 8
entity_set_vector(grab[id-1],EV_VEC_velocity,velocity)
// Push and Pull
if(buttons&IN_ATTACK) {
entity_set_int(id,EV_INT_button,buttons&~IN_ATTACK)
grabdistance[id-1] += 7
}
else if(buttons&IN_ATTACK2) {
entity_set_int(id,EV_INT_button,buttons&~IN_ATTACK2)
grabdistance[id-1] -= 7
if(grabdistance[id-1] < MIN_DIST)
grabdistance[id-1] = MIN_DIST
}
else if(buttons&IN_JUMP) {
entity_set_int(id,EV_INT_button,buttons&~IN_JUMP)
VelocityByAim(id,THROW_POWER,velocity)
entity_set_vector(grab[id-1],EV_VEC_velocity,velocity)
grab[id-1] = 0
}
}
if(is_user_grabbed(id) != -1)
entity_set_int(id,EV_INT_button,buttons&~IN_MOVELEFT&~IN_MOVERIGHT&~IN_FORWARD&~IN_BACK&~IN_JUMP) // Stop sucking :o
}
// =================================================================================================
public deathmsg() {
new attacker = read_data(1) // attacker
new victim = read_data(2)
if (!attacker || attacker > MaxPlayers)
return;
grab[attacker-1] = 0
grabsearch[attacker-1] = false
new pid = is_user_grabbed(victim)
if(pid != -1)
grab[pid-1] = 0
}
public resethud(id) {
new pid = is_user_grabbed(id)
if(pid != -1) {
grab[pid-1] = 0
}
grab[id-1] = 0
grabsearch[id-1] = false
}
// =================================================================================================
public client_disconnect(id) {
grabsearch[id-1] = false
grab[id-1] = 0
}
public client_putinserver(id) {
grabsearch[id-1] = false
grab[id-1] = 0
}
// You reached the end of file
// This plugin was made by p4ddY :)
// Credits to KCE