ID:156156
 
I was wondering if there was a way to turn this click targeting that targets a single mob into a target system that targets all mob's on a players screen.
This is the clicking system.
mob
var
targeting=0
Tgt = ""
mob
DblClick()
if(usr.targeting==0)
usr.targeting=1
usr.Tgt= src
var/image/I = image('Target.dmi',src)
usr.client.images += I
usr<<output("<font color=red>You targeted [src].","output1")
spawn(600)
if(usr.targeting)
usr<<output("<font color=blue>[src] was automatically untargetted.","output1")
del(I)
usr.Tgt= null
usr.targeting=0
else
usr<<output("<font color=blue>You untargeted [src].","output1")
for(var/image/I in usr.client.images)
del(I)
usr.Tgt= null
usr.targeting=0
hump
--You can use a list to keep track of an arbitrary number of multiple elements (items).

--To do something with all the mobs on a player's screen, you can loop through all the mobs in the list that view(player_client) returns. You can also loop through view(player_mob,player_mob.client.view) instead for what is visible for the player mob within the player's current viewing range, which is a little different (using view(player_mob) will give you what is visible to the player mob within the default player's viewing range, which could be different).

EDIT: The bump was useless, by the way, and also exactly half an hour too early to be considered legitimate. ;)
In response to Kaioken (#2)
Hey i need this too and i didnt understand anything you said. It was just the way you worded it that confused the shit out of me.
In response to Kaioken (#2)
This may sound noobish to some and may cause some to tell me to go back, to read the guide. Which i have grown tired of reading over my years on byond but could you give me a small example about what you are talking bout.
In response to Akriloth (#4)
No doubt, you need to learn the language and consult the available resources to understand what you need to do and what I said. I did not intend to spoonfeed you; rather, that you consult guides and tutorials (including the DM Guide, indeed) to learn about using the language in general and the DM Reference to learn about the language aspects which I've specifically mentioned (lists, view()).
It doesn't matter how many times you've read, say, the DM Guide (though I doubt you've ever even read it in whole once). Merely reading is worthless; you have to understand and practice. Put in effort, in other words.

Killa kidd9490, the same naturally goes for you, of course.
Nevertheless, I shall answer your requests this one time out of courtesy:

Killa kidd9490 wrote:
It was just the way you worded it that confused the shit out of me.

How do you wish me to word it, then? Let me try again.

First, if you want to save multiple values (like "mobs"), then you need to use a type of object called a list. So if you want to keep track of multiple mobs being targeted, you could put all of them in a list.

Second, in order to grab all of the mobs in a player's view, you can use the view() proc and loop through the mobs in the list it returns (i.e., use a for()-list loop in conjunction with view()).

Akriloth wrote:
could you give me a small example about what you are talking bout.

--Saving an arbitrary number of value in a list (in the example, the player using the verb decides the number of values):
client/verb/List_Example(amount as num)
var/list/L //declare a variable and tell the compiler it's supposed to hold a list.
L = new /list() //create a new list and store it in the var
while(amount) //repeat this section of code while 'amount' contains a true value
L.Add(123) //add the number '123' to the list.
amount-- //subtract 1 from amount

src << "The list has [L.len] elements."
/* the resulting list has the number 123 amount-times in it.
so if the player input amount as '6', the list is equivalent to:
list(123,123,123,123,123) */


As usual with programming, there are many different ways to accomplish what the above code does. I tried to keep it simple. I also left out handling the input (for example, what to do if the player enters a negative or decimal number), so the verb is faulty for real usage. It's only for the sake of showing how to use a list, anyway. Read on lists as well as loops for more info.


--Doing something with all the mobs in a player's view:
client/verb/what_mobs_I_see()
for(var/mob/X in view(src))
src << "You can see [X]."
//this outputs a line of text to the player for every mob he can see.


Tidbits:
--In this kind of verb, src is the client of the player who executed the verb, of course.
--view(Client) is equivalent to view(Client,Client.view). In other words, when you specify a client as the center and you specify no range, the range defaults to the client's current viewing range (in contrast to when the center isn't a client and you don't specify a range, in which case it will default to world.view which is the default viewing range).
--view(player_mob) is different from view(player_client) in potentially both range and contents. Just so you know, as view(player_mob) is often used.
view(player_mob,player_client.view) is different from view(player_client) only in contents.