EDIT: I must have installed 1.76d incorrectly. I just tested again with a fresh install and it worked without a hitch.
Now that I'm using AMX Mod X 1.76d, it seems my plugin stopped working properly. The plugin worked just fine with 1.76c.
Sprites or models used to be nice and flush with the walls when I would hold down
+place_ad. Now, they don't appear or they appear in odd places. Maybe it's just me?
I'd appreciate any advice to make this work for 1.76d.
http://forums.alliedmods.net/showthr...583#post424583
It should place an entity flush with the wall the user is looking at, but the entity does not appear at all or it appears in the wrong position.
I think there may be a problem with the highlighted function.
Code:
#include <amxmodx>
#include <fakemeta>
#include <xs>
public plugin_init
()
{
register_forward
(FM_PlayerPreThink,
"PreThink")
}
public PreThink
(id
)
{
if(!is_user_placing_ad
)
return FMRES_HANDLED
if(prethink_counter++ > PRETHINK_REFRESH_TIME
)
{
prethink_counter =
0
fm_get_aim_origin(id, aiming_origins[2])
if(equal_f
(aiming_origins
[1], aiming_origins
[2]) <
3)
{
engfunc
(EngFunc_SetOrigin, ad_ent, aiming_origins
[2])
//move_toward_client(id)
//by using player's origin, I make sure sprites are facing the player
static Float:normal
[3],
Float:player_origin
[3],
Float:test_origin
[3]
normal = cross_product
(diff_f
(aiming_origins
[0], aiming_origins
[1]), diff_f
(aiming_origins
[2], aiming_origins
[1]))
vector_to_angle
(normal, ad_ent_angles
)
minimize_normal
(normal
)
test_origin = sum_f
(aiming_origins
[2], normal
)
pev
(id, pev_origin, player_origin
)
if(get_distance_f(player_origin, test_origin
) >
get_distance_f(player_origin, aiming_origins
[2]))
{
//sprites had the wrong X rotation while models had the correct X rotation
//maybe this problem only involves my wall.mdl
if(contain(ad_model_list
[current_ad_model
],
".spr") !=
-1)
{
ad_ent_angles
[0] *=
-1.0
}
set_pev
(ad_ent, pev_angles, ad_ent_angles
)
}
}
if(equal_f
(aiming_origins
[1], aiming_origins
[2]) <
2 &&
get_distance_f(aiming_origins
[2], aiming_origins
[1]) >
5.0)
{
aiming_origins
[0] = aiming_origins
[1]
aiming_origins
[1] = aiming_origins
[2]
}
}
return FMRES_HANDLED
}
//from fakemeta_util.inc
stock fm_get_aim_origin(index, Float:origin[3])
{
static Float:start
[3],
Float:view_ofs
[3]
pev
(index, pev_origin, start
)
pev
(index, pev_view_ofs, view_ofs
)
xs_vec_add
(start, view_ofs, start
)
static Float:dest
[3]
pev
(index, pev_v_angle, dest
)
engfunc
(EngFunc_MakeVectors, dest
)
global_get
(glb_v_forward, dest
)
xs_vec_mul_scalar
(dest,
9999.0, dest
)
xs_vec_add
(start, dest, dest
)
engfunc
(EngFunc_TraceLine, start, dest,
0, index,
0)
get_tr2
(0, TR_vecEndPos, origin
)
return 1
}
stock equal_f
(Float:origin1
[3],
Float:origin2
[3])
{
new num_equal =
(origin1
[0] == origin2
[0] ?
1 :
0)
num_equal +=
(origin1
[1] == origin2
[1] ?
1 :
0)
num_equal +=
(origin1
[2] == origin2
[2] ?
1 :
0)
return num_equal
}
stock Float:diff_f
(Float:origin1
[3],
Float:origin2
[3])
{
new Float:result
[3]
result
[0] = origin1
[0] - origin2
[0]
result
[1] = origin1
[1] - origin2
[1]
result
[2] = origin1
[2] - origin2
[2]
return result
}
stock Float:cross_product
(Float:origin1
[3],
Float:origin2
[3])
{
new Float:result
[3]
result
[0] = origin1
[1]*origin2
[2] - origin1
[2]*origin2
[1]
result
[1] = origin1
[2]*origin2
[0] - origin1
[0]*origin2
[2]
result
[2] = origin1
[0]*origin2
[1] - origin1
[1]*origin2
[0]
return result
}
stock minimize_normal
(Float:normal
[3])
{
normal
[0] /=
10.0
normal
[1] /=
10.0
normal
[2] /=
10.0
return 1
}
stock Float:sum_f
(Float:origin1
[3],
Float:origin2
[3])
{
new Float:result
[3]
result
[0] = origin1
[0] + origin2
[0]
result
[1] = origin1
[1] + origin2
[1]
result
[2] = origin1
[2] + origin2
[2]
return result
}