ID:165894
 
I've looked a few tutorials and I'm not sure how to do it still. I want the player to have to face the NPC to attack it, and then if damage is done a sprite pops up to show the hit. I'm new to attack systems
Like this?

mob/verb/attack()
for(var/mob/M as mob in get_step(src,src.dir))
world << "attack!"// replace with attack code


It uses a loop to attack any monsters 1 tile infront of the source, using the get_step command (look it up in the ref if you're not sure how it works).

[EDIT]

You wont need to use a loop if all of your mobs are dense though. The above would work even if its possible for more than 1 mob to occupy the same location, if you know for a fact that that isn't going to happen in your game, then you can remove the loop and just have it attack the mob in the returned location from get_step.

- Conj'
In response to The Conjuror
how could I make it into a proc so the player can choose the verb or attack by hud-button?

Also the above starts the attack, even if your not next to and/or facing the monster
In response to FriesOfDoom
um......

bump
In response to FriesOfDoom
How do you mean it starts the attack? If you run the above code, it'll only say "attack!" when you're facing/directly infront of a mob. Tested it myself. Ofcourse, you're not pasting the code into yours and hoping for it to work, right? You're learning from it, and adapting it to fit your code, riiiight?

And to put it in a proc its as simple as changing it from a verb definition to a proc definition (remove the verb word, replace with proc), and then call the proc when the verb is selected.
In response to The Conjuror
A hud button is easy. Here is an EXAMPLE code...Dont try usin it tho.

    Outlinel
Click( )
world << "[usr] is now playing!"
switch(alert("You are about to join the game! What do you want to be?","Icon","Evil","Good","Neutral"))
if("Evil")
usr.loc = locate (1,1,1)
usr.icon = 'person.dmi'
usr.icon_state = "enemy"
if("Good")
usr.loc = locate (1,1,1)
usr.icon = 'person.dmi'
usr.icon_state = "good"
if("Neutral")
usr.loc = locate (1,1,1)
usr.icon = 'person.dmi'
usr.icon_state = "neutral"
icon = 'start.dmi'
icon_state = "l"


Just an example..
In response to Revojake
And if you want to show how much damage is done...
world << "[damage] damage is done!" ...Make sure you have a [damage] proc or var...i forgot wich it would be.
In response to The Conjuror
The Conjuror wrote:
How do you mean it starts the attack? If you run the above code, it'll only say "attack!" when you're facing/directly infront of a mob. Tested it myself. Ofcourse, you're not pasting the code into yours and hoping for it to work, right? You're learning from it, and adapting it to fit your code, riiiight?

And to put it in a proc its as simple as changing it from a verb definition to a proc definition (remove the verb word, replace with proc), and then call the proc when the verb is selected.

The only thing I used was the for() command you showed, and I just noticed my attack code underneath was not indented under the for() command, causing it to work at anytime.

Also what I dont get is, you have to define the mob right? Will the for() define it? im sure it will. But during the proc will the mob count as src, or will the usr using the command count as the src? Now I'm thinking the usr will count as the src, but I wrote the above post while i was fighting sleep. Sorry if I ticked you off
In response to FriesOfDoom
Usr is the person who clicked the HUD, M in this case, is target infront of you. here's a quick, correctly done example.

obj/hud/Attack
icon = 'hud.dmi'
icon_state = "attack"
screen_loc = "1,15" //this will set its location when its created. Don't forget this
Click()
for(var/mob/M in get_step(usr,usr.dir))
view() << "[usr] attacks [M]" //i prefer to tell the view
M.HP -= usr.ATP - M.DEF
view() << "[M.HP -= usr.ATP - M.DEF] damage!"
M.deathcheck()


Ignore the spacing, I kinda spaced it a bit far...oh well.
In response to Revojake
Revojake wrote:
And if you want to show how much damage is done...
world << "[damage] damage is done!" ...Make sure you have a [damage] proc or var...i forgot wich it would be.

lol....I know how to do it through the brower or text panel, but I'm trying to make the damage and health bar pop-up over the player's head.