ID:557259
 
(See the best response by Albro1.)
Code:
mob
verb
Target()
var/Player/M
var/mob/T = Target
if(!Target)
for(M in obounds(usr, 500))
Target = M
break
return
if(Target)
Target = null
for(M in obounds(usr, 500) - T)
Target = M
break
return


Problem description:

Trying to make a macro-based targeting system, and it works, but only with 2 mobs (other than the player.) More than 2 and it just switches back and forth between 2 of them. I know I've done one of these before a few years ago but I just can't figure it out.
Help would be appreciated thanks!
I am not sure what you are trying to do there, but I am surprised that it works, since you are using a variable called "Target" that isn't defined anywhere, or at least not in this code.
Aside from this, your code seems to do this:
- if Target is null, take the first Mob available
- if Target is not null make it null and take the first Mob available with the exception of Target
so it's normal it cycles between the same 2 mobs all the time, there is nothing that would allow the code to go any further.
What is it exactly that you want it to do?
If you can't tell what the code does just by looking at it, you're not going to be able to help me. It's pretty straightforward. And no Target's not defined in this code but obviously I just have
mob/var/tmp/Target elsewhere.
Basically right now if you only have 2 other people in the obounds it'll target between them, but if there's more than 2 it just switches back and forth between 2 of them, instead of all 3 (or more if there is more.)
I don't get why it does this, since I figured obounds() would take the closest Player to the usr. But it doesn't
I've been having the same problem for a while and couldn't come up with anything for it yet so I put it aside :/ Hopefully I'll figure it out soon. It happens with bounds() obounds() view() and oview() for me :/
Okay, I got it working with

mob/var/tmp/Target // NYAH

mob
verb
Target()
var/Player/M //Also this is my Player mob. YEAH I use parent_type get over it.
var/mob/T = Target
var/d = 4
if(!Target)
check
for(M in obounds(usr, d))
Target = M
return
d+=4
if(!(d>320))
goto check
return
if(Target)
Target = null
check
for(M in obounds(usr, d) - T)
Target = M
return
d+=4
if(!(d>320))
goto check
return



If anyone can think up a better method for me, it'd be very much appreciated.
Best response
for(var/i = 1, i <= 320, i+=4)
for(M in obounds(usr, i))
if(M)
Target = M
i = 321
Thanks for the reply Albro, yeah that'd work as well, yours is a neater presentation than mine. But you didn't change the d in the for to i.
Same crap different toilet, but I asked for a better method and it is.

This is solved now, if an Admin could mark it as such.
In response to Jaysburn
Jaysburn wrote:
This is solved now, if an Admin could mark it as such.

It's done automatically after a post gets a certain amount of votes. So "vote up" Albro1's post if you like his answer.