Topic: Grenade spread
Hi, I am trying to get a grenade spread like in the streetwars servers where one click = 3 shots. Here is my current grenade code:
case WEAPON_GRENADE:
{
if(!grenade_shotspread)
grenade_shotspread = 1;
grenade_shotspread = 3;
msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
msg_pack_int(grenade_shotspread);
for(int i = grenade_shotspread; i <= grenade_shotspread; i++)
{
float spreading[] = {-0.185f, -0.070f, 0, 0.070f, 0.185f};
latest_input.target_x= latest_input.target_x+spreading[i+12];
latest_input.target_y= latest_input.target_y+spreading[i+12];
vec2 new_dir = normalize(vec2(latest_input.target_x, latest_input.target_y));
float a = get_angle(direction);
a += spreading[i+2];
float v = 1-(abs(i)/(float)grenade_shotspread);
float speed = mix((float)tuning.grenade_speed, 1.0f, v);
projectile *proj = new projectile(WEAPON_GRENADE,
client_id,
projectile_startpos,
new_dir,
(int)(server_tickspeed()*tuning.grenade_lifetime),
this,
1, projectile::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);
// pack the projectile and send it to the client directly
NETOBJ_PROJECTILE p;
proj->fill_info(&p);
for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++)
msg_pack_int(((int *)&p)[i]);
}
msg_pack_end();
server_send_msg(client_id);
create_sound(pos, SOUND_GRENADE_FIRE);
}
I tried to model the shotgun code, but it didn't work for some reason. Could someone help me with this? For the record, here is the original code:
case WEAPON_GRENADE:
{
projectile *proj = new projectile(WEAPON_GRENADE,
client_id,
projectile_startpos,
direction,
(int)(server_tickspeed()*tuning.grenade_lifetime),
this,
1, projectile::PROJECTILE_FLAGS_EXPLODE, 0, SOUND_GRENADE_EXPLODE, WEAPON_GRENADE);
// pack the projectile and send it to the client directly
NETOBJ_PROJECTILE p;
proj->fill_info(&p);
msg_pack_start(NETMSGTYPE_SV_EXTRA_PROJECTILE, 0);
msg_pack_int(1);
for(unsigned i = 0; i < sizeof(NETOBJ_PROJECTILE)/sizeof(int); i++)
msg_pack_int(((int *)&p)[i]);
msg_pack_end();
server_send_msg(client_id);
create_sound(pos, SOUND_GRENADE_FIRE);
} break;
I would appreciate any input on this.
deny_post($poster);