Sorry to post 2 topics asking for help so close to each other, especially after I figured out the simple solution to my last question. But this one is different, this one I have no clue about and have been searching for an answer for hours now.
Again with WeaponMod, I am trying to make a sawed-off shotgun. The main problem is that WeaponMod doesn't come with a simple native for creating a bullet with spread(bullets always go straight and ignore recoil), so I have to create bullets dynamically as fast-moving entities. I can make a bullet that moves straight, but I can't seem to get the bullet to fire at an angle. I've been searching for hours and I know that I have to do something to alter the velocity or angle values, but I can't just change them without breaking the plugin as far as I know. So how can I make this bullet fire in a random direction(angles should be -5 to 5 degrees).
Code:
public makebullet(id){
new bullet = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,"info_target"))
if(!bullet) return PLUGIN_CONTINUE
set_pev(bullet,pev_classname,"sawedoffbullet")
engfunc(EngFunc_SetModel,bullet,PELLET)
set_pev(bullet,pev_owner,id)
set_pev(bullet,pev_movetype,MOVETYPE_FLY)
set_pev(bullet,pev_solid,SOLID_BBOX)
set_pev(bullet,pev_mins,Float:{-0.01,-0.01,-0.01})
set_pev(bullet,pev_maxs,Float:{0.01,0.01,0.01})
new Float:fStart[3]
wpn_projectile_startpos(id,64,-12,-16,fStart)
set_pev(bullet,pev_origin,fStart)
new Float:fVel[3]
velocity_by_aim(id,BULLET_SPEED,fVel)
set_pev(bullet,pev_velocity,fVel)
new Float:fAngles[3]
fAngles[0] = random_num(-5,5)
fAngles[1] = random_num(-5,5)
fAngles[2] = random_num(-5,5)
vec_to_angle(fVel,fAngles)
set_pev(bullet,pev_angles,fAngles)
//For checking where the bullet goes
message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
write_byte(TE_BEAMFOLLOW)
write_short(bullet)
write_short(g_trail)
write_byte(25)
write_byte(1)
write_byte(224)
write_byte(224)
write_byte(255)
write_byte(255)
message_end()
}
Of course, if there is a more simple way to do this, please tell me. I'm hurting my head.
__________________