ID:178916
 
I have a battle system(real time) which has a spell called Summon Pansaku(Pansaku is a breed of Monster) But I need it so it does the following
* When a Pansaku is summoned the Pansaku gets the Mob who summoned him as his 'Parent' whom he will not attack.
*The /mob/Pansaku to walk around randomly and if a mob(not the parent) appears in the overview of 5 it will chase after it
* If a mob(not the parent) is in the overview of 1 the Pansaku will attack it!

Please answer. I would really appreciate the help!
The simplest way to accomplish the first part is to have a parent variable for the creator. Just set that variable when you summon the monster like this:

mob
Summons
var/mob/owner
Monster
proc
Summon()
var/mob/Summons/Monster/M = new(loc) //create monster
M.owner = src //assign summoner to summoned
M.StartAI() //start the mob in motion

The second half can be done in various different ways but one simple way is to have an AI routine that it goes through that is started when it is created and is called at regular intervals, basically a more advanced random walking algorithm. Whenever it walks you can have it scan through all mobs within 5 spaces of it and pick a target from it (making sure it is != owner). Once a target is picked have it step towards the target instead of stepping randomly. Once it's within a certain distance from the target have it attack it.
In response to English
Thanks, I find asking advice and such much better than demanding code like Watabou.
In response to FireEmblem
Hey! I thought you were on my side!
In response to FireEmblem
It does make people more willing to help, especially when it is a request, not a demand.
In response to English
as the name implies, your code didnt work too well
In response to Watabou
I am your friend but YOU are demanding. I was only telling the truth, I predict now you will get mad at me and call me a nerdy 4.0 teen, AND as a matter of fact I AM a 4.0 student! So now you call me a nerdy kid who goes to a Private school in Toronto, And No I do not, for that matter I have no idea where Toronto is!(I am not the best in Geography! It was sheer luck I got an A!) Well then now what would you do? Oh yes! Storm away grumbling and growling at me. I am the predicter of future!
In response to FireEmblem
Stupid Psychics!
P.S. Whats a Toronto?
In response to FireEmblem
It was a direction for you to head in, not actual code for you to use. The ideas that I presented work (I've used them before) you just have to customize them to your own game based upon what actions your monsters can do, how fast you want them to be, and many other issues.

I don't know the stucture of your game, the categories your mobs are in, or anything else other than the information you gave me so I can't get any more specific than I did.
In response to Watabou
Ever heard of Toronto Canada?
In response to English
mob/proc/AI()
for(var/mob/M in world)
if(M in oview(5)) // I use if M is in your view because it helps keep things less complicated
walk_towards(M,src)
sleep(5)
if(M in oview(1))
var/damage = M.atk + rand(1,5) - src.def
if(damage > 0)
src << "[M] does [damage] points of damage to you!"
src.health -= damage
if(src.health <= 0)
Death()
else
Re_InitAI()
else
src << "[M] did not harm you."
else
Re_InitAI()
else
step_rand(M)
sleep(5)
Re_InitAI()

all and all its very buggy, but with a little work, it would do what you want it to, I had almost bugless at one point but i decided to improve it more, and degenerated quickly to the piece you see before you, if i get it working correctly ill let you know, if your wondering about the ReInit process, me and loops dont get along too well so i call a process that makes the whole thing sleep for about 5 seconds, then restarts the whole thing.
And dont expect it to work right away either, it will probably require a lot of tweaking, and/or help from a coder that knows AI a lot better then I do, well theres not a lot more i can say without typing a few more paragraphs so i guess ill stop now, good luck with it
In response to War_master66
Be careful when you're looking through posts using the search feature, as that is what I assume you did. That post you just replied to is two years old. I have done that on accident before, though I usually realised what I did and deleted the post before anyone could reply.

A code problem that is two years old most likely isn't much of a porblem for the person anymore, as they either would have figured it out by now or given up. (At least, I hope the person is not still staring at the monitor trying to figure out how to do that bit of AI. I feel sorry for anyone that is stuck on the same small function after a few years.)