ID:178590
 
How would I make it where after you attack something it moves back 2 tiles in the direction you hit it in?
SuperGoku15 wrote:
How would I make it where after you attack something it moves back 2 tiles in the direction you hit it in?

If you want it to move 2 tiles right away:
obj/monster
proc/Hit(atom/movable/attacker)
for(var/i=2,i>0,--i)
var/turf/T=get_step(src,attacker.dir)
if(!T || !Move(T)) break

If you want it to move at a certain speed, you'll have to put in sleep(). This code as it stands now will make the monster appear to "jump" 2 tiles over.

Lummox JR
In response to Lummox JR
Hmm this still isn't working for me.This is my attacking verb

mob/verb
A()
set hidden=1
if (usr.sword=="None")
usr<<"<b>You have nothing equiped to slot A</b>"
else
if (usr.normalsworda==1)
for (var/mob/M in oview(1))
M.AttackPC()

And this is my AttackPC proc

mob/proc/AttackPC(atom/movable/attacker)
spawn(20)
src.health-=1
for(var/i=2,i>0,--i)
var/turf/T=get_step(src,attacker.dir)
if(!T || !Move(T)) break

I get no errors from this but when i start the game I get a runtime error that says..

runtime error: Cannot read null.dir
proc name: AttackPC (/mob/proc/AttackPC)
source file: Verbs.dm,119
usr: Empeor Beld (/mob/PC)
src: Talin (/mob/Talin)
call stack:
Talin (/mob/Talin): AttackPC(null)
Empeor Beld (/mob/PC): A()

Can anybody tell me what im doing wrong?
In response to SuperGoku15
SuperGoku15 wrote:
Hmm this still isn't working for me.This is my attacking verb

> mob/verb
> A()
> set hidden=1
> if (usr.sword=="None")
> usr<<"<b>You have nothing equiped to slot A</b>"
> else
> if (usr.normalsworda==1)
> for (var/mob/M in oview(1))
> M.AttackPC()
>
>

And this is my AttackPC proc

> 
> mob/proc/AttackPC(atom/movable/attacker)
> spawn(20)
> src.health-=1
> for(var/i=2,i>0,--i)
> var/turf/T=get_step(src,attacker.dir)
> if(!T || !Move(T)) break
>

I get no errors from this but when i start the game I get a runtime error that says..

runtime error: Cannot read null.dir
proc name: AttackPC (/mob/proc/AttackPC)
source file: Verbs.dm,119
usr: Empeor Beld (/mob/PC)
src: Talin (/mob/Talin)
call stack:
Talin (/mob/Talin): AttackPC(null)
Empeor Beld (/mob/PC): A()

Can anybody tell me what im doing wrong?

Yes, unindent this part once,var/turf/T=get_step(src,attacker.dir)
if(!T || !Move(T)) break
In response to Sariat
Yes, unindent this part once,var/turf/T=get_step(src,attacker.dir)
if(!T || !Move(T)) break
I Did that but now i get errors saying

Verbs.dm:119:error:get_step:undefined proc
Verbs.dm:120:error::invalid expression
Verbs.dm:119:T :warning: variable defined but not used

and this is what the code looks like now

mob/proc/AttackPC(atom/movable/attacker)
spawn(20)
src.health-=1
for(var/i=2,i>0,--i)
var/turf/T=get_step(src,attacker.dir)//<--- errors
if(!T || !Move(T)) break //<---error

Whats wrong here?
In response to SuperGoku15
SuperGoku15 wrote:
Can anybody tell me what im doing wrong?

You're not calling AttackPC with an argument. Look closely at the definition of the proc: It calls for you to specify who the attacker is. Thus, you'd have to call M.AttackPC(src). That's why it can't read null.dir; it thinks the attacker is null.

And pay no attention to what Sariat said, because it's wrong. I have no idea what he was thinking.

Lummox JR
In response to Sariat
Sariat wrote:
Yes, unindent this part once,var/turf/T=get_step(src,attacker.dir)
if(!T || !Move(T)) break

Sariat, that's indented for a reason; it's part of a for loop.

I can't quite figure out how you inferred "indentation error" from "cannot read null.dir". The clue to the actual bug is right in that line: in attacker.dir, attacker is null, and it's happening because the proc isn't being called correctly.

Lummox JR