ID:174171
 
Hello! I am making a complex RTS based on code from Wall04's amazing selection demo. Anyway, I don't really know how to make the units attack. At the moment you build houses, recruit men, and you can make them move, but not attack.

How would I get them to attack 1 enemy in contact with them, with the highest Health, when they came into contact with enemies?

I have a basic Attack proc here, but it is probably messed up :

mob/proc/Attack()
var/list/L = new
var/mob/K=locate() in oview(1,src)
if(K)
for(K in oview(1,src))
L+=K
var/mob/M = pick(L)
if(M.colour != src.colour)
var/damage = src.Attack - M.Defence
if(damage<=1)
M.Health -= 1
damage = 1
else
M.Health -= damage
view(6,src)<<"[src] attack [M] for [damage] damage!"
var/damage2 = M.Attack - src.Defence
if(damage2<=1)
M.Health -= 1
damage2 = 1
else
M.Health -= damage2
view(6,src)<<"[M] attack [src] for [damage2] damage!"
Death()
Death()

mob/proc/Death()
if(src.Health <= 0)
if(!src.client)
view(6,src)<<"[src] has been killed!"
(src.player)<<"You have lost [src]!"
del(src)
else
src<<"You have been defeated!"
src<<"All your building are now destroyed!"
src<<"And all your men lay dead!"
for(var/mob/M in world)
if(M.player == src.name)
spawn()
del(M)
for(var/obj/O in world)
if(O.name != "Town Center")
if(O.player == src.name)
spawn()
del(O)
world<<"[src] has been defeated!"
alert("Please Wait!")
sleep(170)
src.Health = 1000
src.MaxHealth = 1000
src.Attack = 25
src.Defence = 25
src.Mesatta = 1500
src.Wood = 1200
src.Player = 1
world<<"[src] has started again!"
src<<"<B>You are back</B>!"


To explain the colour bit, each person has a colour, which is their team, so enemies will always have a different colour.

If you need any more code just say!

Thank you!

~Ease~
I have thought over it a million times, coming up with a billion answers, but none of them fit. Any help would be more than helpful!

~Ease~

<font size = -3>Everything is at ease with Ease</font>


In response to Ease
i was thinking about making an RTS too, cept ripping the tiberian sun sprites xD...i wasnt successfull though..

anyway, your plan sounds great but i cant help you...i was just wondering why you havent been on MSN...i want to talk to you
In response to Karasu Kami
I hate to bump again, but I really need this before I can do anymore of my game.

All people that help WILL be in the credits, and will have my undying gratitude!

~Ease~

<font size = -3>Everything is at ease with Ease</font>
> mob/proc/Attack()
> var/list/L = new
> var/mob/K=locate() in oview(1,src)
> if(K)
> for(K in oview(1,src))
> L+=K
> var/mob/M = pick(L)
> if(M.colour != src.colour)
> var/damage = src.Attack - M.Defence
> if(damage<=1)
> M.Health -= 1
> damage = 1
> else
> M.Health -= damage
> view(6,src)<<"[src] attack [M] for [damage] damage!"
> var/damage2 = M.Attack - src.Defence
> if(damage2<=1)
> M.Health -= 1
> damage2 = 1
> else
> M.Health -= damage2
> view(6,src)<<"[M] attack [src] for [damage2] damage!"
> Death()
> Death()
>
> mob/proc/Death()
> if(src.Health <= 0)
> if(!src.client)
> view(6,src)<<"[src] has been killed!"
> (src.player)<<"You have lost [src]!"
> del(src)
> else
> src<<"You have been defeated!"
> src<<"All your building are now destroyed!"
> src<<"And all your men lay dead!"
> for(var/mob/M in world)
> if(M.player == src.name)
> spawn()
> del(M)
> for(var/obj/O in world)
> if(O.name != "Town Center")
> if(O.player == src.name)
> spawn()
> del(O)
> world<<"[src] has been defeated!"
> alert("Please Wait!")
> sleep(170)
> src.Health = 1000
> src.MaxHealth = 1000
> src.Attack = 25
> src.Defence = 25
> src.Mesatta = 1500
> src.Wood = 1200
> src.Player = 1
> world<<"[src] has started again!"
> src<<"<B>You are back</B>!"


Do you mean to attack continually? just make them call the attack proc when they are created, and maybe keep calling it every few ticks, that could work.
In response to Wanabe
Wouldn't that REALLY lag the game down, especially seeing as it is an RTS and will have many Units on the "field". Is there a way to only call it once, each time the Unit is selected and has been told where to go (via the user clicking)?

Thank you anyway!

~Ease~
In response to Ease
Please! I beg of you might elitists and all other BYONDers, please help a man in need! Pretty please?

*Gets down on the ground and begs*

Any help, any help at all would be most humbly recieved!

~Ease~ (A poor soul who's computer has returned from the shop with it's hard-drive completely whiped!)
In response to Ease
Hmm...if that's the case, I encourage you to look up "while()". It should provide what you're looking for.
In response to Ease
Ease wrote:
Wouldn't that REALLY lag the game down, especially seeing as it is an RTS and will have many Units on the "field". Is there a way to only call it once, each time the Unit is selected and has been told where to go (via the user clicking)?

Thank you anyway!

~Ease~

well thats probly the only way, to do so....maybe ask wildblood or malver(at least i think thats the maker of clash)