ID:144393
 
Code:
var/hp = 20
var/maxhp = 100
var/str = 3
var/minstr = 1
var/lvl = 1
var/exp = 0
var/maxexp = 30
var/buff = 0
var/poison = 0
var/pvp = 1
var/equipped = "hands"
mob
verb
Attack(mob/M in oview(1))
if (pvp)
M.HurtMe()
view() << "[M] Has been hit with a [equipped] by [usr]!"

proc
HurtMe()
M.hp -= rand(minstr,str)


Problem description: I'm having problems with calling the Proc and proc not being able to minus the M's HP. Basically it thinks M doesnt exist even though it is defined in Attack(mob/M in oview(1))

In the hurtme proc, you don't define the person being hurt as M. This is because you didn't define M (which is completely unnescisary) in the proc. An easier way would be to just go:
src.health-=damage
src is considered M in the proc
In response to Avren
Avren wrote:
In the hurtme proc, you don't define the person being hurt as M. This is because you didn't define M (which is completely unnescisary) in the proc. An easier way would be to just go:
src.health-=damage


So...That would hurt the other person because i called it on M, Right?
In response to Animay3
Prescisely.
In response to Avren
Avren wrote:
Prescisely.

Doesn't work when i call it

mob
verb
Attack(mob/M in oview(1))
if (pvp)
M.HurtMe()


Says M.HurtMe is an undefined proc.
In response to Animay3
That's because Avren gave you half-baked advice and missed the main problems.

Let's cut apart your original post:

1. The variables are defined in the wrong place. They should be defined on the mob:
mob
var/hp = 20
var/maxhp = 100
var/str = 3

2. There's the same indentation problem for the HurtMe() proc.
3. The HurtMe() proc should, as Avren said, reference src's hp variable, not M's- because M there is no M variable in that proc.

However, you need to know what's actually hurting the mob in HurtMe(). You can't just say "src.health - damage", because there is no damage variable.

In HurtMe(), make sure the damage that will be dealt is passed in via an argument.

proc
HurtMe(damage)
src.hp -= damage


Then in the attack procedure, give the HurtMe() proc whatever you want.

            if (pvp)
M.HurtMe(rand(src.minstr,src.str))
view() << "[M] Has been hit with a [equipped] by [src]!"
In response to Elation
Elation wrote:
That's because Avren gave you half-baked advice and missed the main problems.


That's me. XD


I'm no good at explaining things; ill just not post answers
In response to Avren
Avren wrote:
Elation wrote:
That's because Avren gave you half-baked advice and missed the main problems.


That's me. XD


I'm no good at explaining things; ill just not post answers

Naw, still do. It may not sound like it, but you did good. You helped him to solve his code a step, just not all the steps.
Giving [good] half advice is alright. Giving BAD advice is bad and the thing that you should refrain from doing.
In response to Kaioken
It didn't work. I basically used your code and here is what I'm using and ill list the errors I'm getting:

mob
var/hp = 20
var/maxhp = 100
var/str = 3
var/minstr = 1
var/lvl = 1
var/exp = 0
var/maxexp = 30
var/buff = 0
var/poison = 0
var/pvp = 1
var/equipped = "hands"
verb
Attack(mob/M in oview(1))
if (pvp)
M.HurtMe(rand(src.minstr,src.str))
view() << "[M] Has been hit with a [equipped] by [usr]!"

proc
HurtMe(damage)
src.hp -= damage


And...
22:error:src.hp:undefined var
17:error:M.HurtMe:undefined proc
In response to Animay3
mob
var/hp = 20
var/maxhp = 100
var/str = 3
var/minstr = 1
var/lvl = 1
var/exp = 0
var/maxexp = 30
var/buff = 0
var/poison = 0
var/pvp = 1
var/equipped = "hands"
verb
Attack(mob/M in oview(1))
if (pvp)
M.HurtMe(rand(src.minstr,src.str))
view() << "[M] Has been hit with a [equipped] by [usr]!"

mob
proc
HurtMe(damage)
src.hp -= damage
In response to Xx Dark Wizard xX
Xx Dark Wizard xX wrote:
> mob
> var/hp = 20
> var/maxhp = 100
> var/str = 3
> var/minstr = 1
> var/lvl = 1
> var/exp = 0
> var/maxexp = 30
> var/buff = 0
> var/poison = 0
> var/pvp = 1
> var/equipped = "hands"
> verb
> Attack(mob/M in oview(1))
> if (pvp)
> M.HurtMe(rand(src.minstr,src.str))
> view() << "[M] Has been hit with a [equipped] by [usr]!"
>


> mob
> proc
> HurtMe(damage)
> src.hp -= damage



Ok, That worked. But now i need help with this

mob         
proc
HurtMe(damage)
src.hp -= damage
src.Deathcheck()
Deathcheck()
if (src.hp <= 0)
src.icon_state="dead"
sleep(40)
src.loc(73,28,3)
src.Death()
else
return
Death()
src << "You have died, You are transported to the hospital"



Don't ask why i used death proc for one line of code I'm adding more to it currently but the only problem is src.loc, Help?
In response to Animay3
src.loc=locate(position)

position can be replaced with a specific turf (/turf/hospitalspot) or, an excact location. EX: (1,1,1)


src.loc is simply the current location of the player, not where they will be going. saying src.loc(72,73,1) is just changing the var of locate to that.
In response to Avren
Thanks Avren,

I know this should be posted on Developer How-To but ill post it here. How would i give EXP to the killer of the player?
In response to Avren
Avren wrote:
src.loc=locate(position)

position can be replaced with a specific turf (/turf/hospitalspot) or, an excact location. EX: (1,1,1)


src.loc is simply the current location of the player, not where they will be going. saying src.loc(72,73,1) is just changing the var of locate to that.

Not quite exact. You don't really understand the 'loc' var.
atom.loc holds the current location of the atom.
Location means ANOTHER atom. This may happen to be a turf.

locate(x,y,z) will return the turf at the specified X,Y,Z coordinates. That's why atom.loc = locate(x,y,z) works.
In response to Kaioken
Kaioken wrote:
Avren wrote:
src.loc=locate(position)

position can be replaced with a specific turf (/turf/hospitalspot) or, an excact location. EX: (1,1,1)


src.loc is simply the current location of the player, not where they will be going. saying src.loc(72,73,1) is just changing the var of locate to that.

Not quite exact. You don't really understand the 'loc' var.
atom.loc holds the current location of the atom.
Location means ANOTHER atom. This may happen to be a turf.

locate(x,y,z) will return the turf at the specified X,Y,Z coordinates. That's why atom.loc = locate(x,y,z) works.

Oh, ok; that makes sence.
In response to Animay3
Here is something you can look over
mob
var/hp = 20
var/maxhp = 100
var/str = 20
var/minstr = 20
var/lvl = 1
var/exp = 0
var/maxexp = 30
var/buff = 0
var/poison = 0
var/pvp = 1
var/equipped = "hands"
verb
Attack(mob/M in oview(1))
if (pvp)
M.HurtMe(rand(src.minstr,src.str),src)



mob
proc
HurtMe(damage,mob/player)
view() << "[src] Has been hit with a [equipped] by [player]!"
src.hp -= damage
src.Deathcheck(player) //pass the src back even farther

Deathcheck(mob/playerr)
if(src.hp <= 0)
src.icon_state="dead"
sleep(40)
src.loc=locate(73,28,3)
src.Death()
playerr.exp+=10
else
return
Death()
src << "You have died, You are transported to the hospital"
Stat()
stat("exp",src.exp)
This code will give the player the exp by passing back src to player, which then passes player to playerr and then playerr gets the exp (which is src from the attack verb). I'm sure there is a more effecient way, but this is the only way I can think of.

By the way, don't copy&paste, I edited the damage and junk so I could just make sure it worked.
In response to Animay3
(EDIT: Nice job Avren, I have more fixes than you though! :P >.>)

I've changed your code to incorporate this; I altered it to be better formed, too. You will need to change your attack verb to call HurtMe() with the attacking mob (src/usr) as an argument.
mob         
proc
HurtMe(damage,mob/attacker)
src.hp = max(src.maxhp)
src.Deathcheck(attacker)
Deathcheck(mob/M)
if (src.hp <= 0)
src.Die(M)
Die(mob/killer)
viewers(src) << "[src] has been killed[killer ? " by [killer]":""]!"
if(killer) {killer<<"You killed [src]!";killer.exp += 5}
src.icon_state="dead"
sleep(40)
//I have made the relocation more movement-system-friendly. If you have overrided Exited() \
and Entered() of some atoms, moving this way will make \
them still work.

src.set_loc(locate(73,28,3)) //call custom proc defined below
src << "You have died, You are transported to the hospital"

atom/movable/proc/set_loc(atom/newloc)
if(!istype(newloc)) return 0 //if the loc supplied is invalid or isn't of type /atom, stop
var/atom/old_loc = src.loc //store current loc
src.loc = newloc //set to the loc specified
old_loc.Exited(src) //let the movement system know the mob exited his previous location.
newloc.Entered(src,old_loc) //let the movement system know the mob has entered the new location from old_loc.
In response to Kaioken
Kaioken wrote:
(EDIT: Nice job Avren, I have more fixes than you though! :P >.>)
Hey, thanks; mind taking a look at my Enter problem?
message ID is:
512796
In response to Kaioken
Kaioken wrote:
(EDIT: Nice job Avren, I have more fixes than you though! :P >.>)

I've changed your code to incorporate this; I altered it to be better formed, too. You will need to change your attack verb to call HurtMe() with the attacking mob (src/usr) as an argument.
> mob           
> proc
> HurtMe(damage,mob/attacker)
> src.hp = max(src.maxhp)
> src.Deathcheck(attacker)
> Deathcheck(mob/M)
> if (src.hp <= 0)
> src.Die(M)
> Die(mob/killer)
> viewers(src) << "[src] has been killed[killer ? " by [killer]":""]!"
> if(killer) {killer<<"You killed [src]!";killer.exp += 5}
> src.icon_state="dead"
> sleep(40)
> //I have made the relocation more movement-system-friendly. If you have overrided Exited() \
> and Entered() of some atoms, moving this way will make \
> them still work.

> src.set_loc(locate(73,28,3)) //call custom proc defined below
> src << "You have died, You are transported to the hospital"
>
> atom/movable/proc/set_loc(atom/newloc)
> if(!istype(newloc)) return 0 //if the loc supplied is invalid or isn't of type /atom, stop
> var/atom/old_loc = src.loc //store current loc
> src.loc = newloc //set to the loc specified
> old_loc.Exited(src) //let the movement system know the mob exited his previous location.
> newloc.Entered(src,old_loc) //let the movement system know the mob has entered the new location from old_loc.
>



So that should give exp to the killer of the player correct? If so, I completely do not know how that works, Ill look it over, But i still might not get it =(
In response to Animay3
I would explain it more thoroughly, but not tonight, I have to go to bed. I may try to explain it tommorow, unless Kaioken beats me to it ;)
Page: 1 2