ID:160252
 
lets use this code i made for example
mob/gaara
verb
SandC()
set name = "Sand Coffin"
set category = "Jutsu"
if(usr.canmove==1&&usr.using==0&&usr.chakra >= 100)
for(var/mob/M in view())
if(get_dir(usr,M)==dir)
usr.chakra -= 100
view() << "Sand Coffin....."
usr.canmove = 0
M.coffin = 1
M.coffinorigin = usr
M.canmove = 0
flick('sandcoffin.dmi',M)
M.overlays += 'icons/kyuu.dmi'
else
if(usr.chakra < 100)
usr << "You don't have enough Chakra to use this jutsu!"

In this code it tragets any mob infront of you, thats the problem, how would i make it target only one mob
Well, it depends if you want to choose the target, or pick it randomly.

Instead of

for(var/mob/M in view())
...


do

var/list/targets = new
for(var/mob/M in view())
targets += M
var/mob/M = pick(targets) // randomly select a mob
... // the code that originally was in the for block


If you want to pick a mob, do something simple as:

var/mob/M = input(usr, "Pick a target", "Target") as mob in view()
...
In response to CIB
CIB wrote:
> var/list/targets = new
> for(var/mob/M in view())
> targets += M
> var/mob/M = pick(targets) // randomly select a mob
> ... // the code that originally was in the for block
>

If you want to pick a mob, do something simple as:

> var/mob/M = input(usr, "Pick a target", "Target") as mob in view()
> ...
>

Or, third option, you can let it pick the first mob in the list that view returns every time. I usually prefer that in games, especially when switching through all the targets and getting back to the beginning of the list to cycle through again, so I know how many times to press a button to get to a certain target.
var/mob/M = locate() in oview()

And you should be using oview() instead of view(). If you use view(), your own mob is included in the list. That's alright if that's what you want, but it's probably not what is wanted.