ID:161166
 
I made a game where I could attack, kill, and earn money but the mob being attacked couldn't fight back. I'm not sure how to make it so that when I attack them, they attack me.
Please help!
(P.S. The mob isn't another player online, it is just a figure sitting there.)
I will take any answers because I have tried and failed many times.
Thank you. :)
Conno1234 wrote:
I made a game where I could attack, kill, and earn money but the mob being attacked couldn't fight back. I'm not sure how to make it so that when I attack them, they attack me.
Please help!
(P.S. The mob isn't another player online, it is just a figure sitting there.)
I will take any answers because I have tried and failed many times.
Thank you. :)

Um, try Bump()
In response to Eternal Desire
"Bump()" ???
What will this do?
Is it a procedure?
Don't try Bump(), it will do nothing for you in this case. I have a couple of methods in my head to help with this, but I'll let Garthor or someone experienced come in, since I think my methods are inefficient.
In response to Darkmag1c1an11
Ok, but who is Garthor?
In response to Conno1234
Garthor is a robot that's awesome at DM programming.
In response to Darkmag1c1an11
oh ok but does he talk to people and answer their Q's?
In response to Conno1234
Besides Garthor, you said that you had a couple of methods.
Would you mind sharing them with me?
In response to Darkmag1c1an11
It wouldn't be surprising.
In response to Conno1234
Look it up in the ref (F1 in Dream Maker).
Basically, you'll need to write an AI routine for the enemies. This is a very, very broad topic, and can cover a wide range of things. The simplest AI goes something like this:

1) Pick an enemy that we can see
2) While that enemy is still in range:
a) If we're close enough to attack, attack
b) Otherwise, step closer
c) Repeat
3) Repeat

So, we'll do something like this:

mob
var/tmp/mob/target = null
proc
AI()
while(src)
//Find an enemy of type /mob/player
target = locate(/mob/player) in oview(src)
//while they're still in range
while(target && (target in oview(src)))
//attack if we can
if(get_dist(src,target) <= 1)
src.attack(target)

//otherwise, get closer
else
step_to(src, target)

//wait a little while before moving again
sleep(10)

//wait a little while before looking for a new target
sleep(10)


There are about a million ways to improve on that, but that's a start.
In response to Darkmag1c1an11
Darkmag1c1an11 wrote:
Don't try Bump(), it will do nothing for you in this case. I have a couple of methods in my head to help with this, but I'll let Garthor or someone experienced come in, since I think my methods are inefficient.

Really?
mob/monsters/Bump(mob/player/MM)
if(istype(MM)) // This is shorthand for istype(MM,/mob/player)
src.Attack(MM) //attacks the player
src.death_check(MM) //checks if it's dead


I've TESTED that - it works.

Onto moving monsters...
mob/var/mob/player/Target

mob
monsters
icon='monsters.dmi'
New() //when any monsters are created
..() //make sure it happens
spawn(5)
src.Wander() //starts Wander()

mob
proc
Wander()
while(src) //a loop.
sleep(5) //sleeps 5 ticks
for(var/mob/player/MMMM in oview(1)) // how far you want the enemy to target a player
Target = MMMM //MMMM is the player in oview
break
if(Target) //if it has a target
walk_towards(src,Target,5) //walk towards them
else //if not
walk_rand(src,5) //walk randomly
In response to Eternal Desire
That's bad code. Don't post bad code.
In response to Garthor
Garthor wrote:
That's bad code. Don't post bad code.
Regardless, it works.

Besides, it isnt like I'm posting source codes to C/P.
In response to Eternal Desire
It works in the limited case you've provided. It is, however, screwing up a number of things, like using usr in procs (AGAIN, I MIGHT ADD) and using walk_towards() like step_towards(). Bad code is bad code. Don't post it.
In response to Garthor
Garthor wrote:
It works in the limited case you've provided. It is, however, screwing up a number of things, like using usr in procs (AGAIN, I MIGHT ADD) and using walk_towards() like step_towards(). Bad code is bad code. Don't post it.

You didnt even look. There isnt any 'usr' there.

And I lulz'd at the bolded.

fail 4chan meme is fail?????
In response to Eternal Desire
That wasn't a 4chan meme, it was simply a statement of identity.

As for there not being any usr in it, that just shows your own ignorance. See: http://www.byond.com/docs/ref/info.html#/proc/oview

Another reason you should refrain from attempting to help people.
In response to Garthor
Garthor wrote:
That wasn't a 4chan meme, it was simply a statement of identity.

As for there not being any usr in it, that just shows your own ignorance. See: http://www.byond.com/docs/ref/info.html#/proc/oview

Another reason you should refrain from attempting to help people.

Follow your own advice. Click the post and CTRL+F "usr"
In response to Eternal Desire
I linked you to the reference. The default center argument for oview() is usr. You did not provide a center argument for oview(). Therefore, it defaulted to usr, and you used usr in your proc.
In response to Garthor
Garthor wrote:
I linked you to the reference. The default center argument for oview() is usr. You did not provide a center argument for oview(). Therefore, it defaulted to usr, and you used usr in your proc.'

-sigh- How come whenever you guys post over-lengthly-never-getting-to-the-point code, it's good but my short, but to the point code is 'bad'?
Page: 1 2