ID:141434
 
Code:
Gog // A mix of a goat and a dog
hp = 50
icon = 'Animals.dmi'; icon_state = "Gog"
New()
..()
walk_rand(src,20)
Click() // You can attack and kill some animals for meat
set src in oview(1)
if(!src in oview(1))
return // You cannot attack the Gog if it is farther than 1 tile away from you


Problem description:

I can attack the Gog from more than one tile away.

Sometimes you'll hit them before they finish stepping into the tile, but they are, in fact, there. Is that what you're experiencing?
In response to Spunky_Girl
I click them from 5 tiles away and it still hits.
In response to Armiris
Instead of using "set src in oview()", you could try using the get_dist() function o.O I'm not sure if Click() is able to use the "set" keyword >_> I always thought that only verbs could use "set".
The set command should not work in procs, they're only for verbs; the "set src in oview(1)" should have given you an error (I think, it's been a while).

And if you forum searched the problem line, you'll note that this is a common cause of a problem:
You are not bracketing "X in Y" after !.

To see how to fix your problem, and the reason why it didn't work, check out [link]

Like what Spunky said, get_dist would be better for this thing anyways >_>
In response to GhostAnime
GhostAnime wrote:
The set command should not work in procs, they're only for verbs...

Awesome! I was right! :D
In response to GhostAnime
GhostAnime wrote:
The set command should not work in procs, they're only for verbs; the "set src in oview(1)" should have given you an error (I think, it's been a while).


It didn't give me an error, that's why I came here.

Now how would I find the NPC without setting it as src?
In response to Armiris
Gog
//...
Click()
if(get_dist(usr,src)<=1) //if they're 1 tile away or on top of each other...
//...


Shouldn't that work? Don't have the time to test it out :\
In response to Spunky_Girl
Wouldn't usr and src be the same thing though?
In response to Armiris
Not for Click(), no. For all the click procs, and for verbs in this case (that are on an obj|turf), usr references whoever executed the verb, not the root. src always references the parent type (or something along those lines) I believe.

obj/Gog
//...
verb/Talk()
usr<<"Hi!" //outputs to the person who executed the verb. In this case, you :)
src<<"Hi!" //outputs to the obj, Gog
In response to Spunky_Girl
But when I try to use src referring to the Gog through Click(), it always damages me whenever it decreases src.hp
In response to Armiris
Wait, Gog is a mob. Does that change anything?
In response to Armiris
No, it shouldn't.
mob/Gog/Click()
if(get_dist(usr,src)<=1)
src.health -= 1
usr<<"[src] has lost 1 health"

"src" should NOT be referencing you when you click on Gog :\
In response to Spunky_Girl
Click() // You can attack and kill some animals for meat
if(!(src in oview(1)))
return // You cannot attack the Gog if it is farther than 1 tile away from you
if(usr.swmequip) // If the player has the sticks with a marshmallow equipped
usr << "You attack the Gog."
src.hp -= rand(5,10) // Decrease the Gog's health


I can't attack when the Gog is not next to me, but when I do attack it, it decreases my HP.
In response to Armiris
Okay first off, we told you to use get_dist(), not "set" >_>

And I don't get how or why src is referencing usr and not Gog in this case...

I just tested a click on an NPC in my game (below) and it worked out just fine...
mob/NPC/Enemies/Enemy1
Health = 100
Click()
usr<<"[src.Health]" //outputted 100
src.Health --
usr<<"[src.Health]" //outputted 99
In response to Spunky_Girl
I'm using get_dist() now.

And I just realized that the Gog was countering my attack, but it wasn't showing the counter message. So it's working fine now.
In response to Armiris
Like what Spunky_girl mentioned already, usr and src are not the same.

src is the source of the procedure/verb. Since Click() is defined on Gog, Gog is the src (the source of that Click() modification)

usr... I guess it's a play on the word user and this often causes people problems as, sometimes, usr is not defined. However, verbs, Click() and a few other pseudo-procs are usr safe

The usr here would be referencing a mob with a client after the verb/pseduo-proc sets usr directly to whoever call it.

So, here:
src = source = Gog
usr = user = The player who caused the verb/pseudo-proc to be called (see the article linked earlier)
In response to Armiris
lol! Well I'm glad it works for you now xD
In response to GhostAnime
My question is...

Can a non-client-character (lol NCC, not NPC, but they're the same ^-^) call another verb defined on a mob?

mob/NPC
Enemey1
verb/Talk() //cam Enemy2 call this verb?
Enemy2
In response to Spunky_Girl
It can call verbs indirectly... but one important thing about indirect callings is that you must absolutely avoid using usr - as it may not be defined!

These verbs can be called by referencing the mob and calling the verb if it is unique to a certain type:
var/mob/Char1/C = src.target
if(istype(C)) // Checks if C is a /mob/Char1
C.Talk()
or you can use call()

It is important to note that it is a good idea to have an argument of to refer which mob called the verb unless you send the message to oview() where a specific mob does not need to be known.
Page: 1 2