I'm sure the answer I'm looking for is already out there somewhere...
Normally, the RPG I'm programming, you have to repeatedly click attack to repeatedly attack your opponent. However, I'd like to add an element of attack delay which would require a single click attack button that constantly attacks the enemy at regular intervals.
I saw exactly what I'm looking for in Fenris Apocolypse, but couldn't look at the code, so I couldn't get my information from there.
Is there any library that I've overlooked that shows how to do something like this, or is the solution so simple that I'm just overlooking it?
Thanks.
ID:173938
Oct 24 2003, 2:28 pm
|
|
In response to Spuzzum
|
|
Thanks a lot, Spuzzum. I can definitely figure it out, now. :)
|
The key to getting an automatic attack system like that one is to set up some kind of attack loop internally. Here's an example:
mob/player
var/tmp/mob/target
var/attack_range = 1
New()
..()
spawn() AttackLoop() //start off the attack loop
proc/AttackLoop()
while(1) //loop infinitely
if(target)
if(get_dist(src,target) <= attack_range)
src.Hit(target) //if I'm in range, hit it
sleep(rand(5,15)) //wait a random time before it loops again
proc/Hit(mob/M)
//do your attack damage here
Then all you need to do is set the player's target, either by clicking on the target or by using a verb. That's an exercise for the reader. =)