No it's not, you should check inflictor if it's a player index, if it is then get the player's weapon... if not, then it's a nade, c4, map entity or map itself.
Just replace "attacker != 0" with "1 <= inflictor <= maxplayers" (maxplayers is the get_maxplayers() global var)