ID:160724
 
Ok im have a targeting system and it works fine but i want to adjust it to cycle through mobs instead of just randomly pick one, obviously if your using the mouse to target it doesnt matter but i want the player to be able to use only there keyboard if they want. Heres the code:
mob/verb
Select_Target()
set category="Commands"
var
list/piv=list()
mob/attack
for(var/mob/M in oview(7))
piv+=M
attack=pick(piv)
if(attack == usr||get_dist(attack,usr) >= 10)
return
if(attack==usr.target)
usr.DeleteTarget()
return
for(var/image/x in usr.client.images)
if(x.icon=='target.dmi')
del(x)
var/image/I = image('target.dmi',attack)
usr<<I
usr.target=attack
usr<<"You target [attack]"
I think i made this as easy as possible.

mob/verb/picktarget(mob/A in oview(7))//no need for get_dist proc
set category = "Commands"
if(A==usr.target)//I think the rest is self explaintory
usr.DeleteTarget()
else
for(var/image/B in usr.client.images)
if(B.icon=='target.dmi')
del(B)
var/image/C=image('target.dmi',A)
usr<<C
usr.target=A
usr<<"You target [A]"


If you got questions dont hesitate to ask :)
In response to Generation
That would be good if it was in Click or DBLClick ;).
In response to Generation
See the problem with that is there is a pop up window that ask you which mob, im trying to avoid that for speed, if you look at my code it automatically does it. The only thing i would like to see different would be if it would cycle through the mobs starting with the closest.
In response to NightJumper88
In your code, it randomly picks a target. Is that what you want?
In response to Generation
no thats what im trying to fix instead of random i want it to go with the closest person first then the next closest and so on.
mob/verb
Select_Target()
set category="Commands"
var
list/piv=list()

for(var/mob/M in oview(7, src))
piv+=M
if(!piv.len) return

// try to find our current target in piv
var/target_in_piv = piv.Find(src.target)
// cycle back to the first target if our target is the last one
if(piv.len == target_in_piv) target_in_piv = 0
// select the next target (or the first target if target_in_piv is 0)
src.target = piv[target_in_piv+1]

for(var/image/x in src.client.images)
if(x.icon=='target.dmi')
del(x)
var/image/I = image('target.dmi',src.target)
src << I
src << "You target [src.target]"