attackphysics(from, to); hits.setsizenodelete(0); raydamage(from, to, owner); attackfx(from, to, 0); gunwait = info.attackdelay; mag--; sendshoot(from, to);

float tdist=9999999.9; //max distance we want
int target=-1; // temporary target
vec newto; // where our new hit location is
loopv(players)
{
if(players[i]==NULL) continue; //if the pointer is not NULL
if(!isteam(player1->team, players[i]->team) && players[i] != player1 && players[i]->state == CS_ALIVE) // and the team isnt the same, its not pointing to our own player and the enemy is alive
{
if(from.distxy(players[i]->o)<tdist) // check if the distance is below the best distance
{
tdist=from.distxy(players[i]->o);// if it is save our new distance as best distance
target=i; // assign our target
}
}
}
newto = players[target]->o; // the new hit location is our enemys location
attackphysics(from, newto);// send the attack physics
hits.setsizenodelete(0);
raydamage(from, newto, owner); // apply the damage
attackfx(from, newto, 0); // apply the effects
gunwait = info.attackdelay; // apply the gun wait time
mag--; // decrease our ammo
sendshoot(from, newto); // send our shot over to the server
float tdist=9999999.9; //max distance we want
int target=-1; // temporary target
vec newto; // where our new hit location is
loopv(players)
{
if(players[i]==NULL) continue; //if the pointer is not NULL
if(!isteam(player1->team, players[i]->team) && players[i] != player1 && players[i]->state == CS_ALIVE) // and the team isnt the same, its not pointing to our own player and the enemy is alive
{
if(from.distxy(players[i]->o)<tdist) // check if the distance is below the best distance
{
tdist=from.distxy(players[i]->o);// if it is save our new distance as best distance
target=i; // assign our target
}
}
}
if(target != -1)
{
newto = players[target]->o; // the new hit location is our enemys location
attackphysics(from, newto);// send the attack physics
hits.setsizenodelete(0);
raydamage(from, newto, owner); // apply the damage
attackfx(from, newto, 0); // apply the effects
gunwait = info.attackdelay; // apply the gun wait time
mag--; // decrease our ammo
sendshoot(from, newto); // send our shot over to the server
}
else
{
attackphysics(from, to);// send the attack physics
hits.setsizenodelete(0);
raydamage(from, to, owner); // apply the damage
attackfx(from, to, 0); // apply the effects
gunwait = info.attackdelay; // apply the gun wait time
mag--; // decrease our ammo
sendshoot(from, to); // send our shot over to the server
}
fixes a crash when shooting if there is no enemy