ID:148067
 
My Game Is Suposed To Be Kind OF A "You Need 3 People To Get Through This Part" Game, But We Keep Acidently Killing Eachother
Heres The Attack Code I'm Using:


verb
Attack(mob/M in oview(1))
var/damage = rand(1,strength)
usr << "You attack [M]!"
usr << "You Do [damage] damage!" M << "[usr] attacks you!"
M << "[usr] Does [damage] damage!"
M.HP -= damage
M.Death()


How Should I Change It To Make It So It Only Attacks Monsters And Not Other Players?
DarkCampainger wrote:
verb
Attack(mob/M in oview(1))
var/damage = rand(1,strength)
usr << "You attack [M]!"
usr << "You Do [damage] damage!" M << "[usr] attacks you!"
M << "[usr] Does [damage] damage!"
M.HP -= damage
M.Death()

I think if you throw in:
if(istype(M,/mob/monsters))

and then indent under that, it should only work for monsters. You may have to change /mob/monsters to whatever you "tree" for monsters is.

<-Airjoe->
In response to Airjoe
Thanks!
I'll Try It Now!
In response to DarkCampainger
YES! IT WORKED! THANKS!!!!!
In response to DarkCampainger
You cuold also check the mobs client var, which will only be true if it is a player.
In response to Hazman
Unless the player has logged out and left his mob intact somehow. Checking for mob/monster is probably the most secure way to do it. My prefered method is to create a filter for the verb, like this:

<code>proc/AtomTypeInRange(source, range, type) var/list/results = list() for(var/atom/A in range(source, range)) if(istype(A, type)) results += A return results</code>

Then use it in the verb arguments, like this:

<code>mob/verb/Attack(mob/monster/M in AtomTypeInRange(src, 1, /mob/monster)) // Attack M</code>

That will prevent you from even targetting player, or non-/mob/monster types with the attack verb, so if you're trapped between a player and a monster, you won't get a window popping up asking which one to attack, because the monster will be the only valid option.

Of course, if you want a better approach to attacking in a game in the first place, you should try using something besides a verb; perhaps Bump() to attack any /mob/monsters that you bump into, or a macro like Center() to attack any /mob/monsters in the next square in the direction you're facing when you hit the "5" key on your numpad.
In response to Foomer
You know, I never thought of making procs to use in verb argument definitions like that; would've come in useful several times. Silly Crispy! *slaps himself* =)
I know people already replied but you can also do this

Attack(mob/monster/M in oview(1))
Dude Iv'e got 2 things for oyu.

1.) Don't use a capital for all of your words. It's VERY annoying.

2.) Try using the
<dm>
tag for code snippets.
In response to Crispy
Just goes to show that I've been preaching verb argument filter procs all these years in vain.
In response to Foomer
Thank You Everyone For The Help!
In response to Crispy
Crispy wrote:
You know, I never thought of making procs to use in verb argument definitions like that; would've come in useful several times. Silly Crispy! *slaps himself* =)

The only problem with that is that the right click menu doesn't work too well with it since the proc won't filter that out for other objects of the same base atom type. Then if you click on the verb for an object that isn't in the list you'll get an error.
In response to Theodis
Which goes back to the other thing I'm always telling people: Verbs are bad!

(Action games use macros, non-action games use mouse-commands. Some games use both. I've never seen anything outside of BYOND that uses verbs, and the only thing that comes close is Telnet's command system.)

((Although I suppose popup menus and menu bars come close in some situations.))
All of your aneres were great and all, but this can all be achieved so much easier. Why not simply set the user to a dense turf. Same thing except he/she cant be hurt. Just do this with all mobs you dont want hurt, CPU controlled or human controlled it should work
In response to The Conjuror
if the people couldn't be hurt is it really that interesting..?
In response to Foomer
Which goes back to the other thing I'm always telling people: Verbs are bad!

Verbs rule as they are the fastest way to handle complex commands if you use the autocompletion features. Menus even if done right tend to be sluggish or have annoying delays. Macros are cool for most games but some commands requires too many parameters to effectivly macro.
In response to Theodis
A combination of click and macro can work well. Click on target, macro command.
In response to Theodis
Somehow quite a few other programs in existence manage to get along without them, and they somehow manage to have better interfaces too!
In response to Foomer
Not text adventures, though! Or those cool games like Day of the Tentacle and Maniac Mansion (or is it Manic Mansion?)
In response to Garthor
It's Maniac Mansion.

I want to play Day of the Tentacle, it sounds hilarious. I've played all of Grim Fandango (my favourite), Monkey Island 3 (second favourite) and partway through #2 and #4, but that's all the Lucasarts adventures games I've been able to get my hands on. =(