ID:158698
 
Code:
mob/troj
verb
Divine_Rage()
set category = "Fighting"
var/ID=input("Who will you kill?")as text
if(ID == "")
return



world<<"<b><font color = Yellow>[usr] :<font size=3>DIVINE RAGE!!"



for(var/mob/M in world)
if(M.name == ID)
spawn(5)
M.health = 0
M.safe = 0
M.Death(usr)


Problem description:

Could someone here tell me how to add a sound to this attack?
Example: When I kill him, you hear the sound of a gunshot.

mob/verb/Kill()
var/E[0] // Just an array, will be used for storing players.
for(var/mob/M in world)
if(M.client) M += E // Round up any clients and add them to the E array.
var/mob/Target = input("Who do you wish to kill?","Fighting") as null|anything in E // Prompting the player with an input, asking him/her who to kill.
if(Target) // Because I'm nice and I added, "as null|" before "anything in E" you get a button to cancel.
spawn(5)
Target.health = 0
Target.safe = 0
Target.Death(src) // Dead.
world << 'Gunshot.wav' // Assuming you have Gunshot.wav, it plays it to the world.
world << "[usr] has brutally murdered [Target]!"


Just a recreation of what you were trying to make there. Plus sound. You really shouldn't handle player/mob selection with strings. Lists and arrays are your friends.
In response to Duelmaster409
You also shouldn't loop through every mob in the world looking for clients, you should do it the other way around:

for(var/client/C)
if(C.mob) E += M
In response to Garthor
Both work efficiently, though. There's no real difference besides looking for a client first then looking for a mob, looking for a mob first then a client works exactly the same.
In response to Duelmaster409
Er, except there are almost always more mobs than clients, and effectively never more clients than mobs. So, looping through clients will be faster, in general.
In response to Garthor
That does seem right. But I don't think the time that's taken to round up the data's dramatically faster. But I'll keep that in mind.
In response to Duelmaster409
Let's see; looping through all the mobs, including all the NPCs and monsters or what-have-you (which would certainly be very numerous) in the game and checking if each is a player, versus looping through all players directly (theoretically, you don't normally need to even check if a client has a mob there, though there's a BYOND "issue" where a fake client can be caught in a very specific situation), which may even be a handful or none at all, for that matter. You can probably see which is the more efficient method and which is the more roundabout one. =P