ID:141426
 
Code:
mob/verb/Attack(M as mob in view(1))
view() << "[usr] Attacks [M] for [D]!"
exp += 1
hp = hp - D
icon_state = "att"
if (hp < 0)
view() << "[src] dies!"
usr << "You have Died and Respawned in Coville"
Move(locate (8,9,1))
hp += 100


Problem description: I don't know how to make it so the Mobs HP subtracts and not the players HP. And Another thing is that the icon state will just keep going, How Can I make it so it does the state once?

mob/verb/Attack(mob/M in oview(src,1)) //lol view makes it so you can attack yourself
var/dmg = 1 //arbitrary number
src.exp += 1
M.hp -= dmg
if(M.hp < 0)
M<<"You died >:O" //You want to output the text to the mob, not the person executing the verb
M.hp += 100
viewers(M)<<"[M] has died!" //anyone who can see M will see this text
M.Move(locate(8,9,1))
Kridane wrote:
I don't know how to make it so the Mobs HP subtracts and not the players HP.

You use the . (dot) operator to do this. As you can see below you've created a var to hold the mob the player uses the verb on, which will be the var you use to affect it.
mob/verb/Attack(M as mob in view(1)

This is very elementary stuff and so since you don't know it I heavily suggest working with this article and the links in it such as the ZBT tutorials and the DM Guide, in order to learn how to use the language.

And Another thing is that the icon state will just keep going, How Can I make it so it does the state once?

That's because you've changed the icon_state to another value with the = operator. It won't return back until you change it back again the same way. To do a one-time animation (which also doesn't affect the icon_state), you call the flick() proc. As with everything you are going to use, look it up first in the DM Reference, accessible either online through this site or through pressing F1 in Dream Maker. Here's a direct link to the flick() proc's entry.
In response to Spunky_Girl
Spunky_Girl wrote:
>     M.hp -= dmg
> if(M.hp < 0)
>


What Variable can I make for M.hp ... I don't Quite understand...

i.e

mob/Idk
icon = 'Mobs.dmi'
icon_state = "ghetto"
name = "Josh"
M.hp = 10

is what I thought but didnt work...
In response to Kaioken
Kaioken wrote:
This is very elementary stuff and so since you don't know it I heavily suggest working with this article and the links in it such as the ZBT tutorials and the DM Guide, in order to learn how to use the language.

QFT

This link will learn you a thing or two about Byond coding, including what you are asking now. I also strongly urge you to look into the tutorials and DM Guide. They are the best tools you have at your disposal. It is how presumably all good Byond coders got to where they are.
mob/verb/Attack(M as mob in view(1)) //defines the variable M as a mob
view() << "[usr] Attacks [M] for [D]!"//this says that the usr(the person who clicked the verb) attacked M(the person in view(1)) for damage
exp += 1 //without usr, src, or any other variable before it in a mob verb, the automatic variable is usr
hp = hp - D //this says the usr's hp is the usr's hp minus D which was never defined
icon_state = "att" //this needs to be flick("att",usr) to change it for a second
if (hp < 0) //this says if the usr's hp is lower then 0 which needs to be if(hp <= 0)
view() << "[src] dies!" //says that src died
usr << "You have Died and Respawned in Coville" //says that you have died blah blah blah
Move(locate (8,9,1)) //changes your location on the map
hp += 100 //this adds 100 hp for some reason, I think it needs to be usr.hp = 100 but whatever
mob/Idk
icon = 'Mobs.dmi'
icon_state = "ghetto"
name = "Josh"
M.hp = 10 //this is a no-no you never defined M as a mob and besides that your just trying to make the mobs hp 10 so it just needs to be hp = 10


Read the things after // for an explanation of what I think is wrong.

//The way to code it:

mob/verb/Attack(M as mob in view(1))
var/D = rand(1,50) //determines a random damage between 1,50 and names it D
view() << "[usr] Attacks [M] for [D]!"
usr.exp += 1
usr.hp -= D
flick("Att".usr)
if(hp <= 0)
view() << "[src] dies!"
usr << "You have Died and Respawned in Coville"
Move(locate (8,9,1))
usr.hp = 100
mob/Idk
icon = 'Mobs.dmi'
icon_state = "ghetto"
name = "Josh"
hp = 10


You should try Zizal's tutorials. I did read those :)
In response to SadoSoldier
Zilal* >_>
In response to Spunky_Girl
Sorry ^.^ I'm bad with names
In response to Spunky_Girl
Im getting a Compliling error with M.HP
I modified the Code a lil But M.HP = Unidentified variable

mob/verb/Attack(mob/M in view(1))
var/D = rand(D1,D2)
view() << "[usr] Attacks [M] for [D]!"
M.HP -= D
usrexp += 5
if(M.HP < 0)
view() << "[M] dies!"
del M
usrexp *= 1.2


These are my Global vars

var/client
usrstr = 10
HP = 100
usrint = 10
usrlvl = 1
usrexp = 1
usrmny = 100
D1 = usrstr*3
D2 = usrstr*1.5
MaxExp = 100
In response to Kridane
You're attacking a mob, not another person's client. That's why it says undefined. If you want to attack other clients, you need to use "client/M" instead of "mob/M".

However I suggest against that method, and define all your variables under an atom type of mob, obj, turf, or area (this case, mob).
In response to Spunky_Girl
He couldn't look for clients in view() instead, seeing as there are only atoms there. And note those vars are global (which is very bad), not defined under /client type. Rather they're typecasted as of /client type, even though they don't refer to an object at all but numbers...
In response to Spunky_Girl
Spunky_Girl wrote:
You're attacking a mob, not another person's client. That's why it says undefined. If you want to attack other clients, you need to use "client/M" instead of "mob/M".


Im Aware of that... it's no help, it still says undefined.

mob/Idk
name = "Kerk"
icon = 'Mobs.dmi'
icon_state = "ghetto"
var
HP = 9999999

is What some one told me to do. (Add the HP var to mobs)
And it worked for a bit and now its bugged.
    if(M.HP < 0)
view() << "[M] dies!"
del M
usrexp *= 1.2


Was the problem... I had to make that into a proc.
I got it now.. it works thanks guys and/or girls